Blame view

ProjectJudgeServiceImpl.java 7.2 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
package com.zhongzhi.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongzhi.common.constant.SmsCode;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.ExcelUtil;
import com.zhongzhi.common.utils.JwtUtil;
import com.zhongzhi.dto.administer.LoginDTO;
import com.zhongzhi.dto.judge.ProjectJudgePageDTO;
import com.zhongzhi.dto.projectJudge.ImportJudge;
import com.zhongzhi.model.ProjectJudgeDO;
import com.zhongzhi.dao.ProjectJudgeDAO;
import com.zhongzhi.model.ProjectReviewDO;
import com.zhongzhi.model.SmsCodeDO;
import com.zhongzhi.service.ProjectJudgeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.service.ProjectReviewService;
import com.zhongzhi.service.SmsCodeService;
import com.zhongzhi.vo.ExcelFieldVO;
import com.zhongzhi.vo.judge.JudgeInfoVO;
import com.zhongzhi.vo.judge.ProjectJudgePageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目评审员 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-05-28
 */
@Service
public class ProjectJudgeServiceImpl extends ServiceImpl<ProjectJudgeDAO, ProjectJudgeDO> implements ProjectJudgeService {

    @Autowired
    private ProjectReviewService projectReviewService;

    @Autowired
    private SmsCodeService smsCodeService;

    @Override
    public IPage<ProjectJudgePageVO> getProjectJudgePage(ProjectJudgePageDTO projectJudgePageDTO) {
        IPage<ProjectJudgePageVO> iPage = this.baseMapper.getProjectJudgePage(new Page(projectJudgePageDTO.getPageNo(), projectJudgePageDTO.getPageSize()), projectJudgePageDTO.getUsername(), projectJudgePageDTO.getStatus());
        for (ProjectJudgePageVO record : iPage.getRecords()) {
            Integer count = projectReviewService.count(new QueryWrapper<ProjectReviewDO>()
                    .lambda()
                    .eq(ProjectReviewDO::getJudgeId, record.getId()));
            record.setAssignedQuantity(count);
        }
        return iPage;
    }

    @Override
    public void createProjectJudge(ProjectJudgeDO projectJudgeDO) {
        ProjectJudgeDO projectJudge = this.baseMapper.selectOne(new QueryWrapper<ProjectJudgeDO>()
                .lambda()
                .eq(ProjectJudgeDO::getTelephone, projectJudgeDO.getTelephone()));
        if (projectJudge != null) {
            throw new HttpException(10020);
        }

        this.baseMapper.insert(projectJudgeDO);
    }

    @Override
    public void updateProjectJudge(ProjectJudgeDO projectJudgeDO) {
        ProjectJudgeDO projectJudge = this.baseMapper.selectById(projectJudgeDO.getId());
        if (projectJudge != null) {
            if (projectJudge.getTelephone().equals(projectJudgeDO.getTelephone())) {
                this.baseMapper.updateById(projectJudgeDO);
            } else {
                ProjectJudgeDO p = this.baseMapper.selectOne(new QueryWrapper<ProjectJudgeDO>()
                        .lambda()
                        .eq(ProjectJudgeDO::getTelephone, projectJudgeDO.getTelephone()));
                if (p != null) {
                    throw new HttpException(10020);
                } else {
                    this.baseMapper.updateById(projectJudgeDO);
                }
            }
        }
    }

    @Override
    public JudgeInfoVO login(LoginDTO loginDTO) {
        JudgeInfoVO judgeInfoVO = new JudgeInfoVO();

        ProjectJudgeDO projectJudgeDO = this.baseMapper.selectOne(new QueryWrapper<ProjectJudgeDO>()
                .lambda()
                .eq(ProjectJudgeDO::getTelephone, loginDTO.getTelephone()));

        if (null != projectJudgeDO){

            if (null != projectJudgeDO.getPasswordFree() && projectJudgeDO.getPasswordFree() != 1){
                SmsCodeDO smsCodeDO = smsCodeService.getOneByTelePhone(loginDTO.getTelephone(), SmsCode.login, SmsCode.review);
                if (smsCodeDO == null) {
                    throw new HttpException(10025);
                }

                if (!smsCodeDO.getCode().equals(loginDTO.getCode())) {
                    throw new HttpException(10021);
                }

                smsCodeService.removeById(smsCodeDO.getId());

                if (projectJudgeDO == null) {
                    throw new HttpException(10024);
                }

                if (projectJudgeDO.getStatus() == 0) {
                    throw new HttpException(10024);
                }
            }
        }



        String token = JwtUtil.generateToken(projectJudgeDO.getId(), SmsCode.review);
        judgeInfoVO.setTelephone(projectJudgeDO.getTelephone());
        judgeInfoVO.setPosition(projectJudgeDO.getPosition());
        judgeInfoVO.setUnit(projectJudgeDO.getUnit());
        judgeInfoVO.setUsername(projectJudgeDO.getUsername());
        judgeInfoVO.setToken(token);
        return judgeInfoVO;
    }

    @Override
    public IPage<ProjectJudgePageVO> projectJudgesAssigned(ProjectJudgePageDTO projectJudgePageDTO) {
        IPage<ProjectJudgePageVO> iPage = this.baseMapper.projectJudgesAssigned(new Page(projectJudgePageDTO.getPageNo(), projectJudgePageDTO.getPageSize()),
                projectJudgePageDTO.getMatchId(), projectJudgePageDTO.getProjectGroup(), projectJudgePageDTO.getProjectSchedule());
        if (iPage.getRecords() != null && iPage.getRecords().size() > 0) {
            for (ProjectJudgePageVO record : iPage.getRecords()) {
                Integer count = projectReviewService.selectCount(record.getId(), projectJudgePageDTO.getMatchId());
                record.setAssignedQuantity(count);
                Integer notReviewNum = projectReviewService.selectNotReviewCount(record.getId(), projectJudgePageDTO.getMatchId());
                record.setNotReviewedNum(notReviewNum);
            }
        }
        return iPage;
    }

    @Override
    public void importJudge(MultipartFile file) {
        List<ImportJudge> list = ExcelUtil.readExcel(ImportJudge.class, file);
        if (list != null) {
            for (ImportJudge importJudge : list) {
                ProjectJudgeDO projectJudgeDO = new ProjectJudgeDO();
                BeanUtils.copyProperties(importJudge, projectJudgeDO);
                this.baseMapper.insert(projectJudgeDO);
            }
        }
    }

    @Override
    public void downloadTemplate() {
        List<ExcelFieldVO> list = ExcelUtil.getField(ImportJudge.class);
        ExcelUtil.writeExcel(list, new ArrayList<>());
    }

    @Override
    public void exportProjectJudge() {
        List<ExcelFieldVO> field = ExcelUtil.getField(ImportJudge.class);
        List<ProjectJudgeDO> list = this.baseMapper.selectList(new QueryWrapper<>());
        List<Map> data = new ArrayList<>();
        if (list != null && list.size() > 0) {
            for (ProjectJudgeDO projectJudgeDO : list) {
                data.add(JSON.parseObject(JSON.toJSONString(projectJudgeDO), Map.class));
            }
        }
        ExcelUtil.writeExcel(field, data);
    }
}