yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.qianwen.smartman.modules.system.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.constant.ExtCacheConstant;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.modules.system.convert.BasCoderuleConvert;
import com.qianwen.smartman.modules.system.dto.BasCoderuleDTO;
import com.qianwen.smartman.common.cache.CodeRuleCache;
import com.qianwen.smartman.modules.system.dto.BaseCodeRuleQueryDTO;
import com.qianwen.smartman.modules.system.entity.BasCodeRule;
import com.qianwen.smartman.modules.system.entity.MetaObjectType;
import com.qianwen.smartman.modules.system.service.IBasCoderuleService;
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
import com.qianwen.smartman.modules.system.service.IMetaObjectTypeService;
import com.qianwen.smartman.modules.system.vo.UserVO;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tool.api.ResultCode;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.validation.Valid;
import com.qianwen.core.cache.utils.CacheUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
@ApiResource({"blade-system/bascoderule"})
@Api(value = "编码规则", tags = {"编码规则接口"})
@RestController
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/controller/BasCoderuleController.class */
public class BasCoderuleController extends BladeController {
    private IBasCoderuleService basCoderuleService;
    private IMetaObjectTypeService metaObjectTypeService;
    private ICodeGeneratorService codeGeneratorService;
 
    public BasCoderuleController(final IBasCoderuleService basCoderuleService, final IMetaObjectTypeService metaObjectTypeService, final ICodeGeneratorService codeGeneratorService) {
        this.basCoderuleService = basCoderuleService;
        this.metaObjectTypeService = metaObjectTypeService;
        this.codeGeneratorService = codeGeneratorService;
    }
 
    @ApiOperationSupport(order = 1)
    @GetResource({"/detail"})
    @ApiOperation(value = "详情", notes = "根据编码id获取详情")
    public R<BasCoderuleDTO> detail(Long id) {
        BasCoderuleDTO detail = this.basCoderuleService.getCoderuleDetails(id);
        return R.data(detail);
    }
 
    @ApiOperationSupport(order = 2)
    @GetResource({"/list"})
    @ApiOperation(value = "分页", notes = "传入basCoderule")
    @PreAuth
    public R<IPage<BasCodeRule>> list(BaseCodeRuleQueryDTO baseCodeRuleQueryDTO, Query query) {
        List<String> list = new ArrayList<>();
        if (Func.isNotEmpty(baseCodeRuleQueryDTO.getSubsysId())) {
            List<MetaObjectType> metaObjectTypes = this.metaObjectTypeService.list(Wrappers.<MetaObjectType>lambdaQuery()
                    .eq(MetaObjectType::getSubsysId, baseCodeRuleQueryDTO.getSubsysId()));
            /*
            List<MetaObjectType> metaObjectTypes = this.metaObjectTypeService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getSubsysId();
            }, baseCodeRuleQueryDTO.getSubsysId()));*/
            if (metaObjectTypes.isEmpty()) {
                return R.data(new Page<>());
            }
            list = metaObjectTypes.stream().map((v0) -> {
                return v0.getFId();
            }).collect(Collectors.toList());
        }
        IPage<BasCodeRule> pages = this.basCoderuleService.page(Condition.getPage(query), Wrappers.<BasCodeRule>lambdaQuery()
                .eq(Func.isNotEmpty(baseCodeRuleQueryDTO.getDictKey()), BasCodeRule::getRuleFieldDictKey, baseCodeRuleQueryDTO.getDictKey())
                .eq(Func.isNotEmpty(baseCodeRuleQueryDTO.getObjectId()), BasCodeRule::getBillFormId, baseCodeRuleQueryDTO.getObjectId())
                .in(Func.isNotEmpty(list), BasCodeRule::getBillFormId, list)
                .and(Func.isNotEmpty(baseCodeRuleQueryDTO.getCondition()), wrapper -> wrapper.like(BasCodeRule::getName, baseCodeRuleQueryDTO.getCondition()).or().like(BasCodeRule::getRemark, baseCodeRuleQueryDTO.getCondition())));
        /*
        IPage<BasCodeRule> pages = this.basCoderuleService.page(Condition.getPage(query), Wrappers.lambdaQuery().eq(Func.isNotEmpty(baseCodeRuleQueryDTO.getDictKey()), (v0) -> {
            return v0.getRuleFieldDictKey();
        }, baseCodeRuleQueryDTO.getDictKey()).eq(Func.isNotEmpty(baseCodeRuleQueryDTO.getObjectId()), (v0) -> {
            return v0.getBillFormId();
        }, baseCodeRuleQueryDTO.getObjectId()).in(Func.isNotEmpty(list), (v0) -> {
            return v0.getBillFormId();
        }, list).and(Func.isNotEmpty(baseCodeRuleQueryDTO.getCondition()), wrapper -> {
            LambdaQueryWrapper lambdaQueryWrapper = (LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) wrapper.like((v0) -> {
                return v0.getName();
            }, baseCodeRuleQueryDTO.getCondition())).or()).like((v0) -> {
                return v0.getRemark();
            }, baseCodeRuleQueryDTO.getCondition());
        }));*/
        return R.data(pages);
    }
 
    @PreAuth
    @GetResource({"/count"})
    @ApiOperation(value = "count", notes = "编码规则查询数量")
    public R<Long> count(@RequestParam("type") @ApiParam("业务对象名称") String type) {
        return R.data(Long.valueOf(this.basCoderuleService.count(Lambda.eq((v0) -> {
            return v0.getBillFormId();
        }, type))));
    }
 
    @GetResource({"/count-all"})
    @ApiOperation(value = "count-all", notes = "查询所有业务对象编码规则数量")
    public R countAll() {
        Wrapper<BasCodeRule> w = (new QueryWrapper<BasCodeRule>()).select(new String[] { "count(1) as \"count\"", Lambda.getName(BasCodeRule::getBillFormId) }).lambda().groupBy(BasCodeRule::getBillFormId);
        /*
        Wrapper w = (Wrapper) new QueryWrapper().select(new String[]{"count(1) as \"count\"", Lambda.getName((v0) -> {
            return v0.getBillFormId();
        })}).lambda().groupBy((v0) -> {
            return v0.getBillFormId();
        });*/
        return R.data(BasCoderuleConvert.INSTANCE.convert(this.basCoderuleService.listMaps(w)));
    }
 
    @ApiOperationSupport(order = 6)
    @PostResource({"/submit"})
    @ApiOperation(value = "新增或修改", notes = "传入basCoderule")
    @PreAuth
    public R<BasCodeRule> submit(@Valid @RequestBody BasCoderuleDTO basCoderuleDTO) {
        return R.data(this.basCoderuleService.submitCoderule(basCoderuleDTO));
    }
 
    @ApiOperationSupport(order = 7)
    @PostResource({"/remove"})
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    @PreAuth
    public R remove(@RequestParam @ApiParam(value = "主键集合", required = true) String ids) {
        CacheUtil.clear(ExtCacheConstant.CODE_RULE_CACHE, Boolean.FALSE);
        return R.status(this.basCoderuleService.deleteCoderule(Func.toLongList(ids)).booleanValue());
    }
 
    @ApiOperationSupport(order = 8)
    @GetResource({"/is-exist-code-rule"})
    @ApiOperation(value = "根据业务对象查询是否存在编码规则", notes = "传入业务对象")
    public R<Boolean> getIsExistCodeRuleByBillFormId(@RequestParam @ApiParam(value = "业务对象", required = true) String billFormId) {
        boolean existCodeRule = CodeRuleCache.existCodeRule(billFormId);
        return R.data(Boolean.valueOf(existCodeRule));
    }
 
    @PreAuth
    @GetResource({"change-default/{id}"})
    @ApiOperation(value = "启用停用", notes = "启用停用编码规则")
    public R<Boolean> changeDefault(@PathVariable String id) {
        CacheUtil.clear(ExtCacheConstant.CODE_RULE_CACHE, Boolean.FALSE);
        return R.status(this.basCoderuleService.changeDefault(id));
    }
 
    @PostMapping({"/patch-code"})
    @PreAuth
    @ApiOperation(value = "获取手动补号数据", notes = "传入业务对象的编码字段和业务对象,查询手动补号数据")
    public R<List<String>> patchCodeList(@RequestParam @ApiParam("业务对象") String billFormId, @RequestBody Map<String, Object> objectData) {
        try {
            return R.data(this.basCoderuleService.patchCodeList(billFormId, objectData));
        } catch (IllegalArgumentException e) {
            R re = (R) JSONObject.parseObject(e.getMessage(), R.class);
            re.setCode(ResultCode.FAILURE.getCode());
            return re;
        } catch (ServiceException e2) {
            return R.fail(e2.getMessage());
        }
    }
 
    @PostMapping({"/generate"})
    public R<String> generateTest(@ApiParam("新建用户对象") UserVO user) {
        String code = this.codeGeneratorService.getGeneratorCode(user, "User");
        return R.data(code);
    }
}