package com.fzzy.push.shjdjw2023;
|
|
import com.alibaba.fastjson.JSON;
|
import com.fzzy.api.data.ApiParam;
|
import com.fzzy.api.data.PushProtocol;
|
import com.fzzy.api.dto.ResponseDto;
|
import com.fzzy.api.entity.*;
|
import com.fzzy.api.service.ApiCommonService;
|
import com.fzzy.api.service.ApiRemoteService;
|
import com.fzzy.api.service.ApiTriggerService;
|
import com.fzzy.api.utils.AESUtils;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.utils.RedisUtil;
|
import com.fzzy.api.view.repository.*;
|
import com.fzzy.push.sh2023.dto.ShAreaBjw;
|
import com.fzzy.push.shjdjw2023.dto.*;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import java.util.*;
|
|
/**
|
* 上海嘉定纪委监管平台-上传数据服务类
|
*
|
* @author czt
|
* @date 2023/12/26
|
*/
|
@Slf4j
|
@Data
|
@Service
|
public class ShjdjwApiRemoteService2023 implements ApiRemoteService {
|
|
@Autowired
|
private RedisUtil redisUtil;
|
@Autowired
|
private ApiCommonService apiCommonService;
|
@Autowired
|
private ApiTriggerService apiTriggerService;
|
@Autowired
|
private ApiLogRep apiLogRep;
|
@Autowired
|
private Api1101Rep api1101Rep;
|
@Autowired
|
private Api1102Rep api1102Rep;
|
@Autowired
|
private Api1103Rep api1103Rep;
|
@Autowired
|
private Api1104Rep api1104Rep;
|
@Autowired
|
private Api1105Rep api1105Rep;
|
@Autowired
|
private Api1202Rep api1202Rep;
|
@Autowired
|
private Api1205Rep api1205Rep;
|
@Autowired
|
private Api1208Rep api1208Rep;
|
@Autowired
|
private Api1210Rep api1210Rep;
|
@Autowired
|
private Api1403Rep api1403Rep;
|
@Autowired
|
private Api1404Rep api1404Rep;
|
|
@Override
|
public String getProtocol() {
|
return PushProtocol.SB_SHJdJW_2023.getCode();
|
}
|
|
@Override
|
public ResponseDto pushData(ApiParam param, Object data) {
|
return pushData(param, null, data);
|
}
|
|
@Override
|
public ResponseDto pullData(ApiParam param, ApiConfs conf) {
|
//该协议无此实现
|
return null;
|
}
|
|
@Override
|
public ResponseDto pushData(ApiParam param, ApiConfs conf, Object data) {
|
String inteId = param.getInteId();
|
String kqdm = param.getKqdm();
|
String bizId = param.getBizId();
|
|
try {
|
if (null == conf) {
|
conf = apiCommonService.getConf(kqdm);
|
}
|
//添加日志
|
ApiLog apiLog = new ApiLog();
|
apiLog.setId(ContextUtil.getUUID());
|
apiLog.setInteId(inteId);
|
|
if (StringUtils.isEmpty(inteId)) {
|
ResponseDto responseDto = new ResponseDto(99, "没有获取到接口", bizId);
|
apiLog.setStatus(99);
|
apiLog.setResult("没有获取到接口");
|
apiLogRep.save(apiLog);
|
return responseDto;
|
}
|
|
//查询库区信息行政区划码
|
List<Api1102> api1102List = api1102Rep.findPushData(kqdm);
|
//获取json数据
|
List<Object> list = getJsonData(inteId, data, api1102List.get(0).getXzqhdm());
|
ShjdjwReqDto reqData = new ShjdjwReqDto();
|
//接口ID
|
reqData.setId(getInteId(inteId));
|
//上传数据,加密
|
reqData.setData(list);
|
|
apiLog.setData(JSON.toJSONString(reqData));
|
apiLog.setKqdm(kqdm);
|
apiLog.setUploadTime(new Date());
|
if (conf == null) {
|
ResponseDto responseDto = new ResponseDto(99, "没有获取到上传配置", bizId);
|
apiLog.setStatus(99);
|
apiLog.setResult("没有获取到上传配置");
|
apiLogRep.save(apiLog);
|
return responseDto;
|
}
|
|
String jsonStr = JSON.toJSONString(reqData);
|
log.info("上报数据信息=" + jsonStr);
|
jsonStr = AESUtils.encryptByEcb(jsonStr, conf.getPublicKey());
|
|
ShjdjwRespDto responseDto = Shjdjw2023HttpClientUtil.postPushData(conf.getApiUrl(), jsonStr, conf);
|
|
responseDto.setBizId(bizId);
|
apiLog.setStatus(responseDto.getCode() == 1 ? 0 : responseDto.getCode());
|
apiLog.setResult(responseDto.getDescription());
|
apiLogRep.save(apiLog);
|
ResponseDto resd = new ResponseDto();
|
resd.setSuccess(responseDto.getCode() == 1 ? 0 : responseDto.getCode());
|
resd.setMsg(responseDto.getDescription());
|
return resd;
|
} catch (Exception e) {
|
log.error(e.getMessage(), e);
|
return new ResponseDto(99, e.getMessage());
|
}
|
}
|
|
/**
|
* 获取接口id
|
*
|
* @param inteId
|
* @return
|
*/
|
private String getInteId(String inteId) {
|
switch (inteId) {
|
case "1101":
|
return ShjdjwApiCodeConstant.API_CODE_1101_ID;
|
case "1102":
|
return ShjdjwApiCodeConstant.API_CODE_1102_ID;
|
case "1103":
|
return ShjdjwApiCodeConstant.API_CODE_1103_ID;
|
case "1104":
|
return ShjdjwApiCodeConstant.API_CODE_1104_ID;
|
case "1105":
|
return ShjdjwApiCodeConstant.API_CODE_1105_ID;
|
case "1202":
|
return ShjdjwApiCodeConstant.API_CODE_1202_ID;
|
case "1203":
|
return ShjdjwApiCodeConstant.API_CODE_1203_ID;
|
case "1205":
|
return ShjdjwApiCodeConstant.API_CODE_1205_ID;
|
case "1209":
|
return ShjdjwApiCodeConstant.API_CODE_1209_ID;
|
case "1310":
|
return ShjdjwApiCodeConstant.API_CODE_1310_ID;
|
case "1403":
|
return ShjdjwApiCodeConstant.API_CODE_1403_ID;
|
case "1404":
|
return ShjdjwApiCodeConstant.API_CODE_1404_ID;
|
default:
|
return inteId;
|
}
|
}
|
|
/**
|
* 转为JSON
|
*
|
* @param inteId
|
* @param data
|
* @param code
|
* @return
|
*/
|
private List<Object> getJsonData(String inteId, Object data, String code) {
|
|
List<Object> list = new ArrayList<>();
|
Object object = getJsonApiData(inteId, data, code);
|
list.add(object);
|
return list;
|
}
|
|
/**
|
* 调整数据封装,获取json数据
|
*
|
* @param inteId
|
* @param data
|
* @return
|
* @throws Exception
|
*/
|
|
private Object getJsonApiData(String inteId, Object data, String code) {
|
//具体根据接口进行封装
|
if (ShjdjwApiCodeConstant.API_CODE_1101.equals(inteId)) {
|
Shjdjw2023Api1101 api1101 = new Shjdjw2023Api1101();
|
BeanUtils.copyProperties(data, api1101);
|
|
return api1101;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1102.equals(inteId)) {
|
Shjdjw2023Api1102 api1102 = new Shjdjw2023Api1102();
|
BeanUtils.copyProperties(data, api1102);
|
|
return api1102;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1103.equals(inteId)) {
|
Shjdjw2023Api1103 api1103 = new Shjdjw2023Api1103();
|
BeanUtils.copyProperties(data, api1103);
|
|
return api1103;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1104.equals(inteId)) {
|
Shjdjw2023Api1104 api1104 = new Shjdjw2023Api1104();
|
Api1104 apiData = (Api1104) data;
|
|
//查询仓房信息
|
List<Api1103> api1103List = api1103Rep.findPushDataByCfdm(apiData.getCfbh());
|
List<Api1104> api1104List = api1104Rep.findDataByCfbh(apiData.getCfbh());
|
int num = 2;
|
if (null != api1104List && api1104List.size() > 0) {
|
num = api1104List.size();
|
}
|
if (null != api1103List && api1103List.size() > 0) {
|
Api1103 api1103 = api1103List.get(0);
|
BeanUtils.copyProperties(api1103, api1104);
|
api1104.setCwc(api1103.getCwc() / num);
|
api1104.setCnc(api1103.getCnc() / num);
|
api1104.setSjcr(api1103.getSjcr() / num);
|
}
|
BeanUtils.copyProperties(apiData, api1104);
|
api1104.setAjdm(apiData.getAjdh());
|
api1104.setCfdm(apiData.getCfbh());
|
|
//设置粮食性质代码(查看廒间对应的最新库存进行赋值)
|
List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1104.getAjdm() + "01");
|
if (null != api1208List && api1208List.size() > 0) {
|
api1104.setLsxzdm(api1208List.get(0).getLsxzdm());
|
}
|
|
return api1104;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1105.equals(inteId)) {
|
Shjdjw2023Api1105 api1105 = new Shjdjw2023Api1105();
|
BeanUtils.copyProperties(data, api1105);
|
|
return api1105;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1202.equals(inteId)) {
|
Shjdjw2023Api1202 api1202 = new Shjdjw2023Api1202();
|
Api1202 apiData = (Api1202) data;
|
BeanUtils.copyProperties(apiData, api1202);
|
api1202.setBjw(ShAreaBjw.getBjw(code));
|
api1202.setJzrq(apiData.getCmsj());
|
if (StringUtils.isEmpty(api1202.getCddm())) {
|
api1202.setCddm(api1202.getHwdm().substring(2, 8));
|
}
|
if (StringUtils.isEmpty(api1202.getRkjsdh())) {
|
api1202.setRkjsdh("0");
|
}
|
//设置粮食轮换年度,根据计划明细号查询计划明细,再根据计划明细查询轮换计划
|
List<Api1404> api1404List = api1404Rep.getDataByJhmxdh(apiData.getJhmxh());
|
if (null != api1404List && api1404List.size() > 0) {
|
api1202.setShnd(api1404List.get(0).getShnd());
|
List<Api1403> api1403List = api1403Rep.getDataByLhjhdh(api1404List.get(0).getLhjhdh());
|
if (null != api1403List && api1403List.size() > 0) {
|
if (StringUtils.isNotEmpty(api1403List.get(0).getJhnd())) {
|
api1202.setLhnd(api1403List.get(0).getJhnd());
|
}
|
}
|
}
|
//查询粮食性质转变单号(根据入库时间和货位代码查询粮食性质转变单)
|
List<Api1210> api1210List = api1210Rep.findDataByHwdmAndTime(api1202.getHwdm(), api1202.getCmsj());
|
if (null != api1210List && api1210List.size() > 0) {
|
api1202.setLsxzzbdh(api1210List.get(0).getLsxzzbdh());
|
}
|
//设置批次号
|
List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1202.getHwdm());
|
if (null != api1208List && api1208List.size() > 0) {
|
api1202.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
|
}
|
//粮食性质
|
api1202.setLsxzdm("200");
|
|
return api1202;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1203.equals(inteId)) {
|
Shjdjw2023Api1203 api1203 = new Shjdjw2023Api1203();
|
Api1203 apiData = (Api1203) data;
|
BeanUtils.copyProperties(apiData, api1203);
|
api1203.setBjw(ShAreaBjw.getBjw(code));
|
if (StringUtils.isEmpty(api1203.getJyxm())) {
|
api1203.setJyxm("0");
|
}
|
if (StringUtils.isEmpty(api1203.getJyz())) {
|
api1203.setJyz("0");
|
}
|
if (StringUtils.isEmpty(api1203.getZkj())) {
|
api1203.setZkj("0");
|
}
|
if (StringUtils.isEmpty(api1203.getZkl())) {
|
api1203.setZkl("0");
|
}
|
//设置批次号
|
List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1203.getHwdm());
|
if (null != api1208List && api1208List.size() > 0) {
|
api1203.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
|
}
|
//设置质检编码(默认等同于入库质检单号),若为船运,则设置为系统内船运的单号
|
api1203.setZjbh(api1203.getRkjydh());
|
List<Api1202> api1202List = api1202Rep.getDataById(api1203.getRkywdh());
|
if (null != api1202List && api1202List.size() > 0) {
|
if (api1202List.get(0).getYsgj().equals("3")) {
|
api1203.setZjbh(api1202List.get(0).getBizId().substring(2));
|
}
|
}
|
return api1203;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1205.equals(inteId)) {
|
|
Shjdjw2023Api1205 api1205 = new Shjdjw2023Api1205();
|
Api1205 apiData = (Api1205) data;
|
BeanUtils.copyProperties(apiData, api1205);
|
api1205.setBjw(ShAreaBjw.getBjw(code));
|
|
api1205.setJzrq(apiData.getCmsj());
|
if (StringUtils.isEmpty(api1205.getCddm())) {
|
api1205.setCddm(api1205.getHwdm().substring(2, 8));
|
}
|
if (StringUtils.isEmpty(api1205.getCkjsdh())) {
|
api1205.setCkjsdh("0");
|
}
|
|
//设置粮食轮换年度
|
List<Api1404> api1404List = api1404Rep.getDataByJhmxdh(apiData.getJhmxh());
|
if (null != api1404List && api1404List.size() > 0) {
|
List<Api1403> api1403List = api1403Rep.getDataByLhjhdh(api1404List.get(0).getLhjhdh());
|
if (null != api1403List && api1403List.size() > 0) {
|
if (StringUtils.isNotEmpty(api1403List.get(0).getJhnd())) {
|
api1205.setLhnd(api1403List.get(0).getJhnd());
|
}
|
}
|
}
|
|
//设置批次号
|
List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1205.getHwdm());
|
if (null != api1208List && api1208List.size() > 0) {
|
api1205.setPch(apiData.getHwdm() + api1208List.get(0).getShnd());
|
}
|
|
//粮食性质
|
api1205.setLsxzdm("200");
|
|
return api1205;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1209.equals(inteId)) {
|
|
Shjdjw2023Api1209 api1209 = new Shjdjw2023Api1209();
|
Api1209 apiData = (Api1209) data;
|
|
BeanUtils.copyProperties(apiData, api1209);
|
api1209.setDjlx("2");
|
api1209.setSzjl(apiData.getQzszkl());
|
api1209.setZrshde(apiData.getQzzrshde());
|
api1209.setBjw(ShAreaBjw.getBjw(code));
|
api1209.setJzrq(apiData.getYwrq());
|
List<Api1208> api1208List = api1208Rep.findDataByHwdm(api1209.getHwdm());
|
if (null != api1208List && api1208List.size() > 0) {
|
api1209.setPch(api1209.getHwdm() + api1208List.get(0).getShnd());
|
}
|
|
//粮食性质,暂时默认区级储备
|
api1209.setLsxzdm("122");
|
|
return api1209;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1310.equals(inteId)) {
|
Shjdjw2023Api1310 api1310 = new Shjdjw2023Api1310();
|
Api1310 apiData = (Api1310) data;
|
BeanUtils.copyProperties(apiData, api1310);
|
api1310.setBjw(ShAreaBjw.getBjw(code));
|
api1310.setJyrq(apiData.getJysj());
|
|
if (StringUtils.isEmpty(api1310.getJyxm())) {
|
api1310.setJyxm("0");
|
}
|
if (StringUtils.isEmpty(api1310.getJyxmz())) {
|
api1310.setJyxmz("0");
|
}
|
String lsxzdm = "122";
|
String pch = "";
|
List<Api1208> api1208List = api1208Rep.getDataByHwdm(api1310.getHwdm());
|
if (null != api1208List && api1208List.size() > 0) {
|
if (StringUtils.isNotEmpty(api1208List.get(0).getLsxzdm())) {
|
lsxzdm = api1208List.get(0).getLsxzdm();
|
pch = apiData.getHwdm() + api1208List.get(0).getShnd();
|
}
|
}
|
//设置批次号
|
api1310.setPch(pch);
|
api1310.setLsxzdm(lsxzdm);
|
if (api1310.getYpsl() == 0.0) {
|
api1310.setYpsl(5.0);
|
}
|
if (StringUtils.isEmpty(api1310.getQyrxm())) {
|
api1310.setQyrxm("扦样人");
|
}
|
if (StringUtils.isEmpty(api1310.getJdrxm())) {
|
api1310.setJdrxm("监督人");
|
}
|
if (StringUtils.isEmpty(api1310.getShrxm())) {
|
api1310.setShrxm("审核人");
|
}
|
//设置空属性为默认值
|
return api1310;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1403.equals(inteId)) {
|
Shjdjw2023Api1403 api1403 = new Shjdjw2023Api1403();
|
Api1403 apiData = (Api1403) data;
|
BeanUtils.copyProperties(apiData, api1403);
|
List<Api1101> api1101List = api1101Rep.findDataByDwdm(apiData.getLhjhdh().substring(0, 18));
|
|
api1403.setJhzxdw(api1101List.get(0).getDwdm());
|
api1403.setJhzxdwmc(api1101List.get(0).getDwmc());
|
api1403.setBjw(ShAreaBjw.getBjw(code));
|
|
//查询轮换计划的轮入数量和轮出数量
|
List<Api1404> list = api1404Rep.getDataByLhjhdh(api1403.getLhjhdh());
|
Double lrsl = 0.0, lcsl = 0.0; //用于统计轮入数量和轮出数量
|
if (null != list && list.size() > 0) {
|
for (Api1404 api1404 : list) {
|
if (null != api1404.getLhlx() && "2".equals(api1404.getLhlx())) {
|
lrsl += api1404.getLhsl();
|
}
|
if (null != api1404.getLhlx() && "1".equals(api1404.getLhlx())) {
|
lcsl += api1404.getLhsl();
|
}
|
}
|
}
|
api1403.setLrsl(lrsl + "");
|
api1403.setLcsl(lcsl + "");
|
|
//设置空属性为默认值
|
return api1403;
|
}
|
if (ShjdjwApiCodeConstant.API_CODE_1404.equals(inteId)) {
|
Shjdjw2023Api1404 api1404 = new Shjdjw2023Api1404();
|
BeanUtils.copyProperties(data, api1404);
|
api1404.setMxzt("1");
|
api1404.setBjw(ShAreaBjw.getBjw(code));
|
|
//设置空属性为默认值
|
return api1404;
|
}
|
return data;
|
}
|
|
}
|