Browse Source

试验编号优化

cr 1 month ago
parent
commit
ce9c6ba80a

+ 129 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/TrialAutoNumberController.java

@@ -0,0 +1,129 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import lombok.AllArgsConstructor;
+import javax.validation.Valid;
+
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestParam;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.business.entity.TrialAutoNumber;
+import org.springblade.business.vo.TrialAutoNumberVO;
+import org.springblade.business.service.ITrialAutoNumberService;
+import org.springblade.core.boot.ctrl.BladeController;
+
+/**
+ *  控制器
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/trialautonumber")
+@Api(value = "试验编号自增", tags = "试验编号自增")
+public class TrialAutoNumberController extends BladeController {
+
+	private final ITrialAutoNumberService trialAutoNumberService;
+
+	/**
+	 * 详情
+	 */
+	@GetMapping("/detail")
+	@ApiOperationSupport(order = 1)
+	@ApiOperation(value = "详情", notes = "传入trialAutoNumber")
+	public R<TrialAutoNumber> detail(TrialAutoNumber trialAutoNumber) {
+		TrialAutoNumber detail = trialAutoNumberService.getOne(Condition.getQueryWrapper(trialAutoNumber));
+		return R.data(detail);
+	}
+
+	/**
+	 * 分页
+	 */
+	@GetMapping("/list")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "分页", notes = "传入trialAutoNumber")
+	public R<IPage<TrialAutoNumber>> list(TrialAutoNumber trialAutoNumber, Query query) {
+		IPage<TrialAutoNumber> pages = trialAutoNumberService.page(Condition.getPage(query), Condition.getQueryWrapper(trialAutoNumber));
+		return R.data(pages);
+	}
+
+	/**
+	 * 自定义分页
+	 */
+	@GetMapping("/page")
+	@ApiOperationSupport(order = 3)
+	@ApiOperation(value = "分页", notes = "传入trialAutoNumber")
+	public R<IPage<TrialAutoNumberVO>> page(TrialAutoNumberVO trialAutoNumber, Query query) {
+		IPage<TrialAutoNumberVO> pages = trialAutoNumberService.selectTrialAutoNumberPage(Condition.getPage(query), trialAutoNumber);
+		return R.data(pages);
+	}
+
+	/**
+	 * 新增
+	 */
+	@PostMapping("/save")
+	@ApiOperationSupport(order = 4)
+	@ApiOperation(value = "新增", notes = "传入trialAutoNumber")
+	public R save(@Valid @RequestBody TrialAutoNumber trialAutoNumber) {
+		return R.status(trialAutoNumberService.save(trialAutoNumber));
+	}
+
+	/**
+	 * 修改
+	 */
+	@PostMapping("/update")
+	@ApiOperationSupport(order = 5)
+	@ApiOperation(value = "修改", notes = "传入trialAutoNumber")
+	public R update(@Valid @RequestBody TrialAutoNumber trialAutoNumber) {
+		return R.status(trialAutoNumberService.updateById(trialAutoNumber));
+	}
+
+	/**
+	 * 新增或修改
+	 */
+	@PostMapping("/submit")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "新增或修改", notes = "传入trialAutoNumber")
+	public R submit(@Valid @RequestBody TrialAutoNumber trialAutoNumber) {
+		return R.status(trialAutoNumberService.saveOrUpdate(trialAutoNumber));
+	}
+
+
+	/**
+	 * 删除
+	 */
+	@PostMapping("/remove")
+	@ApiOperationSupport(order = 7)
+	@ApiOperation(value = "逻辑删除", notes = "传入ids")
+	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+		return R.status(trialAutoNumberService.deleteLogic(Func.toLongList(ids)));
+	}
+
+
+
+
+}

+ 347 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/TrialNumberRuleController.java

@@ -0,0 +1,347 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.controller;
+
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.models.auth.In;
+import lombok.AllArgsConstructor;
+import javax.validation.Valid;
+
+import org.springblade.business.dto.TrialNumberRuleDTO;
+import org.springblade.business.mapper.TrialNumberRuleMapper;
+import org.springblade.business.vo.TrialNumberRuleVO1;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.mp.support.Query;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.ObjectUtil;
+import org.springblade.manager.entity.WbsTreePrivate;
+import org.springframework.beans.BeanUtils;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestParam;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.business.entity.TrialNumberRule;
+import org.springblade.business.vo.TrialNumberRuleVO;
+import org.springblade.business.service.ITrialNumberRuleService;
+import org.springblade.core.boot.ctrl.BladeController;
+
+import java.io.FileNotFoundException;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ *  控制器
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+@RestController
+@AllArgsConstructor
+@RequestMapping("/trialnumberrule")
+@Api(value = "试验编号规则", tags = "试验编号规则")
+public class TrialNumberRuleController extends BladeController {
+
+	private final ITrialNumberRuleService trialNumberRuleService;
+    private final TrialNumberRuleMapper  trialNumberRuleMapper;
+    private final JdbcTemplate jdbcTemplate;
+
+	/**
+	 * 详情
+	 */
+//	@GetMapping("/detail")
+//	@ApiOperationSupport(order = 1)
+//	@ApiOperation(value = "详情", notes = "传入trialNumberRule")
+//	public R<TrialNumberRule> detail(TrialNumberRule trialNumberRule) {
+//		TrialNumberRule detail = trialNumberRuleService.getOne(Condition.getQueryWrapper(trialNumberRule));
+//		return R.data(detail);
+//	}
+//
+//	/**
+//	 * 分页
+//	 */
+//	@GetMapping("/list")
+//	@ApiOperationSupport(order = 2)
+//	@ApiOperation(value = "分页", notes = "传入trialNumberRule")
+//	public R<IPage<TrialNumberRule>> list(TrialNumberRule trialNumberRule, Query query) {
+//		IPage<TrialNumberRule> pages = trialNumberRuleService.page(Condition.getPage(query), Condition.getQueryWrapper(trialNumberRule));
+//		return R.data(pages);
+//	}
+
+	/**
+	 * 自定义分页
+	 */
+//	@GetMapping("/page")
+//	@ApiOperationSupport(order = 3)
+//	@ApiOperation(value = "分页", notes = "传入trialNumberRule")
+//	public R<IPage<TrialNumberRuleVO>> page(TrialNumberRuleVO trialNumberRule, Query query) {
+//		IPage<TrialNumberRuleVO> pages = trialNumberRuleService.selectTrialNumberRulePage(Condition.getPage(query), trialNumberRule);
+//		return R.data(pages);
+//	}
+
+	/**
+	 * 新增
+	 */
+	@PostMapping("/save")
+	@ApiOperationSupport(order = 4)
+	@ApiOperation(value = "新增", notes = "传入trialNumberRule")
+	public R<String> save(@Valid @RequestBody TrialNumberRule trialNumberRule) {
+        if(trialNumberRule.getRule()==6){
+            if(StringUtils.isEmpty(trialNumberRule.getData())){
+                throw new ServiceException("数据填充不能为空");
+            }
+            String data = trialNumberRule.getData();
+            if (!data.matches("\\d+")) {
+                throw new ServiceException("数据填充只能为数字且不能有其他字符");
+            }
+        }
+        Integer maxSort=trialNumberRuleMapper.selectMaxSort(trialNumberRule.getProjectId(),trialNumberRule.getContractId(),trialNumberRule.getType());
+        List<TrialNumberRule> rules = trialNumberRuleMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, trialNumberRule.getProjectId()).eq(TrialNumberRule::getContractId, trialNumberRule.getContractId()).eq(TrialNumberRule::getType, trialNumberRule.getType()));
+        if(!rules.isEmpty()){
+            for (TrialNumberRule rule : rules) {
+                if(Objects.equals(rule.getRule(), trialNumberRule.getRule())&&trialNumberRule.getRule()==6){
+                    throw new ServiceException("已存在流水号规则");
+                }
+            }
+        }
+        trialNumberRule.setSort(maxSort+1);
+        if(trialNumberRule.getContractId()==null||trialNumberRule.getContractId()==0L){
+            trialNumberRule.setStatus(1);
+        }else {
+            trialNumberRule.setStatus(2);
+        }
+        trialNumberRuleService.save(trialNumberRule);
+        if(trialNumberRule.getContractId()!=0L){
+            trialNumberRuleService.clearTrialNumber(trialNumberRule.getProjectId(),trialNumberRule.getContractId(),trialNumberRule.getType());
+        }
+        Map<String, String> map = trialNumberRuleService.getTrialNumber(trialNumberRule.getProjectId(),trialNumberRule.getContractId(), trialNumberRule.getType(), null, false);
+		return R.data(map.get("trialNumber"));
+	}
+
+    @PostMapping("/submitList")
+    public R<String> saveList(@RequestBody List<TrialNumberRule>list){
+        List<TrialNumberRule> collect = list.stream().filter(rule -> rule.getRule() == 6).collect(Collectors.toList());
+        if(collect.size()>1){
+            throw new ServiceException("流水只保存一个,不可保存多个");
+        }
+        List<TrialNumberRule> rules = trialNumberRuleMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, list.get(0).getProjectId()).eq(TrialNumberRule::getContractId, list.get(0).getContractId()).eq(TrialNumberRule::getType, list.get(0).getType()));
+        List<TrialNumberRule> collect1 = rules.stream().filter(rule -> rule.getRule() == 6).collect(Collectors.toList());
+        TrialNumberRule rule6 = null;
+        if(collect1.size()>0){
+            rule6=collect1.get(0);
+        }
+        int i=1;
+        for (TrialNumberRule rule : list) {
+            if(rule.getContractId()==null||rule.getContractId()==0L){
+                rule.setStatus(1);
+            }else {
+                rule.setStatus(2);
+            }
+            rule.setSort(i++);
+            if(rule.getRule()==6){
+                if(StringUtils.isEmpty(rule.getData())){
+                    throw new ServiceException("数据填充不能为空");
+                }
+                String data = rule.getData();
+                if (!data.matches("\\d+")) {
+                    throw new ServiceException("数据填充只能为数字且不能有其他字符");
+                }
+                if(rule6!=null){
+                    if(rule.getId()!=null&&rule.getId().equals(rule6.getId())){
+                        if(rule.getContractId()!=null&&rule.getContractId()!=0L){
+                            if(!StringUtils.equals(rule.getData(),rule6.getData())){
+                                trialNumberRuleMapper.updateAutoIncrement(rule.getId());
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        trialNumberRuleService.saveOrUpdateBatch(list);
+        Map<String, String> map = trialNumberRuleService.getTrialNumber(list.get(0).getProjectId(),list.get(0).getContractId(), list.get(0).getType(), null, false);
+        return R.data(map.get("trialNumber"));
+    }
+
+	/**
+	 * 修改
+	 */
+	@PostMapping("/update")
+	@ApiOperationSupport(order = 5)
+	@ApiOperation(value = "修改", notes = "传入trialNumberRule")
+	public R<String> update(@Valid @RequestBody TrialNumberRule trialNumberRule) {
+        if(trialNumberRule.getRule()==6){
+            if(StringUtils.isEmpty(trialNumberRule.getData())){
+                throw new ServiceException("数据填充不能为空");
+            }
+            String data = trialNumberRule.getData();
+            if (!data.matches("\\d+")) {
+                throw new ServiceException("数据填充只能为数字且不能有其他字符");
+            }
+        }
+        List<TrialNumberRule> rules = trialNumberRuleMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, trialNumberRule.getProjectId()).eq(TrialNumberRule::getContractId, trialNumberRule.getContractId()).eq(TrialNumberRule::getType, trialNumberRule.getType()));
+        if(!rules.isEmpty()){
+            for (TrialNumberRule rule : rules) {
+                if(!Objects.equals(rule.getId(), trialNumberRule.getId())&&trialNumberRule.getRule()==6&&rule.getRule()==6){
+                    throw new ServiceException("已存在流水号规则");
+                }
+            }
+        }
+        if(trialNumberRule.getRule()==6){
+            //查出流水号规则
+            TrialNumberRule trialNumberRule1 = trialNumberRuleService.getById(trialNumberRule.getId());
+            //如果是合同段的规则
+            if(trialNumberRule.getContractId()!=null&&trialNumberRule.getContractId()!=0L){
+                //并且数据填充发生改变
+                if(!StringUtils.equals(trialNumberRule1.getData(),trialNumberRule.getData())){
+                    //将自增表的数据删除
+                    trialNumberRuleMapper.updateAutoIncrement(trialNumberRule.getId());
+                }
+            }
+        }
+        trialNumberRuleService.updateById(trialNumberRule);
+        Map<String, String> map = trialNumberRuleService.getTrialNumber(trialNumberRule.getProjectId(),trialNumberRule.getContractId(), trialNumberRule.getType(), null, false);
+		return R.data(map.get("trialNumber"));
+	}
+
+	/**
+	 * 调整排序
+	 */
+	@PostMapping("/sort")
+	@ApiOperationSupport(order = 6)
+	@ApiOperation(value = "调整排序", notes = "传入List<TrialNumberRule>")
+	public R<String> sort(@Valid @RequestBody List<TrialNumberRule> trialNumberRules) {
+        for (int i = 0; i < trialNumberRules.size(); i++) {
+            trialNumberRules.get(i).setSort(i+1);
+        }
+        trialNumberRuleService.saveOrUpdateBatch(trialNumberRules);
+        if(ObjectUtil.isNotEmpty(trialNumberRules.get(0).getContractId())&&trialNumberRules.get(0).getContractId()!=0L){
+            trialNumberRuleService.clearTrialNumber(trialNumberRules.get(0).getProjectId(),trialNumberRules.get(0).getContractId(),trialNumberRules.get(0).getType());
+        }
+        Map<String, String> map = trialNumberRuleService.getTrialNumber(trialNumberRules.get(0).getProjectId(),trialNumberRules.get(0).getContractId(), trialNumberRules.get(0).getType(), null, false);
+        return R.data(map.get("trialNumber"));
+	}
+
+
+    /**
+     * 新增或修改
+     */
+//    @PostMapping("/submit")
+//    @ApiOperationSupport(order = 6)
+//    @ApiOperation(value = "新增或修改", notes = "传入trialNumberRule")
+//    public R<String> submit(@Valid @RequestBody TrialNumberRule trialNumberRule,BladeUser bladeUser) {
+//
+//
+//
+//
+//        return null;
+//    }
+
+
+	/**
+	 * 删除
+	 */
+	@PostMapping("/remove")
+	@ApiOperationSupport(order = 7)
+	@ApiOperation(value = "逻辑删除", notes = "传入ids")
+	public R<String> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
+        String[] idss = ids.split(",");
+        TrialNumberRule trialNumberRule = trialNumberRuleService.getById(idss[0]);
+        trialNumberRuleService.clearTrialNumber(trialNumberRule.getProjectId(),trialNumberRule.getContractId(),trialNumberRule.getType());
+        trialNumberRuleService.deleteLogic(Func.toLongList(ids));
+        Map<String, String> map = trialNumberRuleService.getTrialNumber(trialNumberRule.getProjectId(),trialNumberRule.getContractId(), trialNumberRule.getType(), null, false);
+		return R.data(map.get("trialNumber"));
+	}
+
+
+
+
+    /**
+     * type 1材料 2样品  4记录表 5报告表
+     * 委托单另外一个方法单独获取
+     */
+    @GetMapping("/getTrialNumber")
+    @ApiOperationSupport(order = 8)
+    @ApiOperation(value = "获取试验编号", notes = "传入projectId,contractId,type,nodeId")
+    public R<Map<String, String>> getTrialNumber(Long projectId,Long contractId, Integer type, Long nodeId){
+        Map<String, String> map = trialNumberRuleService.getTrialNumber(projectId,contractId, type, nodeId, true);
+        return  R.data(map);
+    }
+    @GetMapping("/getEntrustNumber")
+    @ApiOperationSupport(order = 11)
+    @ApiOperation(value = "获取委托单编号")
+    public R<Map<String, String>>getEntrustNumber(Long pkeyId,Long contractId) throws FileNotFoundException {
+        return R.data(trialNumberRuleService.getEntrustNumber(pkeyId,contractId));
+    }
+
+    /**
+     * 获取试验编号规则
+     * @param
+     * @param contractId
+     * @param type
+     * @return
+     */
+    @GetMapping("/getTrialNumberRule")
+    @ApiOperationSupport(order = 9)
+    @ApiOperation(value = "获取试验编号规则", notes = "传入projectId,contractId(后管查询传0),type")
+    public R<TrialNumberRuleVO1> getTrialNumberRule(Long projectId,Long contractId, Integer type){
+        return R.data(trialNumberRuleService.getTrialNumberRule(projectId,contractId,type));
+    }
+
+    @GetMapping("/reTrialNumberRule")
+    @ApiOperationSupport(order = 10)
+    @ApiOperation(value = "重置试验编号规则")
+    public R<String> reTrialNumberRule(Long projectId, Long contractId, Integer type){
+        List<TrialNumberRule> trialNumberRules = trialNumberRuleService.getBaseMapper().selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, projectId).eq(TrialNumberRule::getContractId, contractId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,2).orderByAsc(TrialNumberRule::getSort));
+        if(!trialNumberRules.isEmpty()){
+            String ids = trialNumberRules.stream()
+                    .map(o -> o.getId().toString())
+                    .collect(Collectors.joining(","));
+            TrialNumberRule trialNumberRule = trialNumberRules.get(0);
+            trialNumberRuleService.clearTrialNumber(trialNumberRule.getProjectId(),trialNumberRule.getContractId(),trialNumberRule.getType());
+            trialNumberRuleService.deleteLogic(Func.toLongList(ids));
+        }
+        List<TrialNumberRule> rules = trialNumberRuleService.getBaseMapper().selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, projectId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus, 1).orderByAsc(TrialNumberRule::getSort));
+        if(!rules.isEmpty()){
+            for (TrialNumberRule rule : rules) {
+                rule.setId(null);
+                rule.setStatus(2);
+                rule.setContractId(contractId);
+            }
+            trialNumberRuleService.saveOrUpdateBatch(rules);
+            Map<String, String> map = trialNumberRuleService.getTrialNumber(projectId,contractId, type, null, false);
+            return R.data(map.get("trialNumber"));
+        }else {
+            return R.fail("请先在后管设置编号规则");
+        }
+    }
+
+
+
+
+
+
+}

+ 44 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TrialAutoNumberMapper.java

@@ -0,0 +1,44 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.mapper;
+
+import org.apache.ibatis.annotations.Param;
+import org.springblade.business.entity.TrialAutoNumber;
+import org.springblade.business.vo.TrialAutoNumberVO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import java.util.List;
+
+/**
+ *  Mapper 接口
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+public interface TrialAutoNumberMapper extends BaseMapper<TrialAutoNumber> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param trialAutoNumber
+	 * @return
+	 */
+	List<TrialAutoNumberVO> selectTrialAutoNumberPage(IPage page, TrialAutoNumberVO trialAutoNumber);
+
+    void clearTrialAutoNumber(@Param("nameRuleId") Long nameRuleId);
+}

+ 22 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TrialAutoNumberMapper.xml

@@ -0,0 +1,22 @@
+<?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.springblade.business.mapper.TrialAutoNumberMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="trialAutoNumberResultMap" type="org.springblade.business.entity.TrialAutoNumber">
+        <result column="id" property="id"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="auto_increment_number" property="autoIncrementNumber"/>
+        <result column="form_data_id" property="formDataId"/>
+        <result column="type" property="type"/>
+    </resultMap>
+    <update id="clearTrialAutoNumber">
+        update u_trial_auto_number set is_deleted = 1 where name_rule_id = #{nameRuleId}
+    </update>
+
+
+    <select id="selectTrialAutoNumberPage" resultMap="trialAutoNumberResultMap">
+        select * from u_trial_auto_number where is_deleted = 0
+    </select>
+
+</mapper>

+ 46 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TrialNumberRuleMapper.java

@@ -0,0 +1,46 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.mapper;
+
+import org.apache.ibatis.annotations.Param;
+import org.springblade.business.entity.TrialNumberRule;
+import org.springblade.business.vo.TrialNumberRuleVO;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import java.util.List;
+
+/**
+ *  Mapper 接口
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+public interface TrialNumberRuleMapper extends BaseMapper<TrialNumberRule> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param trialNumberRule
+	 * @return
+	 */
+	List<TrialNumberRuleVO> selectTrialNumberRulePage(IPage page, TrialNumberRuleVO trialNumberRule);
+
+    Integer selectMaxSort(@Param("projectId") Long projectId, @Param("contractId") Long contractId, @Param("type") Integer type);
+
+    void updateAutoIncrement(@Param("id") Long id);
+}

+ 34 - 0
blade-service/blade-business/src/main/java/org/springblade/business/mapper/TrialNumberRuleMapper.xml

@@ -0,0 +1,34 @@
+<?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.springblade.business.mapper.TrialNumberRuleMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="trialNumberRuleResultMap" type="org.springblade.business.entity.TrialNumberRule">
+        <result column="id" property="id"/>
+        <result column="create_time" property="createTime"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_dept" property="createDept"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+        <result column="project_id" property="projectId"/>
+        <result column="contract_id" property="contractId"/>
+        <result column="type" property="type"/>
+        <result column="rule" property="rule"/>
+        <result column="data" property="data"/>
+        <result column="is_auto_increment" property="isAutoIncrement"/>
+    </resultMap>
+    <update id="updateAutoIncrement">
+        update u_trial_auto_number set is_deleted=1 where number_rule_id = #{id}
+    </update>
+
+
+    <select id="selectTrialNumberRulePage" resultMap="trialNumberRuleResultMap">
+        select * from u_trial_number_rule where is_deleted = 0
+    </select>
+    <select id="selectMaxSort" resultType="java.lang.Integer">
+        select IFNULL(MAX(sort), 0) from u_trial_number_rule where project_id = #{projectId} and contract_id = #{contractId} and type = #{type}
+    </select>
+
+</mapper>

+ 41 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/ITrialAutoNumberService.java

@@ -0,0 +1,41 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.service;
+
+import org.springblade.business.entity.TrialAutoNumber;
+import org.springblade.business.vo.TrialAutoNumberVO;
+import org.springblade.core.mp.base.BaseService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+/**
+ *  服务类
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+public interface ITrialAutoNumberService extends BaseService<TrialAutoNumber> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param trialAutoNumber
+	 * @return
+	 */
+	IPage<TrialAutoNumberVO> selectTrialAutoNumberPage(IPage<TrialAutoNumberVO> page, TrialAutoNumberVO trialAutoNumber);
+
+}

+ 57 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/ITrialNumberRuleService.java

@@ -0,0 +1,57 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.service;
+
+import cn.hutool.core.lang.hash.Hash;
+import org.springblade.business.entity.TrialNumberRule;
+import org.springblade.business.vo.TrialNumberRuleVO;
+import org.springblade.business.vo.TrialNumberRuleVO1;
+import org.springblade.core.mp.base.BaseService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springblade.core.secure.BladeUser;
+
+import java.io.FileNotFoundException;
+import java.util.Map;
+
+/**
+ *  服务类
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+public interface ITrialNumberRuleService extends BaseService<TrialNumberRule> {
+
+	/**
+	 * 自定义分页
+	 *
+	 * @param page
+	 * @param trialNumberRule
+	 * @return
+	 */
+	IPage<TrialNumberRuleVO> selectTrialNumberRulePage(IPage<TrialNumberRuleVO> page, TrialNumberRuleVO trialNumberRule);
+
+    Map<String,String> getTrialNumber(Long projectId,Long contractId, Integer type, Long nodeId, Boolean isSaveRedis);
+
+    TrialNumberRuleVO1 getTrialNumberRule(Long project,Long contractId, Integer type);
+    //编号规则发生改变,清空对应的编号
+    boolean clearTrialNumber(Long projectId, Long contractId, Integer type);
+
+	boolean checkTrialNumberIsExist(String trialNumber,Integer type,Long contractId);
+
+
+    Map<String, String> getEntrustNumber(Long pkeyId,Long contractId) throws FileNotFoundException;
+}

+ 45 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialAutoNumberServiceImpl.java

@@ -0,0 +1,45 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.service.impl;
+
+import org.springblade.business.entity.TrialAutoNumber;
+import org.springblade.business.vo.TrialAutoNumberVO;
+import org.springblade.business.mapper.TrialAutoNumberMapper;
+import org.springblade.business.service.ITrialAutoNumberService;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+/**
+ *  服务实现类
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+@Service
+public class TrialAutoNumberServiceImpl extends BaseServiceImpl<TrialAutoNumberMapper, TrialAutoNumber> implements ITrialAutoNumberService {
+
+	@Override
+	public IPage<TrialAutoNumberVO> selectTrialAutoNumberPage(IPage<TrialAutoNumberVO> page, TrialAutoNumberVO trialAutoNumber) {
+		return page.setRecords(baseMapper.selectTrialAutoNumberPage(page, trialAutoNumber));
+	}
+
+    public void clearTrialAutoNumber(Long nameRuleId){
+        baseMapper.clearTrialAutoNumber(nameRuleId);
+    }
+
+}

+ 457 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialNumberRuleServiceImpl.java

@@ -0,0 +1,457 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.business.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.springblade.business.entity.TrialAutoNumber;
+import org.springblade.business.entity.TrialNumberRule;
+import org.springblade.business.vo.TrialNumberRuleVO;
+import org.springblade.business.mapper.TrialNumberRuleMapper;
+import org.springblade.business.service.ITrialNumberRuleService;
+import org.springblade.business.vo.TrialNumberRuleVO1;
+import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.base.BaseServiceImpl;
+import org.springblade.core.redis.cache.BladeRedis;
+import org.springblade.core.secure.BladeUser;
+import org.springblade.core.tool.api.R;
+import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.core.tool.utils.ResourceUtil;
+import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.entity.WbsTreePrivate;
+import org.springblade.manager.feign.WbsTreePrivateClient;
+import org.springblade.system.cache.ParamCache;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.SingleColumnRowMapper;
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.time.LocalDate;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ *  服务实现类
+ *
+ * @author BladeX
+ * @since 2025-06-10
+ */
+@Service
+public class TrialNumberRuleServiceImpl extends BaseServiceImpl<TrialNumberRuleMapper, TrialNumberRule> implements ITrialNumberRuleService {
+
+    @Resource
+    private JdbcTemplate jdbcTemplate;
+    @Resource
+    private BladeRedis bladeRedis;
+    @Resource
+    private  TrialAutoNumberServiceImpl trialAutoNumberService;
+
+
+    @Override
+	public IPage<TrialNumberRuleVO> selectTrialNumberRulePage(IPage<TrialNumberRuleVO> page, TrialNumberRuleVO trialNumberRule) {
+		return page.setRecords(baseMapper.selectTrialNumberRulePage(page, trialNumberRule));
+	}
+
+    @Override
+    public Map<String,String> getTrialNumber(Long projectId,Long contractId, Integer type,Long nodeId,Boolean isSaveRedis) {
+        HashMap<String, String> map = new HashMap<>();
+        StringBuilder trialNumber = new StringBuilder();
+        List<TrialNumberRule> rules;
+        if(contractId==null||contractId==0L){
+            rules = baseMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, projectId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,1).orderByAsc(TrialNumberRule::getSort));
+        }else {
+             rules = baseMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getContractId, contractId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,2).orderByAsc(TrialNumberRule::getSort));
+        }
+        boolean flag=true;
+        int i=1;
+        do {
+            for (TrialNumberRule rule : rules) {
+                if(rule.getRule()==1){
+                    trialNumber.append(rule.getData());
+                } else if (rule.getRule()==2) {
+                    if(contractId!=null&&contractId!=0L){
+                        String sql1="select contract_number from m_contract_info where id="+contractId;
+                        String result = jdbcTemplate.query(sql1, rs -> {
+                            if (rs.next()) {
+                                return rs.getString(1);
+                            } else {
+                                return "";
+                            }
+                        });
+                        trialNumber.append(result==null?"":result);
+                    }else {
+                        trialNumber.append("TJ01");
+                    }
+                } else if (rule.getRule()==3) {
+                    if (nodeId!=null) {
+                        String sql2="select unique_code from m_wbs_tree_private where p_key_id="+nodeId+" and is_deleted=0";
+                        String  result = jdbcTemplate.query(sql2, rs -> {
+                            if (rs.next()) {
+                                return rs.getString(1);
+                            } else {
+                                return "";
+                            }
+                        });
+                        trialNumber.append(result==null?"":result);
+                    }else {
+                        trialNumber.append("SNY");
+                    }
+                } else if (rule.getRule()==4) {
+                    String currentYearStr = String.valueOf(LocalDate.now().getYear());
+                    trialNumber.append(currentYearStr);
+                } else if (rule.getRule()==5) {
+                    int currentMonthValue = LocalDate.now().getMonthValue();
+                    String currentMonthStr = String.format("%02d", currentMonthValue);
+                    trialNumber.append(currentMonthStr);
+                } else if (rule.getRule()==6) {
+                    if(StringUtils.isEmpty(rule.getData())){
+                        trialNumber.append("");
+                        map.put("autoIncrementNumber","");
+                        continue;
+                    }
+                    if(!isSaveRedis){
+                        trialNumber.append(rule.getData());
+                        map.put("autoIncrementNumber",rule.getData());
+                    }
+                    if(rule.getIsAutoIncrement()!=null&&rule.getIsAutoIncrement()==1){
+                        String autoIncrementNumber="";
+                        //如果是需要自增的 先要查出当前数据库中自增编号的最大值
+                        String sql3 = "SELECT auto_increment_number FROM u_trial_auto_number where type="+type+" and contract_id="+contractId+" and is_deleted=0 ORDER BY auto_increment_number DESC LIMIT 1";
+                        String maxNumber = jdbcTemplate.query(sql3, rs -> {
+                            if (rs.next()) {
+                                return rs.getObject(1, String.class);
+                            } else {
+                                return null;
+                            }
+                        });
+                        if(StringUtils.isEmpty(maxNumber)){
+                            autoIncrementNumber=rule.getData();
+                        }else {
+                            autoIncrementNumber=incrementFormattedNumberWithCheck(maxNumber,i);
+                        }
+//
+//                    String sql4="select auto_increment_number FROM u_trial_auto_number where type="+type+" and contract_id="+contractId+" and is_deleted=0  ORDER BY auto_increment_number ASC";
+//                    List<String> autoNumbers = jdbcTemplate.query(sql4, new SingleColumnRowMapper<>(String.class));
+//                    //判断自增的流水号是否是连续的 是连续的就在最大值加1,不是连续的先使用缺失的编号
+//                    List<String> missingNumbers = findMissingNumberPatterns(autoNumbers);
+//                    if(missingNumbers.isEmpty()){
+//                        while (true){
+//                            maxNumber=incrementFormattedNumberWithCheck(maxNumber);
+//                            Object o = bladeRedis.get("trialAutoNumber:" + contractId + ":" + type + ":" + nodeId + ":" + "lock:" + maxNumber);
+//                            if(o==null){
+//                                break;
+//                            }
+//                        }
+//                        autoIncrementNumber=maxNumber;
+//                    }else {
+//                        for (int i = 0; i < missingNumbers.size(); i++) {
+//                            autoIncrementNumber=missingNumbers.get(i);
+//                            Object o = bladeRedis.get("trialAutoNumber:" + contractId + ":" + type + ":" + nodeId + ":" + "lock:" + autoIncrementNumber);
+//                            if(o==null){
+//                                break;
+//                            }
+//                            autoIncrementNumber="";
+//                        }
+//                        if(autoIncrementNumber.equals("")){
+//                            while (true){
+//                                maxNumber=incrementFormattedNumberWithCheck(maxNumber);
+//                                Object o = bladeRedis.get("trialAutoNumber:" + contractId + ":" + type + ":" + nodeId + ":" + "lock:" + maxNumber);
+//                                if(o==null){
+//                                    break;
+//                                }
+//                            }
+//                            autoIncrementNumber=String.valueOf(maxNumber);
+//                        }
+//                    }
+//                      if (isSaveRedis) {
+//                        bladeRedis.setEx("trialAutoNumber:" + contractId + ":" + type + ":" + nodeId + ":" + "lock:" + autoIncrementNumber , autoIncrementNumber,10 * 60 * 1000L);
+//                      }
+                        map.put("autoIncrementNumber",autoIncrementNumber);
+                        trialNumber.append(autoIncrementNumber);
+                    }
+                    else {
+                        map.put("autoIncrementNumber","");
+                        trialNumber.append(rule.getData());
+                    }
+                }
+            }
+            if(isSaveRedis){
+                flag=checkTrialNumberIsExist(trialNumber.toString(),type,contractId);
+                i++;
+                if(!flag){
+                    trialNumber.setLength(0);
+                }
+            }
+        }while (!flag);
+        map.put("trialNumber",trialNumber.toString());
+        return map;
+    }
+
+    public String incrementFormattedNumberWithCheck(String data,int i) {
+        if (data == null || data.isEmpty()) {
+            return "0";
+        }
+
+        int length = data.length();
+        int number = Integer.parseInt(data);
+        number += i;
+
+        // 检查自增后的数字位数是否超过原始数据的长度
+        if (String.valueOf(number).length() > length) {
+            throw new ServiceException("自增后的编号超出原始格式位数限制:" + data);
+        }
+
+        return String.format("%0" + length + "d", number);
+    }
+
+    public List<String> findMissingNumberPatterns(List<String> autoNumbersStr) {
+        if (autoNumbersStr == null || autoNumbersStr.size() <= 1) {
+            return Collections.emptyList();
+        }
+
+        // 提取数字和最大长度
+        List<Long> numbers = new ArrayList<>();
+        int maxLength = 0;
+
+        for (String s : autoNumbersStr) {
+            try {
+                Long num = Long.parseLong(s);
+                numbers.add(num);
+                maxLength = Math.max(maxLength, s.length());
+            } catch (NumberFormatException ignored) {
+            }
+        }
+
+        if (numbers.size() <= 1) {
+            return Collections.emptyList();
+        }
+
+        // 排序
+        numbers.sort(Long::compareTo);
+
+        long start = numbers.get(0);
+        long end = numbers.get(numbers.size() - 1);
+        Set<Long> numberSet = new HashSet<>(numbers);
+
+        List<String> missing = new ArrayList<>();
+
+        for (long i = start; i <= end; i++) {
+            if (!numberSet.contains(i)) {
+                // 使用原始最长字符串的长度进行格式化
+                String formatted = String.format("%0" + maxLength + "d", i);
+                missing.add(formatted);
+            }
+        }
+
+        return missing;
+    }
+    @Override
+    public boolean checkTrialNumberIsExist(String trialNumber,Integer type,Long contractId){
+        String tableName="";
+        String number="";
+        if(type==1){
+            tableName="u_trial_material_mobilization";
+            number="material_number";
+        }
+        if(type==2){
+            tableName="u_trial_sample_info";
+            number="specification_number";
+        }
+        if(type==3){
+            tableName="u_entrust_info";
+            number="entrust_no";
+        }
+        if(type==4){
+            tableName="u_trial_self_inspection_record";
+            number="record_no";
+        }
+        if(type==5){
+            tableName="u_trial_self_inspection_record";
+            number="report_no";
+        }
+        String sql="select count(id) from "+tableName+" where "+number+" = '"+trialNumber+"' and is_deleted=0 and contract_id="+contractId;
+        System.out.println(sql);
+        Integer count = jdbcTemplate.queryForObject(sql, Integer.class);
+        if(count==0){
+            return true;
+        }else {
+            return false;
+        }
+    }
+
+    @Override
+    public TrialNumberRuleVO1 getTrialNumberRule(Long projectId,Long contractId, Integer type) {
+        TrialNumberRuleVO1 vo1 = new TrialNumberRuleVO1();
+        List<TrialNumberRule> trialNumberRules;
+        if(contractId==0L){
+            trialNumberRules = baseMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getProjectId, projectId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,1).orderByAsc(TrialNumberRule::getSort));
+        }else {
+            trialNumberRules = baseMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getContractId, contractId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,2).orderByAsc(TrialNumberRule::getSort));
+        }
+        if(trialNumberRules.size()>0){
+            for (TrialNumberRule rule : trialNumberRules) {
+                if(rule.getRule()==2){
+                    if(rule.getContractId()==null||rule.getContractId()==0L){
+                        rule.setData("TJ01");
+                    }else {
+                        String sql1="select contract_number from m_contract_info where id="+contractId;
+                        String result = jdbcTemplate.query(sql1, rs -> {
+                            if (rs.next()) {
+                                return rs.getString(1);
+                            } else {
+                                return "";
+                            }
+                        });
+                        rule.setData(result);
+                    }
+                } else if (rule.getRule()==3) {
+                    rule.setData("SNY");
+                } else if (rule.getRule()==4) {
+                    String currentYearStr = String.valueOf(LocalDate.now().getYear());
+                    rule.setData(currentYearStr);
+                } else if (rule.getRule()==5) {
+                    int currentMonthValue = LocalDate.now().getMonthValue();
+                    String currentMonthStr = String.format("%02d", currentMonthValue);
+                    rule.setData(currentMonthStr);
+                }
+            }
+        }
+        if(trialNumberRules!=null){
+            Map<String, String> map = getTrialNumber(projectId,contractId, type, null, false);
+            vo1.setList(trialNumberRules);
+            vo1.setTrialNumber(map.get("trialNumber"));
+            return vo1;
+        }
+        return null;
+    }
+
+    /**
+     * type 1材料 2样品 3委托单 4记录表 5报告表
+     * @param projectId
+     * @param contractId
+     * @param type
+     * @return
+     */
+    @Override
+    public boolean clearTrialNumber(Long projectId, Long contractId, Integer type) {
+        if(contractId!=null&&contractId!=0L){
+//            String update;
+//            if(type==1){
+//                update="update u_trial_material_mobilization set material_number = NULL where contract_id="+contractId;
+//            } else if (type==2) {
+//                update="update u_trial_sample_info set specification_number = NULL where contract_id="+contractId;
+//            } else if (type==3) {
+//                update="update u_entrust_info set entrust_no = NULL where contract_id="+contractId+" and status=1";
+//            } else if (type==4) {
+//                update="update u_trial_self_inspection_record set record_no = NULL where contract_id="+contractId+" and task_status='未上报'";
+//            }else{
+//                update="update u_trial_self_inspection_record set report_no = NULL where contract_id="+contractId+" and task_status='未上报'";
+//            }
+//            jdbcTemplate.execute(update);
+            List<TrialNumberRule> trialNumberRules;
+            trialNumberRules = baseMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getContractId, contractId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,2).orderByAsc(TrialNumberRule::getSort));
+            if(!trialNumberRules.isEmpty()){
+                boolean b = trialNumberRules.stream().anyMatch(t -> t.getRule() == 6);
+                if(b){
+                    String sql="update u_trial_auto_number set is_deleted=1 where contract_id="+contractId+" and type="+ type;
+                    jdbcTemplate.update(sql);
+                }
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public Map<String, String> getEntrustNumber(Long pkeyId,Long contractId) throws FileNotFoundException {
+        final Long nodeId=pkeyId;
+        // 合同段信息
+        String sql="select * from m_contract_info where id="+contractId;
+        ContractInfo contractInfo =jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(ContractInfo.class));
+        String sql1="select * from m_wbs_tree_private where p_key_id="+pkeyId;
+        // 节点数
+        WbsTreePrivate treePrivate = jdbcTemplate.queryForObject(sql1,new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+        if (contractInfo == null) {
+            throw new ServiceException("合同段信息为null");
+        }
+        if (contractInfo.getContractType() == 2) { //3 监理
+            pkeyId = treePrivate.getJlerTreeId();
+        } else if (contractInfo.getContractType() == 3 || contractInfo.getContractType() == 8) { //业主
+            pkeyId = treePrivate.getYzerTreeId();
+        }else {
+            return null;
+        }
+        String sql2="select * from m_wbs_tree_private where p_key_id="+pkeyId;
+        WbsTreePrivate wbsTreePrivate1 = jdbcTemplate.queryForObject(sql2, new BeanPropertyRowMapper<>(WbsTreePrivate.class));
+        String fileUrl = wbsTreePrivate1.getHtmlUrl();
+        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        String sys_file_net_url = ParamCache.getValue(CommonConstant.SYS_FILE_NET_URL);
+        File file1 = ResourceUtil.getFile(fileUrl);
+        InputStream fileInputStream;
+        if (file1.exists()) {
+            fileInputStream = new FileInputStream(file1);
+        } else {
+            String path = sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path, "");
+            fileInputStream = CommonUtil.getOSSInputStream(path);
+        }
+        String htmlString = IoUtil.readToString(fileInputStream);
+        Document doc = Jsoup.parse(htmlString);
+        Elements elementsWithPlaceholderxx = doc.select("el-input[placeholder*=委托单编号]");
+        if(!elementsWithPlaceholderxx.isEmpty()){
+            Element first = elementsWithPlaceholderxx.first();
+            String key = first.attr("id");
+            Map<String, String> map = getTrialNumber(Long.valueOf(wbsTreePrivate1.getProjectId()),contractId, 3, nodeId, true);
+            map.put(key,map.get("trialNumber"));
+            return map;
+        }
+        return null;
+    }
+
+
+    public void checkSave(Long contractId,Integer type,Long formDataId,String autoNumber){
+        List<TrialNumberRule> list = baseMapper.selectList(Wrappers.<TrialNumberRule>query().lambda().eq(TrialNumberRule::getContractId, contractId).eq(TrialNumberRule::getType, type).eq(TrialNumberRule::getStatus,2).orderByAsc(TrialNumberRule::getSort));
+            if(list!=null&&list.size()>0){
+                List<TrialNumberRule> collect = list.stream().filter(o -> o.getRule() == 6 && o.getIsAutoIncrement() == 1).collect(Collectors.toList());
+                if(!collect.isEmpty()){
+                    TrialAutoNumber one = trialAutoNumberService.getOne(Wrappers.lambdaQuery(TrialAutoNumber.class).eq(TrialAutoNumber::getFormDataId, formDataId).eq(TrialAutoNumber::getType, type));
+                    if(one==null){
+                        TrialAutoNumber trialAutoNumber = new TrialAutoNumber();
+                        trialAutoNumber.setId(SnowFlakeUtil.getId());
+                        trialAutoNumber.setContractId(contractId);
+                        trialAutoNumber.setType(type);
+                        trialAutoNumber.setNumberRuleId(collect.get(0).getId());
+                        trialAutoNumber.setFormDataId(formDataId);
+                        trialAutoNumber.setAutoIncrementNumber(autoNumber);
+                        trialAutoNumberService.save(trialAutoNumber);
+                    }
+                }
+            }
+    }
+
+}