懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
71e81e 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         param.setStatus("ENABLE");
42         Position entity = getEntity(param);
43         this.save(entity);
44     }
45
46     @Override
47     public void delete(PositionParam param) {
48         this.removeById(getKey(param));
49     }
50
51     @Override
52     public void update(PositionParam param) {
53         Position oldEntity = getOldEntity(param);
54         Position newEntity = getEntity(param);
55         ToolUtil.copyProperties(newEntity, oldEntity);
56         this.updateById(newEntity);
57     }
58
59     @Override
60     public PositionResult findBySpec(PositionParam param) {
61         return null;
62     }
63
64     @Override
65     public List<PositionResult> findListBySpec(PositionParam param) {
66         return null;
67     }
68
69     @Override
70     public LayuiPageInfo findPageBySpec(PositionParam param) {
71         Page pageContext = getPageContext();
72         IPage page = this.baseMapper.customPageList(pageContext, param);
73         return LayuiPageFactory.createPageInfo(page);
74     }
75
76     @Override
77     public LayuiPageInfo listPositions(Long userId) {
78
79         //找出所有职位
80         List<Map<String, Object>> list = this.baseMapper.getAllPositionMap();
81
82         //用户id为空,则直接返回
83         if (userId == null) {
84
85         } else {
86
87             //查询用户的职位id列表
88             List<UserPos> userPosList = this.userPosService.list(new QueryWrapper<UserPos>().eq("user_id", userId));
89
90             if (userPosList != null && userPosList.size() > 0) {
91                 for (UserPos userPos : userPosList) {
92                     for (Map<String, Object> positionMap : list) {
93                         Object positionId = positionMap.get("positionId");
94                         if (positionId instanceof BigDecimal) {
95                             if (new BigDecimal(userPos.getPosId()).equals(positionId)) {
96                                 positionMap.put("selected", true);
97                             }
98                         } else {
99                             if (userPos.getPosId().equals(positionId)) {
100                                 positionMap.put("selected", true);
101                             }
102                         }
103                     }
104                 }
105             }
106         }
107
108         LayuiPageInfo layuiPageInfo = new LayuiPageInfo();
109         layuiPageInfo.setData(list);
110         return layuiPageInfo;
111
112     }
113
114     private Serializable getKey(PositionParam param) {
115         return param.getPositionId();
116     }
117
118     private Page getPageContext() {
119         return LayuiPageFactory.defaultPage();
120     }
121
122     private Position getOldEntity(PositionParam param) {
123         return this.getById(getKey(param));
124     }
125
126     private Position getEntity(PositionParam param) {
127         Position entity = new Position();
128         ToolUtil.copyProperties(param, entity);
129         return entity;
130     }
131
132 }