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.api.vo.Result;
import com.trs.ggzyexchange.entity.*;
import com.trs.ggzyexchange.enums.ClassIfy;
import com.trs.ggzyexchange.service.ChangeitembulletinService;
import com.trs.ggzyexchange.service.GcNoticeandfileService;
import com.trs.ggzyexchange.service.TenderDetailsVoService;
import com.trs.ggzyexchange.service.ZcAlternationeNoticeService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 更正公告 前端控制器
 * </p>
 *
 * @author trs
 * @since 2023-03-03
 */
@RestController
@RequestMapping("/zc-alternatione-notice")
public class ZcAlternationeNoticeController extends BaseController {

    @Autowired
    private ZcAlternationeNoticeService zcAlternationeNoticeService;

    @Autowired
    private GcNoticeandfileService gcNoticeandfileService;

    @Autowired
    private TenderDetailsVoService tenderDetailsVoService;



    //@GetMapping(value = "/queryPageListAll")
    public Result<IPage<TenderDetailsVo>> queryPageListAll(
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
            HttpServletRequest req
    ){
        Page<ZcAlternationeNotice> page = new Page<ZcAlternationeNotice>(pageNo, pageSize);
        IPage<TenderDetailsVo> tenderDetailsVoIPage = zcAlternationeNoticeService.queryZcAlternationeNoticeAllList(page);
        for (TenderDetailsVo record : tenderDetailsVoIPage.getRecords()) {
            record.setNoticeTypeCode(ClassIfy.CORRECTION_ANNOUNCEMENT.getCode());
            record.setNoticeTypeName(ClassIfy.CORRECTION_ANNOUNCEMENT.getName());
            record.setTransactionTypeCode(ClassIfy.GOVERNMENT_PROCUREMENT.getCode());
            record.setTransactionTypeName(ClassIfy.GOVERNMENT_PROCUREMENT.getName());
            record = tenderDetailsVoService.getTenderDetailsVoAllOrther(record);
            TenderDetailsVoUtils.isNull(record);
        }
        return Result.OK(tenderDetailsVoIPage);
    }

    //@GetMapping(value = "/queryPageListUpdateEs")
    public Integer queryPageListUpdateEs() throws JsonProcessingException {
        int count = zcAlternationeNoticeService.count();
        Integer pageNo = 1;
        Integer pageSize = 1000;
        Integer pageNum = (int)Math.ceil((double)count/pageSize);
        List<TenderDetailsVo> tenderDetailsVos = new ArrayList<TenderDetailsVo>();
        for(int i = 1; i <= pageNum;i++){
            List<TenderDetailsVo> tenderDetailsVoListAll = getTenderDetailsVoListAll(i, pageSize);
            Boolean aBoolean = gcNoticeandfileService.parseTenderDetailsVo(tenderDetailsVoListAll);
        }
        return tenderDetailsVos.size();
    }
    public List<TenderDetailsVo> getTenderDetailsVoListAll(Integer pageNo,Integer pageSize){
        Page<ZcAlternationeNotice> page = new Page<ZcAlternationeNotice>(pageNo, pageSize);
        IPage<TenderDetailsVo> tenderDetailsVoIPage = zcAlternationeNoticeService.queryZcAlternationeNoticeAllList(page);
        for (TenderDetailsVo record : tenderDetailsVoIPage.getRecords()) {
            record.setNoticeTypeCode(ClassIfy.CORRECTION_ANNOUNCEMENT.getCode());
            record.setNoticeTypeName(ClassIfy.CORRECTION_ANNOUNCEMENT.getName());
            record.setTransactionTypeCode(ClassIfy.GOVERNMENT_PROCUREMENT.getCode());
            record.setTransactionTypeName(ClassIfy.GOVERNMENT_PROCUREMENT.getName());
            record = tenderDetailsVoService.getTenderDetailsVoAllOrther(record);
            TenderDetailsVoUtils.isNull(record);
        }
        return tenderDetailsVoIPage.getRecords();
    }



}
