|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
|---|
|  |  |  | import com.zy.asrs.common.domain.dto.DetlDto; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.dto.OrderListDto; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.param.CreateMatParam; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakInParam; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.param.GenerateOrderPakOutParam; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.param.OrderListParam; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.entity.param.*; | 
|---|
|  |  |  | import com.zy.asrs.common.openapi.service.ApiService; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.common.wms.service.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!orderService.save(order)) { | 
|---|
|  |  |  | throw new CoolException("生成单据主档失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 单据明细档 | 
|---|
|  |  |  | List<DetlDto> list = new ArrayList<>(); | 
|---|
|  |  |  | List<DetlDto> orderDetails = param.getOrderDetails(); | 
|---|
|  |  |  | for (DetlDto detail : orderDetails) { | 
|---|
|  |  |  | DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme()); | 
|---|
|  |  |  | if (DetlDto.has(list, dto)) { | 
|---|
|  |  |  | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); | 
|---|
|  |  |  | assert detlDto != null; | 
|---|
|  |  |  | detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list.add(dto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (DetlDto detlDto : list) { | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detlDto.getMatnr()).eq(Mat::getHostId, param.getHostId())); | 
|---|
|  |  |  | List<GenerateOrderMatParam> mats = param.getMats(); | 
|---|
|  |  |  | for (GenerateOrderMatParam matParam : mats) { | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId())); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); | 
|---|
|  |  |  | throw new CoolException(matParam.getMatnr() + "编号商品检索失败,请先添加商品"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetl orderDetl = new OrderDetl(); | 
|---|
|  |  |  | orderDetl.sync(mat); | 
|---|
|  |  |  | orderDetl.setBatch(detlDto.getBatch()); | 
|---|
|  |  |  | orderDetl.setAnfme(detlDto.getAnfme()); | 
|---|
|  |  |  | orderDetl.setBatch(matParam.getBatch()); | 
|---|
|  |  |  | orderDetl.setAnfme(matParam.getAnfme()); | 
|---|
|  |  |  | orderDetl.setOrderId(order.getId()); | 
|---|
|  |  |  | orderDetl.setOrderNo(order.getOrderNo()); | 
|---|
|  |  |  | orderDetl.setCreateBy(9527L); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!orderService.save(order)) { | 
|---|
|  |  |  | throw new CoolException("生成单据主档失败,请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 单据明细档 | 
|---|
|  |  |  | List<DetlDto> list = new ArrayList<>(); | 
|---|
|  |  |  | List<DetlDto> orderDetails = param.getOrderDetails(); | 
|---|
|  |  |  | for (DetlDto detail : orderDetails) { | 
|---|
|  |  |  | DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getAnfme()); | 
|---|
|  |  |  | if (DetlDto.has(list, dto)) { | 
|---|
|  |  |  | DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch()); | 
|---|
|  |  |  | assert detlDto != null; | 
|---|
|  |  |  | detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list.add(dto); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (DetlDto detlDto : list) { | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, detlDto.getMatnr()).eq(Mat::getHostId, param.getHostId())); | 
|---|
|  |  |  | List<GenerateOrderMatParam> mats = param.getMats(); | 
|---|
|  |  |  | for (GenerateOrderMatParam matParam : mats) { | 
|---|
|  |  |  | Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>().eq(Mat::getMatnr, matParam.getMatnr()).eq(Mat::getHostId, param.getHostId())); | 
|---|
|  |  |  | if (Cools.isEmpty(mat)) { | 
|---|
|  |  |  | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); | 
|---|
|  |  |  | throw new CoolException(matParam.getMatnr() + "编号商品检索失败,请先添加商品"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | OrderDetl orderDetl = new OrderDetl(); | 
|---|
|  |  |  | orderDetl.sync(mat); | 
|---|
|  |  |  | orderDetl.setBatch(detlDto.getBatch()); | 
|---|
|  |  |  | orderDetl.setAnfme(detlDto.getAnfme()); | 
|---|
|  |  |  | orderDetl.setBatch(matParam.getBatch()); | 
|---|
|  |  |  | orderDetl.setAnfme(matParam.getAnfme()); | 
|---|
|  |  |  | orderDetl.setOrderId(order.getId()); | 
|---|
|  |  |  | orderDetl.setOrderNo(order.getOrderNo()); | 
|---|
|  |  |  | orderDetl.setCreateBy(9527L); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public int createMat(List<CreateMatParam> mats, Long hostId) { | 
|---|
|  |  |  | public int createMat(CreateMatParam param) { | 
|---|
|  |  |  | int count = 0; | 
|---|
|  |  |  | for (CreateMatParam matParam : mats) { | 
|---|
|  |  |  | Long hostId = param.getHostId(); | 
|---|
|  |  |  | for (MatParam matParam : param.getMats()) { | 
|---|
|  |  |  | //获取分类 | 
|---|
|  |  |  | Tag tag = tagService.getTag(matParam.getFirstTag(), matParam.getSecondTag(), hostId); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | mat.setMatnr(matParam.getMatnr());//物料号 | 
|---|
|  |  |  | mat.setHostId(hostId);//仓库ID | 
|---|
|  |  |  | mat.setTagId(tag.getId());//分类ID | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getShopCategory())) { | 
|---|
|  |  |  | Tag shopTag = tagService.getOne(new LambdaQueryWrapper<Tag>() | 
|---|
|  |  |  | .eq(Tag::getName, matParam.getShopCategory()) | 
|---|
|  |  |  | .eq(Tag::getHostId, hostId)); | 
|---|
|  |  |  | if (shopTag == null) { | 
|---|
|  |  |  | //商品分类为空,创建商品分类 | 
|---|
|  |  |  | shopTag = new Tag(); | 
|---|
|  |  |  | shopTag.setName(matParam.getShopCategory()); | 
|---|
|  |  |  | shopTag.setParentId(tag.getId()); | 
|---|
|  |  |  | shopTag.setStatus(1); | 
|---|
|  |  |  | shopTag.setHostId(hostId); | 
|---|
|  |  |  | shopTag.setCreateTime(new Date()); | 
|---|
|  |  |  | shopTag.setUpdateTime(new Date()); | 
|---|
|  |  |  | tagService.save(shopTag); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | mat.setTagId(shopTag.getId());//分类ID | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getMaktx())) { | 
|---|
|  |  |  | mat.setMaktx(matParam.getMaktx()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getSpecs())) { | 
|---|
|  |  |  | mat.setSpecs(matParam.getSpecs()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getModel())) { | 
|---|
|  |  |  | mat.setModel(matParam.getModel()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getColor())) { | 
|---|
|  |  |  | mat.setColor(matParam.getColor()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getBrand())) { | 
|---|
|  |  |  | mat.setBrand(matParam.getBrand()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getUnit())) { | 
|---|
|  |  |  | mat.setUnit(matParam.getUnit()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getPrice())) { | 
|---|
|  |  |  | mat.setPrice(matParam.getPrice()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getSku())) { | 
|---|
|  |  |  | mat.setSku(matParam.getSku()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getUnits())) { | 
|---|
|  |  |  | mat.setUnits(matParam.getUnits()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getBarcode())) { | 
|---|
|  |  |  | mat.setBarcode(matParam.getBarcode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getOrigin())) { | 
|---|
|  |  |  | mat.setOrigin(matParam.getOrigin()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getManu())) { | 
|---|
|  |  |  | mat.setManu(matParam.getManu()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getManuDate())) { | 
|---|
|  |  |  | mat.setManuDate(matParam.getManuDate()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getItemNum())) { | 
|---|
|  |  |  | mat.setItemNum(matParam.getItemNum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getWeight())) { | 
|---|
|  |  |  | mat.setWeight(matParam.getWeight()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getLength())) { | 
|---|
|  |  |  | mat.setLength(matParam.getLength()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getVolume())) { | 
|---|
|  |  |  | mat.setVolume(matParam.getVolume()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getThreeCode())) { | 
|---|
|  |  |  | mat.setThreeCode(matParam.getThreeCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getSupp())) { | 
|---|
|  |  |  | mat.setSupp(matParam.getSupp()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getSuppCode())) { | 
|---|
|  |  |  | mat.setSuppCode(matParam.getSuppCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getDeadTime())) { | 
|---|
|  |  |  | mat.setDeadTime(matParam.getDeadTime()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getMemo())) { | 
|---|
|  |  |  | mat.setMemo(matParam.getMemo()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | mat.setStatus(1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getMainHost())) { | 
|---|
|  |  |  | mat.setMainHost(matParam.getMainHost()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getMainSource())) { | 
|---|
|  |  |  | mat.setMainSource(matParam.getMainSource()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getBarcode())) { | 
|---|
|  |  |  | mat.setBarcode(matParam.getBarcode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getCyclePickCode())) { | 
|---|
|  |  |  | mat.setCyclePickCode(matParam.getCyclePickCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getLocationStock())) { | 
|---|
|  |  |  | mat.setLocationStock(matParam.getLocationStock()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getMaterial())) { | 
|---|
|  |  |  | mat.setMaterial(matParam.getMaterial()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getModel())) { | 
|---|
|  |  |  | mat.setModel(matParam.getModel()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getDecrees())) { | 
|---|
|  |  |  | mat.setDecrees(matParam.getDecrees()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getWeight())) { | 
|---|
|  |  |  | mat.setWeight(matParam.getWeight()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getImgNum())) { | 
|---|
|  |  |  | mat.setImgNum(matParam.getImgNum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getPurchasingUnits())) { | 
|---|
|  |  |  | mat.setPurchasingUnits(matParam.getPurchasingUnits()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getProcessNumber())) { | 
|---|
|  |  |  | mat.setProcessNumber(matParam.getProcessNumber()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getBom())) { | 
|---|
|  |  |  | mat.setBom(matParam.getBom()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getSafeNum())) { | 
|---|
|  |  |  | mat.setSafeNum(matParam.getSafeNum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getMiniCount())) { | 
|---|
|  |  |  | mat.setMiniCount(matParam.getMiniCount()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getReplenishmentNum())) { | 
|---|
|  |  |  | mat.setReplenishmentNum(matParam.getReplenishmentNum()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getTmp1())) { | 
|---|
|  |  |  | mat.setTmp1(matParam.getTmp1()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getTmp2())) { | 
|---|
|  |  |  | mat.setTmp2(matParam.getTmp2()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getTmp3())) { | 
|---|
|  |  |  | mat.setTmp3(matParam.getTmp3()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getRestockDemand())) { | 
|---|
|  |  |  | mat.setRestockDemand(matParam.getRestockDemand()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getLapse())) { | 
|---|
|  |  |  | mat.setLapse(matParam.getLapse()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getShortcuts())) { | 
|---|
|  |  |  | mat.setShortcuts(matParam.getShortcuts()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getUnits())) { | 
|---|
|  |  |  | mat.setUnits(matParam.getUnits()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getLength())) { | 
|---|
|  |  |  | mat.setLength(matParam.getLength()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getWidth())) { | 
|---|
|  |  |  | mat.setWidth(matParam.getWidth()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getHeight())) { | 
|---|
|  |  |  | mat.setHeight(matParam.getHeight()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getAccountingClass())) { | 
|---|
|  |  |  | mat.setAccountingClass(matParam.getAccountingClass()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getBatch())) { | 
|---|
|  |  |  | mat.setBatch(matParam.getBatch()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!Cools.isEmpty(matParam.getInventoryAccount())) { | 
|---|
|  |  |  | mat.setInventoryAccount(matParam.getInventoryAccount()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (matService.save(mat)) { | 
|---|
|  |  |  | count++; | 
|---|
|  |  |  | } | 
|---|