package com.mortals.xhx.module.sheet.web;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.feign.site.ISiteFeign;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.sheet.model.SheetMatterEntity;
import com.mortals.xhx.module.sheet.service.SheetMatterService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 基础事项
*
* @author zxfei
* @date 2022-09-27
*/
@RestController
@RequestMapping("sheet/matter")
public class SheetMatterController extends BaseCRUDJsonBodyMappingController<SheetMatterService,SheetMatterEntity,Long> {

    @Autowired
    private ParamService paramService;
    @Autowired
    private ISiteFeign siteFeign;

    public SheetMatterController(){
        super.setModuleDesc( "基础事项");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        this.addDict(model, "appoveObjectShow", paramService.getParamBySecondOrganize("SheetMatter","appoveObjectShow"));
        this.addDict(model, "operatScopeShow", paramService.getParamBySecondOrganize("SheetMatter","operatScopeShow"));
        this.addDict(model, "appoveTimeLimitShow", paramService.getParamBySecondOrganize("SheetMatter","appoveTimeLimitShow"));
        this.addDict(model, "handleType", paramService.getParamBySecondOrganize("SheetMatter","handleType"));
        this.addDict(model, "isChargesShow", paramService.getParamBySecondOrganize("SheetMatter","isChargesShow"));
        this.addDict(model, "certificationLevelsShow", paramService.getParamBySecondOrganize("SheetMatter","certificationLevelsShow"));
        this.addDict(model, "windowToTheSceneNum", paramService.getParamBySecondOrganize("SheetMatter","windowToTheSceneNum"));
        this.addDict(model, "isOnlineSubscribeShow", paramService.getParamBySecondOrganize("SheetMatter","isOnlineSubscribeShow"));
        this.addDict(model, "isExpressTakeShow", paramService.getParamBySecondOrganize("SheetMatter","isExpressTakeShow"));
        this.addDict(model, "isProvinceAcquisitionShow", paramService.getParamBySecondOrganize("SheetMatter","isProvinceAcquisitionShow"));
        this.addDict(model, "isApplyProvinceShow", paramService.getParamBySecondOrganize("SheetMatter","isApplyProvinceShow"));
        this.addDict(model, "onlineType", paramService.getParamBySecondOrganize("SheetMatter","onlineType"));
        this.addDict(model, "onlineToTheSceneNum", paramService.getParamBySecondOrganize("SheetMatter","onlineToTheSceneNum"));
        this.addDict(model, "onlineOperatDeep", paramService.getParamBySecondOrganize("SheetMatter","onlineOperatDeep"));
        this.addDict(model, "isExpressTakeOnlineShow", paramService.getParamBySecondOrganize("SheetMatter","isExpressTakeOnlineShow"));
        this.addDict(model, "isDoorTakeShow", paramService.getParamBySecondOrganize("SheetMatter","isDoorTakeShow"));
        this.addDict(model, "eventTypeShow", paramService.getParamBySecondOrganize("SheetMatter","eventTypeShow"));
        this.addDict(model, "performHierarchyShow", paramService.getParamBySecondOrganize("SheetMatter","performHierarchyShow"));
        this.addDict(model, "powerSourceShow", paramService.getParamBySecondOrganize("SheetMatter","powerSourceShow"));
        this.addDict(model, "performDeptTypeShow", paramService.getParamBySecondOrganize("SheetMatter","performDeptTypeShow"));
        this.addDict(model, "goveServiceCenterShow", paramService.getParamBySecondOrganize("SheetMatter","goveServiceCenterShow"));
        this.addDict(model, "isConvenientCenterShow", paramService.getParamBySecondOrganize("SheetMatter","isConvenientCenterShow"));
        this.addDict(model, "terminalHandle", paramService.getParamBySecondOrganize("SheetMatter","terminalHandle"));
        this.addDict(model, "isOnline", paramService.getParamBySecondOrganize("SheetMatter","isOnline"));
        this.addDict(model, "isOnlinePayShow", paramService.getParamBySecondOrganize("SheetMatter","isOnlinePayShow"));
        this.addDict(model, "entrustmentDepartmen", paramService.getParamBySecondOrganize("SheetMatter","entrustmentDepartmen"));
        this.addDict(model, "matterStatus", paramService.getParamBySecondOrganize("SheetMatter","matterStatus"));
        this.addDict(model, "type", paramService.getParamBySecondOrganize("SheetMatter","type"));
        this.addDict(model, "mattertype", paramService.getParamBySecondOrganize("SheetMatter","mattertype"));
        this.addDict(model, "parson", paramService.getParamBySecondOrganize("SheetMatter","parson"));
        this.addDict(model, "lengal", paramService.getParamBySecondOrganize("SheetMatter","lengal"));
        this.addDict(model, "isRecommend", paramService.getParamBySecondOrganize("SheetMatter","isRecommend"));
        super.init(model, context);
    }


    @Override
    protected void doListBefore(SheetMatterEntity query, Map<String, Object> model, Context context) throws AppException {
        if(!ObjectUtils.isEmpty(query.getMatterName())){
            query.setMatterName("%"+query.getMatterName()+"%");
        }
        Rest<SitePdu> rest = siteFeign.info(query.getSiteId());
        if(rest.getCode()== YesNoEnum.YES.getValue()){
            query.setSiteId(null);
            query.setAreaCode(rest.getData().getAreaCode());
        }
        super.doListBefore(query, model, context);
    }
}