package com.ruoyi.web.controller.projectV2.common;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.projectV2.*;
import com.ruoyi.system.domain.projectV2.Vo.ZpVo;
import com.ruoyi.system.service.projectV2.IZsyzLcjlService;
import com.ruoyi.system.service.projectV2.IZsyzProjectDeptService;
import com.ruoyi.system.service.projectV2.IZsyzSbbzbService;
import com.ruoyi.system.service.projectV2.common.IZsyzCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.ruoyi.common.constant.CommonConstants.*;

/**
 * 公共Controller
 *
 * @author 博曼
 * @date 2023-02-22
 */
@RestController
@RequestMapping("/projectV2/common")
public class ZsyzCommonController extends BaseController {
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IZsyzSbbzbService zsyzSbbzbService;

    @Autowired
    private IZsyzCommonService zsyzCommonService;


    /**
     * 首页统计
     *
     * @return
     */
    @GetMapping("/census")
    public AjaxResult census(ZsyzSbbzb zsyzSbbzb) {
        return zsyzCommonService.census(zsyzSbbzb);
    }

    /**
     * 首页统计折线图
     *
     * @return
     */
    @GetMapping("/censusXy")
    public AjaxResult censusXy() {
        return zsyzCommonService.censusXy();
    }

    /***
     * 招商引资_情况月统计表
     * @param year 年
     * @param month 月
     * @return
     */
    @GetMapping("/statistics/month")
    public AjaxResult statisticsMonth(String year, String month) {
        return  AjaxResult.success(zsyzCommonService.statisticsMonthNew(year,month));
    }

    /**
     * 生成项目编号接口
     *
     * @return
     */
    @GetMapping("/xmbh")
    public AjaxResult xmbh() {
        //获取当前日期
        String nowDate = DateUtils.dateTime();
        String xmbhDate = XMBH + nowDate;
        Integer cacheObject = redisCache.getCacheObject(xmbhDate);
        int number = 100;
        if (cacheObject != null) {
            number = cacheObject + 1;
        }
        StringBuffer stringBuffer = new StringBuffer(ZS);
        stringBuffer.append(nowDate).append(number);
        //生成一个项目编码
        redisCache.setCacheObject(xmbhDate, number);
        return AjaxResult.success(stringBuffer);
    }


    /**
     * 项目指派接口
     *
     * @return
     */
    @PostMapping("/xszp")
    @PreAuthorize("@ss.hasPermi('projectV2:common:xszp')")
    public AjaxResult xszp(@RequestBody ZpVo zpVo) {
        return zsyzCommonService.xszp(zpVo);
    }

    /**
     * 线索暂存/终止接口
     *
     * @return
     */
    @PostMapping("/xszc")
    @PreAuthorize("@ss.hasPermi('projectV2:common:xszc')")
    public AjaxResult xszc(@RequestBody ZsyzSbbzb zsyzSbbzb) {
        return toAjax(zsyzSbbzbService.updateZsyzSbbzbForZc(zsyzSbbzb));
    }


    /**
     * 招商中心项目审核/驳回接口
     * 参数是审核建议
     *
     * @return
     */
    @PostMapping("/xssh")
    @PreAuthorize("@ss.hasPermi('projectV2:common:xssh')")
    public AjaxResult xssh(@RequestBody ZsyzShyj zsyzShyj) {
        //所有审核需要往审核意见表插入数据
        return zsyzCommonService.xssh(zsyzShyj);
    }

    /**
     * Cjd的项目审核/驳回接口
     * 参数是审核建议
     *
     * @return
     */
    @PostMapping("/xsshCjd")
    @PreAuthorize("@ss.hasPermi('projectV2:common:xsshCjd')")
    public AjaxResult xsshCjd(@RequestBody ZsyzShyj zsyzShyj) {
        //所有审核需要往审核意见表插入数据
        return zsyzCommonService.xsshCjd(zsyzShyj);
    }

    /**
     * 要素部门的项目审核/驳回接口
     * 参数是审核建议
     *
     * @return
     */
    @PostMapping("/xsshYsbm")
    @PreAuthorize("@ss.hasPermi('projectV2:common:xsshYsbm')")
    public AjaxResult xsshYsbm(@RequestBody ZsyzShyj zsyzShyj) {
        //所有审核需要往审核意见表插入数据
        return zsyzCommonService.xsshYsbm(zsyzShyj);
    }


    /**
     * 项目撤回
     * 参数是项目
     *
     * @return
     */
    @PostMapping("/xsch")
    @PreAuthorize("@ss.hasPermi('projectV2:common:xsch')")
    public AjaxResult xsch(@RequestBody ZsyzSbbzb zsyzSbbzb) {
        return zsyzCommonService.xsch(zsyzSbbzb);
    }


    /**
     * 查询招商引资_审核意见列表/APP使用首页问题列表
     */

    @PostMapping("/wt")
    public TableDataInfo wt(@RequestBody ZsyzSbbzb zsyzSbbzb) {
        startPage();
        zsyzSbbzb.setXmStatus(THR);
        List<ZsyzSbbzb> list = zsyzSbbzbService.selectZsyzSbbzbList(zsyzSbbzb);
        return getDataTable(list);
    }

    /**
     *省库项目审核
     *
     * @return
     */
    @PostMapping("/sksh")
    @PreAuthorize("@ss.hasPermi('projectV2:common:sksh')")
    public AjaxResult sksh(@RequestBody ZsyzSkxm zsyzSkxm) {
        return zsyzCommonService.sksh(zsyzSkxm);
    }

    /**
     *获取省市
     *
     * @return
     */
    @GetMapping("/area/{pid}")
    public AjaxResult area(@PathVariable("pid") String pid ) {
        //所有审核需要往审核意见表插入数据
        return zsyzCommonService.area(pid);
    }
}
