Browse Source

feat: [模板管理] 编号修改

master
memorylkf 1 day ago
parent
commit
3c48659467
12 changed files with 266 additions and 19 deletions
  1. +10
    -0
      hxhq-modules/hxhq-system/pom.xml
  2. +18
    -12
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/PublicController.java
  3. +64
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SnGenController.java
  4. +4
    -1
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/TemplateController.java
  5. +42
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/SnGen.java
  6. +11
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Template.java
  7. +20
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/mapper/SnGenMapper.java
  8. +20
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISnGenService.java
  9. +58
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SnGenServiceImpl.java
  10. +9
    -5
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyServiceImpl.java
  11. +9
    -0
      hxhq-modules/hxhq-system/src/main/resources/mapper/business/SnGenMapper.xml
  12. +1
    -1
      hxhq-modules/hxhq-system/src/main/resources/mapper/business/TemplateMapper.xml

+ 10
- 0
hxhq-modules/hxhq-system/pom.xml View File

@ -99,6 +99,16 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
<build>

+ 18
- 12
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/PublicController.java View File

@ -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<String, Object> map = new HashMap<String, Object>(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<String, Object> map = new HashMap<String, Object>(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);
}

+ 64
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SnGenController.java View File

@ -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<SnGen> 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)));
}
}

+ 4
- 1
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/TemplateController.java View File

@ -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();
}
/**

+ 42
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/SnGen.java View File

@ -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;
}
}

+ 11
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/Template.java View File

@ -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;
}

+ 20
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/mapper/SnGenMapper.java View File

@ -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<SnGen>
{
/**
* 递增id
* @param date
*/
void addSn(@Param("date") String date);
}

+ 20
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISnGenService.java View File

@ -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<SnGen>
{
/**
* 获取新编号
* @return
*/
String getNewSn();
}

+ 58
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SnGenServiceImpl.java View File

@ -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<SnGenMapper, SnGen> 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<SnGen> 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;
}
}

+ 9
- 5
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudyServiceImpl.java View File

@ -182,7 +182,15 @@ public class StudyServiceImpl extends ServiceImpl implements
public void saveInfo(StudySaveForm form) {
Study study = form.getStudy();
SignForm sign = form.getSign();
//判断编号重复
QueryWrapper<Study> 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<StudyJcgj> jcgjList = new ArrayList<>();
List<ObjectCompareUtil.FieldChange> 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<String, String> 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<String, String> formData = new LinkedHashMap<>();
formData.put("暂存人", SecurityUtils.getNickName());

+ 9
- 0
hxhq-modules/hxhq-system/src/main/resources/mapper/business/SnGenMapper.xml View File

@ -0,0 +1,9 @@
<?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.hxhq.business.mapper.SnGenMapper">
<update id="addSn">
update t_sn_gen set sn = sn+1 where `date`=#{date} and del_flag='0'
</update>
</mapper>

+ 1
- 1
hxhq-modules/hxhq-system/src/main/resources/mapper/business/TemplateMapper.xml View File

@ -4,7 +4,7 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hxhq.business.mapper.TemplateMapper">
<select id="queryList">
SELECT t.`id`,t.`sn`,t.`name`,t.`dept_id`,t.`status`,t.`need_pre`,t.`type`,d.`dept_name`
SELECT t.`id`,t.`sn`,t.`show_sn`,t.`name`,t.`dept_id`,t.`status`,t.`need_pre`,t.`type`,d.`dept_name`
FROM `t_template` t
LEFT JOIN `sys_dept` d ON t.`dept_id`=d.`dept_id`
<if test="ew.sqlSegment != '' and ew.sqlSegment != null">

Loading…
Cancel
Save