package com.trs.ggzyexchange.controller;

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.fasterxml.jackson.core.JsonProcessingException;
import com.trs.ggzyexchange.entity.Changeitembulletin;
import com.trs.ggzyexchange.entity.TenderDetailsVo;
import com.trs.ggzyexchange.enums.ClassIfy;
import com.trs.ggzyexchange.service.ChangeitembulletinService;
import com.trs.ggzyexchange.service.GcNoticeandfileService;
import com.trs.ggzyexchange.utils.DateUtils;
import com.trs.ggzyexchange.utils.TenderDetailsVoUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 采购公告/资格预审  更正公告/更正事项 前端控制器
 * </p>
 *
 * @author trs
 * @since 2023-09-27
 */
@RestController
@RequestMapping("/changeitembulletin")
public class ChangeitembulletinController extends BaseController {

    @Autowired
    private GcNoticeandfileService gcNoticeandfileService;

    @Autowired
    private ChangeitembulletinService changeitembulletinService;

    //@GetMapping(value = "/queryChangeItemBulletininUpdateEs")
    public Integer queryBulletinUpdateEs() throws JsonProcessingException {
        int count = changeitembulletinService.count();
        Integer pageSize = 1000;
        Integer pageNum = (int)Math.ceil((double)count/pageSize);
        List<TenderDetailsVo> tenderDetailsVosList = new ArrayList<TenderDetailsVo>();
        for(int i = 1; i <= pageNum;i++){
            QueryWrapper<Changeitembulletin> queryWrapper = new QueryWrapper<Changeitembulletin>();
            Page<Changeitembulletin> page = new Page<Changeitembulletin>(i, pageSize);
            IPage<Changeitembulletin> pageList = changeitembulletinService.page(page, queryWrapper);
            List<TenderDetailsVo> tenderDetailsVos = new ArrayList<TenderDetailsVo>();
            for (Changeitembulletin changeitembulletin : pageList.getRecords()) {
                TenderDetailsVo tenderDetailsVo = new TenderDetailsVo();
                tenderDetailsVo.setSourceDataKey(changeitembulletin.getGuid());
                tenderDetailsVo.setProjectCode(changeitembulletin.getPurchaseprojectcode());
                tenderDetailsVo.setProjectName(changeitembulletin.getPurchaseprojectname());
                tenderDetailsVo.setTenderProjectCode(changeitembulletin.getPurchaseprojectcode());
                tenderDetailsVo.setNoticeName(changeitembulletin.getTerminationbulletintitle());
                tenderDetailsVo.setNoticeContent(changeitembulletin.getTerminationbulletincontent());
                tenderDetailsVo.setNoticeSendTime(changeitembulletin.getModificationstarttime());
                tenderDetailsVo.setNoticeTypeCode(ClassIfy.CORRECTION_ANNOUNCEMENT.getCode());
                tenderDetailsVo.setNoticeTypeName(ClassIfy.CORRECTION_ANNOUNCEMENT.getName());
                tenderDetailsVo.setTransactionTypeCode(ClassIfy.GOVERNMENT_PROCUREMENT.getCode());
                tenderDetailsVo.setTransactionTypeName(ClassIfy.GOVERNMENT_PROCUREMENT.getName());
                tenderDetailsVo.setRegionCode(changeitembulletin.getCode());
                tenderDetailsVo.setRegionName(changeitembulletin.getCodePram());
                tenderDetailsVo.setDataSourceCode(changeitembulletin.getJyptid());
                tenderDetailsVos.add(tenderDetailsVo);
                TenderDetailsVoUtils.isNull(tenderDetailsVo);
            }
            tenderDetailsVosList = tenderDetailsVos;
            Boolean aBoolean = gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVos);
        }
        return tenderDetailsVosList.size();
    }
}
