| | |
| | | import com.ruoyi.basic.service.CustomerFollowUpFileService; |
| | | import com.ruoyi.common.enums.PlanStageEnum; |
| | | import com.ruoyi.common.enums.ReviewStatusEnum; |
| | | import com.ruoyi.common.enums.IsDeleteEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.projectManagement.dto.InfoStageDto; |
| | | import com.ruoyi.projectManagement.dto.PlanStageDto; |
| | |
| | | import com.ruoyi.projectManagement.service.PlanService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import jakarta.validation.constraints.NotNull; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | private final CustomerFollowUpFileService customerFollowUpFileService; |
| | | |
| | | private final NamedParameterJdbcTemplate jdbc; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long save(@NotNull SaveInfoDto saveInfoDto) { |
| | | Info info = BeanUtil.copyProperties(saveInfoDto, Info.class); |
| | | |
| | | if (info.getPlanStartTime() != null && info.getPlanEndTime() != null |
| | | && info.getPlanEndTime().isBefore(info.getPlanStartTime())) { |
| | | throw new ServiceException("预计结束时间不能早于预计开始时间"); |
| | | } |
| | | bindProjectCategory(info); |
| | | |
| | | // 附件特殊处理 |
| | | String attachmentIds = StrUtil.join(",", Optional.ofNullable(saveInfoDto.getAttachmentIds()).orElse(Collections.emptyList())); |
| | |
| | | infoMapper.insert(info); |
| | | } else { |
| | | Info existing = infoMapper.selectById(info.getId()); |
| | | if (existing == null) throw new ServiceException("项目不存在"); |
| | | if (existing == null || Integer.valueOf(IsDeleteEnum.DELETED.getCode()).equals(existing.getIsDelete())) { |
| | | throw new ServiceException("项目不存在或已删除"); |
| | | } |
| | | if (!StrUtil.isBlank(existing.getCurrentPhase()) && !"未开始".equals(existing.getCurrentPhase())) { |
| | | throw new ServiceException("项目开始后,项目基本信息、负责人和项目经理均不可修改"); |
| | | } |
| | | infoMapper.updateById(info); |
| | | } |
| | | return info.getId(); |
| | | } |
| | | |
| | | private void bindProjectCategory(Info info) { |
| | | if (info.getProjectCategoryId() != null) { |
| | | List<String> names = jdbc.queryForList(""" |
| | | select category_name from project_management_category |
| | | where id=:id and is_deleted=0 |
| | | """, Map.of("id", info.getProjectCategoryId()), String.class); |
| | | if (names.isEmpty()) throw new ServiceException("项目分类不存在或已删除"); |
| | | info.setProjectClassification(names.getFirst()); |
| | | return; |
| | | } |
| | | if (!StrUtil.isBlank(info.getProjectClassification())) { |
| | | List<Long> ids = jdbc.queryForList(""" |
| | | select id from project_management_category |
| | | where category_name=:name and is_deleted=0 order by id |
| | | """, Map.of("name", info.getProjectClassification().trim()), Long.class); |
| | | if (ids.size() == 1) info.setProjectCategoryId(ids.getFirst()); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | |
| | | public SaveInfoDto getInfoById(@NotNull Long id) { |
| | | Info info = infoMapper.selectById(id); |
| | | if (info == null || Integer.valueOf(IsDeleteEnum.DELETED.getCode()).equals(info.getIsDelete())) { |
| | | throw new ServiceException("项目不存在或已删除"); |
| | | } |
| | | return convert(info); |
| | | } |
| | | |
| | |
| | | public List<SaveInfoDto> getSubordinateInfo(@NotNull Long id) { |
| | | LambdaQueryWrapper<Info> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Info::getProjectManagementInfoParentId, id); |
| | | queryWrapper.eq(Info::getIsDelete, IsDeleteEnum.NOT_DELETED.getCode()); |
| | | queryWrapper.orderByAsc(Info::getCreateTime); |
| | | List<Info> infoList = infoMapper.selectList(queryWrapper); |
| | | return infoList.stream().map(this::convert).collect(Collectors.toList()); |