| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.api.controller.params.BaseMatParms; |
| | | import com.vincent.rsf.server.api.controller.params.QueryOrderParam; |
| | | import com.vincent.rsf.server.api.controller.params.WkOrderDto; |
| | | import com.vincent.rsf.server.api.controller.erp.params.*; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.manager.controller.dto.LocStockDto; |
| | | import com.vincent.rsf.server.manager.entity.*; |
| | | import com.vincent.rsf.server.manager.enums.CompanysType; |
| | | import com.vincent.rsf.server.manager.enums.OrderSourceType; |
| | | import com.vincent.rsf.server.manager.enums.OrderType; |
| | | import com.vincent.rsf.server.manager.enums.OrderWorkType; |
| | | import com.vincent.rsf.server.manager.service.*; |
| | | import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl; |
| | | import com.vincent.rsf.server.manager.service.impl.TransferItemServiceImpl; |
| | | import com.vincent.rsf.server.system.constant.SerialRuleCode; |
| | | import com.vincent.rsf.server.api.controller.params.OrderParams; |
| | | import com.vincent.rsf.server.system.entity.Fields; |
| | | import com.vincent.rsf.server.system.service.FieldsItemService; |
| | | import com.vincent.rsf.server.system.service.FieldsService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | private LocService locService; |
| | | @Autowired |
| | | private LocItemService locItemService; |
| | | @Autowired |
| | | private WarehouseAreasService warehouseAreasService; |
| | | @Autowired |
| | | private WarehouseService warehouseService; |
| | | @Autowired |
| | | private CompanysService companysService; |
| | | @Autowired |
| | | private TransferService transferService; |
| | | @Autowired |
| | | private TransferItemService transferItemService; |
| | | |
| | | |
| | | /** |
| | | * @author Ryan |
| | |
| | | /** |
| | | * @author Ryan |
| | | * @date 2025/8/15 |
| | | * @description: 同步库位信息 |
| | | * @description: 查询库位信息 |
| | | * @version 1.0 |
| | | */ |
| | | @Override |
| | |
| | | Page<Object> page = new Page<>(); |
| | | page.setCurrent(pageParam.getCurrent()).setSize(pageParam.getSize()); |
| | | IPage<LocStockDto> locStocks = locService.getLocDetls(page); |
| | | return null; |
| | | 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(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional(timeout = 60, rollbackFor = Exception.class) |
| | | public R syncCheckOrder(SyncOrderParams syncOrders, Long loginUserId) { |
| | | List<SyncOrdersItem> ordersItems = syncOrders.getItems(); |
| | | Map<String, List<SyncOrdersItem>> listMap = ordersItems.stream().collect(Collectors.groupingBy(SyncOrdersItem::getOrderCode)); |
| | | listMap.keySet().forEach(orderCode -> { |
| | | WkOrder wkOrder = new WkOrder(); |
| | | String ruleCode = null; |
| | | if (syncOrders.getType().equals(OrderType.ORDER_CHECK.type)) { |
| | | ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_CHECK_RULE_CODE, null); |
| | | } else if (syncOrders.getType().equals(OrderType.ORDER_IN.type)) { |
| | | ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_ASN_ORDER, null); |
| | | } else if (syncOrders.getType().equals(OrderType.ORDER_OUT.type)) { |
| | | ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_OUT_STOCK_CODE, null); |
| | | } else if (syncOrders.getType().equals(OrderType.ORDER_REVISE.type)) { |
| | | ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_LOC_REVISE_CODE, null); |
| | | } else if (syncOrders.getType().equals(OrderType.ORDER_TRANSFER.type)) { |
| | | ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TRANSFER_ORDER_CODE, null); |
| | | } |
| | | |
| | | SyncOrdersItem ordersItem = listMap.get(orderCode).stream().findFirst().get(); |
| | | Double anfmes = listMap.get(orderCode).stream().mapToDouble(SyncOrdersItem::getAnfme).sum(); |
| | | wkOrder.setType(syncOrders.getType()) |
| | | .setWkType(OrderWorkType.getWorkType(ordersItem.getWkType())) |
| | | .setAnfme(anfmes) |
| | | .setPoCode(orderCode) |
| | | .setPoId(ordersItem.getId()) |
| | | .setCode(ruleCode) |
| | | .setId(null) |
| | | .setCreateTime(new Date()) |
| | | .setUpdateTime(new Date()) |
| | | .setCreateBy(loginUserId) |
| | | .setUpdateBy(loginUserId); |
| | | |
| | | if (!asnOrderService.save(wkOrder)) { |
| | | throw new CoolException("单据保存失败!!"); |
| | | } |
| | | |
| | | listMap.get(orderCode).forEach(order -> { |
| | | WkOrderItem wkOrderItem = new WkOrderItem(); |
| | | BeanUtils.copyProperties(order, wkOrderItem); |
| | | wkOrderItem.setOrderCode(wkOrder.getCode()) |
| | | .setOrderId(wkOrder.getId()) |
| | | .setId(null); |
| | | |
| | | if (!asnOrderItemService.save(wkOrderItem)) { |
| | | 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) { |
| | | Transfer transfer = new Transfer(); |
| | | WarehouseAreas warehouseAreas = warehouseAreasService |
| | | .getOne(new LambdaQueryWrapper<WarehouseAreas>() |
| | | .eq(WarehouseAreas::getName, transfer.getOrgAreaName())); |
| | | if (Objects.isNull(warehouseAreas)) { |
| | | throw new CoolException("原库区不存在!!"); |
| | | } |
| | | |
| | | WarehouseAreas warehouseAreas1 = warehouseAreasService.getOne(new LambdaQueryWrapper<WarehouseAreas>() |
| | | .eq(WarehouseAreas::getName, transfer.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()) |
| | | .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()) |
| | | .setTransferCode(transfer.getCode()); |
| | | |
| | | if (!transferItemService.save(transferItem)) { |
| | | throw new CoolException("调拔单明细保存失败!!"); |
| | | } |
| | | }); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |