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