package cn.gyee.tamplate.controller.analysis;

import cn.gyee.tamplate.config.R;
import cn.gyee.tamplate.model.vo.AnalysisMainVo;
import cn.gyee.tamplate.service.analysis.AnalysisNewService;
import cn.gyee.tamplate.util.DateUtils;
import cn.gyee.tamplate.util.common.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName : AnalysisNewController
 * @Author : xieshengjie
 * @Date: 2021/3/17 21:13
 * @Description : 统计分析controller
 */
@RestController
@RequestMapping("//analysisplus")
public class AnalysisNewController {
    @Resource
    private AnalysisNewService analysisNewService;


    /**
     * 首页list
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public List<AnalysisMainVo> list(
            @RequestParam(value = "beginDate",required = true)String beginDate,
            @RequestParam(value = "endDate",required = true)String endDate){
        List<AnalysisMainVo> resultList = analysisNewService.analysismainlist(beginDate,endDate);
        return resultList;
    }

    /**
     * 首页确认
     * @param vo
     */
    @PostMapping("/commit")
    @CrossOrigin(origins = "*", maxAge = 3600)
    public void commit(@RequestBody AnalysisMainVo vo){
        analysisNewService.commit(vo);
    }


    /**
     * 表底查询
     * @param theday
     * @param wpid
     * @return
     */
    @GetMapping("/bdzlist")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public List<Object> bdzlist(
            @RequestParam(value = "theday",required = true)String theday,
            @RequestParam(value = "wpid",required = true)String wpid) throws IllegalAccessException, IntrospectionException, InvocationTargetException {
        List<Object> bdzlist =analysisNewService.bdzlist(theday,wpid);
        return bdzlist;
    }

    /**
     * 统计分析查询
     * @param theday
     * @param wpid
     * @param identity
     * @return
     */
    @GetMapping("/tjfxlist")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public List<Object>  tjfxlist(
            @RequestParam(value = "theday",required = true)String theday,
            @RequestParam(value = "wpid",required = true)String wpid,
            @RequestParam(value = "identity",required = true) Integer identity) {
        List<Object> tjfxlist = analysisNewService.tjfxlist(theday, wpid, identity);
        return tjfxlist;
    }

    /**
     * 表底值修改
     * @param bdzVo
     */
    @PostMapping("/bdzupdate")
    @CrossOrigin(origins = "*", maxAge = 3600)
    public void   bdzupdate(@RequestBody Map<String,Object> bdzVo) {
        if (StringUtils.isNotEmpty(bdzVo))
            analysisNewService.updateBdz(bdzVo);
    }

    /**
     * 统计分析修改
     * @param tjfxVo
     */
    @PostMapping("/tjfxupdate")
    @CrossOrigin(origins = "*", maxAge = 3600)
    public void   tjfxupdate(@RequestBody List<Map<String,Object>> tjfxVo) {
        if (StringUtils.isNotEmpty(tjfxVo))
            analysisNewService.updateTjfx(tjfxVo);
    }
}
