|
@@ -0,0 +1,581 @@
|
|
|
|
+package com.prolog.cs.biz.inbound.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+import com.prolog.cs.basic.chain.model.cargo.BaseCargoOwnerMst;
|
|
|
|
+import com.prolog.cs.basic.chain.model.customer.BaseCustomerMst;
|
|
|
|
+import com.prolog.cs.basic.chain.model.supplier.BaseSupplierMst;
|
|
|
|
+import com.prolog.cs.basic.item.model.BaseMtlItemMst;
|
|
|
|
+import com.prolog.cs.basic.warehouse.model.BaseWmsWarehouseMst;
|
|
|
|
+import com.prolog.cs.biz.inbound.dao.OmsAsnBillDMapper;
|
|
|
|
+import com.prolog.cs.biz.inbound.dao.OmsAsnBillHMapper;
|
|
|
|
+import com.prolog.cs.biz.inbound.dao.SupervisionCodeMapper;
|
|
|
|
+import com.prolog.cs.biz.inbound.dao.rcv.RcvHeadersMapper;
|
|
|
|
+import com.prolog.cs.biz.inbound.model.OmsAsnBillD;
|
|
|
|
+import com.prolog.cs.biz.inbound.model.OmsAsnBillH;
|
|
|
|
+import com.prolog.cs.biz.inbound.model.SupervisionCode;
|
|
|
|
+import com.prolog.cs.biz.inbound.remote.*;
|
|
|
|
+import com.prolog.cs.biz.inbound.utils.ExcelUtil;
|
|
|
|
+import com.prolog.cs.biz.inbound.vo.SupervisionCodeImportVo;
|
|
|
|
+import com.prolog.cs.biz.outbound.model.OmsDoBillHDO;
|
|
|
|
+import com.prolog.cs.biz.outbound.model.entity.OmsDoBillDDO;
|
|
|
|
+import com.prolog.framework.authority.core.dto.UserDTO;
|
|
|
|
+import com.prolog.framework.authority.user.UserTemplate;
|
|
|
|
+import com.prolog.framework.common.message.RestMessage;
|
|
|
|
+import com.prolog.framework.core.exception.BizException;
|
|
|
|
+import com.prolog.framework.core.restriction.Criteria;
|
|
|
|
+import com.prolog.framework.core.restriction.FieldSelector;
|
|
|
|
+import com.prolog.framework.core.restriction.Restriction;
|
|
|
|
+import com.prolog.framework.core.restriction.Restrictions;
|
|
|
|
+import com.prolog.upcloud.base.inventory.model.WmsInvBatchNumbers;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.text.ParseException;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.concurrent.Callable;
|
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
|
+import java.util.concurrent.FutureTask;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class SupervisionCodeExcelHandler {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserTemplate userTemplate;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ChainRemoteCaller chainRemoteCaller;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseInventoryRemoteCaller baseInventoryRemoteCaller;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseItemRemoteCaller baseItemRemoteCaller;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseWmsWarehouseCaller baseWmsWarehouseCaller;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OutboundCaller outboundCaller;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OmsAsnBillHMapper omsAsnBillHMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private OmsAsnBillDMapper omsAsnBillDMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RcvHeadersMapper rcvHeadersMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SupervisionCodeMapper supervisionCodeMapper;
|
|
|
|
+
|
|
|
|
+ public void importSupervisionCodes(MultipartFile file) {
|
|
|
|
+ if(file == null){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ UserDTO userDTO = userTemplate.getUserDTO();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ List<SupervisionCodeImportVo> listAll = ExcelUtil.importExcel(file.getInputStream(), SupervisionCodeImportVo.class);
|
|
|
|
+ checkParams(listAll);
|
|
|
|
+
|
|
|
|
+ List<SupervisionCode> supervisionCodes = new ArrayList<>();
|
|
|
|
+ List<List<SupervisionCodeImportVo>> partitionedList = Lists.partition(listAll, 2);
|
|
|
|
+
|
|
|
|
+ CountDownLatch latch = new CountDownLatch(partitionedList.size());
|
|
|
|
+
|
|
|
|
+ for (List<SupervisionCodeImportVo> list : partitionedList) {
|
|
|
|
+ handleSupervisionCodeRunable runable = new handleSupervisionCodeRunable(latch, list,supervisionCodes,userDTO);
|
|
|
|
+ FutureTask ft = new FutureTask(runable);
|
|
|
|
+ new Thread(ft).start();
|
|
|
|
+ try {
|
|
|
|
+ Object o = ft.get();
|
|
|
|
+ if(o != null){
|
|
|
|
+ throw new BizException("上传错误:"+String.valueOf(o));
|
|
|
|
+ }
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (ExecutionException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ // 等待所有线程处理完成
|
|
|
|
+ latch.await();
|
|
|
|
+ if(supervisionCodes.size() > 0){
|
|
|
|
+ supervisionCodeMapper.saveBatch(supervisionCodes);
|
|
|
|
+ }
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 校验入参
|
|
|
|
+ * @param list
|
|
|
|
+ */
|
|
|
|
+ private void checkParams(List<SupervisionCodeImportVo> list) {
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+ SupervisionCodeImportVo vo = list.get(i);
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isBlank(vo.getSupervisionCode())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,监管码不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getEnterpriseId())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,企业ID不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getWarehouseCode())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,仓库编码不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getCargoOwnerCode())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,货主不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getItemCode())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,商品编码不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getPackLevel())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,包装级别不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getManufacturerLotNum())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,批号不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getRefBillNo())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,单号不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getSaveType())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,监管类型不能为空!");
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isBlank(vo.getDate())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,日期不能为空!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!"1".equals(vo.getSaveType()) && !"2".equals(vo.getSaveType())){
|
|
|
|
+ throw new BizException("第"+(i+1)+"行,监管类型只能为1和2!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<String> supervisionCodes = list.stream().map(item -> item.getSupervisionCode()+";"+item.getSaveType()).collect(Collectors.toList());
|
|
|
|
+ List<String> duplicates = supervisionCodes.stream().filter(i -> Collections.frequency(supervisionCodes, i) > 1)
|
|
|
|
+ .distinct()
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ if(duplicates != null && duplicates.size() > 0){
|
|
|
|
+ throw new BizException("监管码:"+JSON.toJSONString(duplicates)+"重复!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询仓
|
|
|
|
+ * @param list
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<BaseWmsWarehouseMst> getWarehouseMstList(List<SupervisionCodeImportVo> list){
|
|
|
|
+ Set<String> warehouseCodes = list.stream().map(x -> x.getWarehouseCode()).collect(Collectors.toSet());
|
|
|
|
+ List<BaseWmsWarehouseMst> warehouseMstList = null;
|
|
|
|
+ if(warehouseCodes.size()>0){
|
|
|
|
+ RestMessage<Map<String, BaseWmsWarehouseMst>> byWarehouseCode = baseWmsWarehouseCaller.getByWarehouseCode(warehouseCodes);
|
|
|
|
+ if(byWarehouseCode.getData()!=null&&byWarehouseCode.isSuccess()){
|
|
|
|
+ Map<String, BaseWmsWarehouseMst> warehouseMstMap = byWarehouseCode.getData();
|
|
|
|
+ warehouseMstList = new ArrayList<>(warehouseMstMap.values());
|
|
|
|
+ if(warehouseMstList.size()==0){
|
|
|
|
+ throw new BizException("仓库信息查询失败");
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ throw new BizException("仓库信息查询失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return warehouseMstList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询货主
|
|
|
|
+ * @param list
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Map<String, BaseCargoOwnerMst> getCargoMap(List<SupervisionCodeImportVo> list){
|
|
|
|
+ Set<String> cargoOwnerCodes = list.stream().filter(p -> StringUtils.isNotBlank(p.getCargoOwnerCode()))
|
|
|
|
+ .map(SupervisionCodeImportVo::getCargoOwnerCode).collect(Collectors.toSet());
|
|
|
|
+
|
|
|
|
+ RestMessage<Map<String, BaseCargoOwnerMst>> cargoMapRet = chainRemoteCaller.getByCode(cargoOwnerCodes);
|
|
|
|
+ if(cargoMapRet==null || !cargoMapRet.isSuccess()){
|
|
|
|
+ throw new BizException("获取货主失败!");
|
|
|
|
+ }
|
|
|
|
+ Map<String, BaseCargoOwnerMst> cargoMap = cargoMapRet.getData();
|
|
|
|
+ Map<String, BaseCargoOwnerMst> cargoCodeMap = Maps.newHashMap();
|
|
|
|
+ for (String cargoOwnerId : cargoMap.keySet()) {
|
|
|
|
+ BaseCargoOwnerMst baseCargoOwnerMst = cargoMap.get(cargoOwnerId);
|
|
|
|
+ cargoCodeMap.put(baseCargoOwnerMst.getCargoOwnerCode(),baseCargoOwnerMst);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cargoCodeMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询批次
|
|
|
|
+ * @param list
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<WmsInvBatchNumbers> getBatchNumbers(List<SupervisionCodeImportVo> list){
|
|
|
|
+ Set<String> manufacturerLotNums = list.stream().filter(p -> StringUtils.isNotBlank(p.getManufacturerLotNum()))
|
|
|
|
+ .map(SupervisionCodeImportVo::getManufacturerLotNum).collect(Collectors.toSet());
|
|
|
|
+
|
|
|
|
+ RestMessage<List<WmsInvBatchNumbers>> listByManufacturerLotNums = baseInventoryRemoteCaller.getListByManufacturerLotNums(String.join(",", manufacturerLotNums));
|
|
|
|
+ if(listByManufacturerLotNums == null || !listByManufacturerLotNums.isSuccess() || listByManufacturerLotNums.getData() == null || listByManufacturerLotNums.getData().size() <= 0){
|
|
|
|
+ throw new BizException("根据批次号:"+ JSON.toJSONString(manufacturerLotNums)+"查询批次失败");
|
|
|
|
+ }
|
|
|
|
+ List<WmsInvBatchNumbers> wmsInvBatchNumbers = listByManufacturerLotNums.getData();
|
|
|
|
+ return wmsInvBatchNumbers;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取商品信息
|
|
|
|
+ * @param list
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<BaseMtlItemMst> getIitemMstList(List<SupervisionCodeImportVo> list,BaseCargoOwnerMst baseCargoOwnerMst){
|
|
|
|
+ Set<String> itemCodes = list.stream().map(x->x.getItemCode()).collect(Collectors.toSet());
|
|
|
|
+ //请求商品信息
|
|
|
|
+ List<BaseMtlItemMst> itemMstList = null;
|
|
|
|
+ RestMessage<List<BaseMtlItemMst>> itemResult = baseItemRemoteCaller.getByItemCodesE(baseCargoOwnerMst.getCargoOwnerId(),itemCodes,baseCargoOwnerMst.getEnterpriseId());
|
|
|
|
+ if(itemResult.getData()!=null&&itemResult.isSuccess()){
|
|
|
|
+ itemMstList = itemResult.getData();
|
|
|
|
+ if(itemMstList.size()==0){
|
|
|
|
+ throw new BizException("商品信息查询失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return itemMstList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询出库单和入库单
|
|
|
|
+ * @param list
|
|
|
|
+ * @param baseWmsWarehouseMst
|
|
|
|
+ * @param omsDoBillHDOList
|
|
|
|
+ * @param asnBillHList
|
|
|
|
+ */
|
|
|
|
+ private void getRefBills(List<SupervisionCodeImportVo> list,BaseWmsWarehouseMst baseWmsWarehouseMst,List<OmsDoBillHDO> omsDoBillHDOList,List<OmsAsnBillH> asnBillHList){
|
|
|
|
+ Map<String, List<SupervisionCodeImportVo>> map = list.stream().collect(Collectors.groupingBy(SupervisionCodeImportVo::getSaveType));
|
|
|
|
+ for (Map.Entry<String, List<SupervisionCodeImportVo>> entry : map.entrySet()) {
|
|
|
|
+ String key = entry.getKey();
|
|
|
|
+ List<SupervisionCodeImportVo> value = entry.getValue();
|
|
|
|
+ Set<String> billNos = value.stream().map(SupervisionCodeImportVo::getRefBillNo).collect(Collectors.toSet());
|
|
|
|
+ if("1".equals(key)){
|
|
|
|
+ Criteria crt = Criteria.forClass(OmsAsnBillH.class);
|
|
|
|
+ crt.setRestriction(Restrictions.in("billno", billNos.toArray()));
|
|
|
|
+ asnBillHList.addAll(omsAsnBillHMapper.findByCriteria(crt));
|
|
|
|
+// asnBillHList.addAll(omsAsnBillHMapper.findByIds(OmsAsnBillH.class, billNos.toArray(), null));
|
|
|
|
+ if(asnBillHList == null || asnBillHList.size() <= 0){
|
|
|
|
+ throw new BizException("根据入库单编码:"+JSON.toJSONString(billNos)+"查询入库单失败!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ RestMessage<List<OmsDoBillHDO>> doBillHByBillNos = outboundCaller.getDoBillHByBillNos(billNos.toArray(new String[billNos.size()]), baseWmsWarehouseMst.getWarehouseId());
|
|
|
|
+ if(doBillHByBillNos == null || !doBillHByBillNos.isSuccess() || doBillHByBillNos.getData() == null || doBillHByBillNos.getData().size() <= 0){
|
|
|
|
+ throw new BizException("根据出库单编码:"+JSON.toJSONString(billNos)+"查询出库单失败!");
|
|
|
|
+ }
|
|
|
|
+ omsDoBillHDOList.addAll(doBillHByBillNos.getData());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询出入库单明细
|
|
|
|
+ * @param omsDoBillHDOList
|
|
|
|
+ * @param asnBillHList
|
|
|
|
+ * @param omsDoBillDDOS
|
|
|
|
+ * @param omsAsnBillDS
|
|
|
|
+ */
|
|
|
|
+ private void getrefBillDetails(List<OmsDoBillHDO> omsDoBillHDOList, List<OmsAsnBillH> asnBillHList, List<OmsDoBillDDO> omsDoBillDDOS, List<OmsAsnBillD> omsAsnBillDS) {
|
|
|
|
+ if(omsDoBillHDOList.size() > 0){
|
|
|
|
+ List<String> doBillIds = omsDoBillHDOList.stream().map(OmsDoBillHDO::getBillid).distinct().collect(Collectors.toList());
|
|
|
|
+ RestMessage<List<OmsDoBillDDO>> doBillDByBillIds = outboundCaller.getDoBillDByBillIds(doBillIds);
|
|
|
|
+ if(doBillDByBillIds == null || !doBillDByBillIds.isSuccess() || doBillDByBillIds.getData() == null || doBillDByBillIds.getData().size() <= 0){
|
|
|
|
+ throw new BizException("根据出库单:"+JSON.toJSONString(doBillIds)+"查询入库单明细失败!");
|
|
|
|
+ }
|
|
|
|
+ omsDoBillDDOS.addAll(doBillDByBillIds.getData());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(asnBillHList.size() > 0 ){
|
|
|
|
+ List<String> asnBillIds = asnBillHList.stream().map(OmsAsnBillH::getBillid).distinct().collect(Collectors.toList());
|
|
|
|
+ Criteria crt = Criteria.forClass(OmsAsnBillD.class);
|
|
|
|
+ Restriction r1 = Restrictions.in("billid", asnBillIds.toArray());
|
|
|
|
+ crt.setRestriction(Restrictions.and(r1));
|
|
|
|
+ omsAsnBillDS.addAll(omsAsnBillDMapper.findByCriteria(crt));
|
|
|
|
+ if(omsAsnBillDS.size() <= 0){
|
|
|
|
+ throw new BizException("根据入库单:"+JSON.toJSONString(asnBillIds)+"查询出库单明细失败!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取客户供应商列表
|
|
|
|
+ * @param omsDoBillHDOList
|
|
|
|
+ * @param asnBillHList
|
|
|
|
+ * @param supplierMsts
|
|
|
|
+ * @param customerMsts
|
|
|
|
+ */
|
|
|
|
+ private void getShippers(List<OmsDoBillHDO> omsDoBillHDOList,
|
|
|
|
+ List<OmsAsnBillH> asnBillHList,
|
|
|
|
+ List<BaseSupplierMst> supplierMsts,
|
|
|
|
+ List<BaseCustomerMst> customerMsts
|
|
|
|
+ ){
|
|
|
|
+ List<String> shipperIds = omsDoBillHDOList.stream().map(OmsDoBillHDO::getShipperid).distinct().collect(Collectors.toList());
|
|
|
|
+ shipperIds.addAll(asnBillHList.stream().map(OmsAsnBillH :: getShipperid).distinct().collect(Collectors.toList()));
|
|
|
|
+ supplierMsts.addAll(rcvHeadersMapper.findSupplierMstByIds(shipperIds));
|
|
|
|
+ customerMsts.addAll(rcvHeadersMapper.findCustomerMstByIds(shipperIds));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转换为监管码对象
|
|
|
|
+ * @param list
|
|
|
|
+ * @param warehouseMstList
|
|
|
|
+ * @param cargoMap
|
|
|
|
+ * @param batchNumbers
|
|
|
|
+ * @param iitemMstList
|
|
|
|
+ * @param omsDoBillHDOList
|
|
|
|
+ * @param asnBillHList
|
|
|
|
+ * @param supplierMsts
|
|
|
|
+ * @param customerMsts
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<SupervisionCode> convertSupervisionCodes(List<SupervisionCodeImportVo> list,
|
|
|
|
+ List<BaseWmsWarehouseMst> warehouseMstList,
|
|
|
|
+ Map<String, BaseCargoOwnerMst> cargoMap,
|
|
|
|
+ List<WmsInvBatchNumbers> batchNumbers,
|
|
|
|
+ List<BaseMtlItemMst> iitemMstList,
|
|
|
|
+ List<OmsDoBillHDO> omsDoBillHDOList,
|
|
|
|
+ List<OmsAsnBillH> asnBillHList,
|
|
|
|
+ List<BaseSupplierMst> supplierMsts,
|
|
|
|
+ List<BaseCustomerMst> customerMsts,
|
|
|
|
+ List<OmsDoBillDDO> omsDoBillDDOS,
|
|
|
|
+ List<OmsAsnBillD> omsAsnBillDS,
|
|
|
|
+ UserDTO userDTO
|
|
|
|
+ ) {
|
|
|
|
+ List<SupervisionCode> result = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
|
+
|
|
|
|
+ SupervisionCodeImportVo vo = list.get(i);
|
|
|
|
+
|
|
|
|
+ SupervisionCode supervisionCode = new SupervisionCode();
|
|
|
|
+ supervisionCode.setSupervisionCode(vo.getSupervisionCode());
|
|
|
|
+ supervisionCode.setEnterpriseId(vo.getEnterpriseId());
|
|
|
|
+
|
|
|
|
+ supervisionCode.setWarehouseCode(vo.getWarehouseCode());
|
|
|
|
+ BaseWmsWarehouseMst baseWmsWarehouseMst = warehouseMstList.stream().filter(item -> item.getWarehouseCode().equals(vo.getWarehouseCode())).findFirst().orElse(null);
|
|
|
|
+ if(baseWmsWarehouseMst == null){
|
|
|
|
+ throw new BizException("根据仓编码:"+vo.getWarehouseCode()+"查询仓失败!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setWarehouseId(baseWmsWarehouseMst.getWarehouseId());
|
|
|
|
+
|
|
|
|
+ BaseCargoOwnerMst baseCargoOwnerMst = cargoMap.get(vo.getCargoOwnerCode());
|
|
|
|
+ if(baseCargoOwnerMst == null){
|
|
|
|
+ throw new BizException("根据货主编码:"+vo.getCargoOwnerCode()+"查询货主失败!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setCargoOwnerCode(baseCargoOwnerMst.getCargoOwnerCode());
|
|
|
|
+ supervisionCode.setCargoOwnerId(baseCargoOwnerMst.getCargoOwnerId());
|
|
|
|
+
|
|
|
|
+ BaseMtlItemMst baseMtlItemMst = iitemMstList.stream().filter(item -> item.getItemCode().equals(vo.getItemCode())).findFirst().orElse(null);
|
|
|
|
+ if(baseCargoOwnerMst == null){
|
|
|
|
+ throw new BizException("根据商品编码:"+vo.getItemCode()+"查询商品资料失败!");
|
|
|
|
+ }
|
|
|
|
+ if(baseMtlItemMst.getBaseMtlItemHealth().getItemHealthSuperviseflag()!=1){
|
|
|
|
+ throw new BizException("商品:"+baseMtlItemMst.getItemCode()+"不扫监管码!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setItemId(baseMtlItemMst.getItemId());
|
|
|
|
+ supervisionCode.setItemCode(baseMtlItemMst.getItemCode());
|
|
|
|
+ supervisionCode.setItemName(baseMtlItemMst.getItemName());
|
|
|
|
+ supervisionCode.setPackSize(String.valueOf(baseMtlItemMst.getBaseMtlItemUomConversionsList().get(0).getConversionRate()));
|
|
|
|
+
|
|
|
|
+ if("1".equals(vo.getSaveType())){
|
|
|
|
+ OmsAsnBillH omsAsnBillH = asnBillHList.stream().filter(item -> item.getBillno().equals(vo.getRefBillNo())).findFirst().orElse(null);
|
|
|
|
+ if(omsAsnBillH == null){
|
|
|
|
+ throw new BizException("根据入库单号:"+vo.getRefBillNo()+"查询入库单失败!");
|
|
|
|
+ }
|
|
|
|
+ if(!"1".equals(omsAsnBillH.getBilltype()) && !"2".equals(omsAsnBillH.getBilltype())){
|
|
|
|
+ throw new BizException("入库单:"+vo.getRefBillNo()+"单据类型不正确!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setRefBillId(omsAsnBillH.getBillid());
|
|
|
|
+ supervisionCode.setSrcCode(omsAsnBillH.getBillno());
|
|
|
|
+ supervisionCode.setSrcId(omsAsnBillH.getBillid());
|
|
|
|
+ supervisionCode.setBillType(omsAsnBillH.getBilltype());
|
|
|
|
+
|
|
|
|
+ supervisionCode.setSupplierId(omsAsnBillH.getShipperid());
|
|
|
|
+ supervisionCode.setSupplierCode(omsAsnBillH.getShippercode());
|
|
|
|
+ supervisionCode.setCompanyCode(omsAsnBillH.getShippercode());
|
|
|
|
+ supervisionCode.setUploadShippId(omsAsnBillH.getShipperid());
|
|
|
|
+
|
|
|
|
+ supervisionCode.setSupervisionType("1".equals(omsAsnBillH.getBilltype()) ? 0 : 1);
|
|
|
|
+
|
|
|
|
+ OmsAsnBillD omsAsnBillD = omsAsnBillDS.stream().filter(item -> item.getBillid().equals(omsAsnBillH.getBillid()) && item.getItemid().equals(baseMtlItemMst.getItemId())).findFirst().orElse(null);
|
|
|
|
+ if(omsAsnBillD == null){
|
|
|
|
+ throw new BizException("入库单:"+vo.getRefBillNo()+",商品:"+baseMtlItemMst.getItemCode()+"查询入库单明细失败!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setPieceQty(String.valueOf(omsAsnBillD.getItemQty()));
|
|
|
|
+ supervisionCode.setRefBillLineId(omsAsnBillD.getLineid());
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ OmsDoBillHDO omsDoBillHDO = omsDoBillHDOList.stream().filter(item -> item.getBillno().equals(vo.getRefBillNo())).findFirst().orElse(null);
|
|
|
|
+ if(omsDoBillHDO == null){
|
|
|
|
+ throw new BizException("根据出库单号:"+vo.getRefBillNo()+"查询出库单失败!");
|
|
|
|
+ }
|
|
|
|
+ if(!"1".equals(omsDoBillHDO.getBilltype())){
|
|
|
|
+ throw new BizException("出库单:"+vo.getRefBillNo()+"单据类型不正确!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setRefBillId(omsDoBillHDO.getBillid());
|
|
|
|
+ supervisionCode.setSrcCode(omsDoBillHDO.getBillno());
|
|
|
|
+ supervisionCode.setSrcId(omsDoBillHDO.getBillid());
|
|
|
|
+ supervisionCode.setBillType(omsDoBillHDO.getBilltype());
|
|
|
|
+
|
|
|
|
+ supervisionCode.setSupplierId(omsDoBillHDO.getShipperid());
|
|
|
|
+ supervisionCode.setSupplierCode(omsDoBillHDO.getShipperCode());
|
|
|
|
+ supervisionCode.setCompanyCode(omsDoBillHDO.getShipperCode());
|
|
|
|
+ supervisionCode.setUploadShippId(omsDoBillHDO.getShipperid());
|
|
|
|
+
|
|
|
|
+ supervisionCode.setSupervisionType(2);
|
|
|
|
+
|
|
|
|
+ OmsDoBillDDO omsDoBillDDO = omsDoBillDDOS.stream().filter(item -> item.getBillid().equals(omsDoBillHDO.getBillid()) && item.getItemid().equals(baseMtlItemMst.getItemId())).findFirst().orElse(null);
|
|
|
|
+ if(omsDoBillDDO == null){
|
|
|
|
+ throw new BizException("出库单:"+vo.getRefBillNo()+",商品:"+baseMtlItemMst.getItemCode()+"查询出库单明细失败!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setPieceQty(String.valueOf(omsDoBillDDO.getItemQty()));
|
|
|
|
+ supervisionCode.setRefBillLineId(omsDoBillDDO.getLineid());
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setSaveType(Integer.valueOf(vo.getSaveType()));
|
|
|
|
+ supervisionCode.setUploadFlag("0");
|
|
|
|
+ supervisionCode.setUploadType("1".equals(vo.getSaveType()) ? 0 : 1);
|
|
|
|
+ supervisionCode.setDownFlag(0);
|
|
|
|
+ supervisionCode.setUploadTimes(0);
|
|
|
|
+
|
|
|
|
+ supervisionCode.setCodeType("1");
|
|
|
|
+ supervisionCode.setPackLevel(vo.getPackLevel());
|
|
|
|
+ supervisionCode.setStatus("10");
|
|
|
|
+ supervisionCode.setBillno(vo.getRefBillNo());
|
|
|
|
+
|
|
|
|
+ WmsInvBatchNumbers wmsInvBatchNumbers = batchNumbers.stream().filter(item -> item.getManufacturerLotNum().equals(vo.getManufacturerLotNum())).findFirst().orElse(null);
|
|
|
|
+ if(wmsInvBatchNumbers == null){
|
|
|
|
+ throw new BizException("根据批次号:"+vo.getManufacturerLotNum()+"查询批次失败!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setManufacturerLotNum(vo.getManufacturerLotNum());
|
|
|
|
+ supervisionCode.setProductionDate(wmsInvBatchNumbers.getBatchProductionDate());
|
|
|
|
+ supervisionCode.setExpiredDate(wmsInvBatchNumbers.getBatchExpiredDate());
|
|
|
|
+
|
|
|
|
+ supervisionCode.setCreator(userDTO.getUserBizModel().getEmployeeNo());
|
|
|
|
+ supervisionCode.setModifier(userDTO.getUserBizModel().getEmployeeNo());
|
|
|
|
+ supervisionCode.setCreatorName(userDTO.getNickname());
|
|
|
|
+ supervisionCode.setModifierName(userDTO.getNickname());
|
|
|
|
+ supervisionCode.setGmtCreate(new Date());
|
|
|
|
+ supervisionCode.setGmtModified(new Date());
|
|
|
|
+ supervisionCode.setUnlock(0);
|
|
|
|
+
|
|
|
|
+ BaseSupplierMst baseSupplierMst = supplierMsts.stream().filter(item -> item.getSupplierId().equals(supervisionCode.getSupplierId())).findFirst().orElse(null);
|
|
|
|
+ if(baseSupplierMst == null){
|
|
|
|
+ BaseCustomerMst baseCustomerMst = customerMsts.stream().filter(item -> item.getCustomerId().equals(supervisionCode.getSupplierId())).findFirst().orElse(null);
|
|
|
|
+ if(baseCustomerMst == null){
|
|
|
|
+ throw new BizException("根据供应商/客户编码:"+supervisionCode.getSupplierCode()+"查询失败!");
|
|
|
|
+ }
|
|
|
|
+ supervisionCode.setEntId(baseCustomerMst.getEleccode());
|
|
|
|
+ supervisionCode.setUploadShippId(baseCustomerMst.getCustomerId());
|
|
|
|
+ }else {
|
|
|
|
+ supervisionCode.setEntId(baseSupplierMst.getEleccode());
|
|
|
|
+ supervisionCode.setUploadShippId(baseSupplierMst.getSupplierId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ try {
|
|
|
|
+ supervisionCode.setScanDate(simpleDateFormat.parse(vo.getDate()));
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ result.add(supervisionCode);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理监管码对象
|
|
|
|
+ * @param list
|
|
|
|
+ * @param supervisionCodes
|
|
|
|
+ * @param userDTO
|
|
|
|
+ */
|
|
|
|
+ private void handleSupervisionCode(List<SupervisionCodeImportVo> list,List<SupervisionCode> supervisionCodes,UserDTO userDTO){
|
|
|
|
+
|
|
|
|
+ List<String> codes = list.stream().map(SupervisionCodeImportVo::getSupervisionCode).collect(Collectors.toList());
|
|
|
|
+ FieldSelector fs1 = FieldSelector.newInstance().include("supervisionCode");
|
|
|
|
+ Criteria criteria = Criteria.forClass(SupervisionCode.class);
|
|
|
|
+ criteria.restrictionBuilder()
|
|
|
|
+ .in("supervisionCode",codes.toArray());
|
|
|
|
+ criteria.buildRestriction();
|
|
|
|
+ List<SupervisionCode> extSupervisionCodeList = supervisionCodeMapper.findFieldsByCriteria(fs1,criteria);
|
|
|
|
+ if(extSupervisionCodeList != null && extSupervisionCodeList.size() > 0){
|
|
|
|
+ List<String> extCodes = new ArrayList<>();
|
|
|
|
+ for (SupervisionCode supervisionCode : extSupervisionCodeList) {
|
|
|
|
+ SupervisionCodeImportVo vo = list.stream().filter(item -> item.getSupervisionCode().equals(supervisionCode.getSupervisionCode()) && item.getSaveType().equals(supervisionCode.getSaveType())).findFirst().orElse(null);
|
|
|
|
+ if(vo != null){
|
|
|
|
+ extCodes.add(vo.getSupervisionCode());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(extCodes.size() > 0){
|
|
|
|
+ throw new BizException("监管码:"+JSON.toJSONString(extCodes)+"已上传,不能重复上传!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //查询仓
|
|
|
|
+ List<BaseWmsWarehouseMst> warehouseMstList = getWarehouseMstList(list);
|
|
|
|
+ //查询货主
|
|
|
|
+ Map<String, BaseCargoOwnerMst> cargoMap = getCargoMap(list);
|
|
|
|
+ //查询批次
|
|
|
|
+ List<WmsInvBatchNumbers> batchNumbers = getBatchNumbers(list);
|
|
|
|
+ //查询商品资料
|
|
|
|
+ List<BaseMtlItemMst> iitemMstList = getIitemMstList(list, cargoMap.get(list.get(0).getCargoOwnerCode()));
|
|
|
|
+ //查询出库单入库单
|
|
|
|
+ List<OmsDoBillHDO> omsDoBillHDOList = new ArrayList<>();
|
|
|
|
+ List<OmsAsnBillH> asnBillHList = new ArrayList<>();
|
|
|
|
+ getRefBills(list,warehouseMstList.get(0),omsDoBillHDOList,asnBillHList);
|
|
|
|
+ //查询出库单入库单明细
|
|
|
|
+ List<OmsDoBillDDO> omsDoBillDDOS = new ArrayList<>();
|
|
|
|
+ List<OmsAsnBillD> omsAsnBillDS = new ArrayList<>();
|
|
|
|
+ getrefBillDetails(omsDoBillHDOList,asnBillHList,omsDoBillDDOS,omsAsnBillDS);
|
|
|
|
+
|
|
|
|
+ //查询客户、供应商列表
|
|
|
|
+ List<BaseSupplierMst> supplierMsts = new ArrayList<>();
|
|
|
|
+ List<BaseCustomerMst> customerMsts = new ArrayList<>();
|
|
|
|
+ getShippers(omsDoBillHDOList,asnBillHList,supplierMsts,customerMsts);
|
|
|
|
+
|
|
|
|
+ supervisionCodes.addAll(convertSupervisionCodes(list,warehouseMstList,cargoMap,batchNumbers,iitemMstList,omsDoBillHDOList,asnBillHList,supplierMsts,customerMsts,omsDoBillDDOS,omsAsnBillDS,userDTO));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 异步线程
|
|
|
|
+ */
|
|
|
|
+ class handleSupervisionCodeRunable implements Callable {
|
|
|
|
+
|
|
|
|
+ private final CountDownLatch latch;
|
|
|
|
+ private List<SupervisionCodeImportVo> list;
|
|
|
|
+ private List<SupervisionCode> supervisionCodes;
|
|
|
|
+ private UserDTO userDTO;
|
|
|
|
+
|
|
|
|
+ public handleSupervisionCodeRunable(CountDownLatch latch, List<SupervisionCodeImportVo> list,List<SupervisionCode> supervisionCodes,UserDTO userDTO) {
|
|
|
|
+ this.latch = latch;
|
|
|
|
+ this.list = list;
|
|
|
|
+ this.supervisionCodes = supervisionCodes;
|
|
|
|
+ this.userDTO = userDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object call() throws Exception {
|
|
|
|
+ String msg = null;
|
|
|
|
+ try {
|
|
|
|
+ handleSupervisionCode(list,supervisionCodes,userDTO);
|
|
|
|
+ latch.countDown();
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg = e.getMessage();
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|