|  |  | @ -2,33 +2,48 @@ package com.glxp.api.service.inout.impl; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import cn.hutool.core.bean.BeanUtil; |  |  |  | import cn.hutool.core.bean.BeanUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import cn.hutool.core.collection.CollUtil; |  |  |  | import cn.hutool.core.collection.CollUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import cn.hutool.core.util.ReflectUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import cn.hutool.core.util.StrUtil; |  |  |  | import cn.hutool.core.util.StrUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import cn.hutool.json.JSONUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.github.pagehelper.PageHelper; |  |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.constant.Constant; |  |  |  | import com.glxp.api.constant.Constant; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.constant.ConstantStatus; |  |  |  | import com.glxp.api.constant.ConstantStatus; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.dao.auth.DeptDao; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.dao.auth.InvSubWarehouseDao; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.dao.basic.BasicBussinessTypeDao; |  |  |  | import com.glxp.api.dao.basic.BasicBussinessTypeDao; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.dao.basic.BasicCorpDao; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.dao.inout.IoOrderDao; |  |  |  | import com.glxp.api.dao.inout.IoOrderDao; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.entity.basic.BasicBussinessTypeEntity; |  |  |  | import com.glxp.api.entity.basic.BasicBussinessTypeEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.entity.basic.BasicCorpEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.entity.inout.IoOrderEntity; |  |  |  | import com.glxp.api.entity.inout.IoOrderEntity; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.req.inout.FilterOrderRequest; |  |  |  | import com.glxp.api.req.inout.FilterOrderRequest; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.req.inout.OrderEditRequest; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.res.inout.IoOrderResponse; |  |  |  | import com.glxp.api.res.inout.IoOrderResponse; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.res.inout.OrderNoResult; | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.glxp.api.service.inout.IoOrderService; |  |  |  | import com.glxp.api.service.inout.IoOrderService; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import com.glxp.api.util.DateUtil; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.springframework.stereotype.Service; |  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import javax.annotation.Resource; |  |  |  | import javax.annotation.Resource; | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.ArrayList; |  |  |  | import java.lang.reflect.Field; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Arrays; |  |  |  | import java.util.*; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.Collections; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import java.util.List; |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | @Slf4j | 
			
		
	
		
		
			
				
					
					|  |  |  | @Service |  |  |  | @Service | 
			
		
	
		
		
			
				
					
					|  |  |  | public class IoOrderServiceImpl implements IoOrderService { |  |  |  | public class IoOrderServiceImpl implements IoOrderService { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     @Resource |  |  |  |     @Resource | 
			
		
	
		
		
			
				
					
					|  |  |  |     private IoOrderDao orderDao; |  |  |  |     private IoOrderDao orderDao; | 
			
		
	
		
		
			
				
					
					|  |  |  |     @Resource |  |  |  |     @Resource | 
			
		
	
		
		
			
				
					
					|  |  |  |     BasicBussinessTypeDao basicBussinessTypeDao; |  |  |  |     private BasicBussinessTypeDao basicBussinessTypeDao; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Resource | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private BasicCorpDao basicCorpDao; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Resource | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private DeptDao deptDao; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Resource | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private InvSubWarehouseDao invSubWarehouseDao; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     @Override |  |  |  |     @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |     public List<IoOrderEntity> selectAll() { |  |  |  |     public List<IoOrderEntity> selectAll() { | 
			
		
	
	
		
		
			
				
					|  |  | @ -199,6 +214,132 @@ public class IoOrderServiceImpl implements IoOrderService { | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public List<IoOrderEntity> filterOrderTrace(String billNo) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         IoOrderEntity order = orderDao.selectOne(new QueryWrapper<IoOrderEntity>().eq("billNo", billNo)); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (null == order) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return Collections.emptyList(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //查询此单据关联的所有单据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return getAllOrder(order); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public List<IoOrderResponse> findResponse(List<IoOrderEntity> list) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (CollUtil.isEmpty(list)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return Collections.emptyList(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         List<IoOrderResponse> responseList = new ArrayList<>(list.size()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for (IoOrderEntity order : list) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             IoOrderResponse response = new IoOrderResponse(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             BeanUtil.copyProperties(order, response); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //查询单据类型名称
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             String busTypeName = basicBussinessTypeDao.selectNameByAction(order.getAction()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             response.setBillTypeName(busTypeName); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //查询往来单位名称
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             BasicCorpEntity corpEntity = basicCorpDao.selectByErpId(order.getFromCorp()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             response.setFromName(corpEntity.getName()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //查询部门名称
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             String deptName = deptDao.selectNameByCode(order.getDeptCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             response.setDeptName(deptName); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //查询仓库名称
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             String invName = invSubWarehouseDao.selectNameByCode(order.getInvCode()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             response.setInvName(invName); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             responseList.add(response); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return responseList; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     @Override | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     public void updateOrderInfo(OrderEditRequest orderEditRequest) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         log.info("批量更新单据信息,参数列表: {}", JSONUtil.toJsonStr(orderEditRequest)); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         IoOrderEntity order = new IoOrderEntity(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         order.setCreateTime(DateUtil.parseDate(orderEditRequest.getCreateTime())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         order.setAuditTime(DateUtil.parseDate(orderEditRequest.getAuditTime())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         order.setUpdateTime(new Date()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         orderDao.update(order, new QueryWrapper<IoOrderEntity>().in("billNo", orderEditRequest.getOrderIds())); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 查询此单据关联的所有单据 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param order 单据 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private List<IoOrderEntity> getAllOrder(IoOrderEntity order) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Set<String> billNos = new HashSet<>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         billNos.add(order.getBillNo()); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         getLinkedBillNo(order.getBillNo(), billNos); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //去除本单的单据号
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Iterator<String> iterator = billNos.iterator(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         while (iterator.hasNext()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (iterator.next().equals(order.getBillNo())) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 iterator.remove(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         ArrayList<IoOrderEntity> orders = new ArrayList<>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (CollUtil.isNotEmpty(orders)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             List<IoOrderEntity> list = orderDao.selectList(new QueryWrapper<IoOrderEntity>().in("billNo", billNos).orderByDesc("id")); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             orders.addAll(list); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         orders.add(order); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return orders; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 查询关联的单据号 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param billNo | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param billNos | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private void getLinkedBillNo(String billNo, Set<String> billNos) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         List<String> list = getOneBillNosByOrderId(billNo); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (!billNos.containsAll(list)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //找出不包含在原有集合中的单号,回调方法
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             String orderId = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             for (String item : list) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if (!billNos.contains(item)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     orderId = item; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     break; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             billNos.addAll(list); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //递归,继续查询未包含的单据号关联的单据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             getLinkedBillNo(orderId, billNos); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * 查询一条单据上关联的所有单据号 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @param billNo | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      * @return | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private List<String> getOneBillNosByOrderId(String billNo) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         List<String> billNos = new ArrayList<>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         OrderNoResult orderNoResult = orderDao.selectBillNos(billNo); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (null == orderNoResult) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             return billNos; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         Field[] fields = ReflectUtil.getFields(OrderNoResult.class); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for (Field field : fields) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             String value = String.valueOf(ReflectUtil.getFieldValue(orderNoResult, field)); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (StrUtil.isNotBlank(value) && !"null".equals(value)) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if (field.getName().equals("replicateNo")) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     String[] orderIds = value.split(","); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     billNos.addAll(Arrays.asList(orderIds)); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     billNos.add(value); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return billNos; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     boolean checkBusTypeSupplementOrder(IoOrderEntity orderEntity) { |  |  |  |     boolean checkBusTypeSupplementOrder(IoOrderEntity orderEntity) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         BasicBussinessTypeEntity supplementOrderType = basicBussinessTypeDao.selectOne(new QueryWrapper<BasicBussinessTypeEntity>().eq("action", orderEntity.getAction())); |  |  |  |         BasicBussinessTypeEntity supplementOrderType = basicBussinessTypeDao.selectOne(new QueryWrapper<BasicBussinessTypeEntity>().eq("action", orderEntity.getAction())); | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (supplementOrderType != null) { |  |  |  |         if (supplementOrderType != null) { | 
			
		
	
	
		
		
			
				
					|  |  | 
 |