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.OtherTradePubInfo;
import com.trs.ggzyexchange.entity.TenderDetailsVo;
import com.trs.ggzyexchange.enums.ClassIfy;
import com.trs.ggzyexchange.service.BulletinService;
import com.trs.ggzyexchange.service.GcNoticeandfileService;
import com.trs.ggzyexchange.service.OtherTradePubInfoService;
import com.trs.ggzyexchange.utils.TenderDetailsVoUtils;
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-10-19
 */
@RestController
@RequestMapping("/other-trade-pub-info")
public class OtherTradePubInfoController extends BaseController {
    @Autowired
    private GcNoticeandfileService gcNoticeandfileService;

    @Autowired
    private OtherTradePubInfoService otherTradePubInfoService;

    //@GetMapping(value = "/queryOtherTradePubInfoUpdateEs")
    public Integer OtherTradePubInfo() throws JsonProcessingException {
        int count = otherTradePubInfoService.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<OtherTradePubInfo> queryWrapper = new QueryWrapper<OtherTradePubInfo>();
            Page<OtherTradePubInfo> page = new Page<OtherTradePubInfo>(i, pageSize);
            IPage<OtherTradePubInfo> pageList = otherTradePubInfoService.page(page, queryWrapper);
            List<TenderDetailsVo> tenderDetailsVos = new ArrayList<TenderDetailsVo>();
            for (OtherTradePubInfo otherTradePubInfo : pageList.getRecords()) {
                TenderDetailsVo tenderDetailsVo = new TenderDetailsVo();
                tenderDetailsVo.setSourceDataKey(otherTradePubInfo.getGuid());
                tenderDetailsVo.setProjectCode(otherTradePubInfo.getProjectCode());
                tenderDetailsVo.setProjectName(otherTradePubInfo.getProjectName());
                tenderDetailsVo.setTenderProjectCode(otherTradePubInfo.getProjectCode());
                tenderDetailsVo.setNoticeName(otherTradePubInfo.getAnnouncementTitle());
                tenderDetailsVo.setNoticeContent(otherTradePubInfo.getAnnouncementConnect());
                tenderDetailsVo.setNoticeSendTime(otherTradePubInfo.getPublishingTime());
                tenderDetailsVo.setNoticeTypeCode(ClassIfy.OTHER_TRANSACTION_ANNOUNCEMENT.getCode());
                tenderDetailsVo.setNoticeTypeName(ClassIfy.OTHER_TRANSACTION_ANNOUNCEMENT.getName());
                tenderDetailsVo.setTransactionTypeCode(ClassIfy.OTHER_TRANSACTIONS.getCode());
                tenderDetailsVo.setTransactionTypeName(ClassIfy.OTHER_TRANSACTIONS.getName());
                tenderDetailsVo.setRegionCode(otherTradePubInfo.getCode());
                tenderDetailsVo.setRegionName(otherTradePubInfo.getCodePram());
                tenderDetailsVo.setDataSourceCode(otherTradePubInfo.getJyptid());
                tenderDetailsVo.setPlatformCode(otherTradePubInfo.getPlatformCode());
                tenderDetailsVos.add(tenderDetailsVo);
                TenderDetailsVoUtils.isNull(tenderDetailsVo);
            }
            tenderDetailsVosList = tenderDetailsVos;
            Boolean aBoolean = gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVos);
        }
        return tenderDetailsVosList.size();
    }
}
