|
@@ -0,0 +1,743 @@
|
|
|
+package com.zfire.jiasm.syncdata.common;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.zfire.jiasm.syncdata.base.BaseService;
|
|
|
+import com.zfire.jiasm.syncdata.constant.Constant;
|
|
|
+import com.zfire.jiasm.syncdata.constant.DictTypeEnum;
|
|
|
+import com.zfire.jiasm.syncdata.constant.OrderTypeEnum;
|
|
|
+import com.zfire.jiasm.syncdata.gree.GreeLogic;
|
|
|
+import com.zfire.jiasm.syncdata.gree.recycle.GreeLogicT;
|
|
|
+import com.zfire.jiasm.syncdata.helper.GreeFileResponseHelper;
|
|
|
+import com.zfire.jiasm.syncdata.helper.GreeFileSaveHelper;
|
|
|
+import com.zfire.jiasm.syncdata.http.PostObjectSample;
|
|
|
+import com.zfire.jiasm.syncdata.plus.entity.*;
|
|
|
+import com.zfire.jiasm.syncdata.plus.service.*;
|
|
|
+import com.zfire.jiasm.syncdata.request.oldfornew.TradeNewForOldUploadAttachmentBean;
|
|
|
+import com.zfire.jiasm.syncdata.request.oldfornew.TradeNewForOldUploadBean;
|
|
|
+import com.zfire.jiasm.syncdata.response.ResultData;
|
|
|
+import com.zfire.jiasm.syncdata.response.WebsitFWS;
|
|
|
+import com.zfire.jiasm.syncdata.response.WebsitSH;
|
|
|
+import com.zfire.jiasm.syncdata.response.WorderInfo;
|
|
|
+import com.zfire.jiasm.syncdata.service.PublicService;
|
|
|
+import com.zfire.jiasm.syncdata.test;
|
|
|
+import com.zfire.jiasm.syncdata.utils.oss.OSSUtil;
|
|
|
+import io.jsonwebtoken.lang.Collections;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class OldForNewUploadLogic {
|
|
|
+ @Value("${gree.web.url}")
|
|
|
+ private String webUrl;
|
|
|
+ @Autowired
|
|
|
+ private GreeLogicT greeLogic;
|
|
|
+ @Resource
|
|
|
+ GreeLogic greeLogico;
|
|
|
+ @Autowired
|
|
|
+ private OutJiasmToGreeUploadnotifylistService outJiasmToGreeUploadnotifylistService;
|
|
|
+ @Autowired
|
|
|
+ private OldForNewProductService oldForNewProductService;
|
|
|
+ @Autowired
|
|
|
+ private YjhxJddService yjhxJddService;
|
|
|
+ @Autowired
|
|
|
+ private OrderBaseService orderBaseService;
|
|
|
+ @Autowired
|
|
|
+ private ItfTblTradeNewForOldStockInfoUploadTaskService itfTblTradeNewForOldStockInfoUploadTaskService;
|
|
|
+ @Autowired
|
|
|
+ PublicService publicService;
|
|
|
+ @Autowired
|
|
|
+ SysDictRefService sysDictRefService;
|
|
|
+ @Autowired
|
|
|
+ BaseService baseService;
|
|
|
+ @Autowired
|
|
|
+ ItfTblYjhxJddUploadService itfTblYjhxJddUploadService;
|
|
|
+ @Autowired
|
|
|
+ ItfTblYjhxJddFjUploadService itfTblYjhxJddFjUploadService;
|
|
|
+ @Autowired
|
|
|
+ OSSUtil ossUtil;
|
|
|
+
|
|
|
+ private ObjectMapper mapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public OldForNewUploadLogic() {
|
|
|
+ this.mapper = new ObjectMapper();
|
|
|
+ SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ this.mapper.setDateFormat(smt);
|
|
|
+ this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String collection() {
|
|
|
+ // 只有类型为35,36的工单需要同步回总部 自建以旧换新不需要传总部
|
|
|
+ // 提取待同步的以旧换新工单的签定单数据
|
|
|
+ List<OutJiasmToGreeUploadnotifylist> toGreeUploadList = outJiasmToGreeUploadnotifylistService.lambdaQuery()
|
|
|
+ .eq(OutJiasmToGreeUploadnotifylist::getTableName, OrderTypeEnum.YJHX_JDD_TABLE_NAME.getCode())
|
|
|
+ .eq(OutJiasmToGreeUploadnotifylist::getOrderType, OrderTypeEnum.ORDER_TYPE_TRADE_IN.getCode())
|
|
|
+ .eq(OutJiasmToGreeUploadnotifylist::getSynStatus, Constant.SynStatus.UN_SYN.getCode())
|
|
|
+ .list();
|
|
|
+
|
|
|
+ // 无数据不同步
|
|
|
+ if(CollectionUtils.isNotEmpty(toGreeUploadList)) {
|
|
|
+ LinkedHashSet<String> uploadOrderNos = new LinkedHashSet<>();
|
|
|
+ // 提取所有工单号
|
|
|
+ toGreeUploadList.stream().forEach(toGreeUpload->{
|
|
|
+ uploadOrderNos.add(toGreeUpload.getOrderNo());
|
|
|
+ });
|
|
|
+ // 提取以旧换新工单的旧机信息
|
|
|
+ final List<OldForNewProduct> oldForNewProductList = oldForNewProductService.lambdaQuery()
|
|
|
+ .in(OldForNewProduct::getOrderBaseId, uploadOrderNos).list();
|
|
|
+ Map<String, OldForNewProduct> oldForNewProductMap = CollectionUtils.isEmpty(oldForNewProductList)
|
|
|
+ ? null : oldForNewProductList.stream().collect(Collectors.toMap(OldForNewProduct::getOrderBaseId, Function.identity()));
|
|
|
+
|
|
|
+ // 提取已采集需上传的鉴定单数据
|
|
|
+ final List<YjhxJdd> jddList = yjhxJddService.lambdaQuery()
|
|
|
+ .in(YjhxJdd::getOrderBaseId, uploadOrderNos)
|
|
|
+ .eq(YjhxJdd::getCollectionStatus, 1)
|
|
|
+ .eq(YjhxJdd::getUploadNotifyFlag, 1)
|
|
|
+ .list();
|
|
|
+ // 这里ID做为 key
|
|
|
+ final Map<Integer, List<YjhxJdd>> jddMap = (null == jddList || jddList.isEmpty()) ? null : jddList.stream().collect(Collectors.groupingBy(YjhxJdd::getId));
|
|
|
+
|
|
|
+ // 按单来处理 要有鉴定单
|
|
|
+ for(OutJiasmToGreeUploadnotifylist toGreeUpload : toGreeUploadList) {
|
|
|
+ // 存在鉴定单数据
|
|
|
+ if( !Objects.isNull(jddMap) && jddMap.containsKey(Integer.parseInt(toGreeUpload.getId()))) {
|
|
|
+ // 提取工单数据 目的看工单大类数据
|
|
|
+ OrderBase orderBase = orderBaseService.lambdaQuery()
|
|
|
+ .eq(OrderBase::getId,toGreeUpload.getOrderNo()).one();
|
|
|
+
|
|
|
+ for(YjhxJdd jdd : jddList) {
|
|
|
+ // 取工单对应的鉴定单
|
|
|
+ if (!jdd.getOrderBaseId().equals(toGreeUpload.getOrderNo())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 广佛鉴定结果为0(不回收)、不同步总部
|
|
|
+ if( "0".equals(jdd.getIdentifyResult()) ) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成格力总部图片 图片生成失败不同步
|
|
|
+ if (setGreeImage(orderBase, jdd)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 以旧换新鉴定单采集附件表
|
|
|
+ List<ItfTblYjhxJddFjUpload> yjhxJddFjUploadList = new ArrayList<>();
|
|
|
+ ItfTblYjhxJddUpload yjhxJddUpload = new ItfTblYjhxJddUpload();
|
|
|
+ TradeNewForOldUploadBean bean = new TradeNewForOldUploadBean();
|
|
|
+
|
|
|
+ // 鉴定单报文 OK
|
|
|
+ BeanUtils.copyProperties(jdd, bean,new String[] {"gps", "sjcjsfen", "sjcjcshi", "sjcjxian","gpsdizi",
|
|
|
+ "wdno", "wdmc", "azrenno","azren", "azrenyddh"});
|
|
|
+
|
|
|
+ // 赋值旧机信息
|
|
|
+ if (setOldForNewProduct(oldForNewProductMap, jdd, bean)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 部分参数赋值
|
|
|
+ setParame(orderBase, jdd, bean);
|
|
|
+
|
|
|
+ // 鉴定单上传记录表
|
|
|
+ BeanUtils.copyProperties(bean, yjhxJddUpload, ItfTblYjhxJddUpload.class);
|
|
|
+ yjhxJddUpload.setWorkerOrderNo(jdd.getOrderBaseId());
|
|
|
+ yjhxJddUpload.setHxjddid(jdd.getHxjddid());
|
|
|
+
|
|
|
+ // 附件上传记录表
|
|
|
+ List<TradeNewForOldUploadAttachmentBean> jddfjList = new ArrayList<>();
|
|
|
+ // 内、外机全景照处理
|
|
|
+ if(StringUtils.isNotEmpty(jdd.getGreeImgIdAllOther())) {
|
|
|
+ getFileAttUpload(jdd, yjhxJddFjUploadList, yjhxJddUpload, jddfjList);
|
|
|
+ }
|
|
|
+ bean.setJddfj(jddfjList);
|
|
|
+
|
|
|
+ // 同步数据
|
|
|
+ synData(jdd, yjhxJddUpload, bean);
|
|
|
+
|
|
|
+ processSave(yjhxJddUpload, yjhxJddFjUploadList,toGreeUpload,jdd);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // yjhx_jdd无数据不同步
|
|
|
+ processSave(null, null,toGreeUpload,null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean setGreeImage(OrderBase orderBase, YjhxJdd jdd) {
|
|
|
+ WebsitSH websitSH = publicService.ptshwdToshshwd(jdd.getWebsitId(), orderBase.getMainId());
|
|
|
+ Boolean upflag = Boolean.FALSE;
|
|
|
+ // 图片生成 条码图片 njtm图像#wjtm图像
|
|
|
+ if (StringUtils.isEmpty(jdd.getTempBarcodeImg()) &&
|
|
|
+ (StringUtils.isNotEmpty(jdd.getNjtmPicture()) ||
|
|
|
+ StringUtils.isNotEmpty(jdd.getWjtmPicture()))){
|
|
|
+ // 获取条码总部图
|
|
|
+ String greeImageId = getBarcodeImage(jdd, websitSH);
|
|
|
+ if (greeImageId == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 修改
|
|
|
+ jdd.setTempBarcodeImg(greeImageId);
|
|
|
+ upflag = Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 全景图片 in_full_picture#out_full_picture#other_picture
|
|
|
+ if (StringUtils.isEmpty(jdd.getGreeImgIdAllOther()) &&
|
|
|
+ (StringUtils.isNotEmpty(jdd.getInFullPicture()) ||
|
|
|
+ StringUtils.isNotEmpty(jdd.getOutFullPicture()) ||
|
|
|
+ StringUtils.isNotEmpty(jdd.getOtherPicture()))){
|
|
|
+
|
|
|
+ // 获取总部全景图
|
|
|
+ String greeImageId = getFullImage(jdd, websitSH);
|
|
|
+ if (greeImageId == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 修改
|
|
|
+ jdd.setGreeImgIdAllOther(greeImageId);
|
|
|
+ upflag = Boolean.TRUE;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(jdd.getTempBarcodeImg()) &&
|
|
|
+ StringUtils.isNotEmpty(jdd.getGreeImgIdAllOther()) && jdd.getGetGreeImageIdStatus() !=1){
|
|
|
+ jdd.setGetGreeImageIdStatus(1);
|
|
|
+ upflag = Boolean.TRUE;
|
|
|
+ }
|
|
|
+ if (upflag){
|
|
|
+ yjhxJddService.updateById(jdd);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ private String getFullImage(YjhxJdd jdd, WebsitSH websitSH) {
|
|
|
+ String greeImageId = "";
|
|
|
+ String greeImageIdN = "";
|
|
|
+ String greeImageIdW = "";
|
|
|
+ String greeImageIdO = "";
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(jdd.getInFullPicture())){
|
|
|
+ greeImageIdN = getImage(jdd.getInFullPicture(), websitSH);
|
|
|
+ if (greeImageIdN == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(jdd.getOutFullPicture())){
|
|
|
+ greeImageIdW = getImage(jdd.getOutFullPicture(), websitSH);
|
|
|
+ if (greeImageIdW == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(jdd.getOtherPicture())){
|
|
|
+ greeImageIdO = getImage(jdd.getOtherPicture(), websitSH);
|
|
|
+ if (greeImageIdO == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(greeImageIdN)){
|
|
|
+ greeImageId=greeImageIdN;
|
|
|
+ if (StringUtils.isNotEmpty(greeImageIdW)){
|
|
|
+ greeImageId=greeImageId+"#"+greeImageIdW;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(greeImageIdO)){
|
|
|
+ greeImageId=greeImageId+"#"+greeImageIdO;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotEmpty(greeImageIdW)){
|
|
|
+ greeImageId=greeImageIdN;
|
|
|
+ if (StringUtils.isNotEmpty(greeImageIdO)){
|
|
|
+ greeImageId=greeImageId+"#"+greeImageIdO;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ greeImageId=greeImageIdO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return greeImageId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ private String getBarcodeImage(YjhxJdd jdd,WebsitSH websitSH) {
|
|
|
+ String greeImageId = "";
|
|
|
+ String greeImageIdN = "";
|
|
|
+ String greeImageIdW = "";
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(jdd.getNjtmPicture())){
|
|
|
+ greeImageIdN = getImage(jdd.getNjtmPicture(), websitSH);
|
|
|
+ if (greeImageIdN == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(jdd.getWjtmPicture())){
|
|
|
+ greeImageIdW = getImage(jdd.getWjtmPicture(), websitSH);
|
|
|
+ if (greeImageIdW == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(greeImageIdN) && StringUtils.isNotEmpty(greeImageIdW)){
|
|
|
+ greeImageId=greeImageIdN+"#"+greeImageIdW;
|
|
|
+ } else if (StringUtils.isNotEmpty(greeImageIdN)){
|
|
|
+ greeImageId=greeImageIdN;
|
|
|
+ } else {
|
|
|
+ greeImageId=greeImageIdW;
|
|
|
+ }
|
|
|
+ return greeImageId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ private String getImage(String picture, WebsitSH websitSH) {
|
|
|
+ String oldFile;
|
|
|
+ String newFile;
|
|
|
+ String greeImageIdN;
|
|
|
+ oldFile = IdWorker.getIdStr() + ".jpeg";
|
|
|
+ baseService.saveToFile(ossUtil.getUrlWw(picture), oldFile);
|
|
|
+ // 获取文件
|
|
|
+ newFile = oldFile;
|
|
|
+ greeImageIdN = uploadBarCodeexc(newFile, oldFile, websitSH.getWdId());
|
|
|
+ new File(newFile).delete();
|
|
|
+ // 生成图片失败不同步
|
|
|
+ if (StringUtils.isEmpty(greeImageIdN)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return greeImageIdN;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getSaveFileInfo(String id1, ResultData resultData, Map<String, String> req) {
|
|
|
+ req.put("bizAppId","flydiy-auto-sit-default-front-greeshmerge");
|
|
|
+ req.put("bizTable","default");
|
|
|
+ req.put("bizType","default");
|
|
|
+ req.put("accessType","auth");
|
|
|
+ req.put("url", resultData.getExtData().getDir());
|
|
|
+ req.put("name", id1 +".jpeg");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String uploadBarCodeexc(String newFile, String oldFile,String wdno) {
|
|
|
+ String greeImageId ="";
|
|
|
+ try{
|
|
|
+ // 1: 获取签名信息
|
|
|
+ GreeFileResponseHelper response = greeLogico.ossGetSignt(wdno,"GET");
|
|
|
+ if (response.getStatusCode() == 200){
|
|
|
+ ResultData resultData = JSONObject.parseObject(response.getData().toString(), ResultData.class);
|
|
|
+ resultData.getExtData().setDir(resultData.getExtData().getDir()+"/"+oldFile);
|
|
|
+ // 2:文件上传
|
|
|
+ PostObjectSample ossPostObject = new PostObjectSample();
|
|
|
+ String result = ossPostObject.PostObject(newFile, resultData.getExtData());
|
|
|
+ // 3: 保存文件
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isEmpty(result.trim())){
|
|
|
+ Map<String,String>req = new HashMap<>();
|
|
|
+ // 生成对象
|
|
|
+ getSaveFileInfo(oldFile, resultData, req);
|
|
|
+ GreeFileSaveHelper responses = greeLogico.greePostSaveFile(req);
|
|
|
+ if (responses.getStatusCode() == 200){
|
|
|
+ greeImageId = responses.getData().getId();
|
|
|
+ return greeImageId;
|
|
|
+ } else {
|
|
|
+ // 失败
|
|
|
+ return greeImageId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 上传图片到OSS失败
|
|
|
+ return greeImageId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 获取签名信息失败
|
|
|
+ return greeImageId;
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ return greeImageId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void synData(YjhxJdd jdd, ItfTblYjhxJddUpload yjhxJddUpload, TradeNewForOldUploadBean bean) {
|
|
|
+ final String url = webUrl + Constant.GreeWebPath.TBLYJHXJDD_COLLECTION;
|
|
|
+ try {
|
|
|
+ JSONObject response = greeLogic.postPubV3(url, mapper.readValue(mapper.writeValueAsString(bean), Map.class));
|
|
|
+ //log.info("TradeOldForNewLogic.collection接口返回:{}",response.toJSONString());
|
|
|
+ if( 200 == response.getInteger("status").intValue()) {
|
|
|
+ TradeNewForOldUploadBean reponseData = this.mapper.readValue(mapper.writeValueAsString(response.get("data")), TradeNewForOldUploadBean.class) ;
|
|
|
+ // 同步成功,同步鉴定单上传记录表数据
|
|
|
+ yjhxJddUpload.setSynStatus(Constant.SynStatus.SYN.getCode());
|
|
|
+ yjhxJddUpload.setSynTime(new Date());
|
|
|
+ yjhxJddUpload.setWdno(bean.getWdno());
|
|
|
+ yjhxJddUpload.setWdmc(bean.getWdmc());
|
|
|
+ // 这里的ID来自于总部
|
|
|
+ jdd.setGreeId(reponseData.getId());
|
|
|
+ //鉴定结果业务表回写状态为0(无需上传)
|
|
|
+ jdd.setUploadNotifyFlag(0);
|
|
|
+ if( null != reponseData.getJddfj() && !reponseData.getJddfj().isEmpty()) {
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ reponseData.getJddfj().forEach(jddFj->{
|
|
|
+ sb.append("#");
|
|
|
+ sb.append(jddFj.getFjguid());
|
|
|
+ });
|
|
|
+ String fjguids = sb.toString();
|
|
|
+ // 来自总部数据
|
|
|
+ jdd.setGreeFjguid(fjguids.substring(1, fjguids.length()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增一条待入库条码上传记录
|
|
|
+ ItfTblTradeNewForOldStockInfoUploadTask tradeNewForOldStockInfoUploadTask = new ItfTblTradeNewForOldStockInfoUploadTask();
|
|
|
+ tradeNewForOldStockInfoUploadTask.setPgguid(jdd.getPgguid());
|
|
|
+ tradeNewForOldStockInfoUploadTask.setSynStatus(Constant.SynStatus.UN_SYN.getCode());
|
|
|
+ tradeNewForOldStockInfoUploadTask.setSynReqTime(new Date());
|
|
|
+ tradeNewForOldStockInfoUploadTask.setSynTimes(1);
|
|
|
+ itfTblTradeNewForOldStockInfoUploadTaskService.save(tradeNewForOldStockInfoUploadTask);
|
|
|
+ } else {
|
|
|
+ // 修改鉴定单同步失败状态
|
|
|
+ yjhxJddUpload.setSynStatus(Constant.SynStatus.FAIL.getCode());
|
|
|
+ yjhxJddUpload.setSynErrMsg(response.getString("messageCode"));
|
|
|
+ yjhxJddUpload.setSynTime(new Date());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ yjhxJddUpload.setSynStatus(Constant.SynStatus.FAIL.getCode());
|
|
|
+ yjhxJddUpload.setSynErrMsg(e.getMessage().length() > 100 ? e.getMessage().substring(0, 99): e.getMessage());
|
|
|
+ log.error("collection接口报错: {}", e.getMessage());
|
|
|
+ yjhxJddUpload.setSynTime(new Date());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getFileAttUpload(YjhxJdd jdd, List<ItfTblYjhxJddFjUpload> yjhxJddFjUploadList,
|
|
|
+ ItfTblYjhxJddUpload yjhxJddUpload, List<TradeNewForOldUploadAttachmentBean> jddfjList) {
|
|
|
+ // 总部图片,除了tempBarcodeImg以外的所有,#号分割,in_full_picture#out_full_picture#other_picture
|
|
|
+ String[] fullimgs = jdd.getGreeImgIdAllOther().split("#");
|
|
|
+ List<String> greeFjguidArr = new ArrayList<>();
|
|
|
+ // 这里为附件图片处理 格力总部附件id, #号分割,in_fjid#out_fjid#other_fjid
|
|
|
+ // 该参数来自总部 报文同步后才有值
|
|
|
+ if(StringUtils.isNotEmpty(jdd.getGreeFjguid())) {
|
|
|
+ String[] greeFjguids = jdd.getGreeFjguid().split("#");
|
|
|
+ for(String greeFjguid : greeFjguids) {
|
|
|
+ greeFjguidArr.add(greeFjguid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //内机全景图
|
|
|
+ getInFileAttUpload(jdd, yjhxJddFjUploadList, yjhxJddUpload, jddfjList, greeFjguidArr, fullimgs, 1, 0, "旧机内机整机", "复制内机bean异常,{}");
|
|
|
+
|
|
|
+ //外机全景图
|
|
|
+ getOutFileAttUpload(jdd, yjhxJddFjUploadList, yjhxJddUpload, jddfjList, greeFjguidArr, fullimgs, 2, 1, "旧机外机整机", "复制外机bean异常,{}");
|
|
|
+
|
|
|
+ //其他图
|
|
|
+ if(fullimgs.length > 2) {
|
|
|
+ getOtherFileAttUpload(jdd, yjhxJddFjUploadList, yjhxJddUpload, jddfjList, greeFjguidArr, fullimgs, 3, 2, "其他", "复制其他bean异常,{}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getOtherFileAttUpload(YjhxJdd jdd, List<ItfTblYjhxJddFjUpload> yjhxJddFjUploadList,
|
|
|
+ ItfTblYjhxJddUpload yjhxJddUpload, List<TradeNewForOldUploadAttachmentBean> jddfjList,
|
|
|
+ List<String> greeFjguidArr, String[] fullimgs, int i, int i2, String 其他, String s) {
|
|
|
+ ItfTblYjhxJddFjUpload otherFileAttUpload = new ItfTblYjhxJddFjUpload();
|
|
|
+ if (greeFjguidArr.size() >= i) {
|
|
|
+ //其他
|
|
|
+ otherFileAttUpload.setFjguid(greeFjguidArr.get(i2));
|
|
|
+ }
|
|
|
+ otherFileAttUpload.setHxjddid(jdd.getHxjddid());
|
|
|
+ otherFileAttUpload.setFjname(其他);
|
|
|
+ otherFileAttUpload.setFjserverpath(fullimgs[i2]);
|
|
|
+ otherFileAttUpload.setFjindex(i2);
|
|
|
+ otherFileAttUpload.setType(30);
|
|
|
+ otherFileAttUpload.setWorkerOrderNo(yjhxJddUpload.getWorkerOrderNo());
|
|
|
+ yjhxJddFjUploadList.add(otherFileAttUpload);
|
|
|
+ try {
|
|
|
+ jddfjList.add(mapper.readValue(mapper.writeValueAsString(otherFileAttUpload), TradeNewForOldUploadAttachmentBean.class));
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error(s, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getOutFileAttUpload(YjhxJdd jdd, List<ItfTblYjhxJddFjUpload> yjhxJddFjUploadList,
|
|
|
+ ItfTblYjhxJddUpload yjhxJddUpload, List<TradeNewForOldUploadAttachmentBean> jddfjList,
|
|
|
+ List<String> greeFjguidArr, String[] fullimgs, int i, int i2,
|
|
|
+ String 旧机外机整机, String s) {
|
|
|
+ ItfTblYjhxJddFjUpload outFileAttUpload = new ItfTblYjhxJddFjUpload();
|
|
|
+ if (greeFjguidArr.size() >= i) {
|
|
|
+ //内机附件id
|
|
|
+ outFileAttUpload.setFjguid(greeFjguidArr.get(i2));
|
|
|
+ }
|
|
|
+ outFileAttUpload.setHxjddid(jdd.getHxjddid());
|
|
|
+ outFileAttUpload.setFjname(旧机外机整机);
|
|
|
+ outFileAttUpload.setFjserverpath(fullimgs[i2]);
|
|
|
+ outFileAttUpload.setFjindex(i2);
|
|
|
+ outFileAttUpload.setType(30);
|
|
|
+ outFileAttUpload.setWorkerOrderNo(yjhxJddUpload.getWorkerOrderNo());
|
|
|
+ yjhxJddFjUploadList.add(outFileAttUpload);
|
|
|
+ try {
|
|
|
+ jddfjList.add(mapper.readValue(mapper.writeValueAsString(outFileAttUpload), TradeNewForOldUploadAttachmentBean.class));
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error(s, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getInFileAttUpload(YjhxJdd jdd, List<ItfTblYjhxJddFjUpload> yjhxJddFjUploadList, ItfTblYjhxJddUpload yjhxJddUpload,
|
|
|
+ List<TradeNewForOldUploadAttachmentBean> jddfjList, List<String> greeFjguidArr,
|
|
|
+ String[] fullimgs, int i, int i2, String 旧机内机整机, String s) {
|
|
|
+ ItfTblYjhxJddFjUpload inFileAttUpload = new ItfTblYjhxJddFjUpload();
|
|
|
+ if (greeFjguidArr.size() >= i) {
|
|
|
+ //内机附件id
|
|
|
+ inFileAttUpload.setFjguid(greeFjguidArr.get(i2));
|
|
|
+ }
|
|
|
+ inFileAttUpload.setHxjddid(jdd.getHxjddid());
|
|
|
+ inFileAttUpload.setFjname(旧机内机整机);
|
|
|
+ inFileAttUpload.setFjserverpath(fullimgs[i2]);
|
|
|
+ inFileAttUpload.setFjindex(i2);
|
|
|
+ inFileAttUpload.setType(30);
|
|
|
+ inFileAttUpload.setWorkerOrderNo(yjhxJddUpload.getWorkerOrderNo());
|
|
|
+ yjhxJddFjUploadList.add(inFileAttUpload);
|
|
|
+
|
|
|
+ try {
|
|
|
+ jddfjList.add(mapper.readValue(mapper.writeValueAsString(inFileAttUpload), TradeNewForOldUploadAttachmentBean.class));
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error(s, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean setOldForNewProduct(Map<String, OldForNewProduct> oldForNewProductMap, YjhxJdd jdd, TradeNewForOldUploadBean bean) {
|
|
|
+ // 看旧机信息大类决定是否需要上传
|
|
|
+ if( !Objects.isNull(oldForNewProductMap)
|
|
|
+ && oldForNewProductMap.containsKey(jdd.getOrderBaseId())
|
|
|
+ && !Objects.isNull(oldForNewProductMap.get(jdd.getOrderBaseId()))
|
|
|
+ ) {
|
|
|
+ // 以旧换新工单的旧机信息
|
|
|
+ OldForNewProduct oldFornew = oldForNewProductMap.get(jdd.getOrderBaseId());
|
|
|
+ //main_id非空和101时,才传旧机鉴定
|
|
|
+ if( Objects.isNull(oldFornew.getMainId()) || !oldFornew.getMainId().equals("101")){
|
|
|
+ log.info("TradeOldForNewLogic.collection接口: spid为空或非空调类,不上传旧机鉴定");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 旧机信息赋值 OK
|
|
|
+ BeanUtils.copyProperties(oldFornew, bean, TradeNewForOldUploadBean.class);
|
|
|
+ bean.setIdCardStatus(oldFornew.getIdCardStatus());
|
|
|
+ bean.setIsSubsidy(oldFornew.getIsSubsidy());
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setParame(OrderBase orderBase, YjhxJdd jdd, TradeNewForOldUploadBean bean) {
|
|
|
+ WebsitSH websitSH;
|
|
|
+ // hxjddido 为空时自生成
|
|
|
+ if (StringUtils.isEmpty(jdd.getHxjddid())){
|
|
|
+ jdd.setHxjddid(UUID.randomUUID().toString());
|
|
|
+ }
|
|
|
+ bean.setId(jdd.getGreeId());
|
|
|
+ //greeId和hxjddid设置成同一个
|
|
|
+ if(StringUtils.isNotEmpty(jdd.getGreeId())) {
|
|
|
+ jdd.setHxjddid(jdd.getGreeId());
|
|
|
+ }
|
|
|
+
|
|
|
+ //鉴定结果相反,总部鉴定结果0-回收 1-不回收, 广佛鉴定结果1-回收 0-不回收
|
|
|
+ bean.setIdentifyResult("1".equals(StringUtils.isEmpty(jdd.getIdentifyResult()) ? "" : jdd.getIdentifyResult()) ? "0" : "1");
|
|
|
+ //1 格力 0 非格力
|
|
|
+ bean.setBrandFlag( "格力".equals(StringUtils.isEmpty(jdd.getRealBrand()) ? "" : jdd.getRealBrand()) ? 1 : 0 );
|
|
|
+ //0 柜机 1 挂机
|
|
|
+ bean.setTypeFlag("柜机".equals( StringUtils.isEmpty(jdd.getRealType()) ? "" : jdd.getRealType() ) ? 0 : 1);
|
|
|
+ bean.setOldMachineBrand(bean.getRealBrand());
|
|
|
+ bean.setOldMachineType(bean.getRealType());
|
|
|
+ bean.setStat("0");
|
|
|
+ //gps地址
|
|
|
+ if(!StringUtils.isEmpty(jdd.getLat()) && !StringUtils.isEmpty(jdd.getLng())) {
|
|
|
+ bean.setGps(jdd.getLat()+","+ jdd.getLng());
|
|
|
+ }else if(StringUtils.isEmpty(jdd.getLat())) {
|
|
|
+ log.info("TradeOldForNewLogic.collection接口: 经度为空, jdd.id={}", jdd.getId());
|
|
|
+ }else if(StringUtils.isEmpty(jdd.getLng())) {
|
|
|
+ log.info("TradeOldForNewLogic.collection接口: 纬度为空, jdd.id={}", jdd.getId());
|
|
|
+ }
|
|
|
+ // 这里的 GPS 30个字符不能超30个字符
|
|
|
+ if (!StringUtils.isEmpty(bean.getGps())){
|
|
|
+ if (bean.getGps().length()>30){
|
|
|
+ bean.setGps(bean.getGps().substring(0,30));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bean.setSjcjsfen(jdd.getProvince());
|
|
|
+ bean.setSjcjcshi(jdd.getCity());
|
|
|
+ bean.setSjcjxian(jdd.getArea());
|
|
|
+ bean.setGpsdizi(jdd.getAddress());
|
|
|
+ websitSH = publicService.ptshwdToshshwd(jdd.getWebsitId(), orderBase.getMainId());
|
|
|
+ bean.setWdno(websitSH.getWdId());
|
|
|
+ bean.setWdmc(websitSH.getWdmc());
|
|
|
+ WorderInfo worderInfo = publicService.getWorkerInfo(jdd.getWorkerId(),
|
|
|
+ websitSH.getWdId(), orderBase.getGroupCompanyId());
|
|
|
+ bean.setAzren(worderInfo.getBrandWorkerNumber());
|
|
|
+ bean.setAzrenyddh(worderInfo.getMobile());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateJdd(YjhxJdd jdd, TradeNewForOldUploadBean bean) {
|
|
|
+ Boolean flag = Boolean.FALSE;
|
|
|
+ // 来自报文请求后的id,
|
|
|
+ if (StringUtils.isEmpty(jdd.getGreeId())){
|
|
|
+ jdd.setGreeId(UUID.randomUUID().toString());
|
|
|
+ flag=Boolean.TRUE;
|
|
|
+ }
|
|
|
+ bean.setId(jdd.getGreeId());
|
|
|
+ //greeId和hxjddid设置成同一个
|
|
|
+ if(StringUtils.isNotEmpty(jdd.getGreeId())) {
|
|
|
+ jdd.setHxjddid(jdd.getGreeId());
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(jdd.getGreeImgIdAllOther())) {
|
|
|
+ // 这里为内外机全图看有多少个图
|
|
|
+ String[] imgs = jdd.getGreeImgIdAllOther().split("#");
|
|
|
+ // 这里为附件图片处理 格力总部附件id, #号分割,in_fjid#out_fjid#other_fjid
|
|
|
+ // 自生成
|
|
|
+ if (StringUtils.isEmpty(jdd.getGreeFjguid())) {
|
|
|
+ String uuid = "";
|
|
|
+ for (int i = 0; i < imgs.length; i++) {
|
|
|
+ uuid = uuid + UUID.randomUUID().toString() + "#";
|
|
|
+ }
|
|
|
+ // 来自于报文请求后的id
|
|
|
+ jdd.setGreeFjguid(uuid.substring(0, uuid.length() - 1));
|
|
|
+ flag=Boolean.TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag){
|
|
|
+ yjhxJddService.updateById(jdd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 回写状态到中间表
|
|
|
+ * @param yjhxJddUpload
|
|
|
+ * @param yjhxJddFjUploadList
|
|
|
+ * @param toGreeUploadnotifylist
|
|
|
+ * @param jdd
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void processSave(
|
|
|
+ ItfTblYjhxJddUpload yjhxJddUpload,
|
|
|
+ List<ItfTblYjhxJddFjUpload> yjhxJddFjUploadList,
|
|
|
+ OutJiasmToGreeUploadnotifylist toGreeUploadnotifylist
|
|
|
+ ,YjhxJdd jdd) {
|
|
|
+ try {
|
|
|
+ Integer synStatus = -1;
|
|
|
+ String msg = "";
|
|
|
+ //yjhxJddUpload为空,说明没有请求总部接口,toGreeUploadnotifylist请求数需要累加,超过6次不再请求
|
|
|
+ if( null != yjhxJddUpload ) {
|
|
|
+ yjhxJddUpload.setCreatedBy("guangfo");
|
|
|
+ yjhxJddUpload.setCreatedDate(new Date());
|
|
|
+ yjhxJddUpload.setLastModifiedBy("guangfo");
|
|
|
+ yjhxJddUpload.setLastModifiedDate(new Date());
|
|
|
+ itfTblYjhxJddUploadService.saveOrUpdate(yjhxJddUpload);
|
|
|
+ msg = yjhxJddUpload.getSynErrMsg();
|
|
|
+ if( Constant.SynStatus.SYN.getCode().intValue() == yjhxJddUpload.getSynStatus()) {
|
|
|
+ synStatus = Constant.SynStatus.SYN.getCode();
|
|
|
+ }
|
|
|
+ if( null != yjhxJddFjUploadList && !yjhxJddFjUploadList.isEmpty()) {
|
|
|
+ yjhxJddFjUploadList.stream().forEach(fjUpload->{
|
|
|
+ fjUpload.setSynStatus(yjhxJddUpload.getSynStatus());
|
|
|
+ fjUpload.setSynErrMsg(yjhxJddUpload.getSynErrMsg());
|
|
|
+ fjUpload.setSynTime(new Date());
|
|
|
+ //返回状态与上一次相同,则累加,否则重新计算
|
|
|
+ fjUpload.setSynTimes(yjhxJddUpload.getSynTimes());
|
|
|
+ fjUpload.setCreatedBy("guangfo");
|
|
|
+ fjUpload.setCreatedDate(new Date());
|
|
|
+ fjUpload.setLastModifiedBy("guangfo");
|
|
|
+ fjUpload.setLastModifiedDate(new Date());
|
|
|
+ });
|
|
|
+ itfTblYjhxJddFjUploadService.saveOrUpdateBatch(yjhxJddFjUploadList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if( null != toGreeUploadnotifylist ) {
|
|
|
+ if(synStatus == Constant.SynStatus.SYN.getCode().intValue()) {
|
|
|
+ toGreeUploadnotifylist.setSynStatus(synStatus);
|
|
|
+ }else {
|
|
|
+ if(null !=toGreeUploadnotifylist.getSynTimes() && toGreeUploadnotifylist.getSynTimes() >= 6) {
|
|
|
+ toGreeUploadnotifylist.setSynStatus(Constant.SynStatus.FAIL.getCode());
|
|
|
+ toGreeUploadnotifylist.setSynErrMsg(msg);
|
|
|
+ }else {
|
|
|
+ toGreeUploadnotifylist.setSynTimes(null == toGreeUploadnotifylist.getSynTimes() ? 1 : (toGreeUploadnotifylist.getSynTimes()+1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ toGreeUploadnotifylist.setSynTime(new Date());
|
|
|
+ outJiasmToGreeUploadnotifylistService.saveOrUpdate(toGreeUploadnotifylist);
|
|
|
+ }
|
|
|
+
|
|
|
+ if( null != jdd) {
|
|
|
+ if( Constant.SynStatus.SYN.getCode().intValue() == synStatus) {
|
|
|
+ //返回成功,反写业务表 部分数据来自于格力总部要反写
|
|
|
+ yjhxJddService.saveOrUpdate(jdd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+ log.error((Objects.isNull(e) || Objects.isNull(e.getMessage())) ?"TradeOldForNewLogic.processSave异常" : e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 把请求失败的任务变成待处理任务
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Boolean changeJddFailToUnSyn(){
|
|
|
+ List<OutJiasmToGreeUploadnotifylist> failList = outJiasmToGreeUploadnotifylistService.lambdaQuery()
|
|
|
+ .eq(OutJiasmToGreeUploadnotifylist::getSynStatus, Constant.SynStatus.FAIL.getCode()).list();
|
|
|
+ if( null != failList && !failList.isEmpty()) {
|
|
|
+ List<Boolean> resultList = new ArrayList<>();
|
|
|
+ failList.stream().forEach(fail->{
|
|
|
+ fail.setSynStatus(Constant.SynStatus.UN_SYN.getCode());
|
|
|
+ fail.setSynTimes(0);
|
|
|
+ });
|
|
|
+ return outJiasmToGreeUploadnotifylistService.saveOrUpdateBatch(failList);
|
|
|
+ }
|
|
|
+ return Boolean.FALSE;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public String queryRejectJdd() {
|
|
|
+ final String url = webUrl + Constant.GreeWebPath.TBLYJHXJDD_QUERYREJECTJDD;
|
|
|
+ try {
|
|
|
+
|
|
|
+ JSONObject response = greeLogic.getPubV3(url, null);
|
|
|
+ //log.info("TradeOldForNewLogic.queryRejectJdd接口返回:{}", response.toJSONString());
|
|
|
+ if( 200 == response.getInteger("status").intValue()) {
|
|
|
+ List<OutJiasmToGreeUploadnotifylist> tradeNewForOldRejectJddDownloadList = JSONArray.parseArray(this.mapper.writeValueAsString(response.get("data")),
|
|
|
+ OutJiasmToGreeUploadnotifylist.class);
|
|
|
+ if( null != tradeNewForOldRejectJddDownloadList && !tradeNewForOldRejectJddDownloadList.isEmpty() ) {
|
|
|
+ tradeNewForOldRejectJddDownloadList.stream().forEach(reject->{
|
|
|
+ reject.setSynReqTime(new Date());
|
|
|
+ reject.setSynStatus(Constant.SynStatus.UN_SYN.getCode());
|
|
|
+ reject.setSynTimes(1);
|
|
|
+ });
|
|
|
+ outJiasmToGreeUploadnotifylistService.saveOrUpdateBatch(tradeNewForOldRejectJddDownloadList);
|
|
|
+ }else {
|
|
|
+ log.info("TradeOldForNewLogic.queryRejectJdd接口返回记录数为空");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(response.containsKey("messageCode") && null != response.get("messageCode")) {
|
|
|
+ log.error("TradeOldForNewLogic.queryRejectJdd接口异常111: {}", response.getString("messageCode"));
|
|
|
+ }else if(response.containsKey("message") && null != response.get("message")) {
|
|
|
+ log.error("TradeOldForNewLogic.queryRejectJdd接口异常222: {}", response.getString("message"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(Exception e) {
|
|
|
+ log.error("TradeOldForNewLogic.queryRejectJdd接口异常333: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+}
|