cuijian
2023-08-19 bdd0875d4b13a3f1ef472f64d4b6a95e0ef64b22
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
package org.jeecg.modules.base.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.base.entity.EncodeRuleDepart;
import org.jeecg.modules.base.service.IEncodeRuleDepartService;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @Title: Controller
 * @Description: 编码规则部门关联表 前端控制器
 * @Author: cuijian
 * @Date: 2022-11-04
 * @Version: V1.0
 */
@RestController
@RequestMapping("/base/codeRuleDepart")
@Slf4j
public class EncodeRuleDepartController {
 
    @Resource
    private IEncodeRuleDepartService encodeRuleDepartService;
   /* *//**
     * 查询数据 根据编码规则id查询部门信息
     * @author cj
     * @param codeRuleId
     * @return
     *//*
    @GetMapping(value = "/getDepartBycodeRuleId")
    public Result<List<MomBaseEncodeRuleDepart>> getDepartBycodeRuleId(@RequestParam String codeRuleId){
        Result<List<MomBaseEncodeRuleDepart>> result = new Result<>();
        if(oConvertUtils.isEmpty(codeRuleId)){
            return null;
        }else {
            List<MomBaseEncodeRuleDepart> list = encodeRuleDepartService.getDepartBycodeRuleId(codeRuleId);
            result.setResult(list);
            return result;
        }
    }*/
 
    /**
     * 查询数据 根据编码规则id查询有权限的部门信息
     * @author cj
     * @param codeRuleId
     * @return
     */
    @GetMapping(value = "/getDepartBycodeRuleId")
    public Result<Map<String,Object>> getDepartList(@RequestParam String codeRuleId){
        Result<Map<String,Object>> result = new Result<>();
        //全部权限ids
        List<String> ids = new ArrayList<>();
        Map<String,Object> map = new HashMap();
        try {
                List<EncodeRuleDepart> list = encodeRuleDepartService.getDepartBycodeRuleId(codeRuleId);
                //全部树节点数据
                map.put("treeList", list);
                List<EncodeRuleDepart> encodeRuleDepartList = encodeRuleDepartService.lambdaQuery().eq(EncodeRuleDepart::getCodeRuleId,codeRuleId)
                        .eq(EncodeRuleDepart::getDelFlag,CommonConstant.STATUS_0).list();
                for(EncodeRuleDepart encodeRuleDepart : encodeRuleDepartList) {
                    ids.add(encodeRuleDepart.getDepartId());
                }
                map.put("ids",ids);
                result.setResult(map);
                result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return result;
    }
 
    /**
     * 增加数据 添加编码规则和部门关联信息
     * @author cj
     * @param json
     * @return
     */
    @PostMapping(value = "/addEncodeRuleDepart")
    public Result<String> addEncodeRuleDepart(@RequestBody JSONObject json){
        Result<String> result = new Result<>();
        try{
            String codeRuleId = json.getString("codeRuleId");
            this.deleteEncodeRuleDepart(codeRuleId);
            String departIds = json.getString("departIds");
            if(StringUtils.isNotBlank(departIds)){
                String[] departIdList = departIds.split(",");
                for(String departId : departIdList){
                    EncodeRuleDepart encodeRuleDepart = new EncodeRuleDepart();
                    encodeRuleDepart.setCodeRuleId(codeRuleId);
                    encodeRuleDepart.setDepartId(departId);
                    encodeRuleDepartService.save(encodeRuleDepart);
                }
            }
            result.success("新增成功");
        }catch (Exception e){
            result.error500("新增失败");
        }
        return result;
    }
 
    /**
     * 删除数据 根据编码规则id删除和部门的关联信息
     * @author cj
     * @param codeRuleId
     * @return
     */
    @DeleteMapping(value = "/deleteEncodeRuleDepart")
    public Result<EncodeRuleDepart> deleteEncodeRuleDepart(@RequestParam String codeRuleId){
        Result<EncodeRuleDepart> result = new Result<>();
        LambdaQueryWrapper<EncodeRuleDepart> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EncodeRuleDepart::getCodeRuleId,codeRuleId);
        List<EncodeRuleDepart> list = encodeRuleDepartService.list(queryWrapper);
        if(oConvertUtils.isNotEmpty(list)){
            list.forEach(l->{
                encodeRuleDepartService.removeById(l.getId());
            });
        }
        return result;
    }
 
}