yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
smart-man-boot/src/main/java/com/qianwen/smartman/modules/system/controller/BasCoderuleController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,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);
    }
}