懒羊羊
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
package cn.stylefeng.guns.modular.zsx.pm.workOrder.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.workOrder.entity.WorkOrder;
import cn.stylefeng.guns.modular.zsx.pm.workOrder.mapper.WorkOrderMapper;
import cn.stylefeng.guns.modular.zsx.pm.workOrder.model.params.WorkOrderParam;
import cn.stylefeng.guns.modular.zsx.pm.workOrder.model.result.WorkOrderResult;
import  cn.stylefeng.guns.modular.zsx.pm.workOrder.service.WorkOrderService;
import cn.stylefeng.guns.modular.zsx.sys.codingRule.entity.CodingRule;
import cn.stylefeng.guns.modular.zsx.sys.codingRule.service.CodingRuleService;
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.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 生产工单 服务实现类
 * </p>
 *
 * @author ruimin
 * @since 2023-08-26
 */
@Service
public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder> implements WorkOrderService {
    @Autowired
    private CodingRuleService codingRuleService;
 
    @Override
    public void add(WorkOrderParam param){
        param.setCreateUser(LoginContextHolder.getContext().getUser().getName());
        WorkOrder entity = getEntity(param);
        this.save(entity);
    }
 
    @Override
    public void delete(WorkOrderParam param){
        this.removeById(getKey(param));
    }
 
    @Override
    public void update(WorkOrderParam param){
        param.setUpdateUser(LoginContextHolder.getContext().getUser().getName());
        WorkOrder oldEntity = getOldEntity(param);
        WorkOrder newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }
 
    @Override
    public WorkOrderResult findBySpec(WorkOrderParam param){
        return null;
    }
 
    @Override
    public List<WorkOrderResult> findListBySpec(WorkOrderParam param){
        return null;
    }
 
    @Override
    public LayuiPageInfo findPageBySpec(WorkOrderParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }
 
    @Override
    public String getOrderCode() {
        CodingRule codingRule = codingRuleService.getCodingCode("WORK_ORDER");
        String result = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(codingRule.getDateType());
        String dateString = sdf.format(new Date());
        List<WorkOrder>  oneOrder = this.list(new QueryWrapper<WorkOrder>().eq("work_order_code",codingRule.getCurrentCode()));
        if(oneOrder.size() == 0){
            result = codingRule.getCurrentCode();
        }else {
            List<WorkOrder> workOrderCode = this.list(new QueryWrapper<WorkOrder>().like("work_order_code", dateString));
            result = codingRule.getCodingRulePrefix()+simpleDateFormat.format(new Date())+StringUtils.leftPad(String.valueOf(workOrderCode.size()+1), codingRule.getCodeLength(), "0");
        }
        return result;
    }
 
    private Serializable getKey(WorkOrderParam param){
        return param.getId();
    }
 
    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }
 
    private WorkOrder getOldEntity(WorkOrderParam param) {
        return this.getById(getKey(param));
    }
 
    private WorkOrder getEntity(WorkOrderParam param) {
        WorkOrder entity = new WorkOrder();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }
 
}