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

import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PostMapping;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.model.MatterQuery;
import com.mortals.xhx.module.matter.service.MatterService;
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;
/**
*
* 基础事项
*
* @author zxfei
* @date 2022-01-12
*/
@RestController
@RequestMapping("matter")
public class MatterController extends BaseCRUDJsonMappingController<MatterService,MatterForm,MatterEntity,Long> {

    @Autowired
    private ParamService paramService;

    public MatterController(){
        super.setFormClass(MatterForm.class);
        super.setModuleDesc( "基础事项");
    }

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


    /**
     * 添加站点
     */
    @PostMapping(value = "addMatterToSite")
    public String addMatterToSite(@RequestParam(value = "matterIds") String matterIds, @RequestParam(value = "siteId") Long siteId) {
        JSONObject jsonObject = new JSONObject();
        Map<String, Object> model = new HashMap<String, Object>();
        try {
            this.service.addMatterToSite(matterIds,siteId,getContext());
            jsonObject.put(KEY_RESULT_DATA, model);
            jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
        } 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();
    }

}