Browse Source

基础档案

yuansh 1 week ago
parent
commit
3233217a7a

+ 181 - 0
srm-module-code/src/main/java/com/cuidian/srm/baseCode/controller/SerialPatternController.java

@@ -0,0 +1,181 @@
+package com.cuidian.srm.baseCode.controller;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.cuidian.srm.baseCode.entity.SerialPattern;
+import com.cuidian.srm.baseCode.service.ISerialPatternService;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.query.QueryRuleEnum;
+import org.jeecg.common.util.oConvertUtils;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.extern.slf4j.Slf4j;
+
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+import com.alibaba.fastjson.JSON;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+ /**
+ * @Description: serial_pattern
+ * @Author: jeecg-boot
+ * @Date:   2024-11-07
+ * @Version: V1.0
+ */
+@Api(tags="serial_pattern")
+@RestController
+@RequestMapping("/cuspCode/serialPattern")
+@Slf4j
+public class SerialPatternController extends JeecgController<SerialPattern, ISerialPatternService> {
+	@Autowired
+	private ISerialPatternService serialPatternService;
+	
+	/**
+	 * 分页列表查询
+	 *
+	 * @param serialPattern
+	 * @param pageNo
+	 * @param pageSize
+	 * @param req
+	 * @return
+	 */
+	//@AutoLog(value = "serial_pattern-分页列表查询")
+	@ApiOperation(value="serial_pattern-分页列表查询", notes="serial_pattern-分页列表查询")
+	@GetMapping(value = "/list")
+	public Result<IPage<SerialPattern>> queryPageList(SerialPattern serialPattern,
+								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+								   HttpServletRequest req) {
+        QueryWrapper<SerialPattern> queryWrapper = QueryGenerator.initQueryWrapper(serialPattern, req.getParameterMap());
+		Page<SerialPattern> page = new Page<SerialPattern>(pageNo, pageSize);
+		IPage<SerialPattern> pageList = serialPatternService.page(page, queryWrapper);
+		return Result.OK(pageList);
+	}
+	
+	/**
+	 *   添加
+	 *
+	 * @param serialPattern
+	 * @return
+	 */
+	@AutoLog(value = "serial_pattern-添加")
+	@ApiOperation(value="serial_pattern-添加", notes="serial_pattern-添加")
+	@RequiresPermissions("cuspCode:serial_pattern:add")
+	@PostMapping(value = "/add")
+	public Result<String> add(@RequestBody SerialPattern serialPattern) {
+		serialPatternService.save(serialPattern);
+		return Result.OK("添加成功!");
+	}
+	
+	/**
+	 *  编辑
+	 *
+	 * @param serialPattern
+	 * @return
+	 */
+	@AutoLog(value = "serial_pattern-编辑")
+	@ApiOperation(value="serial_pattern-编辑", notes="serial_pattern-编辑")
+	@RequiresPermissions("cuspCode:serial_pattern:edit")
+	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
+	public Result<String> edit(@RequestBody SerialPattern serialPattern) {
+		serialPatternService.updateById(serialPattern);
+		return Result.OK("编辑成功!");
+	}
+	
+	/**
+	 *   通过id删除
+	 *
+	 * @param id
+	 * @return
+	 */
+	@AutoLog(value = "serial_pattern-通过id删除")
+	@ApiOperation(value="serial_pattern-通过id删除", notes="serial_pattern-通过id删除")
+	@RequiresPermissions("cuspCode:serial_pattern:delete")
+	@DeleteMapping(value = "/delete")
+	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
+		serialPatternService.removeById(id);
+		return Result.OK("删除成功!");
+	}
+	
+	/**
+	 *  批量删除
+	 *
+	 * @param ids
+	 * @return
+	 */
+	@AutoLog(value = "serial_pattern-批量删除")
+	@ApiOperation(value="serial_pattern-批量删除", notes="serial_pattern-批量删除")
+	@RequiresPermissions("cuspCode:serial_pattern:deleteBatch")
+	@DeleteMapping(value = "/deleteBatch")
+	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
+		this.serialPatternService.removeByIds(Arrays.asList(ids.split(",")));
+		return Result.OK("批量删除成功!");
+	}
+	
+	/**
+	 * 通过id查询
+	 *
+	 * @param id
+	 * @return
+	 */
+	//@AutoLog(value = "serial_pattern-通过id查询")
+	@ApiOperation(value="serial_pattern-通过id查询", notes="serial_pattern-通过id查询")
+	@GetMapping(value = "/queryById")
+	public Result<SerialPattern> queryById(@RequestParam(name="id",required=true) String id) {
+		SerialPattern serialPattern = serialPatternService.getById(id);
+		if(serialPattern==null) {
+			return Result.error("未找到对应数据");
+		}
+		return Result.OK(serialPattern);
+	}
+
+    /**
+    * 导出excel
+    *
+    * @param request
+    * @param serialPattern
+    */
+    @RequiresPermissions("cuspCode:serial_pattern:exportXls")
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, SerialPattern serialPattern) {
+        return super.exportXls(request, serialPattern, SerialPattern.class, "serial_pattern");
+    }
+
+    /**
+      * 通过excel导入数据
+    *
+    * @param request
+    * @param response
+    * @return
+    */
+    @RequiresPermissions("cuspCode:serial_pattern:importExcel")
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        return super.importExcel(request, response, SerialPattern.class);
+    }
+
+}

+ 82 - 0
srm-module-code/src/main/java/com/cuidian/srm/baseCode/entity/SerialPattern.java

@@ -0,0 +1,82 @@
+package com.cuidian.srm.baseCode.entity;
+
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.math.BigDecimal;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import org.jeecg.common.constant.ProvinceCityArea;
+import org.jeecg.common.util.SpringContextUtils;
+import lombok.Data;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.jeecg.common.aspect.annotation.Dict;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * @Description: serial_pattern
+ * @Author: jeecg-boot
+ * @Date:   2024-11-07
+ * @Version: V1.0
+ */
+@Data
+@TableName("serial_pattern")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@ApiModel(value="serial_pattern对象", description="serial_pattern")
+public class SerialPattern implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+	/**主键id*/
+	@TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "主键id")
+    private String id;
+	/**字段所属表格名称*/
+	@Excel(name = "字段所属表格名称", width = 15)
+    @ApiModelProperty(value = "字段所属表格名称")
+    private String tableName;
+	/**字段名称*/
+	@Excel(name = "字段名称", width = 15)
+    @ApiModelProperty(value = "字段名称")
+    private String fieldName;
+	/**编号模式,支持前缀,年月日时分秒,自增号混编模式。多个部分用英文加号(+)分隔。前缀支持字符串(用大括号括起来{})和同一表其他字段(用中括号括起来)。年月日时分秒必须连一起,如yyyyMMddHHmmss,可以是其中的一部分。自增编号就是一个数字,譬如4,就是表示4位长度。*/
+	@Excel(name = "编号模式,支持前缀,年月日时分秒,自增号混编模式。多个部分用英文加号(+)分隔。前缀支持字符串(用大括号括起来{})和同一表其他字段(用中括号括起来)。年月日时分秒必须连一起,如yyyyMMddHHmmss,可以是其中的一部分。自增编号就是一个数字,譬如4,就是表示4位长度。", width = 15)
+    @ApiModelProperty(value = "编号模式,支持前缀,年月日时分秒,自增号混编模式。多个部分用英文加号(+)分隔。前缀支持字符串(用大括号括起来{})和同一表其他字段(用中括号括起来)。年月日时分秒必须连一起,如yyyyMMddHHmmss,可以是其中的一部分。自增编号就是一个数字,譬如4,就是表示4位长度。")
+    private String serialPattern;
+	/**描述*/
+	@Excel(name = "描述", width = 15)
+    @ApiModelProperty(value = "描述")
+    private String description;
+	/**创建人*/
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+	/**创建时间*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+	/**更新人*/
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+	/**更新时间*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+	/**状态(1-启用,0-停用)*/
+	@Excel(name = "状态(1-启用,0-停用)", width = 15)
+    @ApiModelProperty(value = "状态(1-启用,0-停用)")
+    private Integer status;
+	/**删除状态(0-正常,1-已删除)*/
+	@Excel(name = "删除状态(0-正常,1-已删除)", width = 15)
+    @ApiModelProperty(value = "删除状态(0-正常,1-已删除)")
+    @TableLogic
+    private Integer delFlag;
+}

+ 30 - 0
srm-module-code/src/main/java/com/cuidian/srm/baseCode/mapper/SerialPatternMapper.java

@@ -0,0 +1,30 @@
+package com.cuidian.srm.baseCode.mapper;
+
+import java.util.List;
+import java.util.Map;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.apache.ibatis.annotations.Param;
+import com.cuidian.srm.baseCode.entity.SerialPattern;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * @Description: serial_pattern
+ * @Author: jeecg-boot
+ * @Date:   2024-11-07
+ * @Version: V1.0
+ */
+public interface SerialPatternMapper extends BaseMapper<SerialPattern> {
+
+    SerialPattern findByTableField(@Param("tableName") String tableName, @Param("fieldName") String fieldName);
+
+
+    /**
+     * 查询最大值
+     * @param tableName 表名
+     * @param queryWrapper 查询条件
+     */
+    public Map<String,Object> selectMax(@Param("tableName") String tableName, @Param("field") String field, @Param("ew") QueryWrapper<Map<String,String>> queryWrapper);
+
+
+}

+ 21 - 0
srm-module-code/src/main/java/com/cuidian/srm/baseCode/mapper/xml/SerialPatternMapper.xml

@@ -0,0 +1,21 @@
+<?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="com.cuidian.srm.baseCode.mapper.SerialPatternMapper">
+
+    <select id="findByTableField" resultType="com.cuidian.srm.baseCode.entity.SerialPattern">
+        select
+            *
+        from serial_pattern
+        where table_name=#{tableName} and field_name=#{fieldName}
+          and del_flag=0
+    </select>
+
+
+    <!-- 查询最大值 -->
+    <select id="selectMax" resultType="map"  parameterType="java.util.HashMap">
+        select max(${field}) as ${field} from ${tableName}
+                                      ${ew.customSqlSegment}
+    </select>
+
+
+</mapper>

+ 39 - 0
srm-module-code/src/main/java/com/cuidian/srm/baseCode/service/ISerialPatternService.java

@@ -0,0 +1,39 @@
+package com.cuidian.srm.baseCode.service;
+
+import com.cuidian.srm.baseCode.entity.SerialPattern;
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+
+/**
+ * @Description: serial_pattern
+ * @Author: jeecg-boot
+ * @Date:   2024-11-07
+ * @Version: V1.0
+ */
+public interface ISerialPatternService extends IService<SerialPattern> {
+
+    /**
+     * 根据表格名称和字段名称获取下一个流水号
+     * @param tableName
+     * @param fieldName
+     * @return
+     */
+    Result<String> getNextSerial(String tableName, String fieldName);
+
+    /**
+     * 根据表格名称和字段名称获取编号模式
+     * @param tableName
+     * @param fieldName
+     * @return
+     */
+    Result<String> getSerialModal(String tableName, String fieldName);
+
+    /**
+     * 根据编号模式和当前最大编号,获取下一个编号
+     * @param serialModal
+     * @param curSerial
+     * @return
+     */
+    Result<String> getNextSerialByCurrent(String serialModal, String curSerial);
+
+}

+ 169 - 0
srm-module-code/src/main/java/com/cuidian/srm/baseCode/service/impl/SerialPatternServiceImpl.java

@@ -0,0 +1,169 @@
+package com.cuidian.srm.baseCode.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.cuidian.srm.baseCode.entity.SerialPattern;
+import com.cuidian.srm.baseCode.mapper.SerialPatternMapper;
+import com.cuidian.srm.baseCode.service.ISerialPatternService;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.oConvertUtils;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+import javax.annotation.Resource;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * @Description: serial_pattern
+ * @Author: jeecg-boot
+ * @Date:   2024-11-07
+ * @Version: V1.0
+ */
+@Service
+public class SerialPatternServiceImpl extends ServiceImpl<SerialPatternMapper, SerialPattern> implements ISerialPatternService {
+
+    @Resource
+    SerialPatternMapper sysSerialPatternMapper;  // 编号模式mapper
+
+    private static Pattern pattern = Pattern.compile("\\[\\w+\\]");
+
+
+    /**
+     * @Title:getNextSerial
+     * @Description:获取下一个编号
+     * @param
+     * tableName - 表格名称
+     * fieldName - 字段名称
+     * @return
+     * org.jeecg.modules.system.vo.CallResult<java.lang.String> - 下一个编号
+     */
+    @Override
+    public Result<String> getNextSerial(String tableName, String fieldName){
+
+        try{
+            SerialPattern serialPattern = sysSerialPatternMapper.findByTableField(tableName, fieldName);
+            if (serialPattern == null){
+                return Result.error("表格:"+tableName+",字段:"+fieldName+"的编号未定义");
+            }
+            // 多个部分用英文加号(+)分隔。前缀支持字符串(用大括号括起来{})和同一表其他字段(用中括号括起来)。年月日时分秒必须连一起,如yyyyMMddHHmmss,可以是其中的一部分
+            String pattern = serialPattern.getSerialPattern();
+            // 编号模式内容为空
+            if (oConvertUtils.isEmpty(pattern)){
+                return Result.error("表格:"+tableName+",字段:"+fieldName+"的编号定义为空");
+            }
+            // 查找最大值
+            QueryWrapper<Map<String,String>> queryWrapper = new QueryWrapper<>();
+            Map<String,Object> row = sysSerialPatternMapper.selectMax(tableName, fieldName, queryWrapper);
+            String maxValue = "";
+            if (row != null && row.containsKey(fieldName)){
+                maxValue = oConvertUtils.getString(row.get(fieldName));
+            }
+
+            String[] splitPattern = pattern.split("\\+");
+            String prefix = ""; // 前缀
+            String dateStr = "";// 日期模式
+            int serialLen = 0;  // 流水号长度
+
+            for (String subPattern : splitPattern){
+                if (Pattern.matches("\\{[^{}]+\\}", subPattern)){ // 字符串前缀
+                    prefix = subPattern.substring(1, subPattern.length()-1);
+                }else if(!Pattern.matches("[^yMdHms]", subPattern)){ // yyyyMMddHHmmss
+                    DateFormat dateFormat = new java.text.SimpleDateFormat(subPattern);
+                    dateStr = dateFormat.format(new Date());
+                } else if (Pattern.matches("^[1-9]+[0-9]*$", subPattern)){
+                    serialLen = oConvertUtils.getInt(subPattern);
+                }
+            }
+
+            int maxSerial = 0;
+            if (oConvertUtils.isNotEmpty(maxValue)){
+                if (oConvertUtils.isNotEmpty(prefix)){
+                    maxValue = maxValue.replace(prefix, "");
+                }
+                if (oConvertUtils.isNotEmpty(dateStr)){
+                    maxValue = maxValue.substring(dateStr.length());
+                }
+                maxSerial = oConvertUtils.getInt(maxValue);
+            }
+            maxSerial++;
+            return Result.ok(prefix+ DateUtils.getDate(dateStr)+String.format("%0"+serialLen+"d",maxSerial));
+
+        }catch(Exception ex){
+            ex.printStackTrace();
+            return Result.error(ex.getMessage());
+        }
+    }
+
+
+
+    /**
+     * 根据表格名称和字段名称获取编号模式
+     * @param tableName
+     * @param fieldName
+     * @return
+     */
+    @Override
+    public Result<String> getSerialModal(String tableName, String fieldName){
+        SerialPattern serialPattern = sysSerialPatternMapper.findByTableField(tableName, fieldName);
+        if (serialPattern == null){
+            return Result.error("表格:"+tableName+",字段:"+fieldName+"的编号未定义");
+        }
+        return Result.ok(serialPattern.getSerialPattern());
+    }
+
+    /**
+     * 根据编号模式和当前最大编号,获取下一个编号
+     * @param serialModal
+     * @param curSerial
+     * @return
+     */
+    @Override
+    public Result<String> getNextSerialByCurrent(String serialModal, String curSerial){
+        try{
+            String pattern = serialModal;
+            String maxValue = curSerial;
+
+            String[] splitPattern = pattern.split("\\+");
+            String prefix = ""; // 前缀
+            String dateStr = "";// 日期模式
+            int serialLen = 0;  // 流水号长度
+
+            for (String subPattern : splitPattern){
+                if (Pattern.matches("\\{[^{}]+\\}", subPattern)){ // 字符串前缀
+                    prefix = subPattern.substring(1, subPattern.length()-1);
+                }else if(!Pattern.matches("[^yMdHms]", subPattern)){ // yyyyMMddHHmmss
+                    DateFormat dateFormat = new java.text.SimpleDateFormat(subPattern);
+                    dateStr = dateFormat.format(new Date());
+                } else if (Pattern.matches("^[1-9]+[0-9]*$", subPattern)){
+                    serialLen = oConvertUtils.getInt(subPattern);
+                }
+            }
+
+            int maxSerial = 0;
+            if (oConvertUtils.isNotEmpty(maxValue)){
+                if (oConvertUtils.isNotEmpty(prefix)){
+                    maxValue = maxValue.replace(prefix, "");
+                }
+                if (oConvertUtils.isNotEmpty(dateStr)){
+                    maxValue = maxValue.substring(dateStr.length());
+                }
+                maxSerial = oConvertUtils.getInt(maxValue);
+            }
+            maxSerial++;
+            return Result.ok(prefix+ DateUtils.getDate(dateStr)+String.format("%0"+serialLen+"d",maxSerial));
+
+        }catch(Exception ex){
+            ex.printStackTrace();
+            return Result.error(ex.getMessage());
+        }
+    }
+
+
+
+
+
+}

+ 12 - 1
srm-module-code/src/main/java/com/cuidian/srm/cuspCode/controller/CuspIntermediatorController.java

@@ -10,6 +10,8 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import com.cuidian.srm.baseCode.service.ISerialPatternService;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.query.QueryRuleEnum;
@@ -52,7 +54,9 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
 public class CuspIntermediatorController extends JeecgController<CuspIntermediator, ICuspIntermediatorService> {
 	@Autowired
 	private ICuspIntermediatorService cuspIntermediatorService;
-	
+	@Autowired
+	private ISerialPatternService serialPatternService;
+
 	/**
 	 * 分页列表查询
 	 *
@@ -86,6 +90,13 @@ public class CuspIntermediatorController extends JeecgController<CuspIntermediat
 	@RequiresPermissions("cuspCode:cusp_intermediator:add")
 	@PostMapping(value = "/add")
 	public Result<String> add(@RequestBody CuspIntermediator cuspIntermediator) {
+
+		Result<String> result = serialPatternService.getNextSerial("cusp_intermediator","code");
+		if (!result.isSuccess()){
+			return result;
+		}
+		cuspIntermediator.setCode(result.getMessage());
+
 		cuspIntermediatorService.save(cuspIntermediator);
 		return Result.OK("添加成功!");
 	}