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.FeedbackReq;
import com.mortals.xhx.busiz.rsp.AppealStatInfo;
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/feedback")
public class FeedbackApiController 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 = "feedback/list")
    public Rest<List<PerformAttendAppealEntity>> feedbackList(@RequestBody FeedbackReq feedbackReq) {
        String busiDesc = "个人反馈列表";
        Rest<List<PerformAttendAppealEntity>> rest = Rest.ok(busiDesc + " 【成功】");
        try {
            if (ObjectUtils.isEmpty(feedbackReq.getFeedbackStatus())) {
                //未设置时间的情况，默认为当月
                feedbackReq.setFeedBackStartDate(DateUtil.beginOfMonth(new Date()).toDateStr());
                feedbackReq.setFeedBackEndDate(DateUtil.today());
            }

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


    /**
     * 反馈详细
     */
    @PostMapping(value = "feedback/question")
    public Rest<PerformAttendAppealEntity> performDetail(@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 = "appeal/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) {

    }

}
