package com.mortals.xhx.busiz.web;


import cn.hutool.core.date.DateUtil;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseJsonBodyController;
import com.mortals.xhx.busiz.req.AppealReq;
import com.mortals.xhx.busiz.req.PerformReq;
import com.mortals.xhx.busiz.rsp.PerformDetailInfo;
import com.mortals.xhx.busiz.rsp.PerformInfo;
import com.mortals.xhx.busiz.rsp.PerformStatInfo;
import com.mortals.xhx.common.code.PerformTypeEnum;
import com.mortals.xhx.module.check.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 *  h5 绩效
 * @author: zxfei
 * @date: 2023/7/7 13:20
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/perform")
public class PerformApiController extends BaseJsonBodyController {

    @Autowired
    private CheckAttendRecordService checkAttendRecordService;
    @Autowired
    private CheckReviewRecordService checkReviewRecordService;
    @Autowired
    private CheckComplainRecordService checkComplainRecordService;
    @Autowired
    private CheckEffectRecordService checkEffectRecordService;
    @Autowired
    private CheckGoworkRecordService checkGoworkRecordService;
    @Autowired
    private CheckOtherRecordService checkOtherRecordService;


    /**
     * 个人当天绩效统计
     */
    @PostMapping(value = "perform/stat")
    public Rest<PerformStatInfo> performStat() {
        String busiDesc = "H5 个人绩效统计";
        Rest<PerformStatInfo> rest = Rest.ok(busiDesc + " 【成功】");
        try {
            //todo 查询当前登录人的绩效分数
            recordSysLog(request, busiDesc + " 【成功】");
        } catch (Exception e) {
            log.error(busiDesc, e);
            rest = Rest.fail(super.convertException(e));
        }
        return rest;
    }


    /**
     * 个人当月绩效加分扣分列表
     */
    @PostMapping(value = "perform/list")
    public Rest<List<PerformInfo>> performList(@RequestBody PerformReq performReq) {
        String busiDesc = "个人绩效列表";
        Rest<List<PerformInfo>> rest = Rest.ok(busiDesc + " 【成功】");
        try {
            if (ObjectUtils.isEmpty(performReq.getPerformStartDate())) {
                //未设置时间的情况，默认为当月
                performReq.setPerformStartDate(DateUtil.beginOfMonth(new Date()).toDateStr());
                performReq.setPerformEndDate(DateUtil.today());
            }
            //todo 查询全部扣分绩效
            if (PerformTypeEnum.全部.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.考勤绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.评价差评绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.评价投诉绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.办件绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.效能绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.其它绩效.getValue().equals(performReq.getPerformType())) {

            } else {
                throw new AppException("不支持当前绩效类型");
            }


            recordSysLog(request, busiDesc + " 【成功】");
        } catch (Exception e) {
            log.error(busiDesc, e);
            rest = Rest.fail(super.convertException(e));
        }
        return rest;
    }


    /**
     * 详细
     */
    @PostMapping(value = "perform/info")
    public Rest<PerformDetailInfo> performInfo(@RequestBody PerformReq performReq) {
        String busiDesc = "个人绩效增减详细";
        Rest<PerformDetailInfo> rest = Rest.ok(busiDesc + " 【成功】");
        try {
            if (ObjectUtils.isEmpty(performReq.getId())) {
                throw new AppException("详细查询id不能为空!");
            }
            //todo 查询全部扣分绩效详细
            if (PerformTypeEnum.考勤绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.评价差评绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.评价投诉绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.办件绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.效能绩效.getValue().equals(performReq.getPerformType())) {

            } else if (PerformTypeEnum.其它绩效.getValue().equals(performReq.getPerformType())) {

            } else {
                throw new AppException("不支持当前绩效类型");
            }


            recordSysLog(request, busiDesc + " 【成功】");
        } catch (Exception e) {
            log.error(busiDesc, e);
            rest = Rest.fail(super.convertException(e));
        }
        return rest;
    }

    public static void main(String[] args) {

    }


}
