diff --git a/ant-design-vue-jeecg/src/views/process/ZyProcessList.vue b/ant-design-vue-jeecg/src/views/process/ZyProcessList.vue index cb0d37f7..6760fffd 100644 --- a/ant-design-vue-jeecg/src/views/process/ZyProcessList.vue +++ b/ant-design-vue-jeecg/src/views/process/ZyProcessList.vue @@ -1,460 +1,469 @@ - - - - \ No newline at end of file diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/workorder/service/impl/WorkOrderServiceImpl.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/workorder/service/impl/WorkOrderServiceImpl.java index 34571342..d0eef500 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/workorder/service/impl/WorkOrderServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/workorder/service/impl/WorkOrderServiceImpl.java @@ -1,575 +1,624 @@ -package org.jeecg.modules.workorder.service.impl; - - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import org.jeecg.common.api.vo.Result; -import org.jeecg.modules.demo.base.mapper.ZyProcessMapper; -import org.jeecg.modules.demo.customermeasure.entity.CustomerMeasure; -import org.jeecg.modules.demo.customermeasure.mapper.CustomerMeasureMapper; -import org.jeecg.modules.demo.ordergoods.entity.OrderGoods; -import org.jeecg.modules.demo.ordergoods.mapper.OrderGoodsMapper; -import org.jeecg.modules.demo.ordergoodsaccessories.entity.OrderGoodsAccessories; -import org.jeecg.modules.demo.ordergoodsaccessories.mapper.OrderGoodsAccessoriesMapper; -import org.jeecg.modules.demo.ordergoodsfabric.entity.OrderGoodsFabric; -import org.jeecg.modules.demo.ordergoodsfabric.mapper.OrderGoodsFabricMapper; -import org.jeecg.modules.demo.ordergoodsmodule.entity.OrderGoodsModule; -import org.jeecg.modules.demo.ordergoodsmodule.mapper.OrderGoodsModuleMapper; -import org.jeecg.modules.demo.pro.entity.ZyProcessAccessories; -import org.jeecg.modules.demo.pro.entity.ZyProcessFabric; -import org.jeecg.modules.demo.pro.entity.ZyProcessMachine; -import org.jeecg.modules.demo.pro.mapper.ZyProcessMachineMapper; -import org.jeecg.modules.demo.zyStyleModular.entity.ZyStyleModular; -import org.jeecg.modules.demo.zyStyleModular.mapper.ZyStyleModularMapper; -import org.jeecg.modules.demo.zyorders.entity.ZyOrders; -import org.jeecg.modules.demo.zyorders.mapper.ZyOrdersMapper; -import org.jeecg.modules.operationtool.entity.ZyOperationtool; -import org.jeecg.modules.operationtool.mapper.ZyOperationtoolMapper; -import org.jeecg.modules.product.pdaccessories.entity.ProductAccessories; -import org.jeecg.modules.product.pdaccessories.mapper.ProductAccessoriesMapper; -import org.jeecg.modules.product.pdfabric.entity.ProductFabric; -import org.jeecg.modules.product.pdfabric.mapper.ProductFabricMapper; -import org.jeecg.modules.product.pdmachine.entity.ProductMachine; -import org.jeecg.modules.product.pdmachine.mapper.ProductMachineMapper; -import org.jeecg.modules.product.pdoperationtool.entity.ProductOperationtool; -import org.jeecg.modules.product.pdoperationtool.mapper.ProductOperationtoolMapper; -import org.jeecg.modules.product.productModule.entity.ProductModule; -import org.jeecg.modules.product.productModule.mapper.ProductModuleMapper; -import org.jeecg.modules.product.zyproductprocess.entity.ZyProductProcess; -import org.jeecg.modules.product.zyproductprocess.mapper.ZyProductProcessMapper; -import org.jeecg.modules.productprocessaccessories.entity.ProductProcessAccessories; -import org.jeecg.modules.productprocessaccessories.mapper.ProductProcessAccessoriesMapper; -import org.jeecg.modules.productprocessfabric.entity.ProductProcessFabric; -import org.jeecg.modules.productprocessfabric.mapper.ProductProcessFabricMapper; -import org.jeecg.modules.system.entity.SysDepart; -import org.jeecg.modules.system.mapper.SysDepartMapper; -import org.jeecg.modules.workorder.entity.WorkOrder; -import org.jeecg.modules.workorder.entity.WorkOrderVo; -import org.jeecg.modules.workorder.mapper.WorkOrderMapper; -import org.jeecg.modules.workorder.service.IWorkOrderService; -import org.jeecg.modules.workproduct.entity.ZyProduct; -import org.jeecg.modules.workproduct.mapper.ZyProductMapper; -import org.jeecg.modules.zyclothsample.entity.ZyClothSample; -import org.jeecg.modules.zyclothsample.mapper.ZyClothSampleMapper; -import org.jeecg.modules.zyclothsstyle.entity.ZyClothsStyle; -import org.jeecg.modules.zyclothsstyle.mapper.ZyClothsStyleMapper; -import org.jeecg.modules.zystylemodel.entity.ZyStyleModel; -import org.jeecg.modules.zystylemodel.mapper.ZyStyleModelMapper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; - -import java.util.ArrayList; -import java.util.List; - -/** - * @Description: 工单订单完工 - * @Author: jeecg-boot - * @Date: 2023-01-07 - * @Version: V1.0 - */ -@Service -public class WorkOrderServiceImpl extends ServiceImpl implements IWorkOrderService { - - //订单 - @Autowired - private ZyOrdersMapper zyOrdersMapper; - - //部门 - @Autowired - private SysDepartMapper sysDepartMapper; - - //订单商品 - @Autowired - private OrderGoodsMapper orderGoodsMapper; - - //服装款式表 - @Autowired - private ZyClothsStyleMapper clothsStyleMapper; - - //服装型号 - @Autowired - private ZyStyleModelMapper styleModelMapper; - - //成衣样板 - @Autowired - private ZyClothSampleMapper clothSampleMapper; - - //顾客测体 - @Autowired - private CustomerMeasureMapper customerMeasureMapper; - - //工单产品 - @Autowired - private ZyProductMapper productMapper; - - //服装工序 - @Autowired - private ZyStyleModularMapper styleModularMapper; - - //基本工序 - @Autowired - private ZyProcessMapper processMapper; - - //产品工序 - @Autowired - private ZyProductProcessMapper productProcessMapper; - - //工序工具 - @Autowired - private ZyOperationtoolMapper zyOperationtoolMapper; - //产品工具 - @Autowired - private ProductOperationtoolMapper productOperationtoolMapper; - - //工序设备 - @Autowired - private ZyProcessMachineMapper zyProcessMachine; - //产品设备 - @Autowired - private ProductMachineMapper productMachineMapper; - - - - - //订单商品模块表 - @Autowired - private OrderGoodsModuleMapper orderGoodsModuleMapper; - //产品模块 - @Autowired - private ProductModuleMapper productModuleMapper; - - //订单商品面料表 - @Autowired - private OrderGoodsFabricMapper orderGoodsFabricMapper; - //产品面料表 - @Autowired - private ProductFabricMapper productFabricMapper; - - //订单商品辅料表 - @Autowired - private OrderGoodsAccessoriesMapper orderGoodsAccessoriesMapper; - //产品辅料表 - @Autowired - private ProductAccessoriesMapper productAccessoriesMapper; - //产品工序面料 - @Autowired - private ProductProcessFabricMapper productProcessFabricMapper; - //产品工序辅料 - @Autowired - private ProductProcessAccessoriesMapper productProcessAccessoriesMapper; - - /** - * 自定义分页查询 - * @param page - * @param workOrder - * @return - */ - @Override - public IPage selectPage(Page page, WorkOrderVo workOrder) { - return baseMapper.selectListPage(page,workOrder); - } - - /** - * 派单 - * @param zyOrders - * @return - */ - @Override - public Result paidan(ZyOrders zyOrders,String depId) { - //订单ID - String orderId=zyOrders.getId(); - //商品订单是否存在 - QueryWrapper ogWrapper=new QueryWrapper(); - ogWrapper.eq("orders_id",orderId); - List ogList=orderGoodsMapper.selectList(ogWrapper); - //工单 - WorkOrder workOrder=new WorkOrder(); - if(ogList.size()>0) - {//start if 02 - // 保存工单 - - //获取订单商品 - OrderGoods ogModel=ogList.get(0); - - //服装款式 - //QueryWrapper csWrapper=new QueryWrapper(); - ZyClothsStyle csModel=clothsStyleMapper.selectById(ogModel.getStyleId()); - - - //服装型号 - //QueryWrapper sm=new QueryWrapper(); - ZyStyleModel smModel=styleModelMapper.selectById(ogModel.getModelId()); - if(csModel==null ||smModel==null) - { - return Result.error("该订单服装型号或服装款式不存在,请检查后在操作!"); - } - //得到结构图和排排料图 - QueryWrapper csWrapper=new QueryWrapper(); - csWrapper.eq("style_id",ogModel.getStyleId()); - csWrapper.eq("stylemodel_id",ogModel.getModelId()); - //成衣样板 - List csList=clothSampleMapper.selectList(csWrapper); - if(csList.size()<=0) - { - return Result.error("商品成衣样板不存在,请检查后在操作!"); - } - ZyClothSample cSampleModel=csList.get(0); - - //生成工单 - int goodNum=ogModel.getGoodsNum(); - - workOrder.setProductCode(CreateWorkCode(csModel.getNums(),smModel.getModelNumber()));//工单编号 - workOrder.setOrdersId(orderId);//订单id - workOrder.setOrderGoodsId(ogModel.getId());// 订单商品 - workOrder.setGoodsNum(goodNum);//商品数量 - workOrder.setOrderTime(zyOrders.getOrderTime());//下单时间 - workOrder.setDeliveryTime(zyOrders.getDeliveryTime());//交货期 - workOrder.setWorkOrderStatus(0);//工单状态 - workOrder.setEnterprisesId(depId);//企业id - baseMapper.insert(workOrder); - - //保存产品 - if(goodNum>0) - { - //量体数据 - CustomerMeasure mesureModel=customerMeasureMapper.selectById(ogModel.getMeasureId()); - if(mesureModel==null) { - return Result.error("未找到对客户量体数据!"); - } - - //#region 商品数量对应产品 保存产品 - for(int i=0;i styleModularLWrapper=new QueryWrapper(); - styleModularLWrapper.eq("style_id",ogModel.getStyleId()); - List zyStyleModularList=styleModularMapper.selectList(styleModularLWrapper); - - //将工序保存到产品工序中 - //List productProcessList=new ArrayList<>(); - for(ZyStyleModular item:zyStyleModularList) - { - ZyProductProcess zpp=new ZyProductProcess(); - zpp.setProductId(productModel.getId());//产品id - zpp.setProcessId(item.getProcessId());//工序id - zpp.setNumber(item.getSerialnumber());//序号 - productProcessMapper.insert(zpp);//保存 - - //首先查询到对应的产品工序id,由于产品和工序对应应该唯一 - String productprocessId=productProcessMapper.findProductProcessId(zpp.getProductId(),zpp.getProcessId()); - //然后根据对应的工序id去基本工序关联的辅料和面料表中找到对应的数据 - //面料 - List listFabric= productProcessMapper.findFabric(zpp.getProcessId()); - //辅料 - List listAccessories=productProcessMapper.findAccessories(zpp.getProcessId()); - //然后将产品工序id和辅料面料绑定 - //产品工序面料 - for (ZyProcessFabric zyProcessFabric : listFabric) { - ProductProcessFabric fabric=new ProductProcessFabric(); - fabric.setFabricId(zyProcessFabric.getFabricId()); - fabric.setAmount(zyProcessFabric.getAmount()); - fabric.setProductProcessId(productprocessId); - fabric.setId(null); - productProcessFabricMapper.insert(fabric); - } - //产品工序辅料 - for (ZyProcessAccessories listAccessory : listAccessories) { - ProductProcessAccessories accessories=new ProductProcessAccessories(); - accessories.setAccessoriesId(listAccessory.getAccessoriesId()); - accessories.setAmount(listAccessory.getAmount()); - accessories.setProductProcessId(productprocessId); - accessories.setId(null); - productProcessAccessoriesMapper.insert(accessories); - } - //ZyProcess =processMapper.selectById(item.getProcessId()); - - //region 获取工序工具 - QueryWrapper operationtoolWrapper=new QueryWrapper(); - //根据工序ID - operationtoolWrapper.eq("operationid",item.getProcessId()); - List operationtoolList=zyOperationtoolMapper.selectList(operationtoolWrapper); - int sort=1; - for(ZyOperationtool itemTool:operationtoolList) - { - ProductOperationtool poModel=new ProductOperationtool(); - poModel.setProductId(productModel.getId());//产品id - poModel.setOperationtoolId(itemTool.getToolid());//工具id - - poModel.setSort(sort++);//序号 - productOperationtoolMapper.insert(poModel); - - } - //endregion - - //region 获取工序设备 - QueryWrapper processMachineWrapper=new QueryWrapper(); - //根据工序ID - processMachineWrapper.eq("process_id",item.getProcessId()); - List processMachineList=zyProcessMachine.selectList(processMachineWrapper); - //遍历设备 - sort=1; - for(ZyProcessMachine itemMachine:processMachineList) - { - ProductMachine pmModel=new ProductMachine(); - pmModel.setProductId(productModel.getId());//产品id - pmModel.setMachineId(itemMachine.getMachineId());//设备 - pmModel.setSort(sort++);//序号 - productMachineMapper.insert(pmModel); - - } - //endregion - - //productProcessList.add(zpp); - } - //zyProductProcessService.save() - //#endregion - - - //#region 产品模块-添加(从订单中读取) - //订单商品模块表-根据订单商品id - QueryWrapper productModuleWrapper=new QueryWrapper(); - productModuleWrapper.eq("order_goods_id",ogModel.getId()); - List orderGoodsModuleList=orderGoodsModuleMapper.selectList(productModuleWrapper); - //循环保存 - List ProductModuleList=new ArrayList<>(); - for(OrderGoodsModule item:orderGoodsModuleList) - { - ProductModule pmModel=new ProductModule(); - pmModel.setProductId(productModel.getId());//产品id - pmModel.setStyleModuleId(item.getStyleModuleId());//款式模块id - pmModel.setModuleId(item.getModuleId());//模块id - //保存 - productModuleMapper.insert(pmModel); - //ProductModuleList.add(pmModel); - } - - //productModuleMapper.saveBatch(ProductModuleList); - //#endregion - - //#region 产品面料-添加(从订单中读取) - - //订单商品面料表-根据订单商品id - QueryWrapper ogFabricWrapper=new QueryWrapper(); - ogFabricWrapper.eq("order_goods_id",ogModel.getId()); - List orderGoodsFabricList=orderGoodsFabricMapper.selectList(ogFabricWrapper); - //循环保存 - List productFabricList=new ArrayList<>(); - for(OrderGoodsFabric item:orderGoodsFabricList) - { - ProductFabric ptModel=new ProductFabric(); - ptModel.setProductId(productModel.getId());//产品id - ptModel.setFabricId(item.getFabricId());//面料id - // productFabricList.add(ptModel); - //保存 - productFabricMapper.insert(ptModel); - } - //保存 - // productFabricMapper.saveBatch(productFabricList); - //#endregion - - //#region 产品辅料-添加(从订单中读取) - //订单商品辅料表-根据订单商品id - QueryWrapper ogAccessoriesWrapper=new QueryWrapper(); - ogAccessoriesWrapper.eq("order_goods_id",ogModel.getId()); - List orderGoodsAccessoriesList=orderGoodsAccessoriesMapper.selectList(ogAccessoriesWrapper); - //循环保存 - List productAccessoriesList=new ArrayList<>(); - for(OrderGoodsAccessories item:orderGoodsAccessoriesList) - { - ProductAccessories paModel=new ProductAccessories(); - paModel.setProductId(productModel.getId());//产品id - paModel.setAccessoriesId(item.getAccessoriesId());//辅料id - - productAccessoriesMapper.insert(paModel); - // productAccessoriesList.add(paModel); - } - //保存 - // productAccessoriesMapper.saveBatch(productAccessoriesList); - //#endregion - } - //#endregion - } - - else - { - return Result.error("订单商品数量小于0!"); - - } - - }else//end if 02 - { - return Result.error("订单商品数据未找到!"); - } - //修改订单状态 - zyOrders.setDeliveryStatus(3); - zyOrdersMapper.updateById(zyOrders); - return Result.OK("成功",workOrder); - } - - /** - * 撤销工单 - * @param woModel - * @return - */ - @Override - public Result cancellationWorkOrder(WorkOrder woModel) { - //根据工单获取产品列表,然后循环删除产品列表中的工序,以及工序对应的设备、工具,再删除产品中对应模块、面料、辅料 - - //工单 - //-产品 - QueryWrapper productWrapper = new QueryWrapper(); - productWrapper.eq("work_order_id", woModel.getId()); - List productList = productMapper.selectList(productWrapper); - - for (ZyProduct model:productList) - { - //-工序 - QueryWrapper productProcessWrapper = new QueryWrapper(); - productProcessWrapper.eq("product_id",model.getId()); - productProcessMapper.delete(productProcessWrapper); - //-工具 - QueryWrapper productOperationtoolWrapper = new QueryWrapper(); - productOperationtoolWrapper.eq("product_id",model.getId()); - productOperationtoolMapper.delete(productOperationtoolWrapper); - //-设备 - QueryWrapper productMachineWrapper = new QueryWrapper(); - productMachineWrapper.eq("product_id",model.getId()); - productMachineMapper.delete(productMachineWrapper); - - //产品模块 - QueryWrapper productModuleWrapper = new QueryWrapper(); - productModuleWrapper.eq("product_id",model.getId()); - productModuleMapper.delete(productModuleWrapper); - - //产品面料 - QueryWrapper productFabricWrapper = new QueryWrapper(); - productFabricWrapper.eq("product_id",model.getId()); - productFabricMapper.delete(productFabricWrapper); - - //产品面料 - QueryWrapper productAccessoriesWrapper = new QueryWrapper(); - productAccessoriesWrapper.eq("product_id",model.getId()); - productAccessoriesMapper.delete(productAccessoriesWrapper); - } - - - //修改订单 - UpdateWrapper updateWrapper = new UpdateWrapper(); - updateWrapper.eq("id", woModel.getOrdersId()); - updateWrapper.set("delivery_status", 2); - int update = zyOrdersMapper.update(null, updateWrapper); - - //产品 - productMapper.delete(productWrapper); - //工单 - baseMapper.deleteById(woModel.getId()); - return Result.OK("成功"); - } - - @Override - public List jobPaidan(List orderIds) { - //获取生产部门 - QueryWrapper queryWrapper=new QueryWrapper(); - queryWrapper.eq("org_category",2); - List sysDepList = sysDepartMapper.selectList(queryWrapper); - if(sysDepList.size()>0) - { - - List wordOderIds=new ArrayList<>(); - //生产随机数,然后随机获取生产部门 - int r=(int)Math.random() * sysDepList.size(); - SysDepart dep=sysDepList.get(r); - for(String orderId:orderIds) - { - ZyOrders model=zyOrdersMapper.selectById(orderId); - Result result=this.paidan(model,dep.getId()); - if (result.getCode().toString().equals("500")) - { - return null; - } - WorkOrder wo=(WorkOrder)result.getResult(); - wordOderIds.add(wo.getId()); - } - return wordOderIds; - } - return null; - } - - - //生成工单编号 - - /** - * - * @param styleCode 款式编号 - * @param modelCode 型号编号 - * @return - */ - private String CreateWorkCode(String styleCode,String modelCode) - {//编号规则:款式编号(10)+型号(4)+顺序号(8) - String mrstr = "00000000"; - QueryWrapper query = new QueryWrapper(); - int listsize = baseMapper.selectList(query).size(); - int strsize = listsize+1; - String str = strsize+""; - int strlength = str.length(); - String substr = mrstr.substring(0,mrstr.length()-strlength); - String workCode = styleCode+modelCode+substr+str; - return workCode; - } - - /** - * - * @param workCode 工单编号 - * @return - */ - private String CreateProductCode(String workCode) - {//编号规则:工单编号(22)+顺序号(8) - String mrstr = "00000000"; - QueryWrapper query = new QueryWrapper(); - int listsize = productMapper.selectList(query).size(); - int strsize = listsize+1; - String str = strsize+""; - int strlength = str.length(); - String substr = mrstr.substring(0,mrstr.length()-strlength); - String produceCode = workCode+substr+str; - return produceCode; - } - - -} +package org.jeecg.modules.workorder.service.impl; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.demo.base.mapper.ZyProcessMapper; +import org.jeecg.modules.demo.customermeasure.entity.CustomerMeasure; +import org.jeecg.modules.demo.customermeasure.mapper.CustomerMeasureMapper; +import org.jeecg.modules.demo.ordergoods.entity.OrderGoods; +import org.jeecg.modules.demo.ordergoods.mapper.OrderGoodsMapper; +import org.jeecg.modules.demo.ordergoodsaccessories.entity.OrderGoodsAccessories; +import org.jeecg.modules.demo.ordergoodsaccessories.mapper.OrderGoodsAccessoriesMapper; +import org.jeecg.modules.demo.ordergoodsfabric.entity.OrderGoodsFabric; +import org.jeecg.modules.demo.ordergoodsfabric.mapper.OrderGoodsFabricMapper; +import org.jeecg.modules.demo.ordergoodsmodule.entity.OrderGoodsModule; +import org.jeecg.modules.demo.ordergoodsmodule.mapper.OrderGoodsModuleMapper; +import org.jeecg.modules.demo.pro.entity.ZyProcessAccessories; +import org.jeecg.modules.demo.pro.entity.ZyProcessFabric; +import org.jeecg.modules.demo.pro.entity.ZyProcessMachine; +import org.jeecg.modules.demo.pro.mapper.ZyProcessMachineMapper; +import org.jeecg.modules.demo.zyStyleModular.entity.ZyStyleModular; +import org.jeecg.modules.demo.zyStyleModular.mapper.ZyStyleModularMapper; +import org.jeecg.modules.demo.zyorders.entity.ZyOrders; +import org.jeecg.modules.demo.zyorders.mapper.ZyOrdersMapper; +import org.jeecg.modules.operationtool.entity.ZyOperationtool; +import org.jeecg.modules.operationtool.mapper.ZyOperationtoolMapper; +import org.jeecg.modules.product.pdaccessories.entity.ProductAccessories; +import org.jeecg.modules.product.pdaccessories.mapper.ProductAccessoriesMapper; +import org.jeecg.modules.product.pdfabric.entity.ProductFabric; +import org.jeecg.modules.product.pdfabric.mapper.ProductFabricMapper; +import org.jeecg.modules.product.pdmachine.entity.ProductMachine; +import org.jeecg.modules.product.pdmachine.mapper.ProductMachineMapper; +import org.jeecg.modules.product.pdoperationtool.entity.ProductOperationtool; +import org.jeecg.modules.product.pdoperationtool.mapper.ProductOperationtoolMapper; +import org.jeecg.modules.product.productModule.entity.ProductModule; +import org.jeecg.modules.product.productModule.mapper.ProductModuleMapper; +import org.jeecg.modules.product.zyproductprocess.entity.ZyProductProcess; +import org.jeecg.modules.product.zyproductprocess.mapper.ZyProductProcessMapper; +import org.jeecg.modules.productprocessaccessories.entity.ProductProcessAccessories; +import org.jeecg.modules.productprocessaccessories.mapper.ProductProcessAccessoriesMapper; +import org.jeecg.modules.productprocessfabric.entity.ProductProcessFabric; +import org.jeecg.modules.productprocessfabric.mapper.ProductProcessFabricMapper; +import org.jeecg.modules.system.entity.SysDepart; +import org.jeecg.modules.system.mapper.SysDepartMapper; +import org.jeecg.modules.workorder.entity.WorkOrder; +import org.jeecg.modules.workorder.entity.WorkOrderVo; +import org.jeecg.modules.workorder.mapper.WorkOrderMapper; +import org.jeecg.modules.workorder.service.IWorkOrderService; +import org.jeecg.modules.workproduct.entity.ZyProduct; +import org.jeecg.modules.workproduct.mapper.ZyProductMapper; +import org.jeecg.modules.zyProcessModular.entity.ZyProcessModular; +import org.jeecg.modules.zyProcessModular.mapper.ZyProcessModularMapper; +import org.jeecg.modules.zyclothsample.entity.ZyClothSample; +import org.jeecg.modules.zyclothsample.mapper.ZyClothSampleMapper; +import org.jeecg.modules.zyclothsstyle.entity.ZyClothsStyle; +import org.jeecg.modules.zyclothsstyle.mapper.ZyClothsStyleMapper; +import org.jeecg.modules.zystylemodel.entity.ZyStyleModel; +import org.jeecg.modules.zystylemodel.mapper.ZyStyleModelMapper; +import org.jeecg.modules.zystylemodule.entity.ZyStyleModule; +import org.jeecg.modules.zystylemodule.mapper.ZyStyleModuleMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import java.util.ArrayList; +import java.util.List; + +/** + * @Description: 工单订单完工 + * @Author: jeecg-boot + * @Date: 2023-01-07 + * @Version: V1.0 + */ +@Service +public class WorkOrderServiceImpl extends ServiceImpl implements IWorkOrderService { + + //订单 + @Autowired + private ZyOrdersMapper zyOrdersMapper; + + //部门 + @Autowired + private SysDepartMapper sysDepartMapper; + + //订单商品 + @Autowired + private OrderGoodsMapper orderGoodsMapper; + + //服装款式表 + @Autowired + private ZyClothsStyleMapper clothsStyleMapper; + + //服装型号 + @Autowired + private ZyStyleModelMapper styleModelMapper; + + //成衣样板 + @Autowired + private ZyClothSampleMapper clothSampleMapper; + + //顾客测体 + @Autowired + private CustomerMeasureMapper customerMeasureMapper; + + //工单产品 + @Autowired + private ZyProductMapper productMapper; + + //服装工序 + @Autowired + private ZyStyleModularMapper styleModularMapper; + + //基本工序 + @Autowired + private ZyProcessMapper processMapper; + + //款式模块 + @Autowired + private ZyStyleModuleMapper zyStyleModuleMapper; + + //款式模块工序 + @Autowired + private ZyProcessModularMapper zyProcessModularMapper; + + + //产品工序 + @Autowired + private ZyProductProcessMapper productProcessMapper; + + + + //工序工具 + @Autowired + private ZyOperationtoolMapper zyOperationtoolMapper; + //产品工具 + @Autowired + private ProductOperationtoolMapper productOperationtoolMapper; + + //工序设备 + @Autowired + private ZyProcessMachineMapper zyProcessMachine; + //产品设备 + @Autowired + private ProductMachineMapper productMachineMapper; + + + + + //订单商品模块表 + @Autowired + private OrderGoodsModuleMapper orderGoodsModuleMapper; + //产品模块 + @Autowired + private ProductModuleMapper productModuleMapper; + + //订单商品面料表 + @Autowired + private OrderGoodsFabricMapper orderGoodsFabricMapper; + //产品面料表 + @Autowired + private ProductFabricMapper productFabricMapper; + + //订单商品辅料表 + @Autowired + private OrderGoodsAccessoriesMapper orderGoodsAccessoriesMapper; + //产品辅料表 + @Autowired + private ProductAccessoriesMapper productAccessoriesMapper; + //产品工序面料 + @Autowired + private ProductProcessFabricMapper productProcessFabricMapper; + //产品工序辅料 + @Autowired + private ProductProcessAccessoriesMapper productProcessAccessoriesMapper; + + /** + * 自定义分页查询 + * @param page + * @param workOrder + * @return + */ + @Override + public IPage selectPage(Page page, WorkOrderVo workOrder) { + return baseMapper.selectListPage(page,workOrder); + } + + /** + * 派单 + * @param zyOrders + * @return + */ + @Override + public Result paidan(ZyOrders zyOrders,String depId) { + //订单ID + String orderId=zyOrders.getId(); + //商品订单是否存在 + QueryWrapper ogWrapper=new QueryWrapper(); + ogWrapper.eq("orders_id",orderId); + List ogList=orderGoodsMapper.selectList(ogWrapper); + //工单 + WorkOrder workOrder=new WorkOrder(); + if(ogList.size()>0) + {//start if 02 + // 保存工单 + + //获取订单商品 + OrderGoods ogModel=ogList.get(0); + + //服装款式 + //QueryWrapper csWrapper=new QueryWrapper(); + ZyClothsStyle csModel=clothsStyleMapper.selectById(ogModel.getStyleId()); + + + //服装型号 + //QueryWrapper sm=new QueryWrapper(); + ZyStyleModel smModel=styleModelMapper.selectById(ogModel.getModelId()); + if(csModel==null ||smModel==null) + { + return Result.error("该订单服装型号或服装款式不存在,请检查后在操作!"); + } + //得到结构图和排排料图 + QueryWrapper csWrapper=new QueryWrapper(); + csWrapper.eq("style_id",ogModel.getStyleId()); + csWrapper.eq("stylemodel_id",ogModel.getModelId()); + //成衣样板 + List csList=clothSampleMapper.selectList(csWrapper); + if(csList.size()<=0) + { + return Result.error("商品成衣样板不存在,请检查后在操作!"); + } + ZyClothSample cSampleModel=csList.get(0); + + //生成工单 + int goodNum=ogModel.getGoodsNum(); + + workOrder.setProductCode(CreateWorkCode(csModel.getNums(),smModel.getModelNumber()));//工单编号 + workOrder.setOrdersId(orderId);//订单id + workOrder.setOrderGoodsId(ogModel.getId());// 订单商品 + workOrder.setGoodsNum(goodNum);//商品数量 + workOrder.setOrderTime(zyOrders.getOrderTime());//下单时间 + workOrder.setDeliveryTime(zyOrders.getDeliveryTime());//交货期 + workOrder.setWorkOrderStatus(0);//工单状态 + workOrder.setEnterprisesId(depId);//企业id + baseMapper.insert(workOrder); + + //保存产品 + if(goodNum>0) + { + //量体数据 + CustomerMeasure mesureModel=customerMeasureMapper.selectById(ogModel.getMeasureId()); + if(mesureModel==null) { + return Result.error("未找到对客户量体数据!"); + } + + //#region 商品数量对应产品 保存产品 + for(int i=0;i styleModularLWrapper=new QueryWrapper(); + styleModularLWrapper.eq("style_id",ogModel.getStyleId()); + List zyStyleModularList=styleModularMapper.selectList(styleModularLWrapper); + + List pplist=new ArrayList<>(); + //将款式工序保存到变量pplist中 + for(ZyStyleModular item:zyStyleModularList) + { + ZyProductProcess zpp=new ZyProductProcess(); + zpp.setProductId(productModel.getId());//产品id + zpp.setProcessId(item.getProcessId());//工序id + zpp.setNumber(item.getSerialnumber());//序号 + productProcessMapper.insert(zpp);//保存 + pplist.add(zpp); + } + + //模块工序 + QueryWrapper qwStyleModule = new QueryWrapper<>(); + qwStyleModule.eq("style_id",ogModel.getStyleId()); + List smList=zyStyleModuleMapper.selectList(qwStyleModule); + //将模块工序保存到变量pplist中 + for(ZyStyleModule item:smList) + { + //读取模块工序 + QueryWrapper qwProcessModular = new QueryWrapper<>(); + qwProcessModular.eq("modular_id",item.getModularId()); + List pmList=zyProcessModularMapper.selectList(qwProcessModular); + for(ZyProcessModular pm:pmList) + { + ZyProductProcess zpp=new ZyProductProcess(); + zpp.setProductId(productModel.getId());//产品id + zpp.setProcessId(pm.getProcessId());//工序id + zpp.setNumber(pm.getSerialnumber());//序号 + productProcessMapper.insert(zpp);//保存 + pplist.add(zpp); + } + + } + + + //将工序保存到产品工序中 + //List productProcessList=new ArrayList<>(); + for(ZyProductProcess item:pplist) + { + + //首先查询到对应的产品工序id,由于产品和工序对应应该唯一 + String productprocessId=productProcessMapper.findProductProcessId(item.getProductId(),item.getProcessId()); + //然后根据对应的工序id去基本工序关联的辅料和面料表中找到对应的数据 + //面料 + List listFabric= productProcessMapper.findFabric(item.getProcessId()); + //辅料 + List listAccessories=productProcessMapper.findAccessories(item.getProcessId()); + //然后将产品工序id和辅料面料绑定 + //产品工序面料 + for (ZyProcessFabric zyProcessFabric : listFabric) { + ProductProcessFabric fabric=new ProductProcessFabric(); + fabric.setFabricId(zyProcessFabric.getFabricId()); + fabric.setAmount(zyProcessFabric.getAmount()); + fabric.setProductProcessId(productprocessId); + fabric.setId(null); + productProcessFabricMapper.insert(fabric); + } + //产品工序辅料 + for (ZyProcessAccessories listAccessory : listAccessories) { + ProductProcessAccessories accessories=new ProductProcessAccessories(); + accessories.setAccessoriesId(listAccessory.getAccessoriesId()); + accessories.setAmount(listAccessory.getAmount()); + accessories.setProductProcessId(productprocessId); + accessories.setId(null); + productProcessAccessoriesMapper.insert(accessories); + } + //ZyProcess =processMapper.selectById(item.getProcessId()); + + //region 获取工序工具 + QueryWrapper operationtoolWrapper=new QueryWrapper(); + //根据工序ID + operationtoolWrapper.eq("operationid",item.getProcessId()); + List operationtoolList=zyOperationtoolMapper.selectList(operationtoolWrapper); + int sort=1; + for(ZyOperationtool itemTool:operationtoolList) + { + ProductOperationtool poModel=new ProductOperationtool(); + poModel.setProductId(productModel.getId());//产品id + poModel.setOperationtoolId(itemTool.getToolid());//工具id + + poModel.setSort(sort++);//序号 + productOperationtoolMapper.insert(poModel); + + } + //endregion + + //region 获取工序设备 + QueryWrapper processMachineWrapper=new QueryWrapper(); + //根据工序ID + processMachineWrapper.eq("process_id",item.getProcessId()); + List processMachineList=zyProcessMachine.selectList(processMachineWrapper); + //遍历设备 + sort=1; + for(ZyProcessMachine itemMachine:processMachineList) + { + ProductMachine pmModel=new ProductMachine(); + pmModel.setProductId(productModel.getId());//产品id + pmModel.setMachineId(itemMachine.getMachineId());//设备 + pmModel.setSort(sort++);//序号 + productMachineMapper.insert(pmModel); + + } + //endregion + + //productProcessList.add(zpp); + } + //zyProductProcessService.save() + //#endregion + + + //#region 产品模块-添加(从订单中读取) + //订单商品模块表-根据订单商品id + QueryWrapper productModuleWrapper=new QueryWrapper(); + productModuleWrapper.eq("order_goods_id",ogModel.getId()); + List orderGoodsModuleList=orderGoodsModuleMapper.selectList(productModuleWrapper); + //循环保存 + List ProductModuleList=new ArrayList<>(); + for(OrderGoodsModule item:orderGoodsModuleList) + { + ProductModule pmModel=new ProductModule(); + pmModel.setProductId(productModel.getId());//产品id + pmModel.setStyleModuleId(item.getStyleModuleId());//款式模块id + pmModel.setModuleId(item.getModuleId());//模块id + //保存 + productModuleMapper.insert(pmModel); + //ProductModuleList.add(pmModel); + } + + //productModuleMapper.saveBatch(ProductModuleList); + //#endregion + + //#region 产品面料-添加(从订单中读取) + + //订单商品面料表-根据订单商品id + QueryWrapper ogFabricWrapper=new QueryWrapper(); + ogFabricWrapper.eq("order_goods_id",ogModel.getId()); + List orderGoodsFabricList=orderGoodsFabricMapper.selectList(ogFabricWrapper); + //循环保存 + List productFabricList=new ArrayList<>(); + for(OrderGoodsFabric item:orderGoodsFabricList) + { + ProductFabric ptModel=new ProductFabric(); + ptModel.setProductId(productModel.getId());//产品id + ptModel.setFabricId(item.getFabricId());//面料id + // productFabricList.add(ptModel); + //保存 + productFabricMapper.insert(ptModel); + } + //保存 + // productFabricMapper.saveBatch(productFabricList); + //#endregion + + //#region 产品辅料-添加(从订单中读取) + //订单商品辅料表-根据订单商品id + QueryWrapper ogAccessoriesWrapper=new QueryWrapper(); + ogAccessoriesWrapper.eq("order_goods_id",ogModel.getId()); + List orderGoodsAccessoriesList=orderGoodsAccessoriesMapper.selectList(ogAccessoriesWrapper); + //循环保存 + List productAccessoriesList=new ArrayList<>(); + for(OrderGoodsAccessories item:orderGoodsAccessoriesList) + { + ProductAccessories paModel=new ProductAccessories(); + paModel.setProductId(productModel.getId());//产品id + paModel.setAccessoriesId(item.getAccessoriesId());//辅料id + + productAccessoriesMapper.insert(paModel); + // productAccessoriesList.add(paModel); + } + //保存 + // productAccessoriesMapper.saveBatch(productAccessoriesList); + //#endregion + } + //#endregion + } + + else + { + return Result.error("订单商品数量小于0!"); + + } + + }else//end if 02 + { + return Result.error("订单商品数据未找到!"); + } + //修改订单状态 + zyOrders.setDeliveryStatus(3); + zyOrdersMapper.updateById(zyOrders); + return Result.OK("成功",workOrder); + } + + /** + * 撤销工单 + * @param woModel + * @return + */ + @Override + public Result cancellationWorkOrder(WorkOrder woModel) { + //根据工单获取产品列表,然后循环删除产品列表中的工序,以及工序对应的设备、工具,再删除产品中对应模块、面料、辅料 + + //工单 + //-产品 + QueryWrapper productWrapper = new QueryWrapper(); + productWrapper.eq("work_order_id", woModel.getId()); + List productList = productMapper.selectList(productWrapper); + + for (ZyProduct model:productList) + { + //-工序 + QueryWrapper productProcessWrapper = new QueryWrapper(); + productProcessWrapper.eq("product_id",model.getId()); + productProcessMapper.delete(productProcessWrapper); + //-工具 + QueryWrapper productOperationtoolWrapper = new QueryWrapper(); + productOperationtoolWrapper.eq("product_id",model.getId()); + productOperationtoolMapper.delete(productOperationtoolWrapper); + //-设备 + QueryWrapper productMachineWrapper = new QueryWrapper(); + productMachineWrapper.eq("product_id",model.getId()); + productMachineMapper.delete(productMachineWrapper); + + //产品模块 + QueryWrapper productModuleWrapper = new QueryWrapper(); + productModuleWrapper.eq("product_id",model.getId()); + productModuleMapper.delete(productModuleWrapper); + + //产品面料 + QueryWrapper productFabricWrapper = new QueryWrapper(); + productFabricWrapper.eq("product_id",model.getId()); + productFabricMapper.delete(productFabricWrapper); + + //产品面料 + QueryWrapper productAccessoriesWrapper = new QueryWrapper(); + productAccessoriesWrapper.eq("product_id",model.getId()); + productAccessoriesMapper.delete(productAccessoriesWrapper); + } + + + //修改订单 + UpdateWrapper updateWrapper = new UpdateWrapper(); + updateWrapper.eq("id", woModel.getOrdersId()); + updateWrapper.set("delivery_status", 2); + int update = zyOrdersMapper.update(null, updateWrapper); + + //产品 + productMapper.delete(productWrapper); + //工单 + baseMapper.deleteById(woModel.getId()); + return Result.OK("成功"); + } + + @Override + public List jobPaidan(List orderIds) { + //获取生产部门 + QueryWrapper queryWrapper=new QueryWrapper(); + queryWrapper.eq("org_category",2); + List sysDepList = sysDepartMapper.selectList(queryWrapper); + if(sysDepList.size()>0) + { + + List wordOderIds=new ArrayList<>(); + //生产随机数,然后随机获取生产部门 + int r=(int)Math.random() * sysDepList.size(); + SysDepart dep=sysDepList.get(r); + for(String orderId:orderIds) + { + ZyOrders model=zyOrdersMapper.selectById(orderId); + Result result=this.paidan(model,dep.getId()); + if (result.getCode().toString().equals("500")) + { + return null; + } + WorkOrder wo=(WorkOrder)result.getResult(); + wordOderIds.add(wo.getId()); + } + return wordOderIds; + } + return null; + } + + + //生成工单编号 + + /** + * + * @param styleCode 款式编号 + * @param modelCode 型号编号 + * @return + */ + private String CreateWorkCode(String styleCode,String modelCode) + {//编号规则:款式编号(10)+型号(4)+顺序号(8) + String mrstr = "00000000"; + QueryWrapper query = new QueryWrapper(); + int listsize = baseMapper.selectList(query).size(); + int strsize = listsize+1; + String str = strsize+""; + int strlength = str.length(); + String substr = mrstr.substring(0,mrstr.length()-strlength); + String workCode = styleCode+modelCode+substr+str; + return workCode; + } + + /** + * + * @param workCode 工单编号 + * @return + */ + private String CreateProductCode(String workCode) + {//编号规则:工单编号(22)+顺序号(8) + String mrstr = "00000000"; + QueryWrapper query = new QueryWrapper(); + int listsize = productMapper.selectList(query).size(); + int strsize = listsize+1; + String str = strsize+""; + int strlength = str.length(); + String substr = mrstr.substring(0,mrstr.length()-strlength); + String produceCode = workCode+substr+str; + return produceCode; + } + + +}