| | |
| | | package com.zy.asrs.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.param.*; |
| | | import com.zy.asrs.entity.param.MatSyncParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakinParam; |
| | | import com.zy.asrs.entity.param.OpenOrderPakoutParam; |
| | | import com.zy.asrs.entity.param.PackParam; |
| | | import com.zy.asrs.entity.result.InOutCountDto; |
| | | import com.zy.asrs.entity.result.OpenOrderCompeteResult; |
| | | import com.zy.asrs.entity.result.StockVo; |
| | | import com.zy.asrs.mapper.TagMapper; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.MatUtils; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.DetlDto; |
| | | import com.zy.common.utils.NodeUtils; |
| | | import com.zy.common.utils.Synchro; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private NodeService nodeService; |
| | | @Autowired |
| | | private ManLocDetlService manLocDetlService; |
| | | @Autowired |
| | | private MatV2Service matV2Service; |
| | | |
| | | @Override |
| | | @Transactional |
| | |
| | | } |
| | | for (DetlDto detlDto : list) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | if (Cools.isEmpty(mat)) { |
| | | MatV2 matV2 = matV2Service.selectOne(new EntityWrapper<MatV2>().eq("matnr", detlDto.getMatnr())); |
| | | if(Cools.isEmpty(matV2)){ |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | orderDetl.sync(matV2); |
| | | } else { |
| | | orderDetl.sync(mat); |
| | | } |
| | | |
| | | //批号为空会出现问题,设置一个默认值 |
| | | if (detlDto.getBatch() == null) { |
| | |
| | | } |
| | | for (DetlDto detlDto : list) { |
| | | Mat mat = matService.selectByMatnr(detlDto.getMatnr()); |
| | | if (Cools.isEmpty(mat)) { |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | if (Cools.isEmpty(mat)) { |
| | | MatV2 matV2 = matV2Service.selectOne(new EntityWrapper<MatV2>().eq("matnr", detlDto.getMatnr())); |
| | | if(Cools.isEmpty(matV2)){ |
| | | throw new CoolException(detlDto.getMatnr() + "编号商品检索失败,请先添加商品"); |
| | | } |
| | | orderDetl.sync(matV2); |
| | | } else { |
| | | orderDetl.sync(mat); |
| | | } |
| | | orderDetl.setBatch(detlDto.getBatch() == null ? "" : detlDto.getBatch()); |
| | | orderDetl.setAnfme(detlDto.getAnfme()); |
| | | orderDetl.setOrderId(order.getId()); |
| | |
| | | // 分类 |
| | | Long tagId; |
| | | // 一级分类 |
| | | if (!Cools.isEmpty(matParam.getGroupCode()) && !Cools.isEmpty(matParam.getGroupName())) { |
| | | Tag priTag = tagService.selectByName(matParam.getGroupCode(), 2); |
| | | if (priTag == null) { |
| | | Tag top = tagService.getTop(); |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.executePath(top.getId()); |
| | | priTag = new Tag( |
| | | null, // 编号 |
| | | matParam.getGroupCode(), // 名称 |
| | | top.getId(), // 父级 |
| | | top.getName(), // 父级名称 |
| | | nodeUtils.path.toString(), // 关联路径 |
| | | nodeUtils.pathName.toString(), // 关联路径名 |
| | | 0, // 类型 |
| | | null, // 负责人 |
| | | null, // 图片 |
| | | null, // 简要描述 |
| | | null, // 数量 |
| | | 2, // 等级 |
| | | null, // 排序 |
| | | 1, // 状态 |
| | | now, // 添加时间 |
| | | null, // 添加人员 |
| | | now, // 修改时间 |
| | | null, // 修改人员 |
| | | null // 备注 |
| | | ); |
| | | if (tagMapper.insert(priTag) == 0) { |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } |
| | | } |
| | | if (!Cools.isEmpty(matParam.getGroupName())) { |
| | | // 二级分类 |
| | | Tag secTag = tagService.selectByName(matParam.getGroupName(), 3); |
| | | if (secTag == null) { |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.executePath(priTag.getId()); |
| | | secTag = new Tag( |
| | | null, // 编号 |
| | | matParam.getGroupName(), // 名称 |
| | | priTag.getId(), // 父级 |
| | | priTag.getName(), // 父级名称 |
| | | nodeUtils.path.toString(), // 关联路径 |
| | | nodeUtils.pathName.toString(), // 关联路径名 |
| | | 10010L, // 父级 |
| | | "全部", // 父级名称 |
| | | "10009,10010", // 关联路径 |
| | | "全部,全部", // 关联路径名 |
| | | 0, // 类型 |
| | | null, // 负责人 |
| | | null, // 图片 |
| | |
| | | if (tagMapper.insert(secTag) == 0) { |
| | | throw new CoolException("服务器内部错误,请联系管理员"); |
| | | } |
| | | Tag tag = tagService.selectByName(matParam.getGroupName(), 3); |
| | | tagId = tag.getId(); |
| | | } else { |
| | | tagId = secTag.getId(); |
| | | } |
| | | tagId = secTag.getId(); |
| | | } else { |
| | | tagId = tagService.getTop().getId(); |
| | | throw new CoolException("商品分类不能为空"); |
| | | // tagId = tagService.getTop().getId(); |
| | | } |
| | | mat.sync(matParam); |
| | | // mat.setMatnr(para); |
| | | // mat.setMaktx(param.getMaktx()); |
| | | // mat.setSpecs(param.getSpecs()); |
| | | // mat.setModel(param.getModel()); |
| | | |
| | | mat.setTagId(tagId); |
| | | mat.setStatus(1); |
| | | mat.setCreateTime(now); |
| | |
| | | log.info("同步新物料[商品编号:{}]", mat.getMatnr()); |
| | | } |
| | | } else { |
| | | mat.sync(param); |
| | | // mat.sync(param); |
| | | mat.setMaktx(matParam.getMaktx()); |
| | | mat.setSpecs(matParam.getSpecs()); |
| | | if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", matParam.getMatnr()))) { |
| | | throw new CoolException("更新已存在商品信息失败,请联系管理员"); |
| | | } |
| | |
| | | public R getInOutDetl() { |
| | | List<InOutCountDto> top100 = wrkMastService.selectTop100(); |
| | | return R.ok().add(top100); |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public R manDetlIn(JSONObject json) { |
| | | Date date = new Date(); |
| | | String jsonLocNo = (String) json.get("locNo"); |
| | | Node node = nodeService.selectOne(new EntityWrapper<Node>() |
| | | .eq("name", jsonLocNo)); |
| | | //查订单 |
| | | String jsonOrderNo = (String) json.get("orderNo"); |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>() |
| | | .eq("order_no", jsonOrderNo)); |
| | | if (Cools.isEmpty(node, order)) { |
| | | return R.error("参数为空"); |
| | | } |
| | | |
| | | //判断订单类型是否是入库 |
| | | DocType docType=docTypeService.selectById(order.getDocType()); |
| | | if(docType.getPakin()!=1 || docType.getStatus()!=1){ |
| | | return R.error("该订单是出库订单,无法入库"); |
| | | } |
| | | |
| | | JSONArray combMats = json.getJSONArray("combMats"); |
| | | for (int i = 0; i < combMats.size(); i++) { |
| | | OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class); |
| | | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>() |
| | | .eq("order_no", jsonOrderNo) |
| | | .and() |
| | | .eq("maktx",jsonOrderDetl.getMaktx())); |
| | | if (Cools.isEmpty(orderDetl)) { |
| | | return R.error("单据明细有误,请检查"); |
| | | } |
| | | if (orderDetl.getAnfme() - (jsonOrderDetl.getAnfme() + orderDetl.getWorkQty()) < 0) { |
| | | return R.error("入库数量大于可入数量"); |
| | | } |
| | | ManLocDetl checkManLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", jsonLocNo) |
| | | .eq("matnr", orderDetl.getMatnr())); |
| | | if (checkManLocDetl == null) { |
| | | ManLocDetl manLocDetl = new ManLocDetl(); |
| | | Synchro.Copy(orderDetl, manLocDetl); |
| | | manLocDetl.setLocNo(node.getName()); |
| | | manLocDetl.setNodeId(node.getId()); |
| | | manLocDetl.setMatnr(orderDetl.getMatnr()); |
| | | manLocDetl.setMaktx(jsonOrderDetl.getMaktx()); |
| | | manLocDetl.setAnfme(jsonOrderDetl.getAnfme()); |
| | | manLocDetl.setModiTime(date); |
| | | manLocDetl.setCreateTime(date); |
| | | manLocDetlService.insert(manLocDetl); |
| | | } else { |
| | | checkManLocDetl.setAnfme(checkManLocDetl.getAnfme() + jsonOrderDetl.getAnfme()); |
| | | checkManLocDetl.setModiTime(date); |
| | | manLocDetlService.update(checkManLocDetl, new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", jsonLocNo) |
| | | .eq("matnr", orderDetl.getMatnr())); |
| | | } |
| | | orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setUpdateTime(date); |
| | | orderDetlService.updateById(orderDetl); |
| | | |
| | | //更新订单状态 |
| | | //工作中的数量小于总订单数时,订单状态改为2,作业中 |
| | | if(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme() < orderDetl.getAnfme()){ |
| | | order.setSettle(2L); |
| | | }else{ |
| | | //工作中的数量等于总订单数时,订单状态改为4,完成 |
| | | order.setSettle(4L); |
| | | } |
| | | if(!orderService.updateById(order)){ |
| | | return R.error("更新订单状态失败"); |
| | | } |
| | | |
| | | } |
| | | orderService.checkComplete(order.getOrderNo()); |
| | | |
| | | |
| | | return R.ok("上架完成"); |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public R manDetlOut(JSONObject json) { |
| | | Date date = new Date(); |
| | | String jsonLocNo = (String) json.get("locNo"); |
| | | Node node = nodeService.selectOne(new EntityWrapper<Node>() |
| | | .eq("name", jsonLocNo)); |
| | | String jsonOrderNo = (String) json.get("orderNo"); |
| | | Order order = orderService.selectOne(new EntityWrapper<Order>() |
| | | .eq("order_no", jsonOrderNo)); |
| | | |
| | | //判断订单类型是否是入库 |
| | | DocType docType=docTypeService.selectById(order.getDocType()); |
| | | if(docType.getPakout()!=1 || docType.getStatus()!=1){ |
| | | return R.error("该订单是出库订单,无法入库"); |
| | | } |
| | | if (Cools.isEmpty(node, order)) { |
| | | return R.error("参数为空"); |
| | | } |
| | | |
| | | JSONArray combMats = json.getJSONArray("combMats"); |
| | | for (int i = 0; i < combMats.size(); i++) { |
| | | OrderDetl jsonOrderDetl = combMats.getObject(i, OrderDetl.class); |
| | | OrderDetl orderDetl = orderDetlService.selectOne(new EntityWrapper<OrderDetl>() |
| | | .eq("order_no", jsonOrderNo)); |
| | | if (Cools.isEmpty(orderDetl)) { |
| | | return R.error("单据明细有误,请检查"); |
| | | } |
| | | if (jsonOrderDetl.getAnfme() > (orderDetl.getAnfme() - orderDetl.getWorkQty())) { |
| | | return R.error("出库数量大于单据可出数量"); |
| | | } |
| | | ManLocDetl manLocDetl = manLocDetlService.selectOne(new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", jsonLocNo) |
| | | .eq("matnr", orderDetl.getMatnr())); |
| | | if (manLocDetl == null) { |
| | | return R.error("该库位没有出库的物料信息"); |
| | | } |
| | | if (jsonOrderDetl.getAnfme() > manLocDetl.getAnfme()) { |
| | | return R.error("出库数量大于可出数量"); |
| | | } |
| | | Double finalQty = manLocDetl.getAnfme() - jsonOrderDetl.getAnfme(); |
| | | if (finalQty <= 0){ |
| | | manLocDetlService.delete(new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", jsonLocNo) |
| | | .eq("matnr", orderDetl.getMatnr())); |
| | | }else { |
| | | manLocDetl.setAnfme(finalQty); |
| | | manLocDetl.setModiTime(date); |
| | | manLocDetlService.update(manLocDetl,new EntityWrapper<ManLocDetl>() |
| | | .eq("loc_no", jsonLocNo) |
| | | .eq("matnr", orderDetl.getMatnr())); |
| | | } |
| | | orderDetl.setQty(orderDetl.getQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setWorkQty(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme()); |
| | | orderDetl.setUpdateTime(date); |
| | | orderDetlService.updateById(orderDetl); |
| | | |
| | | //更新订单状态 |
| | | //工作中的数量小于总订单数时,订单状态改为2,作业中 |
| | | if(orderDetl.getWorkQty() + jsonOrderDetl.getAnfme() < orderDetl.getAnfme()){ |
| | | order.setSettle(2L); |
| | | }else{ |
| | | //工作中的数量等于总订单数时,订单状态改为4,完成 |
| | | order.setSettle(4L); |
| | | } |
| | | if(!orderService.updateById(order)){ |
| | | return R.error("更新订单状态失败"); |
| | | } |
| | | |
| | | orderService.checkComplete(order.getOrderNo()); |
| | | } |
| | | return R.ok("下架完成"); |
| | | } |
| | | |
| | | } |