编码生成
This commit is contained in:
@@ -18,7 +18,7 @@ import java.util.Map;
|
||||
@RestController
|
||||
@Api(tags = "系统:编码详情管理")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/codeDetail")
|
||||
@RequestMapping("/api/codeDetail2")
|
||||
public class CodeDetailController {
|
||||
|
||||
private final CodeDetailService codeDetailService;
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Set;
|
||||
@RestController
|
||||
@Api(tags = "系统:编码生成")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/genCode")
|
||||
@RequestMapping("/api/genCode2")
|
||||
public class GenCodeController {
|
||||
private final GenCodeService genCodeService;
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.nl.system.controller.coderule;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.coderule.ISysCodeRuleService;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleQuery;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
@RestController
|
||||
@Api(tags = "系统:编码生成")
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/genCode")
|
||||
public class SysCodeRuleController {
|
||||
private final ISysCodeRuleService codeRuleService;
|
||||
|
||||
@ApiOperation("查询编码")
|
||||
@GetMapping
|
||||
@SaCheckPermission("genCode:list")
|
||||
public ResponseEntity<Object> queryAll(CodeRuleQuery form, PageQuery pageable) {
|
||||
return new ResponseEntity<>(TableDataInfo.build(codeRuleService.queryAll(form, pageable)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增编码")
|
||||
@ApiOperation("新增编码")
|
||||
@PostMapping
|
||||
@SaCheckPermission("genCode:add")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody SysCodeRule codeRule) {
|
||||
codeRuleService.create(codeRule);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("删除编码")
|
||||
@ApiOperation("删除编码")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("genCode:del")
|
||||
public ResponseEntity<Object> delete(@RequestBody Set<String> ids) {
|
||||
codeRuleService.deleteCodeRule(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("修改编码")
|
||||
@ApiOperation("修改编码")
|
||||
@PutMapping
|
||||
@SaCheckPermission("genCode:edit")
|
||||
public ResponseEntity<Object> update(@RequestBody SysCodeRule codeRule) {
|
||||
codeRuleService.updateCodeRule(codeRule);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ApiOperation("导出任务数据")
|
||||
@GetMapping(value = "/codeDemo")
|
||||
@SaCheckPermission("genCode:list")
|
||||
public ResponseEntity<Object> CodeDemo(@RequestParam Map form) throws IOException {
|
||||
return new ResponseEntity<>(codeRuleService.codeDemo(form), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.nl.system.controller.coderule;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.system.service.CodeDetailService;
|
||||
import org.nl.system.service.coderule.ISysCodeRuleDetailService;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleDetailQuery;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则明细表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-20
|
||||
*/
|
||||
@Api(tags = "系统:编码详情管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/codeDetail")
|
||||
public class SysCodeRuleDetailController {
|
||||
private final ISysCodeRuleDetailService codeDetailService;
|
||||
|
||||
@ApiOperation("查询编码明细")
|
||||
@GetMapping
|
||||
@SaCheckPermission("genCode:list")
|
||||
public ResponseEntity<Object> queryAll(CodeRuleDetailQuery form, PageQuery pageable){
|
||||
return new ResponseEntity<>(TableDataInfo.build(codeDetailService.queryAll(form,pageable)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增编码明细")
|
||||
@ApiOperation("新增编码明细")
|
||||
@PostMapping
|
||||
@SaCheckPermission("genCode:add")
|
||||
public ResponseEntity<Object> create(@RequestBody SysCodeRuleDetail codeRuleDetail){
|
||||
codeDetailService.create(codeRuleDetail);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("删除编码明细")
|
||||
@ApiOperation("删除编码明细")
|
||||
@DeleteMapping(value = "/{id}")
|
||||
@SaCheckPermission("genCode:del")
|
||||
public ResponseEntity<Object> delete(@PathVariable String id){
|
||||
codeDetailService.delete(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("修改编码明细")
|
||||
@ApiOperation("修改编码明细")
|
||||
@PutMapping
|
||||
@SaCheckPermission("genCode:edit")
|
||||
public ResponseEntity<Object> update(@RequestBody SysCodeRuleDetail json){
|
||||
codeDetailService.update(json);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.system.service.quartz.ISysQuartzJobService;
|
||||
import org.nl.system.service.quartz.dao.SysQuartzJob;
|
||||
import org.nl.system.service.quartz.dto.JobQuery;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.nl.system.service.coderule;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleDetailQuery;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则明细表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-20
|
||||
*/
|
||||
public interface ISysCodeRuleDetailService extends IService<SysCodeRuleDetail> {
|
||||
|
||||
IPage<SysCodeRuleDetail> queryAll(CodeRuleDetailQuery form, PageQuery pageable);
|
||||
|
||||
void create(SysCodeRuleDetail codeRuleDetail);
|
||||
|
||||
/**
|
||||
* 根据id删除
|
||||
* @param id
|
||||
*/
|
||||
void delete(String id);
|
||||
|
||||
/**
|
||||
* 修改明细
|
||||
* @param json
|
||||
*/
|
||||
void update(SysCodeRuleDetail json);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.nl.system.service.coderule;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleQuery;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
public interface ISysCodeRuleService extends IService<SysCodeRule> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param form
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
IPage<SysCodeRule> queryAll(CodeRuleQuery form, PageQuery pageable);
|
||||
|
||||
/**
|
||||
* 创建编码
|
||||
* @param form
|
||||
* @return
|
||||
*/
|
||||
String codeDemo(Map form);
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param codeRule
|
||||
*/
|
||||
void create(SysCodeRule codeRule);
|
||||
|
||||
/**
|
||||
* 删除编码
|
||||
* @param ids
|
||||
*/
|
||||
void deleteCodeRule(Set<String> ids);
|
||||
|
||||
/**
|
||||
* 修改编码
|
||||
* @param codeRule
|
||||
*/
|
||||
void updateCodeRule(SysCodeRule codeRule);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package org.nl.system.service.coderule.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_code_rule")
|
||||
public class SysCodeRule implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 标识
|
||||
*/
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 当前值
|
||||
*/
|
||||
private String currentValue;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private String isActive;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private String isDelete;
|
||||
|
||||
/**
|
||||
* 创建id
|
||||
*/
|
||||
private String createId;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 修改id
|
||||
*/
|
||||
private String updateId;
|
||||
|
||||
/**
|
||||
* 修改者
|
||||
*/
|
||||
private String updateName;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String demo;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package org.nl.system.service.coderule.dao;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则明细表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_code_rule_detail")
|
||||
public class SysCodeRuleDetail implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 明细标识
|
||||
*/
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 编码规则类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 初始值
|
||||
*/
|
||||
private String initValue;
|
||||
|
||||
/**
|
||||
* 当前值
|
||||
*/
|
||||
private String currentValue;
|
||||
|
||||
/**
|
||||
* 允许最大值
|
||||
*/
|
||||
private String maxValue;
|
||||
|
||||
/**
|
||||
* 步长
|
||||
*/
|
||||
private String step;
|
||||
|
||||
/**
|
||||
* 填充值
|
||||
*/
|
||||
private String fillchar;
|
||||
|
||||
/**
|
||||
* 格式
|
||||
*/
|
||||
private String format;
|
||||
|
||||
/**
|
||||
* 长度
|
||||
*/
|
||||
private Integer length;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private BigDecimal sortNum;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 编码规则标识
|
||||
*/
|
||||
private String codeRuleId;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private String isActive;
|
||||
|
||||
/**
|
||||
* 是否删除
|
||||
*/
|
||||
private String isDelete;
|
||||
|
||||
/**
|
||||
* 创建id
|
||||
*/
|
||||
private String createId;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 修改id
|
||||
*/
|
||||
private String updateId;
|
||||
|
||||
/**
|
||||
* 修改者
|
||||
*/
|
||||
private String updateName;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String dictName;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.coderule.dao.mapper;
|
||||
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则明细表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
public interface SysCodeRuleDetailMapper extends BaseMapper<SysCodeRuleDetail> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.coderule.dao.mapper.SysCodeRuleDetailMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.system.service.coderule.dao.mapper;
|
||||
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
public interface SysCodeRuleMapper extends BaseMapper<SysCodeRule> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.nl.system.service.coderule.dao.mapper.SysCodeRuleMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.nl.system.service.coderule.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.common.domain.query.QParam;
|
||||
import org.nl.common.enums.QueryTEnum;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2022/12/20
|
||||
*/
|
||||
@Data
|
||||
public class CodeRuleDetailQuery extends BaseQuery<SysCodeRuleDetail> {
|
||||
String id;
|
||||
|
||||
@Override
|
||||
public void paramMapping() {
|
||||
this.doP.put("id", QParam.builder().k(new String[]{"code_rule_id"}).type(QueryTEnum.EQ).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.nl.system.service.coderule.dto;
|
||||
|
||||
import org.nl.common.domain.query.BaseQuery;
|
||||
import org.nl.common.domain.query.QParam;
|
||||
import org.nl.common.enums.QueryTEnum;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description:
|
||||
* @Date: 2022/12/19
|
||||
*/
|
||||
public class CodeRuleQuery extends BaseQuery<SysCodeRule> {
|
||||
|
||||
@Override
|
||||
public void paramMapping() {
|
||||
this.doP.put("blurry", QParam.builder().k(new String[]{"code", "name"}).type(QueryTEnum.LK).build());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.nl.system.service.coderule.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
import org.nl.system.service.coderule.dao.mapper.SysCodeRuleDetailMapper;
|
||||
import org.nl.system.service.coderule.ISysCodeRuleDetailService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleDetailQuery;
|
||||
import org.nl.system.service.coderule.utils.CodeRuleTypeEnum;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则明细表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysCodeRuleDetailServiceImpl extends ServiceImpl<SysCodeRuleDetailMapper, SysCodeRuleDetail> implements ISysCodeRuleDetailService {
|
||||
|
||||
private final SysCodeRuleDetailMapper codeRuleDetailMapper;
|
||||
@Override
|
||||
public IPage<SysCodeRuleDetail> queryAll(CodeRuleDetailQuery form, PageQuery page) {
|
||||
LambdaQueryWrapper<SysCodeRuleDetail> lam = new LambdaQueryWrapper<>();
|
||||
lam.eq(SysCodeRuleDetail::getCodeRuleId, form.getId())
|
||||
.orderByAsc(SysCodeRuleDetail::getSortNum);
|
||||
IPage<SysCodeRuleDetail> pages = new Page<>(page.getPage() + 1, page.getSize());
|
||||
codeRuleDetailMapper.selectPage(pages, lam);
|
||||
return pages;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(SysCodeRuleDetail codeRuleDetail) {
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String currentNickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
codeRuleDetail.setId(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||
codeRuleDetail.setCurrentValue(codeRuleDetail.getInitValue());
|
||||
codeRuleDetail.setCreateId(currentUserId);
|
||||
codeRuleDetail.setCreateName(currentNickName);
|
||||
codeRuleDetail.setCreateTime(now);
|
||||
codeRuleDetail.setUpdateId(currentUserId);
|
||||
codeRuleDetail.setUpdateName(currentNickName);
|
||||
codeRuleDetail.setUpdateTime(now);
|
||||
if (codeRuleDetail.getType().equals(CodeRuleTypeEnum.DATE.getType())) {
|
||||
Date date = DateUtil.date();
|
||||
String format = codeRuleDetail.getFormat();
|
||||
String nowDate = DateUtil.format(date, format);
|
||||
codeRuleDetail.setInitValue(nowDate);
|
||||
codeRuleDetail.setCurrentValue(nowDate);
|
||||
}
|
||||
codeRuleDetailMapper.insert(codeRuleDetail);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(String id) {
|
||||
codeRuleDetailMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(SysCodeRuleDetail json) {
|
||||
codeRuleDetailMapper.updateById(json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package org.nl.system.service.coderule.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.tools.MapOf;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRule;
|
||||
import org.nl.system.service.coderule.dao.SysCodeRuleDetail;
|
||||
import org.nl.system.service.coderule.dao.mapper.SysCodeRuleDetailMapper;
|
||||
import org.nl.system.service.coderule.dao.mapper.SysCodeRuleMapper;
|
||||
import org.nl.system.service.coderule.ISysCodeRuleService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.nl.system.service.coderule.dto.CodeRuleQuery;
|
||||
import org.nl.system.service.coderule.utils.CodeRuleTypeEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编码规则表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-19
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysCodeRuleServiceImpl extends ServiceImpl<SysCodeRuleMapper, SysCodeRule> implements ISysCodeRuleService {
|
||||
|
||||
private final SysCodeRuleMapper codeRuleMapper;
|
||||
private final SysCodeRuleDetailMapper codeRuleDetailMapper;
|
||||
|
||||
@Override
|
||||
public IPage<SysCodeRule> queryAll(CodeRuleQuery form, PageQuery pageable) {
|
||||
IPage<SysCodeRule> page = this.page(pageable.build(SysCodeRule.class), form.build());
|
||||
page.getRecords().forEach(sysCodeRule -> sysCodeRule.setDemo(codeDemo(MapOf.of("flag", "0", "code", sysCodeRule.getCode()))));
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized String codeDemo(Map form) {
|
||||
String code = (String) form.get("code");
|
||||
String id = codeRuleMapper.selectOne(new LambdaQueryWrapper<SysCodeRule>().eq(SysCodeRule::getCode, code)).getId();
|
||||
// 如果flag = 1就执行更新数据库的操作
|
||||
String flag = (String) form.get("flag");
|
||||
List<SysCodeRuleDetail> ruleDetails = codeRuleDetailMapper.selectList(new LambdaQueryWrapper<SysCodeRuleDetail>().eq(SysCodeRuleDetail::getCodeRuleId, id));
|
||||
String demo = "";
|
||||
boolean isSame = true;
|
||||
for(SysCodeRuleDetail detail : ruleDetails) {
|
||||
String value = "";
|
||||
String type = detail.getType();
|
||||
//固定直接取值
|
||||
if (type.equals(CodeRuleTypeEnum.FIXED.getType())) {
|
||||
value = detail.getInitValue();
|
||||
}
|
||||
//日期判断数据库的值与当前值是否相同来决定顺序的值
|
||||
if (type.equals(CodeRuleTypeEnum.DATE.getType())) {
|
||||
String currentValue = detail.getCurrentValue();
|
||||
Date date = DateUtil.date();
|
||||
String format = detail.getFormat();
|
||||
String nowDate = DateUtil.format(date, format);
|
||||
if (!nowDate.equals(currentValue)) {
|
||||
isSame = false;
|
||||
}
|
||||
if (flag.equals("1")) {
|
||||
detail.setInitValue(nowDate);
|
||||
detail.setCurrentValue(nowDate);
|
||||
}
|
||||
value = nowDate;
|
||||
}
|
||||
//顺序的值:如果日期一样就+步长,等于最大值就归为初始值;日期不一样就归为初始值
|
||||
if (type.equals(CodeRuleTypeEnum.ORDER.getType())) {
|
||||
String numValue = "";
|
||||
int step = Integer.parseInt(detail.getStep());
|
||||
Long maxValue = Long.valueOf(detail.getMaxValue());
|
||||
if (!isSame && (Long.valueOf(detail.getCurrentValue()) + step) > maxValue) {
|
||||
numValue = detail.getInitValue();
|
||||
} else {
|
||||
numValue = Integer.parseInt(detail.getCurrentValue()) + step + "";
|
||||
}
|
||||
int size = numValue.length();
|
||||
int length = detail.getLength();
|
||||
String fillchar = detail.getFillchar();
|
||||
for (int m = 0; m < (length - size); m++) {
|
||||
value += fillchar;
|
||||
}
|
||||
value += numValue;
|
||||
if (flag.equals("1")) {
|
||||
if (!isSame) {
|
||||
int initValue = Integer.parseInt(detail.getInitValue());
|
||||
if (StrUtil.isEmpty((initValue + ""))) {
|
||||
throw new BadRequestException("请完善编码数值的初始值!");
|
||||
}
|
||||
detail.setCurrentValue(String.valueOf(initValue));
|
||||
} else {
|
||||
int numCurr = Integer.parseInt(detail.getCurrentValue());
|
||||
if (numCurr >= maxValue) {
|
||||
numCurr = Integer.parseInt(detail.getInitValue());
|
||||
detail.setCurrentValue(String.valueOf(numCurr));
|
||||
}else{
|
||||
detail.setCurrentValue(String.valueOf(numCurr + step));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
demo += value;
|
||||
if (flag.equals("1")) {
|
||||
codeRuleDetailMapper.updateById(detail);
|
||||
}
|
||||
}
|
||||
return demo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(SysCodeRule codeRule) {
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String now = DateUtil.now();
|
||||
List<SysCodeRule> sysCodeRules = codeRuleMapper.selectList(new LambdaQueryWrapper<SysCodeRule>().eq(SysCodeRule::getCode, codeRule.getCode()));
|
||||
if (ObjectUtil.isNotEmpty(sysCodeRules)) throw new BadRequestException("编号[" + sysCodeRules.get(0).getCode() + "]已存在");
|
||||
codeRule.setId(IdUtil.getSnowflake(1,1).nextIdStr());
|
||||
codeRule.setCreateId(currentUserId);
|
||||
codeRule.setCreateName(currentUsername);
|
||||
codeRule.setCreateTime(now);
|
||||
codeRule.setUpdateId(currentUserId);
|
||||
codeRule.setUpdateName(currentUsername);
|
||||
codeRule.setUpdateTime(now);
|
||||
codeRuleMapper.insert(codeRule);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCodeRule(Set<String> ids) {
|
||||
ids.forEach(id -> {
|
||||
codeRuleMapper.deleteById(id);
|
||||
codeRuleDetailMapper.delete(new LambdaQueryWrapper<SysCodeRuleDetail>().eq(SysCodeRuleDetail::getCodeRuleId, id));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCodeRule(SysCodeRule codeRule) {
|
||||
List<SysCodeRule> sysCodeRules = codeRuleMapper.selectList(new LambdaQueryWrapper<SysCodeRule>()
|
||||
.eq(SysCodeRule::getCode, codeRule.getCode())
|
||||
.ne(SysCodeRule::getId, codeRule.getId()));
|
||||
if (ObjectUtil.isNotEmpty(sysCodeRules)) throw new BadRequestException("该编码code已存在,请校验!");
|
||||
String currentUserId = SecurityUtils.getCurrentUserId();
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String now = DateUtil.now();
|
||||
codeRule.setUpdateId(currentUserId);
|
||||
codeRule.setUpdateName(currentUsername);
|
||||
codeRule.setUpdateTime(now);
|
||||
codeRuleMapper.updateById(codeRule);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.nl.system.service.coderule.utils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 编码类型枚举
|
||||
* @Date: 2022/12/19
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CodeRuleTypeEnum {
|
||||
FIXED("01", "固定"),
|
||||
DATE("02", "日期"),
|
||||
ORDER("03", "顺序");
|
||||
|
||||
private final String type;
|
||||
private final String description;
|
||||
}
|
||||
Reference in New Issue
Block a user