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

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.dto.ck.CkCleanerQueyr;
import cn.com.countrygarden.bi.main.model.ck.green.CkGreenBasic;
import cn.com.countrygarden.bi.main.service.ck.CkGreenExpandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 基础数据表-绿化业务逻辑层实现
 *
 * @author 李森林
 * @email www.justintoforest@gamail.com
 * @url
 * @date 2020-04-13
 */
@RestController("CkGreenController")
@RequestMapping("/api/ckGreen")
public class CkGreenController extends BaseController {
    @Autowired
    private CkGreenExpandService ckGreenService;

    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    public Result list(CkCleanerQueyr cleanerQueyr,
                       HttpServletRequest request) {
        return ckGreenService.queryPageList(cleanerQueyr,getAccessToken(request));
    }


    @PostMapping(value = "/addOrEdit")
    public Result addOrEdit(@RequestParam(value = "data", required = true) String data,
                            HttpServletRequest request) {
        return ckGreenService.addOrEdit(data, getAccessToken(request));
    }


    @DeleteMapping(value = "/del")
    public Result del(@RequestParam(value = "basicIds", required = true) List<Integer> basicIds,
                      @RequestParam(value = "dataClassification", required = false) String dataClassification,
                      HttpServletRequest request) {
        return ckGreenService.del(basicIds,dataClassification,getAccessToken(request));
    }

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

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

    @PostMapping(value = "/inherit", produces = "application/json;charset=utf-8")
    public Result inheritInfo(CkGreenBasic ckGreenBasic) {
        return Response.response(ckGreenService.inheritInfo(ckGreenBasic));
    }

    @GetMapping(value = "/statisticsProject", produces = "application/json;charset=utf-8")
    public Result statisticsProject(@RequestParam(value = "month", required = false) Integer month,
                                    @RequestParam(value = "year", required = false) Integer year) {
        return ckGreenService.statisticsProject(year,month);
    }

    @GetMapping(value = "/statisProjDetad", produces = "application/json;charset=utf-8")
    public Result statisProjDetad(@RequestParam(value = "page", required = false, defaultValue = "10") int page,
                                  @RequestParam(value = "size", required = false, defaultValue = "1") int size,
                                  @RequestParam(value = "type",required = false) String type,
                                  @RequestParam(value = "month", required = false) Integer month,
                                  @RequestParam(value = "year", required = false) Integer year) {
        return ckGreenService.statisProjDetad(year,month,type,page,size);
    }

    //锁定
    @PostMapping(value = "/locking", produces = "application/json;charset=utf-8")
    public Result locking(CkGreenBasic ckGreenBasic,HttpServletRequest request) {
        return Response.response(ckGreenService.locking(ckGreenBasic,getAccessToken(request)));
    }

    //解锁
    @PostMapping(value = "/unlock", produces = "application/json;charset=utf-8")
    public Result unlock(CkGreenBasic ckGreenBasic,HttpServletRequest request) {
        return Response.response(ckGreenService.unlock(ckGreenBasic,getAccessToken(request)));
    }

    //批量锁定
    @PostMapping(value = "/batchLock", produces = "application/json;charset=utf-8")
    public Result batchLock(@RequestParam(value = "basicIds",required = true) String basicIds,HttpServletRequest request) {
        return Response.response(ckGreenService.batchLock(basicIds,getAccessToken(request)));
    }

}