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

import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.window.model.WindowPerformSummaryEntity;
import com.mortals.xhx.module.window.model.WindowPerformSummaryQuery;
import com.mortals.xhx.module.window.service.WindowPerformSummaryService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* 窗口绩效汇总登记
*
* @author zxfei
* @date 2025-03-10
*/
@RestController
@RequestMapping("window/perform/summary")
public class WindowPerformSummaryController extends BaseCRUDJsonBodyMappingController<WindowPerformSummaryService,WindowPerformSummaryEntity,Long> {

    @Autowired
    private ParamService paramService;

    public WindowPerformSummaryController(){
        super.setModuleDesc( "窗口绩效汇总登记");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        Map<String, String> suggestion = new HashMap<>();
        suggestion.put("0","无");
        suggestion.put("1","红旗窗口");
        this.addDict(model, "suggestion", suggestion);
        super.init(model, context);
    }

//    @Override
//    protected void doListAfter(WindowPerformSummaryEntity query, List<WindowPerformSummaryEntity> list, Context context) throws AppException {
//        super.doListAfter(query, list, context);
//        if(CollectionUtils.isEmpty(list)) {
//            if (query.getYear() != null && query.getMonth() != null) {
//                this.service.initWindowPerformSummary(query.getYear(),query.getMonth());
//            }
//        }
//    }

    @Override
    protected void doListBefore(WindowPerformSummaryEntity query, Map<String, Object> model, Context context) throws AppException {
        super.doListBefore(query, model, context);
        if(query.getYear()!=null && query.getMonth()!=null) {
            List<WindowPerformSummaryEntity> list = this.service.find(new WindowPerformSummaryQuery().year(query.getYear()).month(query.getMonth()));
            if (CollectionUtils.isEmpty(list)) {
                service.initWindowPerformSummary(query.getYear(), query.getMonth());
            }
        }else {
            throw new AppException("汇总年度和月份不能为空");
        }
    }

}