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
132
133
package org.jeecg.modules.base.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.EncodeRule;
import org.jeecg.modules.base.entity.EncodeRuleDetail;
import org.jeecg.modules.base.entity.EncodeRuleTableFieldRelate;
import org.jeecg.modules.base.service.IEncodeRuleDetailService;
import org.jeecg.modules.base.service.IEncodeRuleService;
import org.jeecg.modules.base.service.IEncodeRuleTableFieldRelateService;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * @Title: Controller
 * @Description: 编码规则表 前端控制器
 * @Author: cuijian
 * @Date: 2022-11-03
 * @Version: V1.0
 */
@RestController
@RequestMapping("/base/codeRule")
@Slf4j
public class EncodeRuleController {
 
    @Resource
    private IEncodeRuleService encodeRuleService;
    @Resource
    private IEncodeRuleDetailService encodeRuleDetailService;
    @Resource
    private IEncodeRuleTableFieldRelateService encodeRuleTableFieldRelateService;
    /**
     * 查询数据 根据菜单id查询编码规则信息
     * @author cj
     * @param permissionId
     * @return
     */
    @GetMapping(value = "/getCodeRuleByPermissionId")
    public Result<List<EncodeRule>> getCodeRuleByPermissionId(@RequestParam String permissionId, String enterpriseId){
        Result<List<EncodeRule>> result = new Result<>();
        LambdaQueryWrapper<EncodeRule> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EncodeRule::getPermissionId,permissionId);
        queryWrapper.eq(EncodeRule::getEnterpriseId,enterpriseId);
        List<EncodeRule> list = encodeRuleService.list(queryWrapper);
        result.setResult(list);
        return result;
    }
    /**
     * 增加数据 添加和修改编码规则信息
     * @author cj
     * @param encodeRule
     * @return
     */
    @PostMapping(value = "/addEncodeRule")
    public Result<EncodeRule> addEncodeRule(@RequestBody EncodeRule encodeRule){
        Result<EncodeRule> result = new Result<>();
        try{
            encodeRuleService.saveOrUpdate(encodeRule);
            EncodeRuleTableFieldRelate encodeRuleTableFieldRelate = new EncodeRuleTableFieldRelate();
            encodeRuleTableFieldRelate.setEncodeRuleId(encodeRule.getId());
            encodeRuleTableFieldRelate.setFieldName(encodeRule.getFieldName());
            encodeRuleTableFieldRelate.setTableName(encodeRule.getTableName());
            encodeRuleTableFieldRelateService.save(encodeRuleTableFieldRelate);
            result.success("操作成功");
        }catch (Exception e){
            result.error500("操作失败");
        }
        return result;
    }
 
    /**
     * 启用停用编码规则信息
     * @author cj
     * @param json
     * @return
     */
    @PostMapping(value = "/changeStatus")
    public Result<EncodeRule> changeStatus(@RequestBody JSONObject json){
        Result<EncodeRule> result = new Result<>();
        String ids = json.getString("ids");
        String flag = json.getString("flag");
        if(oConvertUtils.isEmpty(ids)) {
            result.error500("未选中编码规则!");
        }else {
            String[] ls = ids.split(",");
            for (String id : ls) {
                EncodeRule encodeRule = encodeRuleService.lambdaQuery().eq(EncodeRule::getId,id).eq(EncodeRule::getDelFlag, CommonConstant.STATUS_0).one();
                encodeRule.setStatus(flag);
                encodeRuleService.updateById(encodeRule);
            }
            result.success("变更成功!");
        }
        return result;
    }
    /**
     * 删除数据 删除选中的编码规则信息
     * @author cj
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteEncodeRule")
    public Result<EncodeRule> deleteEncodeRule(@RequestParam String ids){
        Result<EncodeRule> result = new Result<>();
        if(oConvertUtils.isEmpty(ids)) {
            result.error500("未选中编码规则!");
        }else {
            String[] ls = ids.split(",");
            for (String id : ls) {
                //删除规则详情信息
                LambdaQueryWrapper<EncodeRuleDetail> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(EncodeRuleDetail::getCodeRuleId ,id);
                List<EncodeRuleDetail> list = encodeRuleDetailService.list(queryWrapper);
                for(EncodeRuleDetail l : list){
                    encodeRuleDetailService.removeById(l.getId());
                }
                if(encodeRuleService.removeById(id)){
                    result.success("删除成功!");
                }else {
                    result.success("删除失败!");
                }
 
            }
        }
        return result;
    }
 
}