package com.ruoyi.projectManagement.service.impl.handle;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.google.common.collect.Lists;
|
import com.ruoyi.basic.service.CustomerFollowUpFileService;
|
import com.ruoyi.common.enums.PlanStageEnum;
|
import com.ruoyi.common.enums.ReviewStatusEnum;
|
import com.ruoyi.common.utils.EnumUtil;
|
import com.ruoyi.projectManagement.dto.PlanStageDto;
|
import com.ruoyi.projectManagement.dto.SaveInfoDto;
|
import com.ruoyi.projectManagement.mapper.InfoMapper;
|
import com.ruoyi.projectManagement.pojo.Info;
|
import com.ruoyi.projectManagement.pojo.PlanNode;
|
import com.ruoyi.projectManagement.service.PlanService;
|
import com.ruoyi.projectManagement.service.impl.PlanServiceImpl;
|
import com.ruoyi.projectManagement.vo.PlanVo;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.validation.constraints.NotNull;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
|
/**
|
* @author buhuazhen
|
* @date 2026/3/9
|
* @email 3038525872@qq.com
|
*/
|
@Component
|
@RequiredArgsConstructor
|
@Transactional(rollbackFor = Exception.class,readOnly = true)
|
public class InfoHandleService {
|
|
private static final String GENERATE_SERIAL_NUMBER_PREFIX = "XM";
|
|
private final InfoMapper infoMapper;
|
|
private final PlanService planService;
|
|
private final CustomerFollowUpFileService customerFollowUpFileService;
|
|
@Transactional(rollbackFor = Exception.class)
|
public Long save(@NotNull SaveInfoDto saveInfoDto){
|
Info info = BeanUtil.copyProperties(saveInfoDto, Info.class);
|
|
// 附件特殊处理
|
String attachmentIds = StrUtil.join(",", Optional.ofNullable(saveInfoDto.getAttachmentIds()).orElse(Collections.emptyList()));
|
info.setAttachment(attachmentIds);
|
|
// 生成序号 (如果需要自动生成的话)
|
if(StrUtil.isBlank(info.getNo())){
|
info.setNo(generateSerialNumber());
|
}
|
info.setTeam(saveInfoDto.getTeamList());
|
if(info.getId() == null){
|
// 生成对应的阶段关系数据
|
info.setPlanStage(getPlanStageList(info.getProjectManagementPlanId()));
|
// 插入默认状态
|
info.setStatus(PlanStageEnum.TO_BEGIN.getCode());
|
info.setReviewStatus(ReviewStatusEnum.PENDING_REVIEW.getCode());
|
infoMapper.insert(info);
|
}else {
|
infoMapper.updateById(info);
|
}
|
return info.getId();
|
}
|
|
public SaveInfoDto getInfoById(@NotNull Long id){
|
Info info = infoMapper.selectById(id);
|
SaveInfoDto saveInfoDto = BeanUtil.copyProperties(info, SaveInfoDto.class);
|
// 附件处理
|
saveInfoDto.setTeamList(info.getTeam());
|
customerFollowUpFileService.fillAttachment(Lists.newArrayList(saveInfoDto), SaveInfoDto::getAttachment, SaveInfoDto::setAttachmentList);
|
return saveInfoDto;
|
}
|
|
|
private List<PlanStageDto> getPlanStageList(@NotNull Long planId) {
|
List<PlanNode> planNodeByPlanId = planService.getPlanNodeByPlanId(planId);
|
return planNodeByPlanId.stream().map(it-> new PlanStageDto(it.getId(), it.getName(), PlanStageEnum.TO_BEGIN)).collect(Collectors.toList());
|
}
|
|
|
/**
|
* 生成项目编号
|
* @return
|
*/
|
private String generateSerialNumber() {
|
// 获取当前日期
|
String date = DateUtil.format(DateUtil.date(), "yyyyMMdd");
|
|
// 查询今天已经生成的数量
|
LambdaQueryWrapper<Info> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.likeRight(Info::getNo, GENERATE_SERIAL_NUMBER_PREFIX + date);
|
|
Long count = infoMapper.selectCount(queryWrapper);
|
|
// 序号 +1
|
Long serial = count + 1;
|
|
// 3位补0
|
String serialStr = String.format("%03d", serial);
|
|
return GENERATE_SERIAL_NUMBER_PREFIX + date + serialStr;
|
}
|
|
}
|