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