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