This commit is contained in:
lijiaqi 2024-05-30 16:52:09 +08:00
parent 9870436b8b
commit 4c6abb0bd2
6 changed files with 165 additions and 8 deletions

View File

@ -27,9 +27,9 @@ public class Generator {
public static void main(String[] args) {
//表名
String tableName = "t_integrated_notice_user";
String tableName = "t_work_flow_file_number";
//表前缀
String tablePrefix = "t_integrated_";
String tablePrefix = "t_";
//作者
String author = "zhouyuan";
@ -66,7 +66,7 @@ public class Generator {
//包配置
PackageConfig pc = new PackageConfig();
pc.setParent("com.ydool.integrated");
pc.setParent("com.ydool.oa.workFlow");
pc.setEntity("entity");
pc.setServiceImpl("service");
pc.setMapper("mapper");

View File

@ -14,6 +14,7 @@ import com.ydool.oa.workFlow.data.entity.WorkFlowNotice;
import com.ydool.oa.workFlow.data.vo.WorkFlowNoticeVo;
import com.ydool.oa.workFlow.data.vo.WorkFlowStepVo;
import com.ydool.oa.workFlow.data.vo.WorkFlowVo;
import com.ydool.oa.workFlow.service.WorkFlowFileNumberService;
import com.ydool.oa.workFlow.service.WorkFlowNoticeService;
import com.ydool.oa.workFlow.service.WorkFlowService;
import io.swagger.annotations.Api;
@ -39,6 +40,9 @@ public class WorkFlowController extends BaseController {
@Autowired
private WorkFlowNoticeService workFlowNoticeService;
@Autowired
private WorkFlowFileNumberService workFlowFileNumberService;
/**
* 发起流程
@ -53,6 +57,17 @@ public class WorkFlowController extends BaseController {
return workFlowService.start(vo);
}
/**
* 获取文件编号
*/
@GetMapping(value = "getFileNumberByType")
@ApiOperation(value = "获取文件编号")
@ApiImplicitParam(name = "type", value = "流程类型")
@ApiOperationSupport(order = 10)
public AjaxResult getFileNumberByType(String type) {
return AjaxResult.ok().data(workFlowFileNumberService.getMaxNumber(type));
}
/**
* 撤销流程

View File

@ -0,0 +1,38 @@
package com.ydool.oa.workFlow.data.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ydool.common.base.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
* 工作流程文件编号
* </p>
*
* @author zhouyuan
* @since 2024-05-30
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("t_work_flow_file_number")
@ApiModel(value="WorkFlowFileNumber对象", description="工作流程文件编号")
public class WorkFlowFileNumber extends BaseEntity{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "关联流程id")
private String workFlowId;
@ApiModelProperty(value = "流程类型")
private String type;
@ApiModelProperty(value = "文件编号年份")
private Integer year;
@ApiModelProperty(value = "文件编号")
private Integer number;
}

View File

@ -0,0 +1,32 @@
package com.ydool.oa.workFlow.mapper;
import com.ydool.oa.workFlow.data.entity.WorkFlowFileNumber;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* <p>
* 工作流程文件编号 Mapper 接口
* </p>
*
* @author zhouyuan
* @since 2024-05-30
*/
@Mapper
public interface WorkFlowFileNumberMapper extends MPJBaseMapper<WorkFlowFileNumber> {
/**
* 获取最大编号
* @param type
* @param year
* @return
*/
@Select("select COALESCE(max(number), 0) + 1\n" +
"from t_work_flow_file_number\n" +
"where type = #{type}\n" +
"and year = #{year}")
Integer getMaxNumber(@Param("type")String type, @Param("year") Integer year);
}

View File

@ -0,0 +1,54 @@
package com.ydool.oa.workFlow.service;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.StrUtil;
import com.ydool.common.base.BaseService;
import com.ydool.common.exception.AjaxResultException;
import com.ydool.oa.workFlow.data.entity.WorkFlowFileNumber;
import com.ydool.oa.workFlow.mapper.WorkFlowFileNumberMapper;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* <p>
* 工作流程文件编号 服务类
* </p>
*
* @author zhouyuan
* @since 2024-05-30
*/
@Service
public class WorkFlowFileNumberService extends BaseService<WorkFlowFileNumberMapper, WorkFlowFileNumber> {
@Resource
private WorkFlowFileNumberMapper workFlowFileNumberMapper;
public synchronized String getMaxNumber(String type) {
if (StrUtil.isBlank(type)) {
throw new AjaxResultException("type不能为空");
}
int year = LocalDateTimeUtil.now().getYear();
Integer maxNumber = workFlowFileNumberMapper.getMaxNumber(type, year);
//maxNumber变成3位数的字符串少的位数补零
return year + String.format("%03d", maxNumber);
}
@SneakyThrows
public synchronized void setMaxNumber(WorkFlowFileNumber workFlowFileNumber) {
try {
synchronized (this) {
Integer maxNumber = workFlowFileNumberMapper.getMaxNumber(workFlowFileNumber.getType(), workFlowFileNumber.getYear());
workFlowFileNumber.setNumber(maxNumber);
workFlowFileNumberMapper.insert(workFlowFileNumber);
}
} catch (Exception e) {
//等待1s后重新
Thread.sleep(1000);
setMaxNumber(workFlowFileNumber);
}
}
}

View File

@ -5,16 +5,14 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ydool.common.base.BaseService;
import com.ydool.common.data.dto.AjaxResult;
import com.ydool.common.exception.ResultException;
import com.ydool.oa.workFlow.data.dto.WorkFlowCountDto;
import com.ydool.oa.workFlow.data.entity.WorkFlow;
import com.ydool.oa.workFlow.data.entity.WorkFlowNotice;
import com.ydool.oa.workFlow.data.entity.WorkFlowStep;
import com.ydool.oa.workFlow.data.entity.WorkFlowStepLog;
import com.ydool.oa.workFlow.data.entity.*;
import com.ydool.oa.workFlow.data.vo.WorkFlowStepVo;
import com.ydool.oa.workFlow.data.vo.WorkFlowVo;
import com.ydool.oa.workFlow.data.wrapper.WorkFlowWrapper;
@ -28,6 +26,7 @@ import com.ydool.staff.service.IAuditService;
import com.ydool.system.entity.User;
import com.ydool.system.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -63,6 +62,10 @@ public class WorkFlowService extends BaseService<WorkFlowMapper, WorkFlow> {
@Autowired
private IAuditService auditService;
@Autowired
@Lazy
private WorkFlowFileNumberService workFlowFileNumberService;
/**
* 发起流程
*
@ -104,6 +107,22 @@ public class WorkFlowService extends BaseService<WorkFlowMapper, WorkFlow> {
workFlow.setStatus(WorkFlowStatusEnum.ACTIVE.getStatus());
boolean flag = save(workFlow);
if (!flag) return AjaxResult.fail("发起失败");
// 判断是否为轮换或药剂
if (vo.getType().equals(WorkFlowTypeEnum.ROTATION.getType()) || vo.getType().equals(WorkFlowTypeEnum.DRUG.getType())) {
// 重新计算文件编号
WorkFlowFileNumber workFlowFileNumber = new WorkFlowFileNumber();
workFlowFileNumber.setWorkFlowId(workFlow.getId());
workFlowFileNumber.setType(vo.getType());
workFlowFileNumber.setYear(LocalDateTime.now().getYear());
workFlowFileNumberService.setMaxNumber(workFlowFileNumber);
String data = workFlow.getData();
data = JSONUtil.toJsonStr(JSONUtil.parseObj(data).set("number", workFlowFileNumber.getYear() + String.format("%03d", workFlowFileNumber.getNumber())));
workFlow.setData(data);
flag = updateById(workFlow);
if (!flag) return AjaxResult.fail("发起失败,请重新发起");
}
// 2.保存流程步骤
WorkFlowStep workFlowStep = new WorkFlowStep(workFlow, WorkFlowStepTypeEnum.START.getType(),
StpUtil.getLoginIdAsString(), WorkFlowStepStatusEnum.SUBMIT.getStatus(), "");
@ -332,7 +351,6 @@ public class WorkFlowService extends BaseService<WorkFlowMapper, WorkFlow> {
WorkFlowStepLog workFlowStepLog = new WorkFlowStepLog(workFlow);
flag = workFlowStepLogService.save(workFlowStepLog);
return flag ? AjaxResult.ok().msg("撤回成功") : AjaxResult.fail("撤回失败");
}