package com.gkhy.assess.system.service.impl;
|
|
import com.gkhy.assess.common.exception.ApiException;
|
import com.gkhy.assess.system.domain.AssProject;
|
import com.gkhy.assess.system.domain.AssRiskEstimate;
|
import com.gkhy.assess.system.enums.ReportProgressEnum;
|
import com.gkhy.assess.system.mapper.AssRiskEstimateMapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gkhy.assess.system.domain.SysUser;
|
import com.gkhy.assess.system.service.AssProjectService;
|
import com.gkhy.assess.system.service.AssRiskEstimateService;
|
import com.gkhy.assess.system.utils.ShiroUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
/**
|
* <p>
|
* 风险评估表 服务实现类
|
* </p>
|
*
|
* @author kzy
|
* @since 2023-12-12 10:46:54
|
*/
|
@Service
|
public class AssRiskEstimateServiceImpl extends ServiceImpl<AssRiskEstimateMapper, AssRiskEstimate> implements AssRiskEstimateService {
|
@Autowired
|
private AssProjectService projectService;
|
@Override
|
@Transactional(rollbackFor = RuntimeException.class)
|
public Long addRiskEstimate(AssRiskEstimate riskEstimate) {
|
SysUser user= ShiroUtils.getSysUser();
|
if(user.getAgencyId()==null){
|
throw new ApiException("无权操作,只有机构用户有权操作");
|
}
|
AssProject project=riskEstimate.getProject();
|
project.setAgencyId(user.getAgencyId());
|
projectService.addProject(project);
|
Long projectId=project.getId();
|
riskEstimate.setProjectId(projectId);
|
riskEstimate.setCreateBy(ShiroUtils.getSysUser().getUsername());
|
int row=baseMapper.insert(riskEstimate);
|
if(row>0){
|
//更新项目状态
|
projectService.changeReportProgress(projectId,ReportProgressEnum.RISK_ESTIMATE);
|
}
|
return projectId;
|
}
|
|
public void checkRiskEstimateCount(Long projectId){
|
//校验项目下风险评估数量
|
int contractCount= baseMapper.getCountByProjectId(projectId);
|
if(contractCount>0){
|
throw new ApiException("项目下已存在风险评估信息");
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = RuntimeException.class)
|
public int editRiskEstimate(AssRiskEstimate riskEstimate) {
|
AssProject project=riskEstimate.getProject();
|
projectService.editProject(project);
|
Long riskId=riskEstimate.getId();
|
if(riskId==null){
|
throw new ApiException("项目风险分析id不能为空");
|
}
|
riskEstimate.setUpdateBy(ShiroUtils.getSysUser().getUsername());
|
int row =baseMapper.updateById(riskEstimate);
|
return row;
|
}
|
|
@Override
|
public AssRiskEstimate getRiskEstimateByProjectId(Long projectId) {
|
projectService.checkUserAllowed(projectId);
|
AssRiskEstimate riskEstimate= baseMapper.getRiskEstimateByProjectId(projectId);
|
if(riskEstimate==null){
|
throw new ApiException("项目风险分析不存在");
|
}
|
riskEstimate.setProject(projectService.getProjectById(riskEstimate.getProjectId()));
|
return riskEstimate;
|
}
|
|
|
@Override
|
public AssRiskEstimate getRiskEstimateById(Long riskId) {
|
return baseMapper.getRiskEstimateById(riskId);
|
}
|
|
}
|