Commit bc17b2b2 by zhu.zewen

新增交接班相关接口

parent 0498b8c9
...@@ -65,3 +65,14 @@ cloudsign: ...@@ -65,3 +65,14 @@ cloudsign:
businessSystemCode: 1176 businessSystemCode: 1176
businessSystemAppID: w6qpjDk1WBSrFCfgcj businessSystemAppID: w6qpjDk1WBSrFCfgcj
# ################################################
# 交接单配置
# ################################################
handover:
cancel:
# 是否允许交班人取消交接单(默认false)
allowTransferor: false
# 是否允许接班人取消交接单(默认false)
allowReceiver: false
# 允许取消的天数限制(默认3天,从0时开始,含当天)
dayLimit: 3
...@@ -2,6 +2,7 @@ package com.jmai.physic.controller; ...@@ -2,6 +2,7 @@ package com.jmai.physic.controller;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jmai.physic.dto.PhysicBillHandoverCancelReq;
import com.jmai.physic.dto.PhysicBillHandoverCreateReq; import com.jmai.physic.dto.PhysicBillHandoverCreateReq;
import com.jmai.physic.dto.PhysicBillHandoverQueryReq; import com.jmai.physic.dto.PhysicBillHandoverQueryReq;
import com.jmai.physic.dto.PhysicBillHandoverSignReq; import com.jmai.physic.dto.PhysicBillHandoverSignReq;
...@@ -66,4 +67,11 @@ public class PhysicBillHandoverController { ...@@ -66,4 +67,11 @@ public class PhysicBillHandoverController {
PhysicBillHandover handover = physicBillService.signHandover(req); PhysicBillHandover handover = physicBillService.signHandover(req);
return ResponseData.ok(handover); return ResponseData.ok(handover);
} }
@PostMapping("/cancelHandover")
@ApiOperation(value = "交接单-取消")
public ResponseData<Void> cancelHandover(@RequestBody @Valid PhysicBillHandoverCancelReq req) {
physicBillService.cancelHandover(req);
return ResponseData.ok();
}
} }
\ No newline at end of file
...@@ -13,7 +13,7 @@ public class PhysicBillHandoverQueryReq extends PageReq { ...@@ -13,7 +13,7 @@ public class PhysicBillHandoverQueryReq extends PageReq {
@ApiModelProperty(value = "部门") @ApiModelProperty(value = "部门")
private Long deptId; private Long deptId;
@ApiModelProperty(value = "状态:0-待移交、1-待接收、100-已完成(0-99审核中)") @ApiModelProperty(value = "状态:-100-已取消、0-待移交、1-待接收、100-已完成(0-99审核中)")
private Integer status; private Integer status;
@ApiModelProperty(value = "开始完成时间") @ApiModelProperty(value = "开始完成时间")
......
...@@ -20,7 +20,7 @@ public class PhysicBillHandover extends BaseVersionEntity { ...@@ -20,7 +20,7 @@ public class PhysicBillHandover extends BaseVersionEntity {
@ApiModelProperty(value = "截止转账ID(包含)") @ApiModelProperty(value = "截止转账ID(包含)")
private Long endBillId; private Long endBillId;
@ApiModelProperty(value = "状态:0-待移交、1-待接收、100-已完成(0-99审核中)") @ApiModelProperty(value = "状态:-100-已取消、0-待移交、1-待接收、100-已完成(0-99审核中)")
private Integer status; private Integer status;
@ApiModelProperty(value = "交班人/移交人签名(transferor)") @ApiModelProperty(value = "交班人/移交人签名(transferor)")
private String yjUser; private String yjUser;
......
...@@ -23,4 +23,5 @@ public interface PhysicBillService { ...@@ -23,4 +23,5 @@ public interface PhysicBillService {
List<PhysicBill> getPendingHandoverPhysicBills(Long deptId); List<PhysicBill> getPendingHandoverPhysicBills(Long deptId);
PhysicBillHandover handover(PhysicBillHandoverCreateReq req); PhysicBillHandover handover(PhysicBillHandoverCreateReq req);
PhysicBillHandover signHandover(PhysicBillHandoverSignReq req); PhysicBillHandover signHandover(PhysicBillHandoverSignReq req);
void cancelHandover(PhysicBillHandoverCancelReq req);
} }
...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; ...@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmai.api.exception.ServiceException; import com.jmai.api.exception.ServiceException;
import com.jmai.physic.cloudsign.CloudsignService; import com.jmai.physic.cloudsign.CloudsignService;
import com.jmai.physic.config.HandoverCancelProperties;
import com.jmai.physic.dto.*; import com.jmai.physic.dto.*;
import com.jmai.physic.entity.PhysicBill; import com.jmai.physic.entity.PhysicBill;
import com.jmai.physic.entity.PhysicBillHandover; import com.jmai.physic.entity.PhysicBillHandover;
...@@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -41,6 +43,8 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill ...@@ -41,6 +43,8 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
@Resource @Resource
private CloudsignService cloudsignService; private CloudsignService cloudsignService;
@Resource
private HandoverCancelProperties handoverCancelProperties;
@Resource @Resource
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
...@@ -165,6 +169,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill ...@@ -165,6 +169,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
// TODO:是否会有未完成的专账? // TODO:是否会有未完成的专账?
List<PhysicBill> billList = physicBillMapper.selectList(Wrappers.<PhysicBill>lambdaQuery() List<PhysicBill> billList = physicBillMapper.selectList(Wrappers.<PhysicBill>lambdaQuery()
.gt(PhysicBill::getId, lastHandoverBillId) .gt(PhysicBill::getId, lastHandoverBillId)
.eq(PhysicBill::getDeptId, deptId)
.orderByAsc(PhysicBill::getId)); .orderByAsc(PhysicBill::getId));
return billList; return billList;
} }
...@@ -212,9 +217,29 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill ...@@ -212,9 +217,29 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
@Override @Override
public PhysicBillHandover handover(PhysicBillHandoverCreateReq req) { public PhysicBillHandover handover(PhysicBillHandoverCreateReq req) {
Long deptId = SpringContextUtils.getDeptId(); Long deptId = SpringContextUtils.getDeptId();
Long userId = SpringContextUtils.getUserId();
assert deptId != null : "部门ID不能为空"; assert deptId != null : "部门ID不能为空";
// 验证是否存在未完成的交接单
PhysicBillHandover unfinishedHandover = physicBillHandoverMapper.selectOne(Wrappers.lambdaQuery(PhysicBillHandover.class)
.eq(PhysicBillHandover::getDeptId, deptId)
.ne(PhysicBillHandover::getStatus, 100)
.ne(PhysicBillHandover::getStatus, -100)
.orderByDesc(PhysicBillHandover::getId));
if (ObjectUtil.isNotEmpty(unfinishedHandover)) {
throw new ServiceException("存在未完成交接单");
}
// 获取最新已完成的交接单
Optional<PhysicBillHandover> lastHandover = getLastHandover(deptId); Optional<PhysicBillHandover> lastHandover = getLastHandover(deptId);
// 验证当前用户是上次接班人
if (lastHandover.isPresent()) {
SignInfoDTO jsUserInfo = JSONUtil.toBean(lastHandover.get().getJsUser(), SignInfoDTO.class);
if (!jsUserInfo.getUserId().equals(userId)) {
throw new ServiceException("仅上次接班人有权限进行下一次交接班");
}
}
Long startBillId = lastHandover.map(PhysicBillHandover::getEndBillId).orElse(0L); Long startBillId = lastHandover.map(PhysicBillHandover::getEndBillId).orElse(0L);
Long endBillId = startBillId; Long endBillId = startBillId;
...@@ -234,7 +259,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill ...@@ -234,7 +259,7 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
physicBillHandoverMapper.insert(billHandover); physicBillHandoverMapper.insert(billHandover);
if (ObjectUtil.isEmpty(req.getSign())) { if (ObjectUtil.isNotEmpty(req.getSign())) {
// 交接人签名 // 交接人签名
PhysicBillHandoverSignReq signReq = new PhysicBillHandoverSignReq(); PhysicBillHandoverSignReq signReq = new PhysicBillHandoverSignReq();
copyTo(req.getSign(), signReq); copyTo(req.getSign(), signReq);
...@@ -258,20 +283,13 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill ...@@ -258,20 +283,13 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
if (!handover.getDeptId().equals(currentDeptId)) { if (!handover.getDeptId().equals(currentDeptId)) {
throw new ServiceException("交接班只能在同一部门内进行"); throw new ServiceException("交接班只能在同一部门内进行");
} }
SysUser sysUser = sysUserMapper.selectById(userId);
if (handover.getStatus().equals(0)) { if (handover.getStatus().equals(0)) {
// 交班人/移交人签名 // 交班人/移交人签名
if (!RoleTypeEum.isPass(sysUser.getRoleAsList(), RoleTypeEum.JBX)) {
throw new ServiceException("需要交班人权限才可进行签名");
}
handover.setStatus(1); handover.setStatus(1);
SignInfoDTO signInfoDTO = new SignInfoDTO(getstamp, LocalDateTime.now(), userId); SignInfoDTO signInfoDTO = new SignInfoDTO(getstamp, LocalDateTime.now(), userId);
handover.setYjUser(JSONUtil.toJsonStr(signInfoDTO)); handover.setYjUser(JSONUtil.toJsonStr(signInfoDTO));
} else if (handover.getStatus().equals(1)) { } else if (handover.getStatus().equals(1)) {
// 接班人/接收人签名 // 接班人/接收人签名
if (!RoleTypeEum.isPass(sysUser.getRoleAsList(), RoleTypeEum.JBY)) {
throw new ServiceException("需要接班人权限才可进行签名");
}
handover.setStatus(100); handover.setStatus(100);
SignInfoDTO signInfoDTO = new SignInfoDTO(getstamp, LocalDateTime.now(), userId); SignInfoDTO signInfoDTO = new SignInfoDTO(getstamp, LocalDateTime.now(), userId);
handover.setJsUser(JSONUtil.toJsonStr(signInfoDTO)); handover.setJsUser(JSONUtil.toJsonStr(signInfoDTO));
...@@ -283,4 +301,117 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill ...@@ -283,4 +301,117 @@ public class PhysicBillServiceImpl extends AbstractService implements PhysicBill
physicBillHandoverMapper.updateById(handover); physicBillHandoverMapper.updateById(handover);
return handover; return handover;
} }
@Override
public void cancelHandover(PhysicBillHandoverCancelReq req) {
Long currentUserId = SpringContextUtils.getUserId();
Long currentDeptId = SpringContextUtils.getDeptId();
PhysicBillHandover handover = physicBillHandoverMapper.selectById(req.getHandoverId());
if (ObjectUtil.isEmpty(handover)) {
throw new ServiceException("未找到交接单:" + req.getHandoverId());
}
if (!handover.getDeptId().equals(currentDeptId)) {
throw new ServiceException("交接班只能在同一部门内进行");
}
if (handover.getStatus().equals(100)) {
if (!handoverCancelProperties.getAllowCancelCompleted()) {
throw new ServiceException("已完成交接班不能取消");
}
}
if (handover.getStatus().equals(-100)) {
throw new ServiceException("交接班已取消,不应重复取消");
}
// 验证是否为最新未取消的交接单
PhysicBillHandover latestHandover = physicBillHandoverMapper.selectOne(Wrappers.lambdaQuery(PhysicBillHandover.class)
.eq(PhysicBillHandover::getDeptId, currentDeptId)
.ne(PhysicBillHandover::getStatus, -100)
.orderByDesc(PhysicBillHandover::getId)
.last("LIMIT 1"));
if (ObjectUtil.isEmpty(latestHandover) || !latestHandover.getId().equals(handover.getId())) {
throw new ServiceException("只允许取消最新一个未取消的交接单");
}
// 验证操作权限
validateCancelPermission(handover, currentUserId);
// 验证时间限制
validateCancelTimeLimit(handover);
handover.setStatus(-100);
physicBillHandoverMapper.updateById(handover);
}
/**
* 验证取消操作的权限
*/
private void validateCancelPermission(PhysicBillHandover handover, Long currentUserId) {
List<String> msg = new ArrayList<>(4);
// 检查是否为创建人
if (handover.getCreateBy() != null && handover.getCreateBy().equals(currentUserId)) {
return;
} else {
msg.add("非创建人");
}
// 检查是否为管理员
boolean isAdmin = SpringContextUtils.isAdmin() || SpringContextUtils.isPlatformAdmin();
if (isAdmin) {
return;
} else {
msg.add("非管理员");
}
// 检查是否允许交班人取消且为交班人
boolean isTransferor = handoverCancelProperties.getAllowTransferor() && handover.getYjUser() != null;
if (isTransferor) {
SignInfoDTO yjUserInfo = JSONUtil.toBean(handover.getYjUser(), SignInfoDTO.class);
if (yjUserInfo.getUserId().equals(currentUserId)) {
return;
} else {
msg.add("非交班人");
}
}
// 检查是否允许接班人取消且为接班人
boolean isReceiver = handoverCancelProperties.getAllowReceiver() && handover.getJsUser() != null;
if (isReceiver) {
SignInfoDTO jsUserInfo = JSONUtil.toBean(handover.getJsUser(), SignInfoDTO.class);
if (jsUserInfo.getUserId().equals(currentUserId)) {
return;
} else {
msg.add("非接班人");
}
}
// 根据不同的权限配置报告不同的错误消息
throw new ServiceException("您没有权限取消此交接单:" + String.join("、", msg));
}
/**
* 验证取消时间限制
* 仅对未完成的交接单进行时间限制校验,已完成的交接单不受时间限制
*/
private void validateCancelTimeLimit(PhysicBillHandover handover) {
// 未完成的交接单不受时间限制
if (handover.getStatus().equals(-100)) {
return;
}
LocalDateTime createdTime = handover.getCreateTime();
if (createdTime == null) {
throw new ServiceException("交接单创建时间异常");
}
// 计算创建日期的开始时间(0时)
LocalDateTime createdDateStart = createdTime.toLocalDate().atStartOfDay();
// 计算允许取消的最后一天的结束时间
LocalDateTime cancelDeadline = createdDateStart.plusDays(handoverCancelProperties.getDayLimit());
// 当前时间
LocalDateTime now = LocalDateTime.now();
if (now.isAfter(cancelDeadline)) {
throw new ServiceException("超过" + handoverCancelProperties.getDayLimit() + "天的交接单不允许取消");
}
}
} }
\ No newline at end of file
...@@ -23,10 +23,7 @@ public enum RoleTypeEum { ...@@ -23,10 +23,7 @@ public enum RoleTypeEum {
YXBZR(101,"药学部主任"), YXBZR(101,"药学部主任"),
YWKKZ(102,"医务科科长"), YWKKZ(102,"医务科科长"),
BWKKZ(103,"保卫科科长"), BWKKZ(103,"保卫科科长"),
ZGYZ(104,"主管院长"), ZGYZ(104,"主管院长");
JBX(201,"交班人"),
JBY(202,"接班人"),;
public long code; public long code;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment