package com.gkhy.assess.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.gkhy.assess.common.enums.DeleteFlagEnum; import com.gkhy.assess.common.exception.ApiException; import com.gkhy.assess.system.domain.AssEstimateSchedule; import com.gkhy.assess.system.mapper.AssEstimateScheduleMapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.assess.system.service.AssEstimateScheduleService; import com.gkhy.assess.system.service.AssProjectService; import com.gkhy.assess.system.utils.ShiroUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; /** *

* 评价日程安排表 服务实现类 *

* * @author kzy * @since 2023-12-12 10:46:54 */ @Service public class AssEstimateScheduleServiceImpl extends ServiceImpl implements AssEstimateScheduleService { @Autowired private AssProjectService projectService; @Override public List getByProjectId(Long projectId) { projectService.checkUserAllowed(projectId); return baseMapper.getEstimateScheduleByProjectId(projectId); } @Override public int addSchedule(AssEstimateSchedule estimateSchedule) { projectService.checkUserAllowed(estimateSchedule.getProjectId()); if(!checkNameUnique(estimateSchedule)){ throw new ApiException("项目下已存在该日程安排"); } estimateSchedule.setCreateBy(ShiroUtils.getSysUser().getUsername()); return baseMapper.insert(estimateSchedule); } public boolean checkNameUnique(AssEstimateSchedule estimateSchedule) { LambdaQueryWrapper lambdaQueryWrapper = Wrappers.lambdaQuery() .eq(AssEstimateSchedule::getName, estimateSchedule.getName()) .eq(AssEstimateSchedule::getDelFlag, DeleteFlagEnum.UN_DELETE) .eq(AssEstimateSchedule::getProjectId, estimateSchedule.getProjectId()); if(estimateSchedule.getId()!=null){ lambdaQueryWrapper.ne(AssEstimateSchedule::getId,estimateSchedule.getId()); } long contractCount= count(lambdaQueryWrapper); if(contractCount>0){ return false; } return true; } @Override public int editSchedule(AssEstimateSchedule estimateSchedule) { projectService.checkUserAllowed(estimateSchedule.getProjectId()); if(!checkNameUnique(estimateSchedule)){ throw new ApiException("项目下已存在该日程安排"); } estimateSchedule.setUpdateBy(ShiroUtils.getSysUser().getUsername()); return baseMapper.updateById(estimateSchedule); } }