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.Bulletin;
import com.trs.ggzyexchange.entity.Cgwinbidbulletin;
import com.trs.ggzyexchange.entity.Changeitembulletin;
import com.trs.ggzyexchange.entity.TenderDetailsVo;
import com.trs.ggzyexchange.enums.ClassIfy;
import com.trs.ggzyexchange.service.BulletinService;
import com.trs.ggzyexchange.service.CgwinbidbulletinService;
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("/cgwinbidbulletin")
public class CgwinbidbulletinController extends BaseController {

    @Autowired
    private CgwinbidbulletinService cgwinbidbulletinService;

    @Autowired
    private GcNoticeandfileService gcNoticeandfileService;

    //@GetMapping(value = "/queryChangeItemBulletininUpdateEs")
    public Integer queryBulletinUpdateEs() throws JsonProcessingException {
        int count = cgwinbidbulletinService.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<Cgwinbidbulletin> queryWrapper = new QueryWrapper<Cgwinbidbulletin>();
            Page<Cgwinbidbulletin> page = new Page<Cgwinbidbulletin>(i, pageSize);
            IPage<Cgwinbidbulletin> pageList = cgwinbidbulletinService.page(page, queryWrapper);
            List<TenderDetailsVo> tenderDetailsVos = new ArrayList<TenderDetailsVo>();
            for (Cgwinbidbulletin cgwinbidbulletin : pageList.getRecords()) {
                TenderDetailsVo tenderDetailsVo = new TenderDetailsVo();
                tenderDetailsVo.setSourceDataKey(cgwinbidbulletin.getGuid());
                tenderDetailsVo.setProjectCode(cgwinbidbulletin.getPurchaseprojectcode());
                tenderDetailsVo.setProjectName(cgwinbidbulletin.getPurchaseprojectname());
                tenderDetailsVo.setTenderProjectCode(cgwinbidbulletin.getPurchaseprojectcode());
                tenderDetailsVo.setNoticeName(cgwinbidbulletin.getWinbidbulletintitle());
                tenderDetailsVo.setNoticeContent(cgwinbidbulletin.getWinbidbulletincontent());
                tenderDetailsVo.setNoticeSendTime(cgwinbidbulletin.getWinbidbulletinstarttime());
                tenderDetailsVo.setNoticeTypeCode(ClassIfy.PREQUALIFICATION_ANNOUNCEMENT.getCode());
                tenderDetailsVo.setNoticeTypeName(ClassIfy.PREQUALIFICATION_ANNOUNCEMENT.getName());
                tenderDetailsVo.setTransactionTypeCode(ClassIfy.GOVERNMENT_PROCUREMENT.getCode());
                tenderDetailsVo.setTransactionTypeName(ClassIfy.GOVERNMENT_PROCUREMENT.getName());
                tenderDetailsVo.setRegionCode(cgwinbidbulletin.getCode());
                tenderDetailsVo.setRegionName(cgwinbidbulletin.getCodePram());
                tenderDetailsVo.setDataSourceCode(cgwinbidbulletin.getPurchaserAgencyCode());
                tenderDetailsVo.setDataSourceName(cgwinbidbulletin.getPurchaserAgencyName());
                tenderDetailsVos.add(tenderDetailsVo);
                TenderDetailsVoUtils.isNull(tenderDetailsVo);
            }
            tenderDetailsVosList = tenderDetailsVos;
            Boolean aBoolean = gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVos);
        }
        return tenderDetailsVosList.size();
    }
}
