MatchDictServiceImpl.java 7.93 KB
package com.zhongzhi.service.impl;

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.ProjectType;
import com.zhongzhi.common.exception.HttpException;
import com.zhongzhi.common.utils.DateFormatUtil;
import com.zhongzhi.dto.match.MatchDictDTO;
import com.zhongzhi.dto.match.SelectListPageDTO;
import com.zhongzhi.model.MatchDictDO;
import com.zhongzhi.dao.MatchDictDAO;
import com.zhongzhi.model.MatchScheduleDO;
import com.zhongzhi.service.MatchDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongzhi.service.MatchScheduleService;
import com.zhongzhi.vo.match.MatchDictVO;
import org.apache.xmlbeans.impl.regex.Match;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * <p>
 * 赛事年份管理 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-05-17
 */
@Service
public class MatchDictServiceImpl extends ServiceImpl<MatchDictDAO, MatchDictDO> implements MatchDictService {

    @Autowired
    private MatchScheduleService matchScheduleService;

    @Override
    public MatchDictDO getMainTrackMatch() {
        return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
                .lambda()
                .eq(MatchDictDO::getMatchType, ProjectType.MAIN_TRACK)
                .eq(MatchDictDO::getStatus, 1));
    }

    @Override
    public MatchDictDO getSeedTrackMatch() {
        return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
                .lambda()
                .eq(MatchDictDO::getMatchType, ProjectType.SEED_TRACK)
                .eq(MatchDictDO::getStatus, 1));
    }

    @Override
    public void updateMatch(MatchDictDTO matchDictDTO) {
        MatchDictDO match = this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
                .lambda()
                .eq(MatchDictDO::getStatus, 1));
        if (matchDictDTO.getStatus() != null) {
            if (match != null && !match.getId().equals(matchDictDTO.getId())) {
                match.setStatus(0);
                this.baseMapper.updateById(match);
            }
        }

        MatchDictDO matchDictDO = new MatchDictDO();
        BeanUtils.copyProperties(matchDictDTO, matchDictDO);
        this.baseMapper.updateById(matchDictDO);

//        if (matchDictDTO.getSchedule() != null && matchDictDTO.getSchedule().size() > 0) {
//            List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
//                    .lambda()
//                    .eq(MatchScheduleDO::getMatchId, matchDictDTO.getId()));
//            if (list.size() > 0) {
//                for (MatchScheduleDO matchScheduleDO : list) {
//                    if (matchDictDTO.getSchedule().stream().filter(ms -> ms.getScheduleTime().equals(matchScheduleDO.getScheduleTime()) &&
//                            ms.getExplains().equals(matchScheduleDO.getExplains())).findAny().isPresent()) {
//                        continue;
//                    } else {
//                        matchScheduleService.removeById(matchScheduleDO.getId());
//                    }
//                }
//            }
//
//            for (MatchScheduleDO matchScheduleDO : matchDictDTO.getSchedule()) {
//                if (list.stream().filter(ms -> ms.getExplains().equals(matchScheduleDO.getExplains()) &&
//                        ms.getScheduleTime().equals(matchScheduleDO.getScheduleTime())).findAny().isPresent()) {
//                    MatchScheduleDO matchSchedule = matchScheduleService.getOne(new QueryWrapper<MatchScheduleDO>()
//                            .lambda()
//                            .eq(MatchScheduleDO::getMatchId, matchScheduleDO.getMatchId())
//                            .eq(MatchScheduleDO::getExplains, matchScheduleDO.getExplains())
//                            .eq(MatchScheduleDO::getScheduleTime, matchScheduleDO.getScheduleTime()));
//                    if (matchSchedule != null) {
//                        matchScheduleDO.setId(matchSchedule.getId());
//                        matchScheduleService.updateById(matchScheduleDO);
//                    }
//                } else {
//                    matchScheduleDO.setMatchId(matchDictDTO.getId());
//                    matchScheduleService.save(matchScheduleDO);
//                }
//            }
//        }
    }

    @Override
    public IPage<MatchDictVO> getSeedTrackMatchPage(SelectListPageDTO selectListPageDTO) {
        Page page = new Page(selectListPageDTO.getPageNo(), selectListPageDTO.getPageSize());
        IPage<MatchDictVO> iPage = this.baseMapper.getSeedTrackMatchPage(page);
        for (MatchDictVO record : iPage.getRecords()) {
            List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
                    .lambda()
                    .eq(MatchScheduleDO::getMatchId, record.getId()));
            record.setSchedule(list);
        }
        return iPage;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createMatch(MatchDictDTO matchDictDTO) {
//        MatchDictDO matchDictDO = new MatchDictDO();

        int count = this.baseMapper.selectCount(new QueryWrapper<MatchDictDO>()
        .lambda()
        .eq(MatchDictDO::getMatchDate,matchDictDTO.getMatchDate())
        .eq(MatchDictDO::getMonth,matchDictDTO.getMonth()));
        if (count > 0){
            throw new HttpException(10032);
        }

//        BeanUtils.copyProperties(matchDictDTO, matchDictDO);
        this.baseMapper.insert(matchDictDTO);

//        if (matchDictDTO.getSchedule().size() > 0) {
//            for (MatchScheduleDO matchScheduleDO : matchDictDTO.getSchedule()) {
//                MatchScheduleDO matchSchedule = new MatchScheduleDO();
//                BeanUtils.copyProperties(matchScheduleDO, matchSchedule);
//                matchSchedule.setMatchId(matchDictDO.getId());
//                matchScheduleService.save(matchSchedule);
//            }
//        }
    }

    @Override
    public List<MatchDictDO> getMatch() {
        return this.baseMapper.selectList(new QueryWrapper<MatchDictDO>()
                .lambda()
                .eq(MatchDictDO::getStatus, 1));
    }

    @Override
    public MatchDictDO getVocationalMatch() {
        return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
                .lambda()
                .eq(MatchDictDO::getStatus, 1));
    }

    public void updateMatchDate(MatchDictDO matchDictDO) {
        this.baseMapper.updateById(matchDictDO);
    }

    public MatchDictDO getMatch(MatchDictDO matchDictDO) {
        return this.baseMapper.selectById(matchDictDO.getId());
    }

    @Override
    public List<MatchDictDO> getList(String projectType, String projectGroup) {
        return this.baseMapper.getList(projectType, projectGroup);
    }

    @Override
    public IPage getVocationalPage(SelectListPageDTO selectListPageDTO) {
        Page page = new Page(selectListPageDTO.getPageNo(), selectListPageDTO.getPageSize());
        IPage<MatchDictVO> iPage = this.baseMapper.getSeedTrackMatchPage(page);
        for (MatchDictVO record : iPage.getRecords()) {
            List<MatchScheduleDO> list = matchScheduleService.list(new QueryWrapper<MatchScheduleDO>()
                    .lambda()
                    .eq(MatchScheduleDO::getMatchId, record.getId()));
            record.setSchedule(list);
        }
        return iPage;
    }

    @Override
    public MatchDictDO getMatchByYearMonth(MatchDictDO matchDictDO){

        return this.baseMapper.selectOne(new QueryWrapper<MatchDictDO>()
                .lambda()
                .eq(MatchDictDO::getMatchDate,matchDictDO.getMatchDate())
                .eq(MatchDictDO::getMonth,matchDictDO.getMonth()));
    }
}