package com.mortals.xhx.module.window.web;

import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.common.code.FillStatusEnum;
import com.mortals.xhx.common.code.SelfLevelEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.window.model.WindowPerformEntity;
import com.mortals.xhx.module.window.model.WindowPerformQuery;
import com.mortals.xhx.module.window.model.vo.WindowPerformAllVo;
import com.mortals.xhx.module.window.service.WindowPerformService;
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.Arrays;
import java.util.List;
import java.util.Map;
/**
*
* 大厅窗口考核登记信息
*
* @author zxfei
* @date 2024-01-17
*/
@RestController
@RequestMapping("window/perform")
public class WindowPerformController extends BaseCRUDJsonBodyMappingController<WindowPerformService,WindowPerformEntity,Long> {


    public WindowPerformController(){
        super.setModuleDesc( "大厅窗口考核登记信息");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        this.addDict(model, "selfLevel", SelfLevelEnum.getEnumMap());
        this.addDict(model, "fillStatus", FillStatusEnum.getEnumMap());
        super.init(model, context);
    }


    /**
     * 查询所有汇总表
     */
    @PostMapping(value = "allList")
    public String getAllList(@RequestBody WindowPerformQuery query) {
        JSONObject jsonObject = new JSONObject();
        String busiDesc = "查询所有汇总表" + this.getModuleDesc();
        try {
            query.setOrderColList(Arrays.asList(new OrderCol("fillDate", OrderCol.DESCENDING)));
            Rest<List<WindowPerformAllVo>> allRest = this.service.getAllList(query, getContext());
            //   Rest<List<String>> performMonthRest = this.service.getPerformMonthList(getContext());
            if(YesNoEnum.YES.getValue()== allRest.getCode()){
                jsonObject.put(KEY_RESULT_DATA, allRest.getData());
                jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
                jsonObject.put(KEY_RESULT_MSG, "查询所有汇总表！");
            }
            recordSysLog(request, busiDesc + " 【成功】");
        } catch (Exception e) {
            log.error("获取异常", e);
            jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
        }
        return jsonObject.toJSONString();
    }

}