新火炬后端单体项目初始化代码
zhangherong
2025-06-12 6abc1a2fb78003bb1ea6283d813b8ccc0bcd9b2b
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package org.jeecg.modules.base.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.base.entity.EncodeRule;
import org.jeecg.modules.base.entity.EncodeRuleDepart;
import org.jeecg.modules.base.entity.EncodeRuleDetail;
import org.jeecg.modules.base.service.IEncodeRuleDepartService;
import org.jeecg.modules.base.service.IEncodeRuleDetailService;
import org.jeecg.modules.base.service.IEncodeRuleService;
import org.jeecg.modules.system.service.SysIdentityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
/**
 * @Title: Controller
 * @Description: 编码规则详情表 前端控制器
 * @Author: cuijian
 * @Date: 2022-11-03
 * @Version: V1.0
 */
@RestController
@RequestMapping("/base/codeRuleDetail")
@Slf4j
public class EncodeRuleDetailController {
 
    @Resource
    private IEncodeRuleService encodeRuleService;
    @Resource
    private IEncodeRuleDetailService encodeRuleDetailService;
    @Autowired
    private IEncodeRuleDepartService encodeRuleDepartService;
    @Autowired
    private SysIdentityService sysIdentityService;
    /**
     * 查询数据 根据规则编码id查询规则编码详细信息
     * @author cj
     * @param ruleCodeId
     * @return
     */
    @GetMapping(value = "/getCodeRuleDetailByRuleCodeId")
    public Result<List<EncodeRuleDetail>> getCodeRuleDetailByCodeRuleId(@RequestParam String ruleCodeId){
        Result<List<EncodeRuleDetail>> result = new Result<>();
        if(StringUtils.isNotBlank(ruleCodeId)){
            List<EncodeRuleDetail> list = encodeRuleDetailService.getCodeRuleDetailByCodeRuleId(ruleCodeId);
            result.setResult(list);
        }
        return result;
    }
    /**
     * 增加数据 添加和修改编码规则详细信息
     * @author cj
     * @param encodeRuleDetail
     * @return
     */
    @PostMapping(value = "/addEncodeRuleDetail")
    public Result<EncodeRuleDetail> addEncodeRuleDetail(@RequestBody EncodeRuleDetail encodeRuleDetail){
        Result<EncodeRuleDetail> result = new Result<>();
        try{
            encodeRuleDetailService.saveOrUpdate(encodeRuleDetail);
            result.success("操作成功");
        }catch (Exception e){
            result.error500("操作失败");
        }
        return result;
    }
 
    /**
     * 删除数据 删除选中的编码规则详情信息
     * @author cj
     * @param ids
     * @return
     */
    @DeleteMapping(value = "/deleteEncodeRuleDetail")
    public Result<EncodeRuleDetail> deleteEncodeRuleDetail(@RequestParam String ids){
        Result<EncodeRuleDetail> result = new Result<>();
        if(oConvertUtils.isEmpty(ids)) {
            result.error500("未选中编码规则详情!");
        }else {
            String[] ls = ids.split(",");
            for (String id : ls) {
                encodeRuleDetailService.removeById(id);
            }
            result.success("删除成功!");
        }
        return result;
    }
 
    /**
     * 生成编码
     * @author cj
     * @param permissionId
     * @return
     */
    @GetMapping(value = "/getCode")
    public Result<String> getCode(@RequestParam String permissionId){
        //获取当前登录用户
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        Result<String> result = new Result<>();
        String prifix = "";
        //查询企业下针对菜单是否有启用的编码规则
        List<EncodeRule> encodeRuleList = encodeRuleService.lambdaQuery()
                .eq(EncodeRule::getPermissionId,permissionId)
//                .eq(EncodeRule::getEnterpriseId,user.getEnterpriseId())
                .eq(EncodeRule::getStatus,"1")
                .eq(EncodeRule::getDelFlag, CommonConstant.DEL_FLAG_0).list();
        if(CollectionUtils.isNotEmpty(encodeRuleList)){
            //查询登录人的部门是否关联了编码规则
            List<EncodeRuleDepart> encodeRuleDepartList = encodeRuleDepartService.lambdaQuery()
                    .eq(EncodeRuleDepart::getCodeRuleId,encodeRuleList.get(0).getId())
                    .eq(EncodeRuleDepart::getDelFlag,CommonConstant.DEL_FLAG_0)
//                    .eq(EncodeRuleDepart::getDepartId,user.getDepartId())
                    .list();
            if(CollectionUtils.isNotEmpty(encodeRuleDepartList)){
                //查询编码规则是否有编码规则详情
                List<EncodeRuleDetail> encodeRuleDetailList = encodeRuleDetailService.lambdaQuery()
                        .eq(EncodeRuleDetail::getCodeRuleId,encodeRuleList.get(0).getId())
                        .eq(EncodeRuleDetail::getDelFlag,CommonConstant.DEL_FLAG_0).orderByAsc(EncodeRuleDetail::getSequence).list();
                if(CollectionUtils.isNotEmpty(encodeRuleDetailList)){
                    for(EncodeRuleDetail encodeRuleDetail : encodeRuleDetailList){
                        if("2".equals(encodeRuleDetail.getCodeElement())){
                            prifix += encodeRuleDetail.getElementValue();
                        }else if("1".equals(encodeRuleDetail.getCodeElement())){
                            if("1".equals(encodeRuleDetail.getTimeFormat())){
                                prifix += DateUtils.date2Str(new Date(),DateUtils.yyyyMMdd.get());
                            }else if("2".equals(encodeRuleDetail.getTimeFormat())){
                                prifix += DateUtils.date2Str(new Date(),new SimpleDateFormat("yyyyMM"));
                            }else if("3".equals(encodeRuleDetail.getTimeFormat())){
                                prifix += DateUtils.date2Str(new Date(),DateUtils.yearFormat.get());
                            }
                        }else if("3".equals(encodeRuleDetail.getCodeElement())){
                            prifix += sysIdentityService.getNumByTypeAndLength(permissionId,encodeRuleDetail.getLength());
                        }
                    }
                }else {
                    result.error500("请维护编码规则详情");
                }
            }else {
                result.error500("您的账号没有关联编码规则");
            }
        }else{
            result.error500("请维护编码规则");
        }
        return Result.OK(prifix);
    }
 
}