package cn.com.countrygarden.bi.main.service.wcx.impl;

import cn.com.countrygarden.bi.main.constant.wcx.WcxConstant;
import cn.com.countrygarden.bi.main.constant.wcx.enumeration.WcxBaselineEnum;
import cn.com.countrygarden.bi.main.dao.wcx.*;
import cn.com.countrygarden.bi.main.dto.wcx.WcxInnovationDto;
import cn.com.countrygarden.bi.main.dto.wcx.WcxPrizeDto;
import cn.com.countrygarden.bi.main.dto.wcx.WcxRegionProjectDto;
import cn.com.countrygarden.bi.main.dto.wcx.WcxUserDto;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.wcx.WcxPrize;
import cn.com.countrygarden.bi.main.model.wcx.WcxPrizeItem;
import cn.com.countrygarden.bi.main.service.wcx.WcxPrizeService;
import cn.com.countrygarden.bi.main.util.PageUtil;
import cn.com.countrygarden.bi.main.util.wcx.CommonUtil;
import cn.com.countrygarden.bi.main.util.wcx.DateUtil;
import com.github.pagehelper.PageRowBounds;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2018/6/19.
 */
@Transactional
@Service
public class WcxPrizeServiceImpl implements WcxPrizeService {
    @Autowired
    private WcxPrizeMapper wcxPrizeMapper;
    @Autowired
    private WcxInnovationMapper wcxInnovationMapper;
    @Autowired
    private WcxUserMapper wcxUserMapper;
    @Autowired
    private WcxThumbMapper wcxThumbMapper;
    @Autowired
    private WcxRegionProjectMapper wcxRegionProjectMapper;

    @Override
    public PageData selectPageList(WcxPrizeDto dto) {
        int pageOffset = PageUtil.getPageOffset(dto.getPageIndex(), dto.getPageSize());
        dto.setPageOffset(pageOffset);

        List<WcxPrizeDto> data = wcxPrizeMapper.selectPageData(dto);
        // 设置待审核数量
        for (WcxPrizeDto datum : data) {
            datum.setItemNumber(wcxPrizeMapper.findItemNumberOfStatus(datum.getPrizeId(), null));
            datum.setItemStayNumber(wcxPrizeMapper.findItemNumberOfStatus(datum.getPrizeId(), WcxConstant.STATUS_STAY));
        }
        // 总数
        Long total = wcxPrizeMapper.selectPageCount(dto);

        PageRowBounds pageRowBounds = new PageRowBounds(dto.getPageIndex(), dto.getPageSize());
        pageRowBounds.setTotal(total);
        pageRowBounds.setCount(true);

        PageData pageData = new PageData(data, pageRowBounds);
        return pageData;
    }

    @Override
    public PageData selectPageListItem(WcxPrizeDto dto) {
        int pageOffset = PageUtil.getPageOffset(dto.getPageIndex(), dto.getPageSize());
        dto.setPageOffset(pageOffset);

        List<WcxPrizeDto> data = wcxPrizeMapper.selectPageDataItem(dto);
        Integer total = wcxPrizeMapper.selectPageCountItem(dto);

        PageRowBounds pageRowBounds = new PageRowBounds(dto.getPageIndex(), dto.getPageSize());
        pageRowBounds.setTotal(total.longValue());
        pageRowBounds.setCount(true);

        PageData pageData = new PageData(data, pageRowBounds);
        return pageData;
    }

    @Override
    public List<WcxPrizeDto> selectPageDataItem(WcxPrizeDto condtionWcxPrize) {
        List<WcxPrizeDto> data = wcxPrizeMapper.selectPageDataItem(condtionWcxPrize);
        return data;
    }

    @Override
    public List<WcxPrizeDto> selectPageDataItem(String prizeId) {
        WcxPrizeDto param = new WcxPrizeDto();
        param.setPageIndex(0);
        param.setPageSize(-1);
        param.setPrizeId(prizeId);
        List<WcxPrizeDto> data = wcxPrizeMapper.selectPageDataItem(param);
        return data;
    }

    @Override
    public PageData selectWillAwardPrizePageList(WcxPrizeDto condition) {
        return null;
    }

    @Override
    public PageData selectBestGetPoint20PageList(WcxPrizeDto condition) {
        Date startDate = condition.getStartDate();
        Date endDate = condition.getEndDate();
        int pageIndex = condition.getPageIndex();
        int pageSize = condition.getPageSize();

        // todo 查出分页后的PrizeDto?相关数据 假分页
        List<WcxPrizeDto> wcxPrizeDtos = selectBestGetPoint20(startDate, endDate);
        int total = wcxPrizeDtos.size();

        PageRowBounds pageRowBounds = new PageRowBounds(pageIndex, pageSize);
        pageRowBounds.setTotal((long) total);
        pageRowBounds.setCount(true);
        PageData pageData = null;
        if (!(1 <= pageIndex && pageIndex <= total)) {
            pageData = new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
        } else {
            int formIndex = PageUtil.getPageOffset(pageIndex, pageSize);
            int toIndex = formIndex + pageSize > total ? total : formIndex + pageSize;
            List<WcxPrizeDto> subWcxPrizeDtos = wcxPrizeDtos.subList(formIndex, toIndex);
            pageData = new PageData(subWcxPrizeDtos, pageRowBounds);
        }
        return pageData;
    }

    /**
     * 点赞前20
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestGetPoint20(Date startDate, Date endDate) {
        int i = wcxInnovationMapper.selectInnCountBetweenDate(startDate, endDate);
        if (i == 0) {
            return Collections.EMPTY_LIST;
        }
        // todo 判断当前时间段是否已有重复存在的数据

        double percent20 = 0.2;
        long numL = Math.round(i * percent20);
        int num = (int) numL;
        List<WcxInnovationDto> wcxInnDtos = wcxInnovationMapper.selectInnOrderByThumbNum(startDate, endDate, (int) num);
        if (wcxInnDtos == null) { // todo 前期不稳定
            throw new ServiceException("未知异常");
        }
        // 移除重复项
        List<String> innIds = wcxInnovationMapper.selectInnIdInPrizeItem();
        if (innIds != null && !innIds.isEmpty()) {
            Iterator<WcxInnovationDto> iter = wcxInnDtos.iterator();
            while (iter.hasNext()) {
                WcxInnovationDto item = iter.next();
                if (innIds.contains(item.getInnovationId())) {
                    iter.remove();
                }
            }
        }

        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);
        Date nowDate = new Date();

        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxInnovationDto wcxInnDto : wcxInnDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeId(CommonUtil.getUUID());
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
            wcxPrizeDto.setAllAwardNumber(numL);
            wcxPrizeDto.setAllJoinNumber(allJoinNumber);
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            wcxPrizeDto.setInnThumbNumber(wcxInnDto.getThumbNumber());
            // items - inn
            wcxPrizeDto.setPrizeItemId(null);
            wcxPrizeDto.setInnId(wcxInnDto.getInnovationId());
            wcxPrizeDto.setInnTitle(wcxInnDto.getInnovationTitle());
            wcxPrizeDto.setInnContent(wcxInnDto.getInnovationContent());
            wcxPrizeDto.setInnType(wcxInnDto.getInnovationType());
            wcxPrizeDto.setInnBaseline(wcxInnDto.getBaseline());
            wcxPrizeDto.setInnClassification(wcxInnDto.getClassification());
            wcxPrizeDto.setInnTeamContent(wcxInnDto.getTeamContent());
            wcxPrizeDto.setInnProjectName(wcxInnDto.getProjectName());
            wcxPrizeDto.setInnRegionName(wcxInnDto.getRegionName());
            wcxPrizeDto.setInnUserId(wcxInnDto.getUserId());
            wcxPrizeDto.setInnEmployeeName(wcxInnDto.getEmployeeName());
            // items - user
            wcxPrizeDto.setPrizeUserId(null);
            wcxPrizeDto.setPrizeEmployeeName(null);
            wcxPrizeDto.setPrizeUserProject(null);
            wcxPrizeDto.setPrizeUserRegion(null);
            // items - project
            wcxPrizeDto.setProjectUserId(null);
            wcxPrizeDto.setProjectEmployeeName(null);
            wcxPrizeDto.setProjectPrizeInnNumber(null);
            wcxPrizeDto.setProjectName(null);
            wcxPrizeDto.setProjectHeadPicUrl(null);
            // items - region
            wcxPrizeDto.setRegionUserId(null);
            wcxPrizeDto.setRegionEmployeeName(null);
            wcxPrizeDto.setRegionPrizeInnNumber(null);
            wcxPrizeDto.setRegionName(null);
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    @Transactional
    public int savePrizeTypeBestGetPoint20(Date startDate, Date endDate, String title, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestGetPoint20(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(title);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        wcxPrize.setCreateDate(wcxPrizeDto.getCreateDate());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());
            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());
            // todo 区域总 项目总待确认
            item.setProjectUserId(null);
            item.setProjectName(null);
            item.setProjectEmployeeName(null);
            item.setProjectHeadPicUrl(null);
            item.setProjectPrizeInnNumber(null);
            // todo 区域总 项目总待确认
            item.setRegionUserId(null);
            item.setRegionName(null);
            item.setRegionEmployeeName(null);
            item.setRegionHeadPicUrl(null);
            item.setRegionPrizeInnNumber(null);

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    /**
     * condition
     * 类别
     *
     * @param condition prizeType 类别
     * @return
     */
    public PageData selectPrizeTypePageList(WcxPrizeDto condition) {
        String prizeType = condition.getPrizeType();
        Date startDate = condition.getStartDate();
        Date endDate = condition.getEndDate();
        if (!StringUtils.hasText(prizeType)) {
            throw new ServiceException("抽奖规则不能为空");
        }
        if (startDate == null) {
            throw new ServiceException("开始时间不能为空");
        }
        if (endDate == null) {
            throw new ServiceException("结束时间不能为空");
        }
        List<WcxPrizeDto> wcxPrizeDtos = null;
        switch (condition.getPrizeType()) {
            case WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20: // 点赞量前20% 1 PRIZE_TYPE_BEST_GET_POINT_20
                wcxPrizeDtos = selectBestGetPoint20(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_GET_POINT_BASELINE_TOP3: // 各基础业务线点赞前三(创新) 2 PRIZE_TYPE_BEST_GET_POINT_BASELINE_TOP3
                wcxPrizeDtos = selectBestPointBaselineTop3(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_PASS_REGION: // 通过终审最多的区域 3 PRIZE_TYPE_BEST_PASS_REGION
                wcxPrizeDtos = selectBestPassRegion(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_PASS_PROJECT: // 通过终审最多的项目 4 PRIZE_TYPE_BEST_PASS_PROJECT
                wcxPrizeDtos = selectBestPassProject(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_PUT_POINT: // 最佳点赞手(人) 5 PRIZE_TYPE_BEST_PUT_POINT
                wcxPrizeDtos = selectBestPutPoint(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_LEADER_PROJECT: // 领导跟赞(创新) 6 PRIZE_TYPE_BEST_LEADER_PROJECT
                wcxPrizeDtos = selectBestLeaderLike(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_NUMBER_INNOVATION: // 最多创新奖(人) 7 PRIZE_TYPE_BEST_NUMBER_INNOVATION
                wcxPrizeDtos = selectBestNumberInn(startDate, endDate);
                break;
        }

        int pageIndex = condition.getPageIndex();
        int pageSize = condition.getPageSize();
        // 处理数据为空
        if (wcxPrizeDtos == null || wcxPrizeDtos.isEmpty()) {
            PageRowBounds pageRowBounds = new PageRowBounds(pageIndex, pageSize);
            pageRowBounds.setTotal(0L);
            pageRowBounds.setCount(true);
            return new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
        }

        // 假分页
        int total = wcxPrizeDtos.size();

        PageRowBounds pageRowBounds = new PageRowBounds(pageIndex, pageSize);
        pageRowBounds.setTotal((long) total);
        pageRowBounds.setCount(true);
        PageData pageData = null;
        if (!(1 <= pageIndex && pageIndex <= total)) {
            pageData = new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
        } else {
            int formIndex = PageUtil.getPageOffset(pageIndex, pageSize);
            int toIndex = formIndex + pageSize > total ? total : formIndex + pageSize;
            if (formIndex > toIndex) {
                pageData = new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
            } else {
                List<WcxPrizeDto> subWcxPrizeDtos = wcxPrizeDtos.subList(formIndex, toIndex);
                pageData = new PageData(subWcxPrizeDtos, pageRowBounds);
            }
        }
        return pageData;
    }

    @Override
    @Transactional
    public void updateItemStatus(String prizeItemId, String itemStatus) {
        // 查询是否是最后一个数据
        //wcxPrizeMapper.findByCondition();
        wcxPrizeMapper.updateItemStatus(prizeItemId, itemStatus);
    }

    @Override
    public Map<String, String> openPrize(String prizeId) {
        wcxPrizeMapper.updatePrizeItemStatusOfSpecifyStatus(prizeId, WcxConstant.STATUS_STAY, WcxConstant.STATUS_ENABLE);
        WcxPrizeDto parameter = new WcxPrizeDto();
        parameter.setPrizeOpenDate(new Date());
        parameter.setPrizeId(prizeId);
        parameter.setAllAwardNumber(wcxPrizeMapper.findItemNumberOfStatus(prizeId, WcxConstant.STATUS_ENABLE));
        parameter.setStatus(WcxConstant.STATUS_ENABLE);
        wcxPrizeMapper.updatePrize(parameter);

        // todo 通过**个,不通过**个,总**个
        return new HashMap<>();
    }

    @Override
    public String haveGet(Date startDate, Date endDate, String prizeType) {
        List<String> prizeIds = wcxPrizeMapper.haveGet(startDate, endDate, prizeType);
        if (prizeIds != null && prizeIds.size() > 0) {
            // todo 大于一个时,打印错误日志
            return prizeIds.get(0);
        }
        return null;
    }

    @Override
    public PageData selectPageListItem(String prizeId, int pageIndex, int pageSize) {
        WcxPrizeDto param = new WcxPrizeDto();
        param.setPrizeId(prizeId);
        param.setPageIndex(pageIndex);
        param.setPageSize(pageSize);
        PageData pageData = this.selectPageListItem(param);
        return pageData;
    }

    @Override
    public void removeGetItem(String prizeItemId) {
        wcxPrizeMapper.deleteGetItem(prizeItemId);
    }

    /**
     * 将抽取的所有数据转变为待审核状态
     *
     * @param prizeId
     */
    private void updatePrizeStatusGetToNewStatus(String prizeId, String newStatus) {
        wcxPrizeMapper.updatePrizeStatusOfSpecifyStatus(prizeId, WcxConstant.STATUS_GET, WcxConstant.STATUS_STAY);
        wcxPrizeMapper.updatePrizeItemStatusOfSpecifyStatus(prizeId, WcxConstant.STATUS_GET, WcxConstant.STATUS_ENABLE);
    }


    @Override
    public Integer findBatchCodeMax() {
        Integer batchCodeMax = wcxPrizeMapper.findBatchCodeMax();
        return batchCodeMax;
    }

    @Override
    @Transactional
    public void updateForExport(Integer batchCode, String prizeTitle, String prizeId) {
        wcxPrizeMapper.updatePrizeBatchCodeAndTitle(batchCode, prizeTitle, prizeId);
        this.updatePrizeStatusGetToNewStatus(prizeId, WcxConstant.STATUS_ENABLE);
    }

    @Override
    @Transactional
    public void updatePrizeItemStatusBatch(List<String> prizeItemIds, String statusType) {
        if (prizeItemIds == null || prizeItemIds.size() <= 0) {
            throw new ServiceException("参数prizeItemIds不能为空");
        }
        // todo 判断是否在同一个奖单下

        // todo 奖单已发布不能更改状态

        wcxPrizeMapper.updateItemStatusBatch(prizeItemIds, statusType);
    }

    @Override
    @Transactional
    public void saveExtraInno(WcxInnovationDto innoDto, String prizeId) {
        WcxPrizeItem wcxPrizeItem = new WcxPrizeItem();
        wcxPrizeItem.setInnId(innoDto.getInnovationId());
        wcxPrizeItem.setInnTitle(innoDto.getInnovationTitle());
        wcxPrizeItem.setInnContent(innoDto.getInnovationContent());
        wcxPrizeItem.setInnType(innoDto.getInnovationType());
        wcxPrizeItem.setInnBaseline(innoDto.getBaseline());
        wcxPrizeItem.setInnClassification(innoDto.getClassification());
        wcxPrizeItem.setInnTeamContent(innoDto.getTeamContent());
        wcxPrizeItem.setInnProjectName(innoDto.getProjectName());
        wcxPrizeItem.setInnRegionName(innoDto.getRegionName());
        wcxPrizeItem.setInnUserId(innoDto.getUserId());
        wcxPrizeItem.setInnEmployeeName(innoDto.getEmployeeName());
        // todo 待处理
        wcxPrizeItem.setInnThumbNumber(innoDto.getThumbNumber());

        wcxPrizeItem.setPrizeId(prizeId);
        wcxPrizeItem.setPrizeItemId(CommonUtil.getUUID());
        wcxPrizeItem.setStatus(WcxConstant.STATUS_ENABLE);
        wcxPrizeItem.setCreateDate(new Date());
        insertPrizeItem(wcxPrizeItem);
    }

    private void insertPrizeItem(WcxPrizeItem item) {
        List<WcxPrizeItem> items = new ArrayList<>();
        items.add(item);
        wcxPrizeMapper.batchInsertPrizeItems(items);
    }

    /**
     * 最多创新奖
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestNumberInn(Date startDate, Date endDate) {
        int innNumMax = wcxInnovationMapper.findBestNumberInnNumMax(startDate, endDate);
        // 获取奖项内容
        List<WcxUserDto> wcxUserDtos = wcxUserMapper.findBestNumberInn(startDate, endDate, innNumMax);
        if (wcxUserDtos == null || wcxUserDtos.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        // 移除重复项
        List<String> userIds = wcxUserMapper.findUserIdsInPrizeItem();
        if (userIds != null && !userIds.isEmpty()) {
            Iterator<WcxUserDto> iter = wcxUserDtos.iterator();
            while (iter.hasNext()) {
                WcxUserDto item = iter.next();
                if (userIds.contains(item.getUserId())) {
                    iter.remove();
                }
            }
        }
       /* List<String> innIds = wcxInnovationMapper.selectInnIdInPrizeItem();
        if (innIds != null && !innIds.isEmpty()) {
            Iterator<WcxInnovationDto> iter = wcxInnDtos.iterator();
            while (iter.hasNext()) {
                WcxInnovationDto item = iter.next();
                if (innIds.contains(item.getInnovationId())) {
                    iter.remove();
                }
            }
        }*/

        Date nowDate = new Date();
        long allAwardNumber = wcxUserDtos.size();
        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);

        // 获奖人员信息转换
        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxUserDto wcxUserDto : wcxUserDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeId(null);
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_NUMBER_INNOVATION);
            wcxPrizeDto.setAllAwardNumber(allAwardNumber); // 奖项数量
            wcxPrizeDto.setAllJoinNumber(allJoinNumber); // 参与人数
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            // items - user
            wcxPrizeDto.setPrizeUserId(wcxUserDto.getUserId());
            wcxPrizeDto.setPrizeEmployeeName(wcxUserDto.getEmployeeName());
            WcxRegionProjectDto condition = new WcxRegionProjectDto();
            condition.setEmployeeCardId(wcxUserDto.getEmployeeCardId());
            WcxRegionProjectDto wcxRegProDto = wcxRegionProjectMapper.selectOne(condition);
            if (wcxRegProDto != null) {
                wcxPrizeDto.setPrizeUserProject(wcxRegProDto.getProjectName());
                wcxPrizeDto.setPrizeUserRegion(wcxRegProDto.getRegionName());
            } else {
                // todo 添加日志
            }
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    public PageData selectBestPointBaselineTop3PageList(WcxPrizeDto condition) {
        Date startDate = condition.getStartDate();
        Date endDate = condition.getEndDate();
        int pageIndex = condition.getPageIndex();
        int pageSize = condition.getPageSize();

        // todo 查出分页后的PrizeDto?相关数据 假分页
        List<WcxPrizeDto> wcxPrizeDtos = selectBestPointBaselineTop3(startDate, endDate);
        int total = wcxPrizeDtos.size();

        PageRowBounds pageRowBounds = new PageRowBounds(pageIndex, pageSize);
        pageRowBounds.setTotal((long) total);
        pageRowBounds.setCount(true);
        PageData pageData = null;
        if (!(1 <= pageIndex && pageIndex <= total)) {
            pageData = new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
        } else {
            int formIndex = PageUtil.getPageOffset(pageIndex, pageSize);
            int toIndex = formIndex + pageSize > total ? total : formIndex + pageSize;
            List<WcxPrizeDto> subWcxPrizeDtos = wcxPrizeDtos.subList(formIndex, toIndex);
            pageData = new PageData(subWcxPrizeDtos, pageRowBounds);
        }
        return pageData;
    }

    /**
     * 查询基础业务线前三
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestPointBaselineTop3(Date startDate, Date endDate) {
        // 获取奖项内容
        List<WcxInnovationDto> wcxInnDtos = new ArrayList<>();
        int allAwardNumber = 0; // 奖项数量
        // 获取各基础业务线前三的点赞量
        for (WcxBaselineEnum c : WcxBaselineEnum.values()) {
            String baseline = c.getBaselineCode();
            List<Integer> thumbNum = wcxInnovationMapper.selectInnTop3NumberThumbNum(startDate, endDate, baseline);
            if (thumbNum == null || thumbNum.isEmpty()) {
                continue;
            }
            List<WcxInnovationDto> wcxInnovationDtos = wcxInnovationMapper.selectInnTop3Number(startDate, endDate, baseline, thumbNum);
            wcxInnDtos.addAll(wcxInnovationDtos);
            allAwardNumber = allAwardNumber + thumbNum.size();
        }
        // 移除重复项
        List<String> innIds = wcxInnovationMapper.selectInnIdInPrizeItem();
        if (innIds != null && !innIds.isEmpty()) {
            Iterator<WcxInnovationDto> iter = wcxInnDtos.iterator();
            while (iter.hasNext()) {
                WcxInnovationDto item = iter.next();
                if (innIds.contains(item.getInnovationId())) {
                    iter.remove();
                }
            }
        }

        Date nowDate = new Date();
        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);
        // 设置奖项内容
        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxInnovationDto wcxInnDto : wcxInnDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeId(null);
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
            wcxPrizeDto.setAllAwardNumber((long) allAwardNumber); // 奖项数量
            wcxPrizeDto.setAllJoinNumber(allJoinNumber); // 参与人数
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            wcxPrizeDto.setInnThumbNumber(wcxInnDto.getThumbNumber());
            // items - inn
            wcxPrizeDto.setPrizeItemId(null);
            wcxPrizeDto.setInnId(wcxInnDto.getInnovationId());
            wcxPrizeDto.setInnTitle(wcxInnDto.getInnovationTitle());
            wcxPrizeDto.setInnContent(wcxInnDto.getInnovationContent());
            wcxPrizeDto.setInnType(wcxInnDto.getInnovationType());
            wcxPrizeDto.setInnBaseline(wcxInnDto.getBaseline());
            wcxPrizeDto.setInnClassification(wcxInnDto.getClassification());
            wcxPrizeDto.setInnTeamContent(wcxInnDto.getTeamContent());
            wcxPrizeDto.setInnProjectName(wcxInnDto.getProjectName());
            wcxPrizeDto.setInnRegionName(wcxInnDto.getRegionName());
            wcxPrizeDto.setInnUserId(wcxInnDto.getUserId());
            wcxPrizeDto.setInnEmployeeName(wcxInnDto.getEmployeeName());
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    public int savePrizeTypeBestPointBaselineTop3(Date startDate, Date endDate, String prizeTitle, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestPointBaselineTop3(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(prizeTitle);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_BASELINE_TOP3);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());
            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());
            // todo 区域总 项目总待确认
            item.setProjectUserId(null);
            item.setProjectName(null);
            item.setProjectEmployeeName(null);
            item.setProjectHeadPicUrl(null);
            item.setProjectPrizeInnNumber(null);
            // todo 区域总 项目总待确认
            item.setRegionUserId(null);
            item.setRegionName(null);
            item.setRegionEmployeeName(null);
            item.setRegionHeadPicUrl(null);
            item.setRegionPrizeInnNumber(null);

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    @Override
    public PageData selectBestPassRegionPageList(WcxPrizeDto condition) {
        Date startDate = condition.getStartDate();
        Date endDate = condition.getEndDate();
        int pageIndex = condition.getPageIndex();
        int pageSize = condition.getPageSize();

        // todo 查出分页后的PrizeDto?相关数据 假分页
        List<WcxPrizeDto> wcxPrizeDtos = selectBestPassRegion(startDate, endDate);
        int total = wcxPrizeDtos.size();

        PageRowBounds pageRowBounds = new PageRowBounds(pageIndex, pageSize);
        pageRowBounds.setTotal((long) total);
        pageRowBounds.setCount(true);
        PageData pageData = null;
        if (!(1 <= pageIndex && pageIndex <= total)) {
            pageData = new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
        } else {
            int formIndex = PageUtil.getPageOffset(pageIndex, pageSize);
            int toIndex = formIndex + pageSize > total ? total : formIndex + pageSize;
            List<WcxPrizeDto> subWcxPrizeDtos = wcxPrizeDtos.subList(formIndex, toIndex);
            pageData = new PageData(subWcxPrizeDtos, pageRowBounds);
        }
        return pageData;
    }

    /**
     * 通过终审最多的区域
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestPassRegion(Date startDate, Date endDate) {
        List<WcxRegionProjectDto> wcxRegionProjectDtos = wcxRegionProjectMapper.selectBestPassNumberRegion(startDate, endDate);
        if (wcxRegionProjectDtos == null || wcxRegionProjectDtos.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        // todo 判断当前时间段是否已有重复存在的数据

        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);
        Date nowDate = new Date();

        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxRegionProjectDto wcxRegionProjectDto : wcxRegionProjectDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
            wcxPrizeDto.setAllAwardNumber((long) wcxRegionProjectDtos.size());
            wcxPrizeDto.setAllJoinNumber(allJoinNumber);
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            // items - region
            wcxPrizeDto.setRegionUserId(null);
            // todo 待处理 区域总名称待确定
            wcxPrizeDto.setRegionEmployeeName("区域总名称待确定");
            wcxPrizeDto.setRegionPrizeInnNumber(wcxRegionProjectDto.getRegionPrizeInnNumber());
            wcxPrizeDto.setRegionName(wcxRegionProjectDto.getRegionName());
            wcxPrizeDto.setRegionHeadPicUrl(null);
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    public int savePrizeTypeBestPassProject(Date startDate, Date endDate, String prizeTitle, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestPassProject(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(prizeTitle);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_PASS_PROJECT);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());
            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());
            // todo 区域总 项目总待确认
            item.setProjectUserId(ele.getPrizeUserId());
            item.setProjectName(ele.getProjectName());
            item.setProjectEmployeeName(ele.getProjectEmployeeName());
            item.setProjectHeadPicUrl(ele.getProjectHeadPicUrl());
            item.setProjectPrizeInnNumber(ele.getProjectPrizeInnNumber());
            // todo 区域总 项目总待确认
            item.setRegionUserId(null);
            item.setRegionName(null);
            item.setRegionEmployeeName(null);
            item.setRegionHeadPicUrl(null);
            item.setRegionPrizeInnNumber(null);

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    /**
     * 通过终审最多的项目
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestPassProject(Date startDate, Date endDate) {
        List<WcxRegionProjectDto> wcxRegionProjectDtos = wcxRegionProjectMapper.selectBestPassNumberProject(startDate, endDate);
        if (wcxRegionProjectDtos == null || wcxRegionProjectDtos.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        // todo 判断当前时间段是否已有重复存在的数据

        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);
        Date nowDate = new Date();

        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxRegionProjectDto wcxRegionProjectDto : wcxRegionProjectDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
            wcxPrizeDto.setAllAwardNumber((long) wcxRegionProjectDtos.size());
            wcxPrizeDto.setAllJoinNumber(allJoinNumber);
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            // items - project
            wcxPrizeDto.setProjectUserId(null);
            // todo 待处理 项目总名称待确定
            wcxPrizeDto.setProjectEmployeeName("项目总名称待确定");
            wcxPrizeDto.setProjectPrizeInnNumber(wcxRegionProjectDto.getProjectPrizeInnNumber());
            wcxPrizeDto.setProjectName(wcxRegionProjectDto.getProjectName());
            wcxPrizeDto.setProjectHeadPicUrl(null);
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    @Deprecated
    public PageData selectBestPassProjectPageList(WcxPrizeDto condition) {
        Date startDate = condition.getStartDate();
        Date endDate = condition.getEndDate();
        int pageIndex = condition.getPageIndex();
        int pageSize = condition.getPageSize();

        // todo 查出分页后的PrizeDto?相关数据 假分页
        List<WcxPrizeDto> wcxPrizeDtos = selectBestPassProject(startDate, endDate);
        int total = wcxPrizeDtos.size();

        PageRowBounds pageRowBounds = new PageRowBounds(pageIndex, pageSize);
        pageRowBounds.setTotal((long) total);
        pageRowBounds.setCount(true);
        PageData pageData = null;
        if (!(1 <= pageIndex && pageIndex <= total)) {
            pageData = new PageData(new ArrayList<WcxPrizeDto>(), pageRowBounds);
        } else {
            int formIndex = PageUtil.getPageOffset(pageIndex, pageSize);
            int toIndex = formIndex + pageSize > total ? total : formIndex + pageSize;
            List<WcxPrizeDto> subWcxPrizeDtos = wcxPrizeDtos.subList(formIndex, toIndex);
            pageData = new PageData(subWcxPrizeDtos, pageRowBounds);
        }
        return pageData;
    }

    @Override
    public int savePrizeTypeBestPassRegion(Date startDate, Date endDate, String prizeTitle, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestLeaderLike(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(prizeTitle);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_PASS_REGION);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            /*item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());
            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());*/
            // todo 区域总 项目总待确认
            item.setProjectUserId(null);
            item.setProjectName(null);
            item.setProjectEmployeeName(null);
            item.setProjectHeadPicUrl(null);
            item.setProjectPrizeInnNumber(null);
            // todo 区域总 项目总待确认
            item.setRegionUserId(ele.getRegionUserId());
            item.setRegionName(ele.getRegionName());
            item.setRegionEmployeeName(ele.getRegionEmployeeName());
            item.setRegionHeadPicUrl(ele.getRegionHeadPicUrl());
            item.setRegionPrizeInnNumber(ele.getRegionPrizeInnNumber());

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    @Override
    public PageData selectBestPutPointPageList(WcxPrizeDto condition) {
        return null;
    }

    /**
     * 最佳点赞手
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestPutPoint(Date startDate, Date endDate) {
        int thumbNumMax = wcxThumbMapper.findBestPutPointThumbNum(startDate, endDate);
        // 获取奖项内容
        List<WcxUserDto> wcxUserDtos = wcxUserMapper.findBestPutPoint(startDate, endDate, thumbNumMax);
        if (wcxUserDtos == null || wcxUserDtos.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        // 移除重复项
        List<String> userIds = wcxUserMapper.findUserIdsInPrizeItem();
        if (userIds != null && !userIds.isEmpty()) {
            Iterator<WcxUserDto> iter = wcxUserDtos.iterator();
            while (iter.hasNext()) {
                WcxUserDto item = iter.next();
                if (userIds.contains(item.getUserId())) {
                    iter.remove();
                }
            }
        }
        Date nowDate = new Date();
        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);

        // 设置奖项内容
        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxUserDto wcxUserDto : wcxUserDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeId(null);
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
            wcxPrizeDto.setAllAwardNumber((long) wcxUserDtos.size()); // 奖项数量
            wcxPrizeDto.setAllJoinNumber(allJoinNumber); // 参与人数
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            // items - user
            wcxPrizeDto.setPrizeUserId(wcxUserDto.getUserId());
            wcxPrizeDto.setPrizeEmployeeName(wcxUserDto.getEmployeeName());
            WcxRegionProjectDto condition = new WcxRegionProjectDto();
            condition.setEmployeeCardId(wcxUserDto.getEmployeeCardId());
            WcxRegionProjectDto wcxRegProDto = wcxRegionProjectMapper.selectOne(condition);
            if (wcxRegProDto != null) {
                wcxPrizeDto.setPrizeUserProject(wcxRegProDto.getProjectName());
                wcxPrizeDto.setPrizeUserRegion(wcxRegProDto.getRegionName());
            }
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    public int savePrizeTypeBestPutPoint(Date startDate, Date endDate, String prizeTitle, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestPutPoint(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(prizeTitle);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_PUT_POINT);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            /*item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());*/
            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());
            // todo 区域总 项目总待确认
            item.setProjectUserId(null);
            item.setProjectName(null);
            item.setProjectEmployeeName(null);
            item.setProjectHeadPicUrl(null);
            item.setProjectPrizeInnNumber(null);
            // todo 区域总 项目总待确认
            item.setRegionUserId(null);
            item.setRegionName(null);
            item.setRegionEmployeeName(null);
            item.setRegionHeadPicUrl(null);
            item.setRegionPrizeInnNumber(null);

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    @Override
    public PageData selectBestLeaderLikePageList(WcxPrizeDto condition) {
        return null;
    }


    /**
     * 领导跟赞
     *
     * @param startDate
     * @param endDate
     * @return
     */
    private List<WcxPrizeDto> selectBestLeaderLike(Date startDate, Date endDate) {
        List<String> leaderLikeInnIds = wcxInnovationMapper.findBestLeaderLikeInnIds(startDate, endDate);
        if (leaderLikeInnIds == null || leaderLikeInnIds.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        // 移除重复项
        List<String> innIds = wcxInnovationMapper.selectInnIdInPrizeItem();
        if (innIds != null && !innIds.isEmpty()) {
            Iterator<String> iter = leaderLikeInnIds.iterator();
            while (iter.hasNext()) {
                String item = iter.next();
                if (innIds.contains(item)) {
                    iter.remove();
                }
            }
        }
        if (leaderLikeInnIds.isEmpty()) {
            return Collections.EMPTY_LIST;
        }
        // 获取创意信息
        List<WcxInnovationDto> wcxInnDtos = wcxInnovationMapper.findList(leaderLikeInnIds);
        long allAwardNumber = wcxInnDtos.size();
        long allJoinNumber = wcxUserMapper.selectAllJoinNumber(startDate, endDate);
        long allThumbNumber = wcxThumbMapper.selectAllThumbNumber(startDate, endDate);
        Date nowDate = new Date();
        // 信息转换
        List<WcxPrizeDto> wcxPrizeDtos = new ArrayList<>();
        for (WcxInnovationDto wcxInnDto : wcxInnDtos) {
            WcxPrizeDto wcxPrizeDto = new WcxPrizeDto();
            // master
            wcxPrizeDto.setPrizeId(CommonUtil.getUUID());
            wcxPrizeDto.setPrizeTitle(null);
            wcxPrizeDto.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20);
            wcxPrizeDto.setAllAwardNumber(allAwardNumber);
            wcxPrizeDto.setAllJoinNumber(allJoinNumber);
            wcxPrizeDto.setAllThumbNumber(allThumbNumber);
            wcxPrizeDto.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
            wcxPrizeDto.setBatchCode(null);
            wcxPrizeDto.setPrizeOpenDate(null);
            wcxPrizeDto.setStatus(null);
            wcxPrizeDto.setCreateDate(nowDate);
            // items - inn
            wcxPrizeDto.setPrizeItemId(null);
            wcxPrizeDto.setInnId(wcxInnDto.getInnovationId());
            wcxPrizeDto.setInnTitle(wcxInnDto.getInnovationTitle());
            wcxPrizeDto.setInnContent(wcxInnDto.getInnovationContent());
            wcxPrizeDto.setInnType(wcxInnDto.getInnovationType());
            wcxPrizeDto.setInnBaseline(wcxInnDto.getBaseline());
            wcxPrizeDto.setInnClassification(wcxInnDto.getClassification());
            wcxPrizeDto.setInnTeamContent(wcxInnDto.getTeamContent());
            wcxPrizeDto.setInnThumbNumber(wcxInnDto.getThumbNumber());
            wcxPrizeDto.setInnProjectName(wcxInnDto.getProjectName());
            wcxPrizeDto.setInnRegionName(wcxInnDto.getRegionName());
            wcxPrizeDto.setInnUserId(wcxInnDto.getUserId());
            wcxPrizeDto.setInnEmployeeName(wcxInnDto.getEmployeeName());
            wcxPrizeDtos.add(wcxPrizeDto);
        }
        return wcxPrizeDtos;
    }

    @Override
    public int savePrizeTypeBestLeaderLike(Date startDate, Date endDate, String prizeTitle, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestLeaderLike(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(prizeTitle);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_LEADER_PROJECT);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());
            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());
            // todo 区域总 项目总待确认
            item.setProjectUserId(null);
            item.setProjectName(null);
            item.setProjectEmployeeName(null);
            item.setProjectHeadPicUrl(null);
            item.setProjectPrizeInnNumber(null);
            // todo 区域总 项目总待确认
            item.setRegionUserId(null);
            item.setRegionName(null);
            item.setRegionEmployeeName(null);
            item.setRegionHeadPicUrl(null);
            item.setRegionPrizeInnNumber(null);

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    @Override
    public PageData selectBestNumberInnovationPageList(WcxPrizeDto condition) {
        return null;
    }

    @Override
    public int savePrizeTypeBestNumberInnovation(Date startDate, Date endDate, String prizeTitle, Integer batchCode) {
        List<WcxPrizeDto> wcxPrizeDtos = this.selectBestNumberInn(startDate, endDate);
        if (wcxPrizeDtos == null || wcxPrizeDtos.size() <= 0) {
            return 0;
        }
        batchCode = wcxPrizeMapper.findBatchCodeMax();
        if (batchCode == null) {
            batchCode = 1;
        } else {
            batchCode = batchCode + 1;
        }
        WcxPrizeDto wcxPrizeDto = wcxPrizeDtos.get(0);
        Date nowDate = new Date();
        WcxPrize wcxPrize = new WcxPrize();
        wcxPrize.setPrizeTitle(prizeTitle);
        String prizeId = CommonUtil.getUUID();
        wcxPrize.setPrizeId(prizeId);
        wcxPrize.setBatchCode(batchCode);
        wcxPrize.setPrizeType(WcxConstant.PRIZE_TYPE_BEST_NUMBER_INNOVATION);
        wcxPrize.setPrizeMonthDate(DateUtil.formatDate(startDate, DateUtil.COMMON_DATE_FORMAT_YM));
        wcxPrize.setStatus(WcxConstant.STATUS_STAY);
        wcxPrize.setAllAwardNumber(wcxPrizeDto.getAllAwardNumber());
        wcxPrize.setAllJoinNumber(wcxPrizeDto.getAllJoinNumber());
        wcxPrize.setAllThumbNumber(wcxPrizeDto.getAllThumbNumber());
        List<WcxPrizeItem> wcxPrizeItems = new ArrayList<>();
        for (WcxPrizeDto ele : wcxPrizeDtos) {
            WcxPrizeItem item = new WcxPrizeItem();
            item.setPrizeItemId(CommonUtil.getUUID());
            /*item.setInnId(ele.getInnId());
            item.setInnTitle(ele.getInnTitle());
            item.setInnContent(ele.getInnContent());
            item.setInnType(ele.getInnType());
            item.setInnBaseline(ele.getInnBaseline());
            item.setInnClassification(ele.getInnClassification());
            item.setInnTeamContent(ele.getInnTeamContent());
            item.setInnProjectName(ele.getInnProjectName());
            item.setInnRegionName(ele.getRegionName());
            item.setInnUserId(ele.getInnUserId());
            item.setInnEmployeeName(ele.getInnEmployeeName());*/

            item.setPrizeUserId(ele.getPrizeUserId());
            item.setPrizeEmployeeName(ele.getPrizeEmployeeName());
            item.setPrizeUserProject(ele.getPrizeUserProject());
            item.setPrizeUserRegion(ele.getPrizeUserRegion());
            // todo 区域总 项目总待确认
            item.setProjectUserId(null);
            item.setProjectName(null);
            item.setProjectEmployeeName(null);
            item.setProjectHeadPicUrl(null);
            item.setProjectPrizeInnNumber(null);
            // todo 区域总 项目总待确认
            item.setRegionUserId(null);
            item.setRegionName(null);
            item.setRegionEmployeeName(null);
            item.setRegionHeadPicUrl(null);
            item.setRegionPrizeInnNumber(null);

            item.setPrizeId(prizeId);
            item.setStatus(WcxConstant.STATUS_STAY);
            item.setCreateDate(nowDate);
            wcxPrizeItems.add(item);
        }
        wcxPrizeMapper.insertPrize(wcxPrize);
        wcxPrizeMapper.batchInsertPrizeItems(wcxPrizeItems);
        return wcxPrizeItems.size();
    }

    @Override
    public void exportItem(WcxPrizeDto condition, HttpServletRequest request, HttpServletResponse response) {
        Date startDate = condition.getStartDate();
        Date endDate = condition.getEndDate();
        List<WcxPrizeDto> data = null;
        switch (condition.getPrizeType()) {
            case WcxConstant.PRIZE_TYPE_BEST_GET_POINT_20: // 点赞量前20% 1 PRIZE_TYPE_BEST_GET_POINT_20
                data = selectBestGetPoint20(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_GET_POINT_BASELINE_TOP3: // 各基础业务线点赞前三(创新) 2 PRIZE_TYPE_BEST_GET_POINT_BASELINE_TOP3
                data = selectBestPointBaselineTop3(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_PASS_REGION: // 通过终审最多的区域 3 PRIZE_TYPE_BEST_PASS_REGION
                data = selectBestPassRegion(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_PASS_PROJECT: // 通过终审最多的项目 4 PRIZE_TYPE_BEST_PASS_PROJECT
                data = selectBestPassProject(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_PUT_POINT: // 最佳点赞手(人) 5 PRIZE_TYPE_BEST_PUT_POINT
                data = selectBestPutPoint(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_LEADER_PROJECT: // 领导跟赞(创新) 6 PRIZE_TYPE_BEST_LEADER_PROJECT
                data = selectBestLeaderLike(startDate, endDate);
                break;
            case WcxConstant.PRIZE_TYPE_BEST_NUMBER_INNOVATION: // 最多创新奖(人) 7 PRIZE_TYPE_BEST_NUMBER_INNOVATION
                data = selectBestNumberInn(startDate, endDate);
                break;
        }
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet();
        createHeader(workbook, sheet);
        if (data != null && data.size() > 0) {
            Integer batchCode = wcxPrizeMapper.findBatchCodeMax();
            if (batchCode == null) {
                batchCode = 1;
            } else {
                batchCode = batchCode + 1;
            }
            for (WcxPrizeDto ele : data) {
                ele.setPrizeTitle(condition.getPrizeTitle());
                ele.setBatchCode(batchCode);
            }
            createBody(data, workbook, sheet);
        }
        response.setContentType("multipart/form-data");
        String fileName = "export.xlsx";
        try {
            fileName = URLEncoder.encode(condition.getPrizeTitle() + ".xlsx", "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-Disposition", "attachment;fileName=" + fileName);

        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                workbook.close();
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    /**
     * 创建表头
     *
     * @param workbook
     * @param sheet
     */
    public void createHeader(Workbook workbook, Sheet sheet) {
        int rowIndex = 0;
        CellStyle headerStyle = createHeaderStyle(workbook);
        Row row = sheet.createRow(rowIndex);
        row.setHeight((short) (250 * 2));
//        createCell("抽取规则", headerStyle, row, 0, false);
        createCell("奖项批次号", headerStyle, row, 0, false);
        createCell("奖项标题", headerStyle, row, 1, false);

        createCell("创新标题", headerStyle, row, 2, false);
        createCell("创意点赞量", headerStyle, row, 3, false);
        createCell("创意提出的用户姓名", headerStyle, row, 4, false);

        createCell("获奖人员名称", headerStyle, row, 5, false);
        createCell("获奖项目", headerStyle, row, 6, false);
        createCell("获奖区域", headerStyle, row, 7, false);

        //createCell("状态", headerStyle, row, 8, false);
    }

    /**
     * 创建表头
     *
     * @param data
     * @param workbook
     * @param sheet
     */
    public void createBody(List<WcxPrizeDto> data, Workbook workbook, Sheet sheet) {
        CellStyle bodyStyle = createBodyStyle(workbook);
        int rowIndex = 1;

        for (WcxPrizeDto tem : data) {
            Row row = sheet.createRow(rowIndex);
            createCell(tem.getBatchCode() + "", bodyStyle, row, 0, false); // 奖项批次号
            createCell(tem.getPrizeTitle(), bodyStyle, row, 1, false); // 奖项标题
            createCell(tem.getInnTitle(), bodyStyle, row, 2, false); // 创新标题
            Long innThumbNumber = tem.getInnThumbNumber();
            createCell(innThumbNumber == null ? "0" : innThumbNumber + "", bodyStyle, row, 3, false); // 创意点赞量
            createCell(tem.getInnEmployeeName(), bodyStyle, row, 4, false); // 创意提出的用户姓名
            createCell(tem.getPrizeEmployeeName(), bodyStyle, row, 5, false); // 获奖人员名称
            createCell(tem.getProjectName(), bodyStyle, row, 6, false); // 获奖项目
            createCell(tem.getRegionName(), bodyStyle, row, 7, false); // 获奖区域
            //createCell(tem.getStatus(), bodyStyle, row, 8, false); // 状态
            rowIndex++;
        }
    }


    /**
     * 创建头风格
     *
     * @param workbook
     * @return
     */
    public CellStyle createHeaderStyle(Workbook workbook) {
        CellStyle headerStyle = workbook.createCellStyle();
        headerStyle.setAlignment(HorizontalAlignment.CENTER);
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        headerStyle.setWrapText(true);
        headerStyle.setBorderBottom(BorderStyle.THIN); //下边框
        headerStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setBorderLeft(BorderStyle.THIN);//左边框
        headerStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setBorderTop(BorderStyle.THIN);//上边框
        headerStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        headerStyle.setBorderRight(BorderStyle.THIN);//右边框
        headerStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        return headerStyle;
    }

    /**
     * @param value
     * @param style
     * @param row
     * @param col
     * @param color
     */
    public void createCell(String value, CellStyle style, Row row, int col, boolean color) {

        Cell cell = row.createCell(col);


        if (color) {
            style.setFillForegroundColor(IndexedColors.RED.getIndex());
            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        }

        cell.setCellStyle(style);


        if (value != null) {
            cell.setCellValue(value);
        }
    }

    public CellStyle createBodyStyle(Workbook workbook) {
        CellStyle style = workbook.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setWrapText(true);
        style.setBorderBottom(BorderStyle.THIN); //下边框
        style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderLeft(BorderStyle.THIN);//左边框
        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);//上边框
        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderRight(BorderStyle.THIN);//右边框
        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        return style;
    }

    public String change(Object object) {
        if (null == object) {
            return "";
        } else {
            return object + "";
        }
    }

    public boolean changeColor(Object o1, Object o2) {
        if (null == o1 && null == o2) {
            return false;
        }
        if (null == o1 || null == o2) {
            return true;
        }

        if (o1.equals(o2)) {
            return false;
        }
        return true;
    }

    public String date2String(Date time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (null == time) {
            return "";
        } else {
            return sdf.format(time);
        }
    }

    public int remove() {
        wcxPrizeMapper.deleteGetStatusPrize();
        wcxPrizeMapper.deleteGetStatusPrizeItem();
        // todo 返回删除条数
        return 0;
    }

    @Override
    public void updateOrderNo(String prizeItemId, Integer orderNo) {
        wcxPrizeMapper.updateOrderNo(prizeItemId, orderNo);
    }

    @Override
    public WcxPrizeDto findFirst(String prizeId) {
        WcxPrizeDto firstByPrimaryKey = wcxPrizeMapper.findFirstByPrimaryKey(prizeId);
        return firstByPrimaryKey;
    }
}
