package cn.com.countrygarden.bi.main.controller.ck;

import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.model.ck.CkPublicBenefits;
import cn.com.countrygarden.bi.main.service.ck.CkPublicBenefitsService;
import cn.com.countrygarden.bi.main.service.project.Scheduling.projectSchedu;
import cn.com.countrygarden.bi.main.service.propertyAgreement.PropertyAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;

/**
 * <p>
 *   公共收益数据表模块接口
 * </p>
 *
 * @author 吕伟峰
 * @date 2021-05-07
 * @version V1.0
 */
@RestController("CkPublicBenefitsController")
@RequestMapping("/api/ckPublicBenefits")
public class CkPublicBenefitsController extends BaseController {
    @Autowired
    private CkPublicBenefitsService ckPublicBenefitsService;

    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    public Result list(CkPublicBenefits ckPublicBenefits,
                       @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                       HttpServletRequest request) {
        return ckPublicBenefitsService.queryPageList(ckPublicBenefits,size,page,getAccessToken(request));
    }

    @GetMapping(value = "/one", produces = "application/json;charset=utf-8")
    public Result one(@RequestParam(value = "id") Integer id,
                      HttpServletRequest request) {
        return ckPublicBenefitsService.one(id,getAccessToken(request));
    }

    @PostMapping(value = "/add")
    public Result add(CkPublicBenefits ckPublicBenefits,
                            HttpServletRequest request) throws ParseException {
        return ckPublicBenefitsService.add(ckPublicBenefits, getAccessToken(request));
    }

    @PostMapping(value = "/edit")
    public Result edit(CkPublicBenefits ckPublicBenefits, HttpServletRequest request){
        return ckPublicBenefitsService.edit(ckPublicBenefits,getAccessToken(request));
    }

    @DeleteMapping(value = "/del")
    public Result del(@RequestParam(value = "id", required = true) Integer id,
                      HttpServletRequest request) {
        return ckPublicBenefitsService.del(id,getAccessToken(request));
    }

    @GetMapping(value = "/getRegionDate", produces = "application/json;charset=utf-8")
    public Result getRegionDate(HttpServletRequest request) {

        return Response.response(ckPublicBenefitsService.getRegionDate(getAccessToken(request)));
    }

    @GetMapping(value = "/getPojDate", produces = "application/json;charset=utf-8")
    public Result getPojDate(HttpServletRequest request,
                             @RequestParam(value = "organCode",required = true) String organCode) {

        return Response.response(ckPublicBenefitsService.getPojDate(getAccessToken(request),organCode));
    }

    @PostMapping(value = "/auto")
    public Result auto(@RequestParam(value = "orgCode") String orgCode,
                       @RequestParam(value = "commCode") String commCode,
                       @RequestParam(value = "createName") String createName,
                       @RequestParam(value = "year") String year,
                       HttpServletRequest request) throws ParseException {
        return ckPublicBenefitsService.auto(orgCode,commCode,createName,year,getAccessToken(request));
    }

    @PostMapping(value = "/getrevenue")
    public Result getrevenue(
                      HttpServletRequest request) throws IOException {
        return ckPublicBenefitsService.getrevenue( getAccessToken(request),request);
    }


    @Autowired
    private PropertyAgreementService propertyAgreementService;

    /**
     * http://localhost:8072/DPshow_depart/api/ckPublicBenefits/syncTest
     * @return
     */
    @Profile(value = {"dev","test"})
    @RequestMapping(value = "/syncTest", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Result syncTest(){
       // propertyAgreementService.synchronizeData();
        projectSchedu projectSc=new projectSchedu();
        projectSc.emergency();
        return Response.response();
    }
}