懒羊羊
2023-08-30 1ac2bc1590406d9babec036e154d8d08f34a6aa1
提交 | 用户 | 时间
1ac2bc 1 package cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.impl;
2
3 import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
4 import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
5 import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
6 import cn.stylefeng.guns.modular.zsx.pm.salesOrder.entity.SalesOrder;
7 import cn.stylefeng.guns.modular.zsx.pm.salesOrder.mapper.SalesOrderMapper;
8 import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.params.SalesOrderParam;
9 import cn.stylefeng.guns.modular.zsx.pm.salesOrder.model.result.SalesOrderResult;
10 import  cn.stylefeng.guns.modular.zsx.pm.salesOrder.service.SalesOrderService;
11 import cn.stylefeng.guns.modular.zsx.pm.salesOrderChild.entity.SalesOrderChild;
12 import cn.stylefeng.guns.modular.zsx.pm.salesOrderChild.service.SalesOrderChildService;
13 import cn.stylefeng.guns.modular.zsx.pm.workOrder.entity.WorkOrder;
14 import cn.stylefeng.guns.modular.zsx.pm.workOrder.service.WorkOrderService;
15 import cn.stylefeng.roses.core.util.ToolUtil;
16 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
17 import com.baomidou.mybatisplus.core.metadata.IPage;
18 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
19 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Service;
22
23 import java.io.Serializable;
24 import java.util.List;
25
26 /**
27  * <p>
28  * 生产订单 服务实现类
29  * </p>
30  *
31  * @author ruimin
32  * @since 2023-08-26
33  */
34 @Service
35 public class SalesOrderServiceImpl extends ServiceImpl<SalesOrderMapper, SalesOrder> implements SalesOrderService {
36     @Autowired
37     private WorkOrderService workOrderService;
38
39     @Autowired
40     private SalesOrderChildService salesOrderChildService;
41
42     @Override
43     public void add(SalesOrderParam param){
44         param.setCreateUser(LoginContextHolder.getContext().getUser().getName());
45         SalesOrder entity = getEntity(param);
46         this.save(entity);
47     }
48
49     @Override
50     public void delete(SalesOrderParam param){
51         this.removeById(getKey(param));
52     }
53
54     @Override
55     public void update(SalesOrderParam param){
56         param.setUpdateUser(LoginContextHolder.getContext().getUser().getName());
57         SalesOrder oldEntity = getOldEntity(param);
58         SalesOrder newEntity = getEntity(param);
59         ToolUtil.copyProperties(newEntity, oldEntity);
60         this.updateById(newEntity);
61     }
62
63     @Override
64     public SalesOrderResult findBySpec(SalesOrderParam param){
65         return null;
66     }
67
68     @Override
69     public List<SalesOrderResult> findListBySpec(SalesOrderParam param){
70         return null;
71     }
72
73     @Override
74     public LayuiPageInfo findPageBySpec(SalesOrderParam param){
75         Page pageContext = getPageContext();
76         IPage page = this.baseMapper.customPageList(pageContext, param);
77         return LayuiPageFactory.createPageInfo(page);
78     }
79
80     @Override
81     public LayuiPageInfo breakDownOrders(SalesOrderParam param) {
82         if(param.getFlag().equals("true")){
83             SalesOrder salesOrder = this.getById(param.getId());
84             salesOrder.setPlanNumber(salesOrder.getPlanNumber()-param.getSplitNumber());
85             this.saveOrUpdate(salesOrder);
86             salesOrder.setPlanNumber(param.getSplitNumber());
87             this.save(salesOrder);
88         }
89         Page pageContext = getPageContext();
90         IPage page = this.baseMapper.salesOrderNotinId(pageContext, param);
91         return LayuiPageFactory.createPageInfo(page);
92     }
93
94     @Override
95     public void DistributeSalesOrder(SalesOrderParam salesOrderParam) {
96         SalesOrder byId = this.getById(salesOrderParam.getId());
97         switch(byId.getState()){
98             case "1" :
99                 WorkOrder workOrder = new WorkOrder();
100                 workOrder.setWorkOrderCode(workOrderService.getOrderCode());
101                 workOrder.setSalesOrderCode(byId.getSalesOrderCode());
102                 workOrder.setProductCode(byId.getProductCode());
103                 workOrder.setProductName(byId.getProductName());
104                 workOrder.setPlanQty(byId.getPlanNumber());
105                 workOrder.setPlanStartTime(byId.getPlanStartTime());
106                 workOrder.setPlanEndTime(byId.getPlanEndTime());
107                 workOrder.setWorkshopCode(byId.getWorkshopCode());
108                 workOrder.setLineCode(byId.getLineCode());
109                 workOrder.setState("1");
110                 workOrder.setRouteCode(salesOrderParam.getRouteCode());
111                 workOrder.setBomCode(salesOrderParam.getBomCode());
112                 workOrder.setRecipeCode(salesOrderParam.getRecipeCode());
113                 workOrderService.save(workOrder);
114                 break;
115             case "2" :
116                 List<SalesOrderChild> salesOrderChild = salesOrderChildService.list(new QueryWrapper<SalesOrderChild>().eq("sales_order_code", byId.getSalesOrderCode()));
117                 for (SalesOrderChild order : salesOrderChild) {
118                     WorkOrder workOrderChild = new WorkOrder();
119                     workOrderChild.setWorkOrderCode(workOrderService.getOrderCode());
120                     workOrderChild.setSalesOrderCode(order.getSalesOrderCode());
121                     workOrderChild.setProductCode(order.getProductCode());
122                     workOrderChild.setProductName(order.getProductName());
123                     workOrderChild.setPlanQty(order.getPlanNumber());
124                     workOrderChild.setPlanStartTime(order.getPlanStartTime());
125                     workOrderChild.setPlanEndTime(order.getPlanEndTime());
126                     workOrderChild.setWorkshopCode(order.getWorkshopCode());
127                     workOrderChild.setLineCode(order.getLineCode());
128                     workOrderChild.setState("1");
129                     workOrderChild.setRouteCode(salesOrderParam.getRouteCode());
130                     workOrderChild.setBomCode(salesOrderParam.getBomCode());
131                     workOrderChild.setRecipeCode(salesOrderParam.getRecipeCode());
132                     workOrderService.save(workOrderChild);
133                 }
134                 break;
135             default :
136         }
137         //更新订单表下发状态
138         byId.setState("3");
139         this.saveOrUpdate(byId);
140     }
141
142     private Serializable getKey(SalesOrderParam param){
143         return param.getId();
144     }
145
146     private Page getPageContext() {
147         return LayuiPageFactory.defaultPage();
148     }
149
150     private SalesOrder getOldEntity(SalesOrderParam param) {
151         return this.getById(getKey(param));
152     }
153
154     private SalesOrder getEntity(SalesOrderParam param) {
155         SalesOrder entity = new SalesOrder();
156         ToolUtil.copyProperties(param, entity);
157         return entity;
158     }
159
160 }