提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.sys.modular.rest.service; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.enums.CommonStatus; |
|
4 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
5 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
6 |
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum; |
|
7 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestDict; |
|
8 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestDictType; |
|
9 |
import cn.stylefeng.guns.sys.modular.rest.mapper.RestDictTypeMapper; |
|
10 |
import cn.stylefeng.guns.sys.modular.system.model.params.DictTypeParam; |
|
11 |
import cn.stylefeng.guns.sys.modular.system.model.result.DictTypeResult; |
|
12 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
13 |
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException; |
|
14 |
import cn.stylefeng.roses.kernel.model.exception.ServiceException; |
|
15 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
16 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
17 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
18 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
19 |
import org.springframework.stereotype.Service; |
|
20 |
import org.springframework.transaction.annotation.Transactional; |
|
21 |
|
|
22 |
import javax.annotation.Resource; |
|
23 |
import java.io.Serializable; |
|
24 |
import java.util.List; |
|
25 |
|
|
26 |
/** |
|
27 |
* <p> |
|
28 |
* 字典类型表 服务实现类 |
|
29 |
* </p> |
|
30 |
* |
|
31 |
* @author stylefeng |
|
32 |
* @since 2019-03-13 |
|
33 |
*/ |
|
34 |
@Service |
|
35 |
public class RestDictTypeService extends ServiceImpl<RestDictTypeMapper, RestDictType> { |
|
36 |
|
|
37 |
@Resource |
|
38 |
private RestDictService restDictService; |
|
39 |
|
|
40 |
/** |
|
41 |
* 新增 |
|
42 |
* |
|
43 |
* @author stylefeng |
|
44 |
* @Date 2019-03-13 |
|
45 |
*/ |
|
46 |
public void add(DictTypeParam param) { |
|
47 |
|
|
48 |
//判断是否已经存在同编码或同名称字典 |
|
49 |
QueryWrapper<RestDictType> dictQueryWrapper = new QueryWrapper<>(); |
|
50 |
dictQueryWrapper.eq("code", param.getCode()).or().eq("name", param.getName()); |
|
51 |
List<RestDictType> list = this.list(dictQueryWrapper); |
|
52 |
if (list != null && list.size() > 0) { |
|
53 |
throw new ServiceException(BizExceptionEnum.DICT_EXISTED); |
|
54 |
} |
|
55 |
|
|
56 |
RestDictType entity = getEntity(param); |
|
57 |
|
|
58 |
//设置状态 |
|
59 |
entity.setStatus(CommonStatus.ENABLE.getCode()); |
|
60 |
|
|
61 |
this.save(entity); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* 删除 |
|
66 |
* |
|
67 |
* @author stylefeng |
|
68 |
* @Date 2019-03-13 |
|
69 |
*/ |
|
70 |
@Transactional(rollbackFor = Exception.class) |
|
71 |
public void delete(DictTypeParam param) { |
|
72 |
|
|
73 |
if (param == null || param.getDictTypeId() == null) { |
|
74 |
throw new RequestEmptyException("字典类型id为空"); |
|
75 |
} |
|
76 |
|
|
77 |
//删除字典类型 |
|
78 |
this.removeById(getKey(param)); |
|
79 |
|
|
80 |
//删除字典 |
|
81 |
this.restDictService.remove(new QueryWrapper<RestDict>().eq("dict_type_id", getKey(param))); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* 更新 |
|
86 |
* |
|
87 |
* @author stylefeng |
|
88 |
* @Date 2019-03-13 |
|
89 |
*/ |
|
90 |
public void update(DictTypeParam param) { |
|
91 |
RestDictType oldEntity = getOldEntity(param); |
|
92 |
RestDictType newEntity = getEntity(param); |
|
93 |
ToolUtil.copyProperties(newEntity, oldEntity); |
|
94 |
|
|
95 |
//判断编码是否重复 |
|
96 |
QueryWrapper<RestDictType> wrapper = new QueryWrapper<RestDictType>() |
|
97 |
.and(i -> i.eq("code", newEntity.getCode()).or().eq("name", newEntity.getName())) |
|
98 |
.and(i -> i.ne("dict_type_id", newEntity.getDictTypeId())); |
|
99 |
int dicts = this.count(wrapper); |
|
100 |
if (dicts > 0) { |
|
101 |
throw new ServiceException(BizExceptionEnum.DICT_EXISTED); |
|
102 |
} |
|
103 |
|
|
104 |
this.updateById(newEntity); |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* 查询单条数据,Specification模式 |
|
109 |
* |
|
110 |
* @author stylefeng |
|
111 |
* @Date 2019-03-13 |
|
112 |
*/ |
|
113 |
public DictTypeResult findBySpec(DictTypeParam param) { |
|
114 |
return null; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* 查询列表,Specification模式 |
|
119 |
* |
|
120 |
* @author stylefeng |
|
121 |
* @Date 2019-03-13 |
|
122 |
*/ |
|
123 |
public List<DictTypeResult> findListBySpec(DictTypeParam param) { |
|
124 |
return null; |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* 查询分页数据,Specification模式 |
|
129 |
* |
|
130 |
* @author stylefeng |
|
131 |
* @Date 2019-03-13 |
|
132 |
*/ |
|
133 |
public LayuiPageInfo findPageBySpec(DictTypeParam param) { |
|
134 |
Page pageContext = getPageContext(); |
|
135 |
QueryWrapper<RestDictType> objectQueryWrapper = new QueryWrapper<>(); |
|
136 |
if (ToolUtil.isNotEmpty(param.getCondition())) { |
|
137 |
objectQueryWrapper.and(i -> i.eq("code", param.getCondition()).or().eq("name", param.getCondition())); |
|
138 |
} |
|
139 |
if (ToolUtil.isNotEmpty(param.getStatus())) { |
|
140 |
objectQueryWrapper.and(i -> i.eq("status", param.getStatus())); |
|
141 |
} |
|
142 |
if (ToolUtil.isNotEmpty(param.getSystemFlag())) { |
|
143 |
objectQueryWrapper.and(i -> i.eq("system_flag", param.getSystemFlag())); |
|
144 |
} |
|
145 |
|
|
146 |
pageContext.setAsc("sort"); |
|
147 |
|
|
148 |
IPage page = this.page(pageContext, objectQueryWrapper); |
|
149 |
return LayuiPageFactory.createPageInfo(page); |
|
150 |
} |
|
151 |
|
|
152 |
private Serializable getKey(DictTypeParam param) { |
|
153 |
return param.getDictTypeId(); |
|
154 |
} |
|
155 |
|
|
156 |
private Page getPageContext() { |
|
157 |
return LayuiPageFactory.defaultPage(); |
|
158 |
} |
|
159 |
|
|
160 |
private RestDictType getOldEntity(DictTypeParam param) { |
|
161 |
return this.getById(getKey(param)); |
|
162 |
} |
|
163 |
|
|
164 |
private RestDictType getEntity(DictTypeParam param) { |
|
165 |
RestDictType entity = new RestDictType(); |
|
166 |
ToolUtil.copyProperties(param, entity); |
|
167 |
return entity; |
|
168 |
} |
|
169 |
|
|
170 |
} |