From 3c48659467d6aed650099f762098bb09d836438a Mon Sep 17 00:00:00 2001
From: memorylkf <312904636@qq.com>
Date: Mon, 12 Jan 2026 10:18:40 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20[=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86]?=
=?UTF-8?q?=20=E7=BC=96=E5=8F=B7=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
hxhq-modules/hxhq-system/pom.xml | 10 ++++
.../hxhq/business/controller/PublicController.java | 30 ++++++----
.../hxhq/business/controller/SnGenController.java | 64 ++++++++++++++++++++++
.../business/controller/TemplateController.java | 5 +-
.../main/java/com/hxhq/business/domain/SnGen.java | 42 ++++++++++++++
.../java/com/hxhq/business/domain/Template.java | 11 ++++
.../java/com/hxhq/business/mapper/SnGenMapper.java | 20 +++++++
.../com/hxhq/business/service/ISnGenService.java | 20 +++++++
.../business/service/impl/SnGenServiceImpl.java | 58 ++++++++++++++++++++
.../business/service/impl/StudyServiceImpl.java | 14 +++--
.../main/resources/mapper/business/SnGenMapper.xml | 9 +++
.../resources/mapper/business/TemplateMapper.xml | 2 +-
12 files changed, 266 insertions(+), 19 deletions(-)
create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SnGenController.java
create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/SnGen.java
create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/mapper/SnGenMapper.java
create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISnGenService.java
create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SnGenServiceImpl.java
create mode 100644 hxhq-modules/hxhq-system/src/main/resources/mapper/business/SnGenMapper.xml
diff --git a/hxhq-modules/hxhq-system/pom.xml b/hxhq-modules/hxhq-system/pom.xml
index 47780a3..5c3ef2f 100644
--- a/hxhq-modules/hxhq-system/pom.xml
+++ b/hxhq-modules/hxhq-system/pom.xml
@@ -99,6 +99,16 @@
org.projectlombok
lombok
+
+ cn.hutool
+ hutool-all
+ 5.8.16
+
+
+ com.belerweb
+ pinyin4j
+ 2.5.1
+
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/PublicController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/PublicController.java
index 7adc751..204b7e4 100644
--- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/PublicController.java
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/PublicController.java
@@ -54,6 +54,8 @@ public class PublicController extends BaseController {
private IZcgService zcgService;
@Autowired
private RedisService redisService;
+ @Autowired
+ public ISnGenService snGenService;
/**
* 获取编号
@@ -65,21 +67,25 @@ public class PublicController extends BaseController {
if (count == null || count.intValue() <= 0) {
return AjaxResult.error("参数错误");
}
- Integer start = 1;
- SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
- String today = sdf.format(new Date());
- //获取当前最大编号
- String maxNum = redisService.getCacheObject(today);
- if (StringUtils.isNoneBlank(maxNum)) {
- start = Integer.parseInt(maxNum)+1;
- }
+// Integer start = 1;
+// SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+// String today = sdf.format(new Date());
+// //获取当前最大编号
+// String maxNum = redisService.getCacheObject(today);
+// if (StringUtils.isNoneBlank(maxNum)) {
+// start = Integer.parseInt(maxNum)+1;
+// }
+// HashMap map = new HashMap(count);
+// for (int i = 0; i < count;i++){
+// map.put("sn"+i,today+String.format("%04d", start));
+// start++;
+// }
+// //更新当前最大编号
+// redisService.setCacheObject(today,start,60*60*24L, TimeUnit.SECONDS);
HashMap map = new HashMap(count);
for (int i = 0; i < count;i++){
- map.put("sn"+i,today+String.format("%04d", start));
- start++;
+ map.put("sn"+i,snGenService.getNewSn());
}
- //更新当前最大编号
- redisService.setCacheObject(today,start,60*60*24L, TimeUnit.SECONDS);
return AjaxResult.success(map);
}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SnGenController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SnGenController.java
new file mode 100644
index 0000000..4040365
--- /dev/null
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SnGenController.java
@@ -0,0 +1,64 @@
+package com.hxhq.business.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import com.hxhq.business.domain.SnGen;
+import com.hxhq.business.service.ISnGenService;
+import com.hxhq.common.core.web.controller.BaseController;
+import com.hxhq.common.core.web.domain.AjaxResult;
+import com.hxhq.common.core.web.page.TableDataInfo;
+
+
+/**
+ * 每日编号生成记录Controller
+ *
+ * @author hxhq
+ * @date 2026-01-12
+ */
+@RestController
+@RequestMapping("/business/snGen")
+public class SnGenController extends BaseController
+{
+ @Autowired
+ private ISnGenService snGenService;
+
+ /**
+ * 查询每日编号生成记录列表
+ */
+ @GetMapping("/list")
+ public TableDataInfo list(SnGen snGen)
+ {
+ startPage();
+ List list = snGenService.queryList(snGen);
+ return getDataTable(list);
+ }
+
+ /**
+ * 获取每日编号生成记录详细信息
+ */
+ @GetMapping(value = "/info")
+ public AjaxResult getInfo(Long id)
+ {
+ return AjaxResult.success(snGenService.getById(id));
+ }
+
+ /**
+ * 新增每日编号生成记录信息
+ */
+ @PostMapping("/save")
+ public AjaxResult save(@RequestBody SnGen snGen)
+ {
+ return toAjax(snGenService.saveOrUpdate(snGen));
+ }
+
+ /**
+ * 删除每日编号生成记录信息
+ */
+ @PostMapping("/delete")
+ public AjaxResult delete(@RequestBody Long[] ids)
+ {
+ return toAjax(snGenService.removeByIds(Arrays.asList(ids)));
+ }
+}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/TemplateController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/TemplateController.java
index 25ef518..c91f143 100644
--- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/TemplateController.java
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/TemplateController.java
@@ -2,6 +2,7 @@ package com.hxhq.business.controller;
import java.util.List;
+import cn.hutool.extra.pinyin.PinyinUtil;
import com.hxhq.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -53,7 +54,9 @@ public class TemplateController extends BaseController
@PostMapping("/save")
public AjaxResult save(@RequestBody Template template)
{
- return toAjax(templateService.saveOrUpdate(template));
+ template.setShowSn("MB"+PinyinUtil.getFirstLetter(template.getName(),"").toUpperCase()+"V1.0");
+ templateService.saveOrUpdate(template);
+ return AjaxResult.success();
}
/**
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/SnGen.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/SnGen.java
new file mode 100644
index 0000000..5e1a12c
--- /dev/null
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/SnGen.java
@@ -0,0 +1,42 @@
+package com.hxhq.business.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.hxhq.common.core.domain.MpBaseEntity;
+
+
+/**
+ * 每日编号生成记录对象 t_sn_gen
+ *
+ * @author hxhq
+ * @date 2026-01-12
+ */
+@TableName("t_sn_gen")
+public class SnGen extends MpBaseEntity
+{
+ private static final long serialVersionUID = 1L;
+
+ /** 日期 */
+ private String date;
+
+ /** 当前编号 */
+ private Integer sn;
+
+
+ public void setDate(String date)
+ {
+ this.date = date;
+ }
+
+ public String getDate()
+ {
+ return date;
+ }
+
+ public Integer getSn() {
+ return sn;
+ }
+
+ public void setSn(Integer sn) {
+ this.sn = sn;
+ }
+}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Template.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Template.java
index c78fd1f..0825fb7 100644
--- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Template.java
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Template.java
@@ -40,6 +40,9 @@ public class Template extends MpBaseEntity
/** 产物:1:试剂;3:供试品;5:给药制剂;7:麻精药 */
private Integer product;
+ /** 显示的编号 */
+ private String showSn;
+
/** 部门名称 */
@TableField(exist = false)
private String deptName;
@@ -118,6 +121,14 @@ public class Template extends MpBaseEntity
this.type = type;
}
+ public String getShowSn() {
+ return showSn;
+ }
+
+ public void setShowSn(String showSn) {
+ this.showSn = showSn;
+ }
+
public String getDeptName() {
return deptName;
}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/mapper/SnGenMapper.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/mapper/SnGenMapper.java
new file mode 100644
index 0000000..b7ed4c3
--- /dev/null
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/mapper/SnGenMapper.java
@@ -0,0 +1,20 @@
+package com.hxhq.business.mapper;
+
+import com.hxhq.business.domain.SnGen;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * 每日编号生成记录Mapper接口
+ *
+ * @author hxhq
+ * @date 2026-01-12
+ */
+public interface SnGenMapper extends BaseMapper
+{
+ /**
+ * 递增id
+ * @param date
+ */
+ void addSn(@Param("date") String date);
+}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISnGenService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISnGenService.java
new file mode 100644
index 0000000..8509f87
--- /dev/null
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISnGenService.java
@@ -0,0 +1,20 @@
+package com.hxhq.business.service;
+
+import java.util.List;
+import com.hxhq.business.domain.SnGen;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 每日编号生成记录Service接口
+ *
+ * @author hxhq
+ * @date 2026-01-12
+ */
+public interface ISnGenService extends IService
+{
+ /**
+ * 获取新编号
+ * @return
+ */
+ String getNewSn();
+}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SnGenServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SnGenServiceImpl.java
new file mode 100644
index 0000000..4747e6a
--- /dev/null
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SnGenServiceImpl.java
@@ -0,0 +1,58 @@
+package com.hxhq.business.service.impl;
+
+import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+ import com.hxhq.common.core.utils.DateUtils;
+import com.hxhq.common.core.utils.SpringUtils;
+import com.hxhq.common.redis.service.RedisService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.hxhq.business.mapper.SnGenMapper;
+import com.hxhq.business.domain.SnGen;
+import com.hxhq.business.service.ISnGenService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * 每日编号生成记录Service业务层处理
+ *
+ * @author hxhq
+ * @date 2026-01-12
+ */
+@Service
+public class SnGenServiceImpl extends ServiceImpl implements ISnGenService
+{
+ /**
+ * true表示公平锁
+ */
+ private final Lock lock = new ReentrantLock(true);
+
+ @Override
+ public String getNewSn() {
+ lock.lock();
+ try {
+ Integer sort = 1;
+ String date = DateUtils.dateTimeNow("yyMMdd");
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("date",date);
+ if(count(queryWrapper)==0){
+ SnGen snGen = new SnGen();
+ snGen.setDate(date);
+ snGen.setSn(sort);
+ save(snGen);
+ }else{
+ baseMapper.addSn(date);
+ sort = getOne(queryWrapper,false).getSn();
+ }
+ return date+"-"+String.format("%04d", sort);
+ } catch (Exception e) {
+ log.error("getNewSn执行被中断", e);
+ } finally {
+ lock.unlock();
+ }
+ return null;
+ }
+}
diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyServiceImpl.java
index 5265a28..8cf1fc2 100644
--- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyServiceImpl.java
+++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyServiceImpl.java
@@ -182,7 +182,15 @@ public class StudyServiceImpl extends ServiceImpl implements
public void saveInfo(StudySaveForm form) {
Study study = form.getStudy();
SignForm sign = form.getSign();
-
+ //判断编号重复
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("sn",study.getSn());
+ if(study.getId()!=null){
+ queryWrapper.ne("id",study.getId());
+ }
+ if(count(queryWrapper)>0){
+ throw new ServiceException("编号已存在");
+ }
if(study.getId()==null){
//新增
save(study);
@@ -192,7 +200,6 @@ public class StudyServiceImpl extends ServiceImpl implements
studyJcgjService.saveInfo(study.getId(), JcgjlxEnum.lc, JcmcysEnum.blue,"暂存实验", JctUtil.formatStr(formData),null,null,null);
}else{
checkPassword(sign);
-
studyJcgjService.saveInfo(study.getId(), JcgjlxEnum.lc, JcmcysEnum.blue,"创建实验", null,SecurityUtils.getUserId(),SecurityUtils.getNickName(),sign.getRemark());
}
}else{
@@ -205,7 +212,6 @@ public class StudyServiceImpl extends ServiceImpl implements
throw new ServiceException("当前状态不允许修改");
}
checkPermit(old);
-
//修改字段的稽查轨迹
List jcgjList = new ArrayList<>();
List fieldChanges = ObjectCompareUtil.compareObjects(old, study);
@@ -226,7 +232,6 @@ public class StudyServiceImpl extends ServiceImpl implements
}
}
studyJcgjService.saveBatch(jcgjList);
-
//修改试验负责人的稽查轨迹
if(!old.getLeaderName().equals(study.getLeaderName())){
Map formData = new LinkedHashMap<>();
@@ -238,7 +243,6 @@ public class StudyServiceImpl extends ServiceImpl implements
studyJcgjService.saveInfo(study.getId(), JcgjlxEnum.ry, JcmcysEnum.blue,"人员变更", JctUtil.formatStr(formData), SecurityUtils.getUserId(),SecurityUtils.getNickName(),sign.getRemark());
}
}
-
if(study.getStatus().equals(StudyStatusEnum.cg.getValue())){
Map formData = new LinkedHashMap<>();
formData.put("暂存人", SecurityUtils.getNickName());
diff --git a/hxhq-modules/hxhq-system/src/main/resources/mapper/business/SnGenMapper.xml b/hxhq-modules/hxhq-system/src/main/resources/mapper/business/SnGenMapper.xml
new file mode 100644
index 0000000..ea7975e
--- /dev/null
+++ b/hxhq-modules/hxhq-system/src/main/resources/mapper/business/SnGenMapper.xml
@@ -0,0 +1,9 @@
+
+
+
+
+ update t_sn_gen set sn = sn+1 where `date`=#{date} and del_flag='0'
+
+
\ No newline at end of file
diff --git a/hxhq-modules/hxhq-system/src/main/resources/mapper/business/TemplateMapper.xml b/hxhq-modules/hxhq-system/src/main/resources/mapper/business/TemplateMapper.xml
index 9f93a37..8afae9c 100644
--- a/hxhq-modules/hxhq-system/src/main/resources/mapper/business/TemplateMapper.xml
+++ b/hxhq-modules/hxhq-system/src/main/resources/mapper/business/TemplateMapper.xml
@@ -4,7 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">