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