package cn.abchinalife.om.controller.payment;
import cn.abchinalife.om.repository.om.LySendToFSUniqeNoDao;
import cn.abchinalife.om.repository.om.LyTransStatusDao;
import cn.abchinalife.om.repository.om.LyfslogDao;
import cn.abchinalife.om.repository.om.entity.*;
import cn.abchinalife.om.repository.om.entity.batchUUCP.ATS;
import cn.abchinalife.om.repository.om.entity.batchUUCP.IN;
import cn.abchinalife.om.repository.om.entity.batchUUCP.PUB;
import cn.abchinalife.om.repository.om.entity.batchUUCP.RD;
import cn.abchinalife.om.service.CheckFinshReturnService;
import cn.abchinalife.om.service.myservices.BatchRepeatedCheckService;
import cn.abchinalife.om.util.PubFun;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.TypeReference;
//import com.alibaba.fastjson.JSONReader;
/**
* Created by Ontheway on 2019/5/31.
*/
@Slf4j
@Controller
public class BachControllerReauest {
@Autowired
private BatchRepeatedCheckService batchRepeatedCheckService;
//记录交易状态与业务状态
@Autowired
private LyTransStatusDao lyTransStatusDao;
@Autowired
private LyfslogDao lyfslogDao;
@Autowired LySendToFSUniqeNoDao lySendToFSUniqeNoDao;
private int port=0;
private int serverPort=0;
@ResponseBody
@RequestMapping(value = "/ws/bachController.do")
public String submitData(HttpServletResponse response, HttpServletRequest request) throws IOException {
log.info("-----------submitData----------");
//String json = request.getParameter("param"); //这是通过get方式去url 拼接的键值对,post方式取不到值。
request.setCharacterEncoding("UTF-8"); //返回页面防止出现中文乱码
StringBuffer requestURL = request.getRequestURL();
String remoteAddr = request.getRemoteAddr();
int serverPort = request.getServerPort();
log.info("serverPort------------"+serverPort);
port = request.getRemotePort();
log.info("requestURL:"+requestURL.toString()+" remoteAddr:"+remoteAddr+" port:"+port);
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));//post方式传递读取字符流
String jsonStr = null;
StringBuilder result = new StringBuilder();
try {
while ((jsonStr = reader.readLine()) != null) {
result.append(jsonStr);
}
} catch (IOException e) {
e.printStackTrace();
}
reader.close();// 关闭输入流
log.info("result===="+result.toString());
//ArrayList<ATS> atsList = JSON.parseObject(result.toString(), new TypeReference<ArrayList<ATS>>(){}); //转换为集合对象
ATS ATSInfo = JSON.parseObject(result.toString(), new TypeReference<ATS>(){});
log.info("ATS:"+ATSInfo.toString());
PUB pub = ATSInfo.getPUB();
log.info(" pub.getAppId()"+pub.getAppId()+" pub.getTransSeq():"+pub.getTransSeq());
IN in = ATSInfo.getIN();
log.info("ATS:"+in.toString());
log.info("批次号:"+in.getBatchNo()+" 总金额:"+in.getTotalAmount()+" 总笔数:"+in.getTotalCount());
List<RD> rdList = in.getRD();
log.info("rdList.size():" + rdList.size());
for (int j=0;j<rdList.size();j++) {
RD rd = rdList.get(j);
//单条数据落地
dataLandingLyTransStatus(pub,in,rd);
dataLandingLyfslog(pub,in,rd);
dataLandingLySendToFSUniqeNoInfo(pub,in,rd);
//封装成对象 进行数据传递
LySendToFSInfo lySendToFSInfo = lySendToFSInfo(pub, in, rd);
log.info("lySendToFSInfo:"+j+" 次"+lySendToFSInfo);
//校验数据
//batchRepeatedCheckService.doService(lySendToFSInfo);
}
/*
//19 位账号 尾号为0
//转换为集合对象
for(int i=0; i<atsList.size();i++){
ATS ATSInfo = atsList.get(i);
log.info("ATS:"+ATSInfo);
PUB pub = ATSInfo.getPUB();
log.info(" pub.getAppId()"+pub.getAppId()+" pub.getTransSeq():"+pub.getTransSeq());
IN in = ATSInfo.getIN();
log.info("ATS:"+in);
log.info("批次号:"+i+"次 "+in.getBatchNo()+" 总金额:"+in.getTotalAmount()+" 总笔数:"+in.getTotalCount());
List<RD> rdList = in.getRD();
for (int j=0;j<rdList.size();j++){
log.info("rdList.size():"+rdList.size());
RD rd = rdList.get(j);
log.info("rd:"+rd);
rd.getAccName();
rd.getAccNo();
rd.getAccType();
rd.getAgentCode();
rd.getAgentCode();
rd.getBankCode();
rd.getBankCode();
rd.getBusinessType();
rd.getCliamNo();
rd.getCliamNo();
rd.getComCode();
rd.getContactCode();
rd.getContactCode();
rd.getContactName();
rd.getContactNo();
rd.getContNo();
rd.getConvertFlag();
rd.getDataType();
log.info("bankCode:"+j+"次"+rd.getBankCode());
log.info("UniqueNo:"+j+"次"+rd.getSerialNo());
//单条数据落地
dataLandingLyTransStatus(pub,in,rd);
dataLandingLyfslog(pub,in,rd);
dataLandingLySendToFSUniqeNoInfo(pub,in,rd);
//封装成对象 进行数据传递
LySendToFSInfo lySendToFSInfo = lySendToFSInfo(pub, in, rd);
log.info("lySendToFSInfo:"+j+" 次"+lySendToFSInfo);
//校验数据
//batchRepeatedCheckService.doService(lySendToFSInfo);
}
}*/
//dealData();
CheckFinshReturnService batchReturn =new CheckFinshReturnService();
//batchReturn.sendMessage();
log.info("-------批次信息接收成功!-----end");
return "G88";
}
//lyfslog 落库
public void dataLandingLyfslog(PUB pub,IN in,RD rd){
Lyfslog lyfslog=new Lyfslog();
lyfslog.setTotalMoney(Double.parseDouble(in.getTotalAmount()));
lyfslog.setTotalNum(Integer.valueOf(in.getTotalCount()));
lyfslog.setModifyDate(Date.valueOf(PubFun.getCurrentDate()));
lyfslog.setModifyTime(PubFun.getCurrentTime());
log.info("pub.getTransDate():"+pub.getTransDate());
//lyfslog.setTransDate(Date.valueOf( pub.getTransDate()));
lyfslog.setBatchNo(in.getBatchNo());
lyfslog.setComCode(rd.getComCode());
lyfslog.setOperationType(rd.getDoType());//业务类型
/* lyfslog.setSuccMoney();
lyfslog.setSuccNum();//成功金额
lyfslog.setCheckMoney();
lyfslog.setCheckNum();
lyfslog.setCheckNum();
lyfslog.setDealState(); //处理状态
lyfslog.setTransOperator(); //交易人*/
try {
batchRepeatedCheckService.insertLyfslog(lyfslog);
}catch (Exception ex){
log.info("添加Lyfslog数据异常");
ex.printStackTrace();
}
}
//LyTransStatus 落库
public void dataLandingLyTransStatus(PUB pub,IN in,RD rd){
LyTransStatus lyTransStatus =new LyTransStatus();
LySendToFSInfo lysend = new LySendToFSInfo();
//封装传递的数据
lysend.setBatchNo(in.getBatchNo());
lysend.setPolNo(rd.getPolNo());
lysend.setContNo(rd.getContNo());
lysend.setUniqueNo(rd.getSerialNo());
lysend.setPayMoney(Double.valueOf(rd.getPayMoney()));
lysend.setAccName(rd.getAccName());
lysend.setAccNo(rd.getAccNo());
lysend.setAgentCode(rd.getBusinessType());
lysend.setBusinessType(rd.getBusinessType());
lysend.setBankCode(rd.getBankCode());
String uniqueSerialNo = batchRepeatedCheckService.getUniqueComposition(rd.getBusinessType(),lysend);
if(!uniqueSerialNo.equals("")&&uniqueSerialNo !=null){
lyTransStatus.setSerialNo(uniqueSerialNo); //全局唯一流水
}
lyTransStatus.setBatchNo(in.getBatchNo());
//lyTransStatus.setSerialNo();
lyTransStatus.setSysFlag(pub.getSYSFlag());
lyTransStatus.setClientPort(String.valueOf(port));
lyTransStatus.setClientIP(String.valueOf(serverPort));
//lyTransStatus.setTransStatus();
lyTransStatus.setTransTime(pub.getTransTime());
String transSeq=pub.getTransSeq()+(int)(Math.random()*100000+(int)(Math.random()*9999)+(int)(Math.random()*999));
log.info("transSeq:"+transSeq);
lyTransStatus.setTransSeq(transSeq); //交易流水号 暂时这样写
lyTransStatus.setMakeDate(Date.valueOf(PubFun.getCurrentDate()));
lyTransStatus.setMakeTime(PubFun.getCurrentTime());
//lyTransStatus.setDescr();
lyTransStatus.setModifyDate(Date.valueOf(PubFun.getCurrentDate()));
lyTransStatus.setModifyTime(PubFun.getCurrentTime());
//lyTransStatus.setServiceCostTime();//交易耗时
lyTransStatus.setServiceStartTime(PubFun.getCurrentDate());//服务处理开始时间
//lyTransStatus.setServiceEndTime();
//lyTransStatus.setStatus(); //业务状态
lyTransStatus.setSysCode(pub.getSYSCode());
//lyTransStatus.setTransDate(Date.valueOf(pub.getTransDate()));
//新增数据
try {
batchRepeatedCheckService.insertLyTransStatus(lyTransStatus);
}catch (Exception ex){
log.info("添加lyTransStatus数据异常");
ex.printStackTrace();
}
}
//LySendToFSUniqeNoInfo 落库
public void dataLandingLySendToFSUniqeNoInfo(PUB pub,IN in,RD rd){
LySendToFSUniqeNoInfo lySendToFSUniqeNo = new LySendToFSUniqeNoInfo();
if(!rd.getXpayTimes().equals("")&&rd.getXpayTimes()!=null){
lySendToFSUniqeNo.setXpayTimes(Integer.parseInt(rd.getXpayTimes()));
}
log.info("UniqueNo:"+rd.getSerialNo());
lySendToFSUniqeNo.setUniqueNo(rd.getSerialNo());
lySendToFSUniqeNo.setTxID(rd.getTxID());
lySendToFSUniqeNo.setTempFeeNo(rd.getTempFeeNo());
lySendToFSUniqeNo.setSyscode(pub.getSYSCode());
//lySendToFSUniqeNo.setState();
log.info("rd.getShouldDate():"+rd.getShouldDate()+" rd.getSendDate():"+rd.getSendDate());
if(!rd.getShouldDate().equals("")&&rd.getShouldDate()!=null){
lySendToFSUniqeNo.setShouldDate( Date.valueOf(rd.getShouldDate()));//应付日期
}
lySendToFSUniqeNo.setSfflag(rd.getSFFlag());
//lySendToFSUniqeNo.setSendTimes();//发盘次数
lySendToFSUniqeNo.setSendDate(Date.valueOf(rd.getSendDate()));
lySendToFSUniqeNo.setPayType(rd.getPayType());
lySendToFSUniqeNo.setPayMoney(Double.valueOf(rd.getPayMoney()));
lySendToFSUniqeNo.setPayCode(rd.getPayCode());
lySendToFSUniqeNo.setName(rd.getName());
lySendToFSUniqeNo.setModifyTime(PubFun.getCurrentTime());
lySendToFSUniqeNo.setModifyDate(Date.valueOf(PubFun.getCurrentDate()));
lySendToFSUniqeNo.setInBankCode(rd.getInBankCode());
lySendToFSUniqeNo.setInAccType(rd.getInAccType());
lySendToFSUniqeNo.setInAccNo(rd.getInAccNo());
lySendToFSUniqeNo.setInAccName(rd.getInAccName());
lySendToFSUniqeNo.setEdorNo(rd.getEdorNo());
lySendToFSUniqeNo.setDoType(rd.getDoType());
lySendToFSUniqeNo.setDealType("1"); //0-实时 1-批量
lySendToFSUniqeNo.setConvertFlag(rd.getConvertFlag());
lySendToFSUniqeNo.setContNo(rd.getContNo());
lySendToFSUniqeNo.setClaimNo(rd.getCliamNo());
lySendToFSUniqeNo.setBusinessType(rd.getBusinessType());
lySendToFSUniqeNo.setBatchNo(in.getBatchNo());
//lySendToFSUniqeNo.setBankDealTime(); //银行处理时间
//lySendToFSUniqeNo.setBankDealDate();
//lySendToFSUniqeNo.setBankSuccFlag();
lySendToFSUniqeNo.setBankCode(rd.getBankCode());
lySendToFSUniqeNo.setAccType(rd.getAccType());
lySendToFSUniqeNo.setAccNo(rd.getAccNo());
lySendToFSUniqeNo.setAccName(rd.getAccName());
//lySendToFSUniqeNo.setAbstract(); //对账码
/*in.getBatchNo();
in.getTotalAmount();
in.getTotalCount();
pub.getAppId();
pub.getSign();
pub.getSYSCode();
pub.getSYSFlag();
pub.getTimestamp();
pub.getTimestamp();
pub.getTransDate();
pub.getTransSeq();
pub.getTransTime();*/
//新增数据
try {
batchRepeatedCheckService.insertLySendToFSUniqeNoInfo(lySendToFSUniqeNo);
}catch (Exception ex){
log.info("添加LySendToFSUniqeNo数据异常");
ex.printStackTrace();
}
}
//获取json解析数据 封装成对象 进行数据传递
public LySendToFSInfo lySendToFSInfo(PUB pub,IN in,RD rd){
LySendToFSInfo lysend = new LySendToFSInfo();
//封装传递的数据
lysend.setBatchNo(in.getBatchNo());
lysend.setPolNo(rd.getPolNo());
lysend.setContNo(rd.getContNo());
lysend.setUniqueNo(rd.getSerialNo());
lysend.setPayMoney(Double.valueOf(rd.getPayMoney()));
lysend.setAccName(rd.getAccName());
lysend.setAccNo(rd.getAccNo());
lysend.setAccType(rd.getAccType());
lysend.setAgentCode(rd.getBusinessType());
lysend.setBankCode(rd.getBankCode());
//lysend.setBankDealDate();
//lysend.setAbstract();
if(!rd.getXpayTimes().equals("")&&rd.getXpayTimes()!=null){
lysend.setXpayTimes(Integer.valueOf(rd.getXpayTimes()));
}
lysend.setUniqueNo(rd.getSerialNo());
lysend.setTxID(rd.getTxID());
lysend.setTempFeeNo(rd.getTempFeeNo());
lysend.setSysCode(pub.getSYSCode());
//lySendToFSUniqeNo.setState();
if(!rd.getShouldDate().equals("")&&rd.getShouldDate()!=null){
lysend.setShouldDate( Date.valueOf(rd.getShouldDate()));//应付日期
}
lysend.setSfFlag(rd.getSFFlag());
//lySendToFSUniqeNo.setSendTimes();//发盘次数
lysend.setSendDate(Date.valueOf(rd.getSendDate()));
lysend.setPayType(rd.getPayType());
lysend.setPayMoney(Double.valueOf(rd.getPayMoney()));
lysend.setPayCode(rd.getPayCode());
lysend.setName(rd.getName());
lysend.setModifyTime(PubFun.getCurrentTime());
lysend.setModifyDate(Date.valueOf(PubFun.getCurrentDate()));
lysend.setInBankCode(rd.getInBankCode());
lysend.setInAccType(rd.getInAccType());
lysend.setInAccNo(rd.getInAccNo());
lysend.setInAccName(rd.getInAccName());
lysend.setEdorNo(rd.getEdorNo());
lysend.setDoType(rd.getDoType());
lysend.setDealType("1"); //0-实时 1-批量
lysend.setConvertFlag(rd.getConvertFlag());
lysend.setContNo(rd.getContNo());
lysend.setClaimNo(rd.getCliamNo());
lysend.setBusinessType(rd.getBusinessType());
lysend.setBatchNo(in.getBatchNo());
/* lysend.setBankDealTime(); //银行处理时间
lysend.setBankDealDate();
lysend.setBankSuccFlag();*/
lysend.setBankCode(rd.getBankCode());
lysend.setAccType(rd.getAccType());
lysend.setAccNo(rd.getAccNo());
lysend.setAccName(rd.getAccName());
//lysend.setAbstract(); //对账码
return lysend;
}
public void dealData(){
BatchRepeatedCheckService batchRepeatedCheckService = new BatchRepeatedCheckService();
//记录交易状态与业务状态
String AppId = "appId12345678";
String transSeq = "G001106169246096";//交易流水号
String timestamp = PubFun.getCurrentDate() + PubFun.getCurrentTime(); //时间戳
String transDate = PubFun.getCurrentDate();
String transTime = PubFun.getCurrentTime();
String sign = "";
String batchNo = "105[2019-01-22]N113463";
String totalCount = "10";
String totalAmount = "1000";
String serialNos = "000491738718026|200943020210294321|19-021201040002379|1000|s";//全局唯一流水
String sysCode = "weixin";//系统来源
String sysflag = "weixin01";//系统标记
String sfflag = "S";
String businesstype = "TBQ";
String txID = "uuid123456";
String dealType = "1"; //0-实时 1-批量
String dataType = "";
String payCode = "NN0000000000459564";
String payType = "04";
String name = "统一天下";
String bankCode = "103";
String accType = "03";
String accName = "中国工商银行";
String accNo = "19-021201040002379";
String polNo = "201337130210003342";
String noType = "LR"; //业务类型
String comCode = "86371399";
String agentCode = "0000163752";
String payMoney = "100";
String sendDate = PubFun.getCurrentDate();
String convertFlag = "";//转换标记
String doType = "";//扣款类型
String inAccType = "03";
String inBankCode = "103";
String inAccName = "中国农业银行";
String inAccNo = "19-021201040002379";
String idType = "111";//证件类型
String idNo = "13012219711227161X"; //证件号
String contactCode = "5101";//联行编码
String contactName = "招商银行股份有限公司成都华阳支行";//联行名称
String contactNo = "308651020218";//联行号
String remark = "备注";//备注
String xpayTimes = "1";
String shouldDate = "2019-6-1";//应付日期
String contNo = "200943020210294321";
String tempFeeNo = "ZS3020210294321";
String edorNo = "BQ3020210294321";
String cliamNo = "";
//获取传递的数据 封装成对象
LySendToFSInfo lysend = new LySendToFSInfo();
LyTransStatus lyTransStatus = new LyTransStatus();
Lyfslog lyfslog = new Lyfslog();
LySendToFSUniqeNoInfo lySendToFSUniqeNo = new LySendToFSUniqeNoInfo();
//封装传递的数据
lysend.setBatchNo(batchNo);
lysend.setPolNo(polNo);
lysend.setContNo(contNo);
//新增lyTransStatus数据
lyTransStatus.setTransSeq("G4741124");
lyTransStatus.setTransDate(Date.valueOf(PubFun.getCurrentDate()));
lyTransStatus.setTransTime(PubFun.getCurrentTime());
lyTransStatus.setBatchNo(batchNo);
lyTransStatus.setSysCode(sysCode);
lyTransStatus.setSysFlag(sysflag);
//lyTransStatus.setClientIP(requestURL.toString());
//lyTransStatus.setClientPort(String.valueOf(port));
//根据规则 获取全局唯一流水
log.info("businesstype:"+businesstype);
String uniqueSerialNo = batchRepeatedCheckService.getUniqueComposition(businesstype,lysend);
log.info("全局唯一流水uniqueSerialNo:------" + uniqueSerialNo);
lyTransStatus.setSerialNo(uniqueSerialNo);
//Integer integer = lyTransStatusDao.insertLyTransStatus(lyTransStatus);
batchRepeatedCheckService.insertLyTransStatus(lyTransStatus);
//新增lyfslog数据
lyfslog.setBatchNo(batchNo);
lyfslog.setTransDate(java.sql.Date.valueOf(transDate));
lyfslog.setSuccMoney(Double.valueOf(totalAmount));
lyfslog.setCheckNum(Integer.valueOf(totalCount));
//lyfslog.setCheckMoney(Double.valueOf(payMoney));
//lyfslog.setSuccMoney(Double.valueOf(payMoney));
lyfslog.setModifyDate(java.sql.Date.valueOf(PubFun.getCurrentDate()));
lyfslog.setModifyTime(PubFun.getCurrentTime());
lyfslog.setComCode(comCode);
lyfslog.setOperationType(businesstype);
//lyfslogDao.insertLyfslog(lyfslog);
batchRepeatedCheckService.insertLyfslog(lyfslog);
//新增lySendToFSUniqeNo数据
lySendToFSUniqeNo.setAbstract("");
lySendToFSUniqeNo.setAccName(accName);
lySendToFSUniqeNo.setAccNo(accNo);
lySendToFSUniqeNo.setAccType(accType);
lySendToFSUniqeNo.setBankCode(bankCode);
//lySendToFSUniqeNo.setBankDealDate( );//银行处理日期
//lySendToFSUniqeNo.setBankDealTime();//银行处理时间
//lySendToFSUniqeNo.setBankSuccFlag(); //成功标记
lySendToFSUniqeNo.setBatchNo(batchNo);
lySendToFSUniqeNo.setBusinessType(businesstype);
lySendToFSUniqeNo.setClaimNo(cliamNo);
lySendToFSUniqeNo.setContNo(contNo);
lySendToFSUniqeNo.setConvertFlag(convertFlag);
lySendToFSUniqeNo.setDealType(dealType);
lySendToFSUniqeNo.setDoType(doType);
lySendToFSUniqeNo.setEdorNo(edorNo);
lySendToFSUniqeNo.setInAccName(inAccName);//公司账户名称
lySendToFSUniqeNo.setInAccNo(inAccNo);//公司账号
lySendToFSUniqeNo.setInAccType(inAccType); //公司账户类型
lySendToFSUniqeNo.setInBankCode(inBankCode); //公司银行编码
lySendToFSUniqeNo.setModifyDate(java.sql.Date.valueOf(PubFun.getCurrentDate()));
lySendToFSUniqeNo.setModifyTime(PubFun.getCurrentTime());
lySendToFSUniqeNo.setName(name);//名称
lySendToFSUniqeNo.setPayCode(payCode);//财务号码
lySendToFSUniqeNo.setPayMoney(Double.valueOf(payMoney));//交费金额
lySendToFSUniqeNo.setPayType(payType); //交退费类型
lySendToFSUniqeNo.setSendDate(java.sql.Date.valueOf(sendDate));
//lySendToFSUniqeNo.setSendTimes();//发盘次数
lySendToFSUniqeNo.setSfflag(sfflag); //收付费类型
lySendToFSUniqeNo.setShouldDate(java.sql.Date.valueOf(shouldDate));//应付日期
//lySendToFSUniqeNo.setState(); //结果状态
lySendToFSUniqeNo.setSyscode(sysCode);//系统来源
lySendToFSUniqeNo.setTempFeeNo(tempFeeNo);//暂收据号
lySendToFSUniqeNo.setTxID(txID);
//lySendToFSUniqeNo.setUniqueNo(); //校验唯一码
lySendToFSUniqeNo.setXpayTimes(Integer.valueOf(xpayTimes)); //续期期数
//lySendToFSUniqeNoDao.insertLySendToFSUniqeNoInfo(lySendToFSUniqeNo);
batchRepeatedCheckService.insertLySendToFSUniqeNoInfo(lySendToFSUniqeNo);
batchRepeatedCheckService.doService(lysend);
}
}