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.AppealStatInfo;
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 com.mortals.xhx.module.perform.model.PerformAttendAppealEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * h5 申诉
 *
 * @author: zxfei
 * @date: 2023/7/7 15:08
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/appeal")
public class AppealApiController 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 = "stat")
    public Rest<AppealStatInfo> appealStat() {
        String busiDesc = "H5个人申诉绩效统计";
        Rest<AppealStatInfo> 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 = "list")
    public Rest<List<PerformAttendAppealEntity>> performList(@RequestBody AppealReq appealReq) {
        String busiDesc = "个人申诉列表";
        Rest<List<PerformAttendAppealEntity>> rest = Rest.ok(busiDesc + " 【成功】");
        try {
            if (ObjectUtils.isEmpty(appealReq.getApperalStartDate())) {
                //未设置时间的情况，默认为当月
                appealReq.setApperalStartDate(DateUtil.beginOfMonth(new Date()).toDateStr());
                appealReq.setAppealEndDate(DateUtil.today());
            }

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


    /**
     * 申诉详细
     */
    @PostMapping(value = "info")
    public Rest<PerformAttendAppealEntity> performInfo(@RequestBody AppealReq appealReq) {
        String busiDesc = "个人申诉详细";
        Rest<PerformAttendAppealEntity> rest = Rest.ok(busiDesc + " 【成功】");
        try {
            if (ObjectUtils.isEmpty(appealReq.getId())) {
                throw new AppException("详细查询id不能为空!");
            }

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


    /**
     * 申诉新增
     */
    @PostMapping(value = "save")
    public Rest<String> appealSave(@RequestBody PerformAttendAppealEntity appealEntity) {
        String busiDesc = "个人申诉新增";
        Rest<String> rest = Rest.ok(busiDesc + " 【成功】");
        try {

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


    public static void main(String[] args) {

    }

}
