提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.sys.modular.rest.service.impl; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
4 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
5 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestPosition; |
|
6 |
import cn.stylefeng.guns.sys.modular.rest.entity.RestUserPos; |
|
7 |
import cn.stylefeng.guns.sys.modular.rest.mapper.RestPositionMapper; |
|
8 |
import cn.stylefeng.guns.sys.modular.rest.service.RestPositionService; |
|
9 |
import cn.stylefeng.guns.sys.modular.rest.service.RestUserPosService; |
|
10 |
import cn.stylefeng.guns.sys.modular.system.model.params.PositionParam; |
|
11 |
import cn.stylefeng.guns.sys.modular.system.model.result.PositionResult; |
|
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.springframework.stereotype.Service; |
|
18 |
|
|
19 |
import javax.annotation.Resource; |
|
20 |
import java.io.Serializable; |
|
21 |
import java.util.List; |
|
22 |
import java.util.Map; |
|
23 |
|
|
24 |
/** |
|
25 |
* <p> |
|
26 |
* 职位表 服务实现类 |
|
27 |
* </p> |
|
28 |
* |
|
29 |
* @author stylefeng |
|
30 |
* @since 2019-06-27 |
|
31 |
*/ |
|
32 |
@Service |
|
33 |
public class RestPositionServiceImpl extends ServiceImpl<RestPositionMapper, RestPosition> implements RestPositionService { |
|
34 |
|
|
35 |
@Resource |
|
36 |
private RestUserPosService restUserPosService; |
|
37 |
|
|
38 |
@Override |
|
39 |
public void add(PositionParam param) { |
|
40 |
RestPosition entity = getEntity(param); |
|
41 |
this.save(entity); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void delete(PositionParam param) { |
|
46 |
this.removeById(getKey(param)); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public void update(PositionParam param) { |
|
51 |
RestPosition oldEntity = getOldEntity(param); |
|
52 |
RestPosition newEntity = getEntity(param); |
|
53 |
ToolUtil.copyProperties(newEntity, oldEntity); |
|
54 |
this.updateById(newEntity); |
|
55 |
} |
|
56 |
|
|
57 |
@Override |
|
58 |
public PositionResult findBySpec(PositionParam param) { |
|
59 |
return null; |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public List<PositionResult> findListBySpec(PositionParam param) { |
|
64 |
return null; |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
68 |
public LayuiPageInfo findPageBySpec(PositionParam param) { |
|
69 |
Page pageContext = getPageContext(); |
|
70 |
IPage page = this.baseMapper.customPageList(pageContext, param); |
|
71 |
return LayuiPageFactory.createPageInfo(page); |
|
72 |
} |
|
73 |
|
|
74 |
@Override |
|
75 |
public LayuiPageInfo listPositions(Long userId) { |
|
76 |
|
|
77 |
//找出所有职位 |
|
78 |
List<Map<String, Object>> list = this.baseMapper.getAllPositionMap(); |
|
79 |
|
|
80 |
//用户id为空,则直接返回 |
|
81 |
if (userId == null) { |
|
82 |
|
|
83 |
} else { |
|
84 |
|
|
85 |
//查询用户的职位id列表 |
|
86 |
List<RestUserPos> userPosList = this.restUserPosService.list(new QueryWrapper<RestUserPos>().eq("user_id", userId)); |
|
87 |
|
|
88 |
if (userPosList != null && userPosList.size() > 0) { |
|
89 |
for (RestUserPos userPos : userPosList) { |
|
90 |
for (Map<String, Object> positionMap : list) { |
|
91 |
if (userPos.getPosId().equals(positionMap.get("positionId"))) { |
|
92 |
positionMap.put("selected", true); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
LayuiPageInfo layuiPageInfo = new LayuiPageInfo(); |
|
100 |
layuiPageInfo.setData(list); |
|
101 |
return layuiPageInfo; |
|
102 |
|
|
103 |
} |
|
104 |
|
|
105 |
private Serializable getKey(PositionParam param) { |
|
106 |
return param.getPositionId(); |
|
107 |
} |
|
108 |
|
|
109 |
private Page getPageContext() { |
|
110 |
return LayuiPageFactory.defaultPage(); |
|
111 |
} |
|
112 |
|
|
113 |
private RestPosition getOldEntity(PositionParam param) { |
|
114 |
return this.getById(getKey(param)); |
|
115 |
} |
|
116 |
|
|
117 |
private RestPosition getEntity(PositionParam param) { |
|
118 |
RestPosition entity = new RestPosition(); |
|
119 |
ToolUtil.copyProperties(param, entity); |
|
120 |
return entity; |
|
121 |
} |
|
122 |
|
|
123 |
} |