提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.modular.zsx.pm.workOrder.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.workOrder.entity.WorkOrder; |
|
7 |
import cn.stylefeng.guns.modular.zsx.pm.workOrder.mapper.WorkOrderMapper; |
|
8 |
import cn.stylefeng.guns.modular.zsx.pm.workOrder.model.params.WorkOrderParam; |
|
9 |
import cn.stylefeng.guns.modular.zsx.pm.workOrder.model.result.WorkOrderResult; |
|
10 |
import cn.stylefeng.guns.modular.zsx.pm.workOrder.service.WorkOrderService; |
|
11 |
import cn.stylefeng.guns.modular.zsx.sys.codingRule.entity.CodingRule; |
|
12 |
import cn.stylefeng.guns.modular.zsx.sys.codingRule.service.CodingRuleService; |
|
13 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
14 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
15 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
16 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
17 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
18 |
import org.apache.commons.lang3.StringUtils; |
|
19 |
import org.springframework.beans.factory.annotation.Autowired; |
|
20 |
import org.springframework.stereotype.Service; |
|
21 |
|
|
22 |
import java.io.Serializable; |
|
23 |
import java.text.SimpleDateFormat; |
|
24 |
import java.util.Date; |
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
/** |
|
28 |
* <p> |
|
29 |
* 生产工单 服务实现类 |
|
30 |
* </p> |
|
31 |
* |
|
32 |
* @author ruimin |
|
33 |
* @since 2023-08-26 |
|
34 |
*/ |
|
35 |
@Service |
|
36 |
public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrder> implements WorkOrderService { |
|
37 |
@Autowired |
|
38 |
private CodingRuleService codingRuleService; |
|
39 |
|
|
40 |
@Override |
|
41 |
public void add(WorkOrderParam param){ |
|
42 |
param.setCreateUser(LoginContextHolder.getContext().getUser().getName()); |
|
43 |
WorkOrder entity = getEntity(param); |
|
44 |
this.save(entity); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
public void delete(WorkOrderParam param){ |
|
49 |
this.removeById(getKey(param)); |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public void update(WorkOrderParam param){ |
|
54 |
param.setUpdateUser(LoginContextHolder.getContext().getUser().getName()); |
|
55 |
WorkOrder oldEntity = getOldEntity(param); |
|
56 |
WorkOrder newEntity = getEntity(param); |
|
57 |
ToolUtil.copyProperties(newEntity, oldEntity); |
|
58 |
this.updateById(newEntity); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public WorkOrderResult findBySpec(WorkOrderParam param){ |
|
63 |
return null; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public List<WorkOrderResult> findListBySpec(WorkOrderParam param){ |
|
68 |
return null; |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public LayuiPageInfo findPageBySpec(WorkOrderParam param){ |
|
73 |
Page pageContext = getPageContext(); |
|
74 |
IPage page = this.baseMapper.customPageList(pageContext, param); |
|
75 |
return LayuiPageFactory.createPageInfo(page); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public String getOrderCode() { |
|
80 |
CodingRule codingRule = codingRuleService.getCodingCode("WORK_ORDER"); |
|
81 |
String result = ""; |
|
82 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); |
|
83 |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(codingRule.getDateType()); |
|
84 |
String dateString = sdf.format(new Date()); |
|
85 |
List<WorkOrder> oneOrder = this.list(new QueryWrapper<WorkOrder>().eq("work_order_code",codingRule.getCurrentCode())); |
|
86 |
if(oneOrder.size() == 0){ |
|
87 |
result = codingRule.getCurrentCode(); |
|
88 |
}else { |
|
89 |
List<WorkOrder> workOrderCode = this.list(new QueryWrapper<WorkOrder>().like("work_order_code", dateString)); |
|
90 |
result = codingRule.getCodingRulePrefix()+simpleDateFormat.format(new Date())+StringUtils.leftPad(String.valueOf(workOrderCode.size()+1), codingRule.getCodeLength(), "0"); |
|
91 |
} |
|
92 |
return result; |
|
93 |
} |
|
94 |
|
|
95 |
private Serializable getKey(WorkOrderParam param){ |
|
96 |
return param.getId(); |
|
97 |
} |
|
98 |
|
|
99 |
private Page getPageContext() { |
|
100 |
return LayuiPageFactory.defaultPage(); |
|
101 |
} |
|
102 |
|
|
103 |
private WorkOrder getOldEntity(WorkOrderParam param) { |
|
104 |
return this.getById(getKey(param)); |
|
105 |
} |
|
106 |
|
|
107 |
private WorkOrder getEntity(WorkOrderParam param) { |
|
108 |
WorkOrder entity = new WorkOrder(); |
|
109 |
ToolUtil.copyProperties(param, entity); |
|
110 |
return entity; |
|
111 |
} |
|
112 |
|
|
113 |
} |