|  |  |  | 
|---|
|  |  |  | package com.vincent.rsf.server.api.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.fasterxml.jackson.databind.ObjectMapper; | 
|---|
|  |  |  | import com.vincent.rsf.framework.common.R; | 
|---|
|  |  |  | import com.vincent.rsf.framework.exception.CoolException; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.OrderType; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.PurchaseItem; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.PurchaseItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.PurchaseService; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.erp.params.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.erp.params.dto.CheckDiffDto; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.erp.params.dto.TransferInfoDto; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.erp.params.dto.WkOrderDto; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.BaseParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.domain.PageParam; | 
|---|
|  |  |  | import com.vincent.rsf.server.common.utils.FieldsUtils; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.controller.dto.LocStockDto; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.enums.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.*; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.DictTypeCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.controller.params.OrderParams; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.entity.DictData; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.entity.DictType; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.entity.Fields; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.FieldsItemService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.DictDataService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.DictTypeService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.FieldsService; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.service.impl.DictDataServiceImpl; | 
|---|
|  |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
|---|
|  |  |  | import com.vincent.rsf.server.api.service.ReceiveMsgService; | 
|---|
|  |  |  | import com.vincent.rsf.server.manager.entity.Purchase; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private FieldsService fieldsService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private FieldsItemService fieldsItemService; | 
|---|
|  |  |  | private MatnrGroupService matnrGroupService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MatnrServiceImpl matnrService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderService asnOrderService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AsnOrderItemService asnOrderItemService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeliveryService deliveryService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeliveryItemService deliveryItemService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocService locService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WarehouseAreasService warehouseAreasService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private WarehouseService warehouseService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CompanysService companysService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TransferService transferService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TransferItemService transferItemService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LocReviseService locReviseService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ReviseLogService reviseLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ReviseLogItemService reviseLogItemService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CheckDiffService checkDiffService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CheckDiffItemService checkDiffItemService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DictDataService dictDataService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DictTypeService dictTypeService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/15 | 
|---|
|  |  |  | * @description: 保存PO/DO单据 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public boolean syncPurchasee(List<OrderParams> orders) { | 
|---|
|  |  |  | if (orders.isEmpty()) { | 
|---|
|  |  |  | throw new CoolException("单据内容不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | orders.forEach(ors -> { | 
|---|
|  |  |  | Purchase purchase = new Purchase(); | 
|---|
|  |  |  | BeanUtils.copyProperties(ors, purchase); | 
|---|
|  |  |  | String wkVal = SerialRuleUtils.generateRuleCode(SerialRuleCode.PURCHASE_CODE, purchase); | 
|---|
|  |  |  | purchase.setCode(wkVal) | 
|---|
|  |  |  | .setType(OrderType.ORDER_PURCHASE_IN.type); | 
|---|
|  |  |  | if (!purchaseService.save(purchase)) { | 
|---|
|  |  |  | throw new CoolException("采购单据保存失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (ors.getType().equals("po")) { | 
|---|
|  |  |  | Purchase purchase = new Purchase(); | 
|---|
|  |  |  | BeanUtils.copyProperties(ors, purchase); | 
|---|
|  |  |  | String wkVal = SerialRuleUtils.generateRuleCode(SerialRuleCode.PURCHASE_CODE, purchase); | 
|---|
|  |  |  | purchase.setCode(wkVal) | 
|---|
|  |  |  | .setType(OrderType.ORDER_IN.type); | 
|---|
|  |  |  | if (!purchaseService.save(purchase)) { | 
|---|
|  |  |  | throw new CoolException("采购单据保存失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询扩展字段是否存在 | 
|---|
|  |  |  | List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1)); | 
|---|
|  |  |  | //查询扩展字段是否存在 | 
|---|
|  |  |  | List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断子列表不为空 | 
|---|
|  |  |  | if (!ors.getChildren().isEmpty()) { | 
|---|
|  |  |  | ArrayList<PurchaseItem> list = new ArrayList<>(); | 
|---|
|  |  |  | ors.getChildren().forEach(orderItem -> { | 
|---|
|  |  |  | PurchaseItem item = new PurchaseItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(orderItem, item); | 
|---|
|  |  |  | //判断子列表不为空 | 
|---|
|  |  |  | if (!ors.getChildren().isEmpty()) { | 
|---|
|  |  |  | ArrayList<PurchaseItem> list = new ArrayList<>(); | 
|---|
|  |  |  | ors.getChildren().forEach(orderItem -> { | 
|---|
|  |  |  | PurchaseItem item = new PurchaseItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(orderItem, item); | 
|---|
|  |  |  | //                    if (!fields.isEmpty()) { | 
|---|
|  |  |  | //                        List<String> fieldValue = fields.stream().map(Fields::getFields).collect(Collectors.toList()); | 
|---|
|  |  |  | //                        fieldValue.forEach(value -> { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        }); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | item.setPurchaseId(purchase.getId()); | 
|---|
|  |  |  | list.add(item); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | if (!purchaseItemService.saveBatch(list)) { | 
|---|
|  |  |  | throw new CoolException("采购单明细保存失败!!"); | 
|---|
|  |  |  | item.setPurchaseId(purchase.getId()); | 
|---|
|  |  |  | list.add(item); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | if (!purchaseItemService.saveBatch(list)) { | 
|---|
|  |  |  | throw new CoolException("采购单明细保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Delivery delivery = new Delivery(); | 
|---|
|  |  |  | BeanUtils.copyProperties(ors, delivery); | 
|---|
|  |  |  | String wkVal = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_DELIVERY_RULE_CODE, delivery); | 
|---|
|  |  |  | delivery.setCode(wkVal) | 
|---|
|  |  |  | .setType(OrderType.ORDER_OUT.type); | 
|---|
|  |  |  | if (!deliveryService.save(delivery)) { | 
|---|
|  |  |  | throw new CoolException("采购单据保存失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //查询扩展字段是否存在 | 
|---|
|  |  |  | List<Fields> fields = fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //判断子列表不为空 | 
|---|
|  |  |  | if (!ors.getChildren().isEmpty()) { | 
|---|
|  |  |  | ArrayList<DeliveryItem> list = new ArrayList<>(); | 
|---|
|  |  |  | ors.getChildren().forEach(orderItem -> { | 
|---|
|  |  |  | DeliveryItem item = new DeliveryItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(orderItem, item); | 
|---|
|  |  |  | //                    if (!fields.isEmpty()) { | 
|---|
|  |  |  | //                        List<String> fieldValue = fields.stream().map(Fields::getFields).collect(Collectors.toList()); | 
|---|
|  |  |  | //                        fieldValue.forEach(value -> { | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        }); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | item.setDeliveryId(delivery.getId()); | 
|---|
|  |  |  | list.add(item); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | if (!deliveryItemService.saveBatch(list)) { | 
|---|
|  |  |  | throw new CoolException("采购单明细保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 物料信息同步 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param matnrs | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public void syncMatnrs(List<BaseMatParms> matnrs) { | 
|---|
|  |  |  | List<Matnr> syncMatnrs = new ArrayList<>(); | 
|---|
|  |  |  | if (!matnrs.isEmpty()) { | 
|---|
|  |  |  | matnrs.forEach(matnr -> { | 
|---|
|  |  |  | Matnr mat = new Matnr(); | 
|---|
|  |  |  | if (Objects.isNull(matnr.getMatnr())) { | 
|---|
|  |  |  | throw new RuntimeException("物料编码不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BeanUtils.copyProperties(matnr, mat); | 
|---|
|  |  |  | mat.setCode(matnr.getMatnr()).setName(matnr.getMaktx()); | 
|---|
|  |  |  | if (!Objects.isNull(matnr.getGroupName())) { | 
|---|
|  |  |  | MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getName, matnr.getGroupName()), false); | 
|---|
|  |  |  | if (Objects.isNull(matnrGroup)) { | 
|---|
|  |  |  | mat.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | syncMatnrs.add(mat); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!matnrService.saveOrUpdateBatch(syncMatnrs)) { | 
|---|
|  |  |  | throw new CoolException("物料信息保存成功!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/15 | 
|---|
|  |  |  | * @description: 订单查询 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R queryOrderStatus(QueryOrderParam queryParams) { | 
|---|
|  |  |  | WkOrder wkOrders = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>() | 
|---|
|  |  |  | .eq(WkOrder::getCode, queryParams.getOrderNo()) | 
|---|
|  |  |  | .eq(StringUtils.isNotBlank(queryParams.getType()), WkOrder::getType, queryParams.getType())); | 
|---|
|  |  |  | if (Objects.isNull(wkOrders)) { | 
|---|
|  |  |  | throw new CoolException("单据不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, wkOrders.getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WkOrderDto wkorderDto = new WkOrderDto(); | 
|---|
|  |  |  | wkorderDto.setOrder(wkOrders).setOrderItems(orderItems); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(wkorderDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/15 | 
|---|
|  |  |  | * @description: 查询库位信息 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R syncLocsDetl(PageParam<Loc, BaseParam> pageParam, QueryWrapper<Loc> wrapper) { | 
|---|
|  |  |  | Page<Object> page = new Page<>(); | 
|---|
|  |  |  | page.setCurrent(pageParam.getCurrent()).setSize(pageParam.getSize()); | 
|---|
|  |  |  | IPage<LocStockDto> locStocks = locService.getLocDetls(page); | 
|---|
|  |  |  | return R.ok().add(locStocks); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/18 | 
|---|
|  |  |  | * @description: 库位同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncLocs(List<SyncLocsParams> locs) { | 
|---|
|  |  |  | List<Loc> syncLocs = new ArrayList<>(); | 
|---|
|  |  |  | locs.forEach(loc -> { | 
|---|
|  |  |  | Loc loc1 = new Loc(); | 
|---|
|  |  |  | BeanUtils.copyProperties(loc, loc1); | 
|---|
|  |  |  | loc1.setCode(loc.getLocCode()).setId(null); | 
|---|
|  |  |  | syncLocs.add(loc1); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | if (!locService.saveBatch(syncLocs)) { | 
|---|
|  |  |  | throw new CoolException("库位同步失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/18 | 
|---|
|  |  |  | * @description: 物料分组信息同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncMatGroups(List<SyncMatGroupsParams> matGroupsParams) { | 
|---|
|  |  |  | List<MatnrGroup> syncMatGroups = new ArrayList<>(); | 
|---|
|  |  |  | matGroupsParams.forEach(matGroupsParam -> { | 
|---|
|  |  |  | MatnrGroup matnrGroup = new MatnrGroup(); | 
|---|
|  |  |  | BeanUtils.copyProperties(matGroupsParam, matnrGroup); | 
|---|
|  |  |  | if (Objects.isNull(matGroupsParam.getCode())) { | 
|---|
|  |  |  | throw new CoolException("物料分组编码不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(matGroupsParam.getName())) { | 
|---|
|  |  |  | throw new CoolException("分组名称不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (Objects.isNull(matGroupsParam.getParCode())) { | 
|---|
|  |  |  | throw new CoolException("上级物料分组编码不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | syncMatGroups.add(matnrGroup); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | if (!matnrGroupService.saveBatch(syncMatGroups)) { | 
|---|
|  |  |  | throw new CoolException("物料分组保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/18 | 
|---|
|  |  |  | * @description: 库区信息同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncWarehouseAreas(List<LocAreasParams> areasParams) { | 
|---|
|  |  |  | areasParams.forEach(param -> { | 
|---|
|  |  |  | WarehouseAreas locArea = new WarehouseAreas(); | 
|---|
|  |  |  | BeanUtils.copyProperties(param, locArea); | 
|---|
|  |  |  | WarehouseAreas warehouseAreas = warehouseAreasService | 
|---|
|  |  |  | .getOne(new LambdaQueryWrapper<WarehouseAreas>() | 
|---|
|  |  |  | .eq(WarehouseAreas::getName, param.getName())); | 
|---|
|  |  |  | if (!Objects.isNull(warehouseAreas)) { | 
|---|
|  |  |  | locArea.setWarehouseId(warehouseAreas.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | locArea.setName(param.getName()) | 
|---|
|  |  |  | .setCode(param.getCode()) | 
|---|
|  |  |  | .setId(null); | 
|---|
|  |  |  | if (!warehouseAreasService.save(locArea)) { | 
|---|
|  |  |  | throw new CoolException("库区保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/18 | 
|---|
|  |  |  | * @description: 仓库同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncWarehouse(List<WarehouseParams> warehouses) { | 
|---|
|  |  |  | warehouses.forEach(warehouse -> { | 
|---|
|  |  |  | Warehouse ware = new Warehouse(); | 
|---|
|  |  |  | BeanUtils.copyProperties(warehouse, ware); | 
|---|
|  |  |  | ware.setId(null); | 
|---|
|  |  |  | if (!warehouseService.save(ware)) { | 
|---|
|  |  |  | throw new CoolException("仓库同步保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/19 | 
|---|
|  |  |  | * @description: 同步企业信息 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncCompanies(List<CompaniesParam> companyParams) { | 
|---|
|  |  |  | companyParams.forEach(param -> { | 
|---|
|  |  |  | Companys companys = new Companys(); | 
|---|
|  |  |  | BeanUtils.copyProperties(param, companys); | 
|---|
|  |  |  | if (Objects.isNull(companys.getCode())) { | 
|---|
|  |  |  | throw new CoolException("企业编码不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Companys one = companysService.getOne(new LambdaQueryWrapper<Companys>().eq(Companys::getName, param.getName())); | 
|---|
|  |  |  | if (Objects.isNull(one)) { | 
|---|
|  |  |  | String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_COMPANYS_CODE, null); | 
|---|
|  |  |  | companys.setCode(ruleCode); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException(one.getName() + ",企业名重复!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | companys.setType(CompanysType.getCustomVal(param.getType())) | 
|---|
|  |  |  | .setId(null); | 
|---|
|  |  |  | if (!companysService.save(companys)) { | 
|---|
|  |  |  | throw new CoolException("企业保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/26 | 
|---|
|  |  |  | * @description: 单据同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncCheckOrder(List<SyncOrderParams> syncOrders, Long loginUserId) { | 
|---|
|  |  |  | if (!syncOrders.isEmpty()) { | 
|---|
|  |  |  | syncOrders.forEach(syncOrder -> { | 
|---|
|  |  |  | WkOrder wkOrder = new WkOrder(); | 
|---|
|  |  |  | DictData one = dictDataService.getOne(new LambdaQueryWrapper<DictData>().eq(DictData::getDictTypeCode, DictTypeCode.DICT_SYS_BUSINESS_TYPE) | 
|---|
|  |  |  | .eq(DictData::getValue, syncOrder.getWkType()), false); | 
|---|
|  |  |  | if (Objects.isNull(one)) { | 
|---|
|  |  |  | throw new CoolException("单据:" + syncOrder.getOrderNo() + ", 业务类型不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WkOrder order = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>() | 
|---|
|  |  |  | .eq(!Objects.isNull(syncOrder.getOrderId()), WkOrder::getPoId, syncOrder.getOrderId()) | 
|---|
|  |  |  | .eq(WkOrder::getPoCode, syncOrder.getOrderNo())); | 
|---|
|  |  |  | if (!Objects.isNull(order)) { | 
|---|
|  |  |  | if (order.getExceStatus().equals(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val) || | 
|---|
|  |  |  | order.getExceStatus().equals(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)) { | 
|---|
|  |  |  | /**删除单据明细*/ | 
|---|
|  |  |  | asnOrderItemService.remove(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId())); | 
|---|
|  |  |  | /**删除主单*/ | 
|---|
|  |  |  | asnOrderService.removeById(order.getId()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | throw new CoolException("单据已添加,不可执行修改或添加操作!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String rule = SerialRuleCode.SYS_ASN_ORDER; | 
|---|
|  |  |  | if (syncOrder.getType().equals(OrderType.ORDER_OUT.type)) { | 
|---|
|  |  |  | rule = SerialRuleCode.SYS_OUT_STOCK_CODE; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String ruleCode = SerialRuleUtils.generateRuleCode(rule, null); | 
|---|
|  |  |  | wkOrder.setType(syncOrder.getType()) | 
|---|
|  |  |  | .setWkType(one.getValue()) | 
|---|
|  |  |  | .setAnfme(syncOrder.getAnfme()) | 
|---|
|  |  |  | .setPoCode(syncOrder.getOrderNo()) | 
|---|
|  |  |  | .setWorkQty(0.0) | 
|---|
|  |  |  | .setQty(0.0) | 
|---|
|  |  |  | .setPoId(syncOrder.getOrderId()) | 
|---|
|  |  |  | .setCode(ruleCode) | 
|---|
|  |  |  | .setArrTime(syncOrder.getArrTime()) | 
|---|
|  |  |  | .setId(null) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateBy(loginUserId); | 
|---|
|  |  |  | if (!asnOrderService.save(wkOrder)) { | 
|---|
|  |  |  | throw new CoolException("单据保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | syncOrder.getOrderItems().forEach(orderItem -> { | 
|---|
|  |  |  | Map<String, Object> map = new ObjectMapper().convertValue(orderItem, Map.class); | 
|---|
|  |  |  | map.put("orderId", wkOrder.getId()); | 
|---|
|  |  |  | map.put("poId", wkOrder.getPoId()); | 
|---|
|  |  |  | map.put("poCode", wkOrder.getPoCode()); | 
|---|
|  |  |  | map.put("order_code", wkOrder.getCode()); | 
|---|
|  |  |  | map.put("matnrCode", orderItem.getMatnr()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!asnOrderItemService.fieldsSave(map, loginUserId)) { | 
|---|
|  |  |  | throw new CoolException("明细保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() | 
|---|
|  |  |  | .eq(WkOrderItem::getOrderId, wkOrder.getId())); | 
|---|
|  |  |  | double sum = orderItems.stream().mapToDouble(WkOrderItem::getAnfme).sum(); | 
|---|
|  |  |  | wkOrder.setAnfme(sum); | 
|---|
|  |  |  | if (!asnOrderService.updateById(wkOrder)) { | 
|---|
|  |  |  | throw new CoolException("计划收货数量修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/19 | 
|---|
|  |  |  | * @description: 调拔单据同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncTransfer(SyncTransferParams transferParams, Long loginUserId) { | 
|---|
|  |  |  | Transfer transfer = new Transfer(); | 
|---|
|  |  |  | WarehouseAreas warehouseAreas = warehouseAreasService | 
|---|
|  |  |  | .getOne(new LambdaQueryWrapper<WarehouseAreas>() | 
|---|
|  |  |  | .eq(WarehouseAreas::getName, transferParams.getOrgAreaName())); | 
|---|
|  |  |  | if (Objects.isNull(warehouseAreas)) { | 
|---|
|  |  |  | throw new CoolException("原库区不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | WarehouseAreas warehouseAreas1 = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>() | 
|---|
|  |  |  | .eq(WarehouseAreas::getName, transferParams.getTarAreaName())); | 
|---|
|  |  |  | if (Objects.isNull(warehouseAreas1)) { | 
|---|
|  |  |  | throw new CoolException("目标库区不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | transfer.setOrgAreaName(warehouseAreas.getName()) | 
|---|
|  |  |  | .setOrgAreaId(warehouseAreas.getId()) | 
|---|
|  |  |  | .setOrgWareName(warehouseAreas.getWarehouseId$()) | 
|---|
|  |  |  | .setOrgWareId(warehouseAreas.getWarehouseId()) | 
|---|
|  |  |  | .setTarWareName(warehouseAreas1.getWarehouseId$()) | 
|---|
|  |  |  | .setTarAreaName(warehouseAreas1.getName()) | 
|---|
|  |  |  | .setTarAreaId(warehouseAreas1.getId()) | 
|---|
|  |  |  | .setTarWareName(warehouseAreas1.getWarehouseId$()) | 
|---|
|  |  |  | .setTarWareId(warehouseAreas1.getWarehouseId()) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | .setCode(SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TRANSFER_ORDER_CODE, null)) | 
|---|
|  |  |  | .setSource(OrderSourceType.ORDER_SOURCE_TYPE_ERP.val); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!transferService.save(transfer)) { | 
|---|
|  |  |  | throw new CoolException("调拔单据保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | transferParams.getItems().forEach(item -> { | 
|---|
|  |  |  | TransferItem transferItem = new TransferItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(item, transferItem); | 
|---|
|  |  |  | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, item.getMatnrCode())); | 
|---|
|  |  |  | if (Objects.isNull(matnr)) { | 
|---|
|  |  |  | throw new CoolException("物料不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | transferItem.setMatnrId(matnr.getId()) | 
|---|
|  |  |  | .setTransferId(transfer.getId()) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setTransferCode(transfer.getCode()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!transferItemService.save(transferItem)) { | 
|---|
|  |  |  | throw new CoolException("调拔单明细保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/20 | 
|---|
|  |  |  | * @description: 库存调整单同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncLocRevise(SyncLocReviseParams reviseParams, Long loginUserId) { | 
|---|
|  |  |  | LocRevise locRevise = new LocRevise(); | 
|---|
|  |  |  | if (Objects.isNull(reviseParams.getAreaName())) { | 
|---|
|  |  |  | throw new CoolException("库区不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WarehouseAreas warehouseAreas = warehouseAreasService | 
|---|
|  |  |  | .getOne(new LambdaQueryWrapper<WarehouseAreas>() | 
|---|
|  |  |  | .eq(WarehouseAreas::getName, reviseParams.getAreaName())); | 
|---|
|  |  |  | if (Objects.isNull(warehouseAreas)) { | 
|---|
|  |  |  | throw new CoolException("库区不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locRevise.setAreaName(warehouseAreas.getName()) | 
|---|
|  |  |  | .setType(LocReviseType.getLocRevise(reviseParams.getType())) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setAreaId(warehouseAreas.getId()); | 
|---|
|  |  |  | locRevise.setCode(SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_LOC_REVISE_CODE, null)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locReviseService.save(locRevise)) { | 
|---|
|  |  |  | throw new CoolException("库存调整单保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | reviseParams.getReviseItems().forEach(revise -> { | 
|---|
|  |  |  | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, revise.getLocCode())); | 
|---|
|  |  |  | ReviseLog reviseLog = new ReviseLog(); | 
|---|
|  |  |  | BeanUtils.copyProperties(loc, reviseLog); | 
|---|
|  |  |  | reviseLog.setReviseId(locRevise.getId()) | 
|---|
|  |  |  | .setLocCode(loc.getCode()) | 
|---|
|  |  |  | .setType(Integer.parseInt(loc.getType())) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setReviseCode(locRevise.getCode()); | 
|---|
|  |  |  | if (!reviseLogService.save(reviseLog)) { | 
|---|
|  |  |  | throw new CoolException("库存调整单不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | revise.getItems().forEach(reviseItem -> { | 
|---|
|  |  |  | ReviseLogItem logItem = new ReviseLogItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(reviseItem, logItem); | 
|---|
|  |  |  | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, reviseItem.getMatnr())); | 
|---|
|  |  |  | if (Objects.isNull(matnr)) { | 
|---|
|  |  |  | throw new CoolException("物料不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | logItem.setLocId(loc.getId()) | 
|---|
|  |  |  | .setLocCode(loc.getCode()) | 
|---|
|  |  |  | .setId(null) | 
|---|
|  |  |  | .setMaktx(matnr.getName()) | 
|---|
|  |  |  | .setMatnrCode(matnr.getCode()) | 
|---|
|  |  |  | .setMatnrId(matnr.getId()) | 
|---|
|  |  |  | .setReviseLogId(reviseLog.getId()) | 
|---|
|  |  |  | .setCreateBy(loginUserId) | 
|---|
|  |  |  | .setUpdateBy(loginUserId) | 
|---|
|  |  |  | .setCreateTime(new Date()) | 
|---|
|  |  |  | .setUpdateTime(new Date()) | 
|---|
|  |  |  | .setReviseQty(reviseItem.getAnfme()); | 
|---|
|  |  |  | if (!reviseLogItemService.save(logItem)) { | 
|---|
|  |  |  | throw new CoolException("调整库存明细保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/20 | 
|---|
|  |  |  | * @description: 单据修改--收货通知单/出库单/盘点单 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncOrderUpdate(List<SyncOrderParams> orders) { | 
|---|
|  |  |  | orders.forEach(order -> { | 
|---|
|  |  |  | List<Short> list = Arrays.asList(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val, | 
|---|
|  |  |  | AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val); | 
|---|
|  |  |  | WkOrder wkOrder = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>() | 
|---|
|  |  |  | .in(WkOrder::getExceStatus, list) | 
|---|
|  |  |  | .eq(WkOrder::getCode, order.getOrderNo())); | 
|---|
|  |  |  | if (Objects.isNull(wkOrder)) { | 
|---|
|  |  |  | throw new CoolException("请确认单据:" + order.getOrderNo() + "是否已经执行或是否同步!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | order.getOrderItems().forEach(orderItem -> { | 
|---|
|  |  |  | WkOrderItem wkOrderItem = asnOrderItemService.getOne(new LambdaUpdateWrapper<WkOrderItem>() | 
|---|
|  |  |  | .eq(WkOrderItem::getMatnrCode, orderItem.getMatnr()) | 
|---|
|  |  |  | .eq(StringUtils.isNotEmpty(orderItem.getBatch()), WkOrderItem::getSplrBatch, orderItem.getBatch()) | 
|---|
|  |  |  | .eq(WkOrderItem::getOrderCode, wkOrder.getCode())); | 
|---|
|  |  |  | if (!Objects.isNull(wkOrderItem)) { | 
|---|
|  |  |  | if (!asnOrderItemService.update(new LambdaUpdateWrapper<WkOrderItem>() | 
|---|
|  |  |  | .eq(WkOrderItem::getOrderCode, wkOrder.getCode()) | 
|---|
|  |  |  | .eq(WkOrderItem::getMatnrCode, orderItem.getMatnr()) | 
|---|
|  |  |  | .eq(StringUtils.isNotEmpty(orderItem.getBatch()), WkOrderItem::getSplrBatch, orderItem.getBatch()) | 
|---|
|  |  |  | .eq(StringUtils.isNotEmpty(orderItem.getPlatItemId()), WkOrderItem::getPlatItemId, orderItem.getPlatItemId()) | 
|---|
|  |  |  | .set(WkOrderItem::getAnfme, orderItem.getAnfme()))) { | 
|---|
|  |  |  | throw new CoolException("单据修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | WkOrderItem wkOrderItem1 = new WkOrderItem(); | 
|---|
|  |  |  | BeanUtils.copyProperties(orderItem, wkOrderItem1); | 
|---|
|  |  |  | wkOrderItem1.setOrderCode(wkOrder.getCode()) | 
|---|
|  |  |  | .setOrderId(wkOrder.getId()); | 
|---|
|  |  |  | if (!asnOrderItemService.save(wkOrderItem1)) { | 
|---|
|  |  |  | throw new CoolException("单据保存失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | wkOrder.setAnfme(order.getAnfme()); | 
|---|
|  |  |  | if (!asnOrderService.updateById(wkOrder)) { | 
|---|
|  |  |  | throw new CoolException("主单据修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/21 | 
|---|
|  |  |  | * @description: 删除单据 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncOrderDelete(List<SyncOrderParams> orders) { | 
|---|
|  |  |  | orders.forEach(order -> { | 
|---|
|  |  |  | List<Short> list = Arrays.asList(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val, | 
|---|
|  |  |  | AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val); | 
|---|
|  |  |  | WkOrder wkOrder = asnOrderService.getOne(new LambdaQueryWrapper<WkOrder>() | 
|---|
|  |  |  | .in(WkOrder::getExceStatus, list) | 
|---|
|  |  |  | .eq(WkOrder::getCode, order.getOrderNo())); | 
|---|
|  |  |  | if (Objects.isNull(wkOrder)) { | 
|---|
|  |  |  | throw new CoolException("订单:" + wkOrder.getCode() + ",当前状态,不可执行删除操作!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | order.getOrderItems().forEach(orderItem -> { | 
|---|
|  |  |  | if (!asnOrderItemService.remove(new LambdaQueryWrapper<WkOrderItem>() | 
|---|
|  |  |  | .eq(WkOrderItem::getMatnrCode, orderItem.getMatnr()) | 
|---|
|  |  |  | .eq(StringUtils.isNotEmpty(orderItem.getBatch()), WkOrderItem::getSplrBatch, orderItem.getBatch()) | 
|---|
|  |  |  | .eq(StringUtils.isNotEmpty(orderItem.getPlatItemId()), WkOrderItem::getPlatItemId, orderItem.getPlatItemId()) | 
|---|
|  |  |  | .eq(WkOrderItem::getOrderCode, wkOrder.getCode()))) { | 
|---|
|  |  |  | throw new CoolException("单据明细删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, wkOrder.getId())); | 
|---|
|  |  |  | if (orderItems.isEmpty()) { | 
|---|
|  |  |  | if (!asnOrderService.removeById(wkOrder.getId())) { | 
|---|
|  |  |  | throw new CoolException("单据删除失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Double sum = orderItems.stream().mapToDouble(WkOrderItem::getAnfme).sum(); | 
|---|
|  |  |  | if (!asnOrderService.update(new LambdaUpdateWrapper<WkOrder>() | 
|---|
|  |  |  | .eq(WkOrder::getId, wkOrder.getId()) | 
|---|
|  |  |  | .set(WkOrder::getAnfme, sum))) { | 
|---|
|  |  |  | throw new CoolException("主单数量修改失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/21 | 
|---|
|  |  |  | * @description: 调拔单明细查询 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public R queryTransfer(QueryOrderParam queryParams) { | 
|---|
|  |  |  | Transfer transfer = transferService.getOne(new LambdaQueryWrapper<Transfer>() | 
|---|
|  |  |  | .in(Transfer::getCode, queryParams.getOrderNo())); | 
|---|
|  |  |  | if (Objects.isNull(transfer)) { | 
|---|
|  |  |  | throw new CoolException("单据不存在!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<TransferItem> orderItems = transferItemService.list(new LambdaQueryWrapper<TransferItem>() | 
|---|
|  |  |  | .eq(TransferItem::getTransferId, transfer.getId())); | 
|---|
|  |  |  | TransferInfoDto wkorderDto = new TransferInfoDto(); | 
|---|
|  |  |  | wkorderDto.setTransfer(transfer).setItems(orderItems); | 
|---|
|  |  |  | return R.ok().add(wkorderDto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @author Ryan | 
|---|
|  |  |  | * @date 2025/8/22 | 
|---|
|  |  |  | * @description: 盘点差异单同步 | 
|---|
|  |  |  | * @version 1.0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(timeout = 60, rollbackFor = Exception.class) | 
|---|
|  |  |  | public R syncCheckDiffs(SyncCheckDiffParams syncParams) { | 
|---|
|  |  |  | List<CheckDiff> diffs = checkDiffService.list(new LambdaQueryWrapper<CheckDiff>() | 
|---|
|  |  |  | .eq(CheckDiff::getExceStatus, CheckDiffExceStatus.CHECK_DIFF_EXCE_STATUS_END.val) | 
|---|
|  |  |  | .in(CheckDiff::getOrderCode, syncParams.getDiffCode())); | 
|---|
|  |  |  | if (diffs.isEmpty()) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<CheckDiffDto> dtos = new ArrayList<>(); | 
|---|
|  |  |  | diffs.forEach(check -> { | 
|---|
|  |  |  | CheckDiffDto checkDto = new CheckDiffDto(); | 
|---|
|  |  |  | CheckDiff checkDiff = new CheckDiff(); | 
|---|
|  |  |  | BeanUtils.copyProperties(check, checkDiff); | 
|---|
|  |  |  | List<CheckDiffItem> items = checkDiffItemService.list(new LambdaQueryWrapper<CheckDiffItem>() | 
|---|
|  |  |  | .eq(CheckDiffItem::getCheckId, check.getId())); | 
|---|
|  |  |  | checkDto.setItems(items) | 
|---|
|  |  |  | .setCheckDiff(checkDiff); | 
|---|
|  |  |  | dtos.add(checkDto); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(dtos); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 基础物料信息变更 | 
|---|
|  |  |  | * @param baseMatParms | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public R matUpdate(BaseMatParms baseMatParms) { | 
|---|
|  |  |  | if (StringUtils.isBlank(baseMatParms.getMatnr())) { | 
|---|
|  |  |  | throw new CoolException("物料编码不能为空!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Matnr matnr = matnrService.getOne(new LambdaQueryWrapper<Matnr>().eq(Matnr::getCode, baseMatParms.getMatnr())); | 
|---|
|  |  |  | if (Objects.isNull(matnr)) { | 
|---|
|  |  |  | BeanUtils.copyProperties(baseMatParms, matnr); | 
|---|
|  |  |  | matnr.setCode(baseMatParms.getMatnr()); | 
|---|
|  |  |  | matnr.setName(baseMatParms.getMaktx()); | 
|---|
|  |  |  | if (!Objects.isNull(baseMatParms.getGroupName())) { | 
|---|
|  |  |  | MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>() | 
|---|
|  |  |  | .eq(MatnrGroup::getName, baseMatParms.getGroupName())); | 
|---|
|  |  |  | if (Objects.isNull(matnrGroup)) { | 
|---|
|  |  |  | matnr.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!matnrService.save(matnr)) { | 
|---|
|  |  |  | throw new CoolException("物料新增失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (!Objects.isNull(baseMatParms.getGroupName())) { | 
|---|
|  |  |  | MatnrGroup matnrGroup = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>() | 
|---|
|  |  |  | .eq(MatnrGroup::getName, baseMatParms.getGroupName())); | 
|---|
|  |  |  | if (!Objects.isNull(matnrGroup)) { | 
|---|
|  |  |  | matnr.setGroupCode(matnrGroup.getCode()).setGroupId(matnrGroup.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | matnr.setName(baseMatParms.getMaktx()) | 
|---|
|  |  |  | .setColor(baseMatParms.getColor()) | 
|---|
|  |  |  | .setModel(baseMatParms.getModel()) | 
|---|
|  |  |  | .setSpec(baseMatParms.getSpec()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!matnrService.updateById(matnr)) { | 
|---|
|  |  |  | throw new CoolException("物料更新失败!!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|