| package com.fzzy.async.fzzy40.impl; | 
|   | 
| import com.fzzy.api.Constant; | 
| import com.fzzy.api.entity.Api1109; | 
| import com.fzzy.api.entity.Api1202; | 
| import com.fzzy.api.entity.Api1205; | 
| import com.fzzy.api.entity.ApiLog; | 
| import com.fzzy.api.utils.ContextUtil; | 
| import com.fzzy.api.utils.FileUtils; | 
| import com.fzzy.api.view.repository.Api1109Rep; | 
| import com.fzzy.api.view.repository.Api1202Rep; | 
| import com.fzzy.api.view.repository.Api1205Rep; | 
| import com.fzzy.api.view.repository.ApiLogRep; | 
| import com.fzzy.async.fzzy40.entity.Fz40FileInfo; | 
| import com.fzzy.async.fzzy40.entity.Fz40InoutRecord; | 
| import com.fzzy.async.fzzy40.repository.Fzzy40Sync1109Rep; | 
| import com.fzzy.async.fzzy40.repository.Fzzy40Sync1202Rep; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.commons.lang.StringUtils; | 
| import org.apache.commons.lang.time.DateFormatUtils; | 
| import org.apache.commons.lang.time.DateUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Component; | 
|   | 
| import java.text.ParseException; | 
| import java.util.*; | 
| import java.util.stream.Collectors; | 
|   | 
| /** | 
|  * 文件信息 | 
|  */ | 
| @Slf4j | 
| @Component | 
| public class Fzzy40Sync1109 { | 
|   | 
|     private final static String IMG_START_C = "C_"; | 
|     private final static String IMG_START_R = "R_"; | 
|     /** | 
|      * 图片类型 | 
|      */ | 
|     private final static String IMG_TYPE_1 = "1";    //库区鸟瞰图 | 
|     private final static String IMG_TYPE_2 = "2";    //入库图片 | 
|     private final static String IMG_TYPE_3 = "3";    //出库图片 | 
|     private final static String IMG_TYPE_4 = "4";    //入库检斤视频 | 
|     private final static String IMG_TYPE_5 = "5";    //出库检斤视频 | 
|     private final static String IMG_TYPE_104 = "104";//熏蒸备案接口附件,用于广东省 | 
|   | 
|     /** | 
|      * 业务类型 | 
|      */ | 
|     private final static String BIZ_TAG_WEIGHT_FULL = "WEIGHT_FULL"; | 
|     private final static String BIZ_TAG_WEIGHT_EMPTY = "WEIGHT_EMPTY"; | 
|     private final static String BIZ_TAG_REGISTER = "REGISTER"; | 
|     private final static String BIZ_TAG_CARD_BACK = "CARD_BACK"; | 
|     /** | 
|      * 出入库类型 | 
|      */ | 
|     private final static String INOUT_TYPE_IN = "IN"; | 
|     private final static String INOUT_TYPE_OUT = "OUT"; | 
|   | 
|     @Autowired | 
|     private Fzzy40Sync1109Rep fzzySync1109Rep; | 
|     @Autowired | 
|     private Fzzy40Sync1202Rep fzzySync1202Rep; | 
|     @Autowired | 
|     private Api1109Rep api1109Rep; | 
|     @Autowired | 
|     private Api1202Rep api1202Rep; | 
|     @Autowired | 
|     private Api1205Rep api1205Rep; | 
|     @Autowired | 
|     private ApiLogRep apiLogRep; | 
|     @Autowired | 
|     private FileUtils fileUtil; | 
|   | 
|     /** | 
|      * 同步文件接口 | 
|      * | 
|      * @param deptId | 
|      * @param start | 
|      * @param end | 
|      */ | 
|     public void syncData(String kqdm, String deptId, Date start, Date end) { | 
|   | 
|         log.info("-------------1109接口数据开始同步------------------"); | 
|   | 
|         //同步数据,只记录失败的信息 | 
|         ApiLog apiLog = new ApiLog(); | 
|         apiLog.setType(ApiLog.TYPE_SYNC); | 
|         apiLog.setKqdm(deptId); | 
|         apiLog.setUploadTime(new Date()); | 
|         apiLog.setInteId(Constant.API_CODE_1109); | 
|         apiLog.setStatus(99); | 
|         apiLog.setId(ContextUtil.getUUID()); | 
|         try { | 
|             //获取出入库数据 | 
|             List<Fz40InoutRecord> list = fzzySync1202Rep.listInAndOutRecord(deptId, INOUT_TYPE_IN, INOUT_TYPE_OUT, start, end); | 
|   | 
|             if (null == list || list.isEmpty()) { | 
|                 log.info("-------------没有获取到文件信息------------------"); | 
|                 return; | 
|             } | 
|   | 
|             Map<String, Integer> map = new HashMap<>(); | 
|             Api1109 apiData; | 
|             String wjlx; | 
|             String wjmc; | 
|             List<Api1109> api1109List; | 
|             List<Api1202> api1202List; | 
|             List<Api1205> api1205List; | 
|             String str = "";  //出入库业务单号 | 
|             List<Fz40FileInfo> fileList; //文件信息 | 
|             List<String> ids; | 
|             for (Fz40InoutRecord inoutData : list) { | 
|                 if (inoutData.getRecordStatus().equals("DEL") || inoutData.getRecordStatus().equals("ERROR")) { | 
|                     continue; | 
|                 } | 
|                 if (!inoutData.getProgress().equals("RECORD")){ | 
|                     continue; | 
|                 } | 
|                 ids = new ArrayList<>(); | 
|                 wjlx = ""; | 
|                 //获取出入库业务单号信息 | 
|                 if (inoutData.getType().equals(INOUT_TYPE_IN)) { | 
|                     wjlx = IMG_TYPE_2; | 
|                     api1202List = api1202Rep.getDataByBizId(inoutData.getId()); | 
|                     if (null == api1202List || api1202List.isEmpty()) { | 
|                         continue; | 
|                     } | 
|                     ids = api1202List.stream().map(Api1202::getRkywdh).collect(Collectors.toList()); | 
|                 } | 
|                 if (inoutData.getType().equals(INOUT_TYPE_OUT)) { | 
|                     wjlx = IMG_TYPE_3; | 
|                     api1205List = api1205Rep.getDataByBizId(inoutData.getId()); | 
|                     if (null == api1205List || api1205List.isEmpty()) { | 
|                         continue; | 
|                     } | 
|                     ids = api1205List.stream().map(Api1205::getCkywdh).collect(Collectors.toList()); | 
|   | 
|                 } | 
|   | 
|                 //若文件类型为空,则跳过 | 
|                 if (StringUtils.isEmpty(wjlx)) { | 
|                     continue; | 
|                 } | 
|   | 
|                 //根据出入库单号获取对应文件信息 | 
|                 fileList = fzzySync1109Rep.listFileInfoByBizId(inoutData.getId()); | 
|                 if (null == fileList || fileList.isEmpty()) { | 
|                     continue; | 
|                 } | 
|                 int num = 1; | 
|                 int idsNum = 0; | 
|                 String bizTag = null; | 
|                 for (Fz40FileInfo sysData : fileList) { | 
|                     apiData = new Api1109(); | 
|   | 
|                     //主键id | 
|                     apiData.setId(sysData.getFileId()); | 
|                     //文件路径 | 
|                     apiData.setWjdz(fileUtil.getInoutFilePath(sysData.getCreateTime()) + sysData.getFileName()); | 
|                     //登记 | 
|                     if (BIZ_TAG_REGISTER.equals(sysData.getBizTag()) || BIZ_TAG_CARD_BACK.equals(sysData.getBizTag())) { | 
|                         str = ids.get(0); | 
|                         wjmc = kqdm + "_" + str; | 
|                         //文件名称 | 
|                         wjmc = getImgNameType(wjmc, sysData.getBizTag(), str, sysData.getFileName(), map); | 
|                         apiData.setWjmc(wjmc); | 
|                         //文件类型 | 
|                         apiData.setWjlx(wjlx); | 
|                     } | 
|                     //称重 | 
|                     if (BIZ_TAG_WEIGHT_FULL.equals(sysData.getBizTag()) || BIZ_TAG_WEIGHT_EMPTY.equals(sysData.getBizTag())) { | 
|                         bizTag = sysData.getBizTag(); | 
|                         if(StringUtils.isNotEmpty(inoutData.getTransType()) && inoutData.getTransType().equals("3")){ | 
|                             if(num > 6){ | 
|                                 num = 1; | 
|                                 idsNum ++; | 
|                             } | 
|                         }else { | 
|                             if(num > 8){ | 
|                                 num = 1; | 
|                                 idsNum ++; | 
|                             } | 
|                         } | 
|                         //2024-05-23 此处暂时设置名称长度限制,后期调整后可删除 | 
|                         if(sysData.getCreateTime().after(DateUtils.parseDate("2024-04-18",new String[]{"yyyy-MM-dd"}))){ | 
|                             if(StringUtils.isNotEmpty(inoutData.getTransType()) && inoutData.getTransType().equals("3")){ | 
|                                 bizTag = sysData.getBizTag(); | 
|                             }else { | 
|                                 bizTag = null; | 
|                             } | 
|                         } | 
|                         if(idsNum == ids.size()){ | 
|                             break; | 
|                         } | 
|                         str = ids.get(idsNum); | 
|   | 
|                         wjmc = kqdm + "_" + str; | 
|   | 
|                         //文件名称 | 
|                         wjmc = getImgNameType(wjmc, bizTag, str, sysData.getFileName(), map); | 
|                         apiData.setWjmc(wjmc); | 
|                         apiData.setWjlx(wjlx); | 
|                         if (wjmc.indexOf(Constant.IMG_NAME_TYPE_IVG) >= 0 || wjmc.indexOf(Constant.IMG_NAME_TYPE_IVT) >= 0) { | 
|                             apiData.setWjlx(IMG_TYPE_4); | 
|                         } | 
|                         if (wjmc.indexOf(Constant.IMG_NAME_TYPE_OVG) >= 0 || wjmc.indexOf(Constant.IMG_NAME_TYPE_OVT) >= 0) { | 
|                             apiData.setWjlx(IMG_TYPE_5); | 
|                         } | 
|                         num ++; | 
|                     } | 
|   | 
|                     //操作标志及最后更新时间 | 
|                     apiData.setZhgxsj(new Date()); | 
|   | 
|                     //业务id、库区编码、同步时间 | 
|                     apiData.setBizId(sysData.getFileId()); | 
|                     apiData.setKqdm(kqdm); | 
|                     apiData.setSyncTime(new Date()); | 
|   | 
|                     api1109List = api1109Rep.getDataByBizId(apiData.getBizId()); | 
|                     if (null == api1109List || api1109List.isEmpty()) { | 
|                         apiData.setCzbz(Constant.CZBZ_I); | 
|                     } else { | 
|                         apiData.setCzbz(api1109List.get(0).getCzbz()); | 
|                     } | 
|   | 
|                     //保存数据 | 
|                     api1109Rep.save(apiData); | 
|                     log.info("1109---同步数据:{}", apiData.toString()); | 
|                 } | 
|             } | 
|         } catch (Exception e) { | 
|             log.error("---文件同步执行失败----{}", e); | 
|             apiLog.setResult("同步文件信息失败:" + e.getMessage()); | 
|             apiLogRep.save(apiLog); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 获取图片命名类型 | 
|      * | 
|      * @param wjmc     需要的文件名称 | 
|      * @param bizTag   文件业务类型 | 
|      * @param bizId    文件业务id | 
|      * @param fileName 原文件名 | 
|      * @param map | 
|      * @return | 
|      */ | 
|     private String getImgNameType(String wjmc, String bizTag, String bizId, String fileName, Map<String, Integer> map) { | 
|         if(null == bizTag){ | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_DJ) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_DJ + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_RK) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_RK + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_CK) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_CK + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_GL) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_GL + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_GR) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_GR + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_GT) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_GT + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_TL) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_TL + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_TR) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_TR + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_TT) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_TT + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_SL) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_SL + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_SF) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_SF + ".jpg"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_IVG) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_IVG + ".mp4"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_IVT) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_IVT + ".mp4"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_OVG) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_OVG + ".mp4"; | 
|             } | 
|             if (fileName.indexOf(Constant.IMG_NAME_TYPE_OVT) >= 0) { | 
|                 return wjmc + "_" + Constant.IMG_NAME_TYPE_OVT + ".mp4"; | 
|             } | 
|         } | 
|   | 
|         Integer num = 0; | 
|         //毛重 | 
|         if (BIZ_TAG_WEIGHT_FULL.equals(bizTag)) { | 
|             if (null == map.get(bizId + "_" + bizTag)) { | 
|                 map.put(bizId + "_" + bizTag, 1); | 
|             } | 
|             num = map.get(bizId + "_" + bizTag); | 
|             if (num == 1) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_GL; | 
|                 map.put(bizId + "_" + bizTag, 2); | 
|             } | 
|             if (num == 2) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_GR; | 
|                 map.put(bizId + "_" + bizTag, 3); | 
|             } | 
|             if (num == 3) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_GT; | 
|                 map.remove(bizId + "_" + bizTag); | 
|             } | 
|         } | 
|         //皮重 | 
|         if (BIZ_TAG_WEIGHT_EMPTY.equals(bizTag)) { | 
|             if (null == map.get(bizId + "_" + bizTag)) { | 
|                 map.put(bizId + "_" + bizTag, 1); | 
|             } | 
|             num = map.get(bizId + "_" + bizTag); | 
|             if (num == 1) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_TL; | 
|                 map.put(bizId + "_" + bizTag, 2); | 
|             } | 
|             if (num == 2) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_TR; | 
|                 map.put(bizId + "_" + bizTag, 3); | 
|             } | 
|             if (num == 3) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_TT; | 
|                 map.remove(bizId + "_" + bizTag); | 
|             } | 
|         } | 
|         //入库登记 | 
|         if (BIZ_TAG_REGISTER.equals(bizTag)) { | 
|             if (null == map.get(bizId + "_" + bizTag)) { | 
|                 map.put(bizId + "_" + bizTag, 1); | 
|             } | 
|             num = map.get(bizId + "_" + bizTag); | 
|             if (num == 1) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_DJ; | 
|                 map.put(bizId + "_" + bizTag, 2); | 
|             } | 
|             if (num == 2) { | 
|                 wjmc += "_" + Constant.IMG_NAME_TYPE_RK; | 
|                 map.remove(bizId + "_" + bizTag); | 
|             } | 
|         } | 
|         //出库照片 | 
|         if (BIZ_TAG_CARD_BACK.equals(bizTag)) { | 
|             wjmc += "_" + Constant.IMG_NAME_TYPE_CK; | 
|         } | 
|         return wjmc + ".jpg"; | 
|     } | 
| } |