创建工单,同步创建工作票优化

This commit is contained in:
tangcy 2026-04-17 17:05:00 +08:00
parent 02c43b3ebe
commit 05fbe663b4
4 changed files with 69 additions and 2 deletions

View File

@ -57,6 +57,10 @@ public interface WorkTicketMapper {
*/
WorkTicket selectWorkTicketByProjectId(Long projectId);
List<Long> selectRelatedTicketIdsByProjectId(@Param("projectId") Long projectId,
@Param("ticketType") String ticketType,
@Param("excludeTicketId") Long excludeTicketId);
/**
* 根据项目ID列表查询工作票ID列表级联删除工作计划时使用
*/

View File

@ -575,8 +575,8 @@ public class WorkPlanServiceImpl implements IWorkPlanService {
}
String approver = SecurityUtils.getUsername();
String approvalTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
// 审批通过更新审批状态为1已通过项目状态改为已提交实施状态设置为1实施中
return workPlanMapper.updateProjectStatusAndApproval(projectId, "1", "1", "1", approver, approvalTime, approvalComment);
// 审批通过更新审批状态为1已通过项目状态改为已提交实施状态设置为0待实施
return workPlanMapper.updateProjectStatusAndApproval(projectId, "1", "0", "1", approver, approvalTime, approvalComment);
}
@Override

View File

@ -772,6 +772,7 @@ public class WorkTicketServiceImpl implements IWorkTicketService {
processJsonFields(workTicket);
workTicket.setCreateBy(SecurityUtils.getUsername());
cleanupRelatedTicketsBeforeSave(workTicket, workTicket.getProjectId());
return workTicketMapper.insertWorkTicket(workTicket);
}
@ -787,9 +788,60 @@ public class WorkTicketServiceImpl implements IWorkTicketService {
// 处理JSON字段
processJsonFields(workTicket);
workTicket.setUpdateBy(SecurityUtils.getUsername());
cleanupRelatedTicketsBeforeSave(workTicket, workTicket.getProjectId());
return workTicketMapper.updateWorkTicket(workTicket);
}
/**
* 保存前先清理同项目下旧工作票及其关联风险控制卡数据
*/
private void cleanupRelatedTicketsBeforeSave(WorkTicket workTicket, Long projectId) {
if (workTicket == null || projectId == null) {
return;
}
Long excludeTicketId = workTicket.getTicketId();
String ticketType = workTicket.getTicketType();
String dangerousOperationType = workTicket.getDangerousOperationType();
if (StringUtils.isEmpty(ticketType) && excludeTicketId != null) {
WorkTicket current = workTicketMapper.selectWorkTicketById(excludeTicketId);
if (current != null) {
ticketType = current.getTicketType();
if (StringUtils.isEmpty(dangerousOperationType)) {
dangerousOperationType = current.getDangerousOperationType();
}
}
}
if (StringUtils.isEmpty(ticketType)) {
return;
}
List<Long> relatedTicketIds = workTicketMapper.selectRelatedTicketIdsByProjectId(
projectId, ticketType, excludeTicketId);
deleteTicketsWithRiskCards(relatedTicketIds);
// 业务要求当危险作业类型为不涉及需额外删除同项目下关联的危险作业票
if ("不涉及".equals(StringUtils.trim(dangerousOperationType))) {
List<Long> hazardousTicketIds = workTicketMapper.selectRelatedTicketIdsByProjectId(
projectId, "危险作业票", excludeTicketId);
deleteTicketsWithRiskCards(hazardousTicketIds);
}
}
private void deleteTicketsWithRiskCards(List<Long> ticketIds) {
if (ticketIds == null || ticketIds.isEmpty()) {
return;
}
if (riskControlCardService != null) {
for (Long ticketId : ticketIds) {
RiskControlCard card = riskControlCardService.selectRiskControlCardByTicketId(ticketId);
if (card != null && card.getCardId() != null) {
riskControlCardService.deleteRiskControlCardById(card.getCardId());
}
}
}
workTicketMapper.deleteWorkTicketByIds(ticketIds.toArray(new Long[0]));
}
/**
* 批量删除工作票申请
*

View File

@ -113,6 +113,17 @@
limit 1
</select>
<select id="selectRelatedTicketIdsByProjectId" resultType="long">
select ticket_id
from work_ticket
where project_id = #{projectId}
and del_flag = '0'
and ticket_type = #{ticketType}
<if test="excludeTicketId != null">
and ticket_id != #{excludeTicketId}
</if>
</select>
<select id="selectTicketIdsByProjectIds" resultType="long">
select ticket_id
from work_ticket