Blame view

ProjectReviewServiceImpl.java 14.7 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
package com.zhongzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongzhi.common.constant.ProjectReview;
import com.zhongzhi.common.constant.ProjectType;
import com.zhongzhi.common.constant.SMSTemplate;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.AliyunSmsUtil;
import com.zhongzhi.common.utils.DateFormatUtil;
import com.zhongzhi.dao.ProjectDAO;
import com.zhongzhi.dto.review.CancelReviewDTO;
import com.zhongzhi.dto.review.ProjectReviewDTO;
import com.zhongzhi.dto.review.SetReviewDTO;
import com.zhongzhi.model.*;
import com.zhongzhi.dao.ProjectReviewDAO;
import com.zhongzhi.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.vo.judge.ProjectReviewVO;
import com.zhongzhi.vo.review.SendNoticeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 项目评审 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-05-18
 */
@Service
public class ProjectReviewServiceImpl extends ServiceImpl<ProjectReviewDAO, ProjectReviewDO> implements ProjectReviewService {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private ProjectJudgeService projectJudgeService;

    @Autowired
    private MatchDictService matchDictService;

    @Autowired
    private ProjectReviewPeriodService projectReviewPeriodService;

    @Autowired
    private AliyunSmsUtil aliyunSmsUtil;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void setReview(SetReviewDTO setReviewDTO) {
        if (setReviewDTO.getProjectId().size() == 0) {
            throw new HttpException(10047);
        }

        if (setReviewDTO.getJudgeId().size() == 0) {
            throw new HttpException(10048);
        }

//        Date startTime = null;
//        Date endTime = null;

        for (Long judgeId : setReviewDTO.getJudgeId()) {
            ProjectJudgeDO projectJudgeDO = projectJudgeService.getById(judgeId);
            if (projectJudgeDO != null) {
                for (Long projectId : setReviewDTO.getProjectId()) {
                    ProjectDO projectDO = projectService.getById(projectId);
                    MatchDictDO matchDictDO = matchDictService.getById(projectDO.getMatchId());
                    if ("种子赛道".equals(matchDictDO.getMatchType())) {
                        if (projectDO != null) {
                            ProjectReviewPeriodDO projectReviewPeriodDO = projectReviewPeriodService.getOne(new QueryWrapper<ProjectReviewPeriodDO>()
                                    .lambda()
                                    .eq(ProjectReviewPeriodDO::getMatchId, projectDO.getMatchId())
                                    .eq(ProjectReviewPeriodDO::getProjectGroup, projectDO.getProjectProgress())
                                    .eq(ProjectReviewPeriodDO::getProjectSchedule, projectDO.getProjectSchedule()));
//                        startTime = projectReviewPeriodDO.getStartTime();
//                        endTime = projectReviewPeriodDO.getEndTime();
                            if (projectReviewPeriodDO == null) {
                                throw new HttpException(10076);
                            }

                            if (projectDO.getProjectAssigned().equals(ProjectReview.UNASSIGNED)) {
                                ProjectDO project = new ProjectDO();
                                project.setId(projectId);
                                project.setProjectAssigned(ProjectReview.ASSIGNED);
                                if (projectDO.getProjectReview().equals(ProjectReview.SUBMITTED)) {
                                    project.setProjectReview(ProjectReview.TO_REVIEWED);
                                }
                                projectService.updateById(project);
                            }

                            ProjectReviewDO projectReview = this.baseMapper.selectOne(new QueryWrapper<ProjectReviewDO>()
                                    .lambda()
                                    .eq(ProjectReviewDO::getProjectId, projectId)
                                    .eq(ProjectReviewDO::getJudgeId, judgeId)
                                    .eq(ProjectReviewDO::getProjectSchedule, projectDO.getProjectSchedule()));
                            if (projectReview != null) {
                                throw new HttpException(10053);
                            }

                            ProjectReviewDO projectReviewDO = new ProjectReviewDO();
                            projectReviewDO.setProjectId(projectId);
                            projectReviewDO.setJudgeId(judgeId);
                            projectReviewDO.setProjectSchedule(projectDO.getProjectSchedule());
                            projectReviewDO.setReviewStatus(ProjectReview.ASSIGNED);
                            this.baseMapper.insert(projectReviewDO);
                        }
                    }
                    else {
                        if (projectDO != null) {
                            ProjectReviewPeriodDO projectReviewPeriodDO = projectReviewPeriodService.getOne(new QueryWrapper<ProjectReviewPeriodDO>()
                                    .lambda()
                                    .eq(ProjectReviewPeriodDO::getMatchId, projectDO.getMatchId())
                                    .eq(ProjectReviewPeriodDO::getProjectGroup, projectDO.getProjectGroup())
                                    .eq(ProjectReviewPeriodDO::getProjectSchedule, projectDO.getProjectSchedule()));
//                        startTime = projectReviewPeriodDO.getStartTime();
//                        endTime = projectReviewPeriodDO.getEndTime();
                            if (projectReviewPeriodDO == null) {
                                throw new HttpException(10076);
                            }

                            if (projectDO.getProjectAssigned().equals(ProjectReview.UNASSIGNED)) {
                                ProjectDO project = new ProjectDO();
                                project.setId(projectId);
                                project.setProjectAssigned(ProjectReview.ASSIGNED);
                                if (projectDO.getProjectReview().equals(ProjectReview.SUBMITTED)) {
                                    project.setProjectReview(ProjectReview.TO_REVIEWED);
                                }
                                projectService.updateById(project);
                            }

                            ProjectReviewDO projectReview = this.baseMapper.selectOne(new QueryWrapper<ProjectReviewDO>()
                                    .lambda()
                                    .eq(ProjectReviewDO::getProjectId, projectId)
                                    .eq(ProjectReviewDO::getJudgeId, judgeId)
                                    .eq(ProjectReviewDO::getProjectSchedule, projectDO.getProjectSchedule()));
                            if (projectReview != null) {
                                throw new HttpException(10053);
                            }

                            ProjectReviewDO projectReviewDO = new ProjectReviewDO();
                            projectReviewDO.setProjectId(projectId);
                            projectReviewDO.setJudgeId(judgeId);
                            projectReviewDO.setProjectSchedule(projectDO.getProjectSchedule());
                            projectReviewDO.setReviewStatus(ProjectReview.ASSIGNED);
                            this.baseMapper.insert(projectReviewDO);
                        }
                    }
                }


                if (setReviewDTO.getSmsMessage() == 1) {
                    MatchDictDO matchDictDO = matchDictService.getById(setReviewDTO.getMatchId());
                    int count = this.baseMapper.selectCount(new QueryWrapper<ProjectReviewDO>()
                            .lambda()
                            .eq(ProjectReviewDO::getReviewStatus, ProjectReview.ASSIGNED)
                            .eq(ProjectReviewDO::getJudgeId, judgeId));
                    String msg = "";
                    if (matchDictDO != null) {
//                        msg = matchDictDO.getMatchName() +","+count+","+ DateFormatUtil.format(startTime,DateFormatUtil.FMT_sdf14_L)+"~"+DateFormatUtil.format(endTime,DateFormatUtil.FMT_sdf14_L);
                        msg = matchDictDO.getMatchName() + "," + count;
                    }

                    aliyunSmsUtil.sendTemplateMsg(msg, projectJudgeDO.getTelephone(), SMSTemplate.REVIEW_INVITATION_OLD);
                }
            }
        }
    }

    @Override
    public void sendNotice(SendNoticeVO sendNoticeVO) {
        MatchDictDO matchDictDO = matchDictService.getById(sendNoticeVO.getMatchId());
        if (matchDictDO != null) {
            for (Long id : sendNoticeVO.getId()) {
                ProjectJudgeDO projectJudgeDO = projectJudgeService.getById(id);
                if (projectJudgeDO != null) {
                    int count = this.baseMapper.selectCount(new QueryWrapper<ProjectReviewDO>()
                            .lambda()
                            .eq(ProjectReviewDO::getReviewStatus, ProjectReview.ASSIGNED)
                            .eq(ProjectReviewDO::getJudgeId, id));
                    List<ProjectReviewPeriodDO> list = projectReviewPeriodService.list(new QueryWrapper<ProjectReviewPeriodDO>()
                            .lambda()
                            .eq(ProjectReviewPeriodDO::getMatchId, matchDictDO.getId()));

                    StringBuffer stringBuffer = new StringBuffer();
                    for (int i = 0; i < list.size(); i++) {
                        stringBuffer.append(list.get(i).getProjectGroup() + ":" + DateFormatUtil.format(list.get(i).getStartTime(), DateFormatUtil.FMT_sdf14_L) + "~" + DateFormatUtil.format(list.get(i).getEndTime(), DateFormatUtil.FMT_sdf14_L));
                        if (i != list.size()) {
                            stringBuffer.append(";");
                        }
                    }

                    String msg = matchDictDO.getMatchName() + "," + count + "," + stringBuffer.toString();
                    aliyunSmsUtil.sendTemplateMsgP(msg, projectJudgeDO.getTelephone(), SMSTemplate.REVIEW_INVITATION_NEW);
                }
            }
        }
    }

    @Override
    public Integer selectCount(Long judgeId, Long matchId) {
        return this.baseMapper.selectCountByMatchId(judgeId, matchId);
    }

    @Override
    public Integer selectNotReviewCount(Long judgeId, Long matchId) {
        return this.baseMapper.selectNotReviewCount(judgeId, matchId);
    }

    @Override
    public List<ProjectReviewVO> getList(String projectSchedule, Long projectId) {
        return this.baseMapper.getList(projectSchedule, projectId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void cancelReview(CancelReviewDTO cancelReviewDTO) {
        if (cancelReviewDTO.getProjectId() == null) {
            throw new HttpException(10047);
        }

        if (cancelReviewDTO.getJudgeId().size() == 0) {
            throw new HttpException(10048);
        }

        for (Long judgeId : cancelReviewDTO.getJudgeId()) {
            ProjectJudgeDO projectJudgeDO = projectJudgeService.getById(judgeId);
            if (projectJudgeDO == null) {
                throw new HttpException(10070);
            }

            ProjectDO projectDO = projectService.getById(cancelReviewDTO.getProjectId());
            if (projectDO != null) {
                ProjectReviewPeriodDO projectReviewPeriodDO = projectReviewPeriodService.getOne(new QueryWrapper<ProjectReviewPeriodDO>()
                        .lambda()
                        .eq(ProjectReviewPeriodDO::getMatchId, projectDO.getMatchId())
                        .eq(ProjectReviewPeriodDO::getProjectGroup, projectDO.getProjectGroup())
                        .eq(ProjectReviewPeriodDO::getProjectSchedule, projectDO.getProjectSchedule()));
                if (projectReviewPeriodDO.getStartTime().before(new Date())) {
                    throw new HttpException(10075);
                }

                if (projectDO != null) {
                    Integer count = this.baseMapper.selectCount(new QueryWrapper<ProjectReviewDO>()
                            .lambda()
                            .eq(ProjectReviewDO::getProjectId, projectDO.getId())
                            .eq(ProjectReviewDO::getProjectSchedule, projectDO.getProjectSchedule()));
                    /*
                        只有最后一个评委是撤销修改项目分配状态
                     */
                    if (count == 1) {
                        ProjectDO project = new ProjectDO();
                        project.setId(projectDO.getId());
                        project.setProjectAssigned(ProjectReview.UNASSIGNED);
                        projectService.updateById(project);
                    }

                    ProjectReviewDO projectReview = this.baseMapper.selectOne(new QueryWrapper<ProjectReviewDO>()
                            .lambda()
                            .eq(ProjectReviewDO::getProjectId, projectDO.getId())
                            .eq(ProjectReviewDO::getJudgeId, judgeId)
                            .eq(ProjectReviewDO::getProjectSchedule, projectDO.getProjectSchedule()));
                    if (projectReview == null) {
                        throw new HttpException(10071);
                    }

                    if (projectReview.getReviewStatus().equals(ProjectReview.SUBMITTED)) {
                        throw new HttpException(10059);
                    }

                    this.baseMapper.deleteById(projectReview.getId());
                }

                aliyunSmsUtil.sendTemplateMsg(projectDO.getProjectName(), projectJudgeDO.getTelephone(), SMSTemplate.CANCEL_REVIEW);
            }
        }
    }

    @Override
    public List<ProjectJudgeDO> getProjectReview(ProjectReviewDTO projectReviewDTO) {
        List<ProjectJudgeDO> data = new ArrayList<>();

        ProjectDO projectDO = projectService.getById(projectReviewDTO.getProjectId());
        if (projectDO != null) {
            List<ProjectReviewDO> list = this.baseMapper.selectList(new QueryWrapper<ProjectReviewDO>()
                    .lambda()
                    .eq(ProjectReviewDO::getProjectSchedule, projectDO.getProjectSchedule())
                    .eq(ProjectReviewDO::getProjectId, projectReviewDTO.getProjectId()));
            for (ProjectReviewDO projectReviewDO : list) {
                ProjectJudgeDO projectJudgeDO = projectJudgeService.getById(projectReviewDO.getJudgeId());
                if (projectJudgeDO != null) {
                    data.add(projectJudgeDO);
                }

            }
        }
        return data;
    }
}