package com.mortals.xhx.modules.information.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.feign.ElasticsearchClient;
import com.mortals.xhx.modules.information.model.InformationEntity;
import com.mortals.xhx.modules.information.service.InformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;


/**
* <p>Title: 办件信息</p>
* <p>Description: InformationController  </p>
* <p>Copyright: Copyright &reg;  </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
@RestController
@RequestMapping("/information")
public class InformationController extends BaseCRUDJsonController<InformationService, InformationForm, InformationEntity,Long> {

//    @Autowired
//    private ElasticsearchClient elasticsearchClient;


    public InformationController(){
        super.setFormClass(InformationForm.class);
        super.setModuleDesc( "办件信息");
    }

    @Override
    protected void init(HttpServletRequest request, HttpServletResponse response, InformationForm form, Map<String, Object> model, Context context) {
        this.addDict(model, "isReport", IBaseEnum.getEnumMap(YesNoEnum.class));
        this.addDict(model, "isSuccess", IBaseEnum.getEnumMap(YesNoEnum.class));
    }



    /**
    * 查询办件信息
    */
    @PostMapping(value="list")
    public String list( InformationForm form) {
    try{
        //数据量过大时，查询效率低下
        return super.list(form);
        //调用es查询接口(目前分页方式为浅分页，分页量超过1W条时，建议使用深分页，但深分页不支持跳页查询)
        //return  elasticsearchClient.queryEla(form.getPageInfo().getCurrPage(),form.getPageInfo().getPrePageResult()).toString();
    }catch(Exception e){
        log.error("查询办件信息列表错误",e);
        JSONObject ret = new JSONObject();
        ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
        ret.put(KEY_RESULT_MSG, super.convertException(e));
        return ret.toJSONString();
        }
    }
    /**
    * 添加办件信息
    */
    @PostMapping(value="add")
    public String add(HttpServletRequest request, HttpServletResponse response, InformationForm form) {
        try{
            return super.add(form);
        }catch(Exception e){
            log.error("添加办件信息错误",e);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            ret.put(KEY_RESULT_MSG, super.convertException(e));
            return ret.toJSONString();
        }
    }
    /**
    * 编辑办件信息
    */
    @PostMapping(value="edit")
    public String edit(HttpServletRequest request, HttpServletResponse response, InformationForm form) {
        try{
            return super.edit(form);
        }catch(Exception e){
            log.error("编辑办件信息错误",e);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            ret.put(KEY_RESULT_MSG, super.convertException(e));
            return ret.toJSONString();
        }
    }
    /**
    * 保存办件信息
    */
    @PostMapping(value="save")
    public String save(HttpServletRequest request, HttpServletResponse response, InformationForm form) {
        try{
            return super.save(form);
        }catch(Exception e){
            log.error("保存办件信息错误",e);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            ret.put(KEY_RESULT_MSG, super.convertException(e));
            return ret.toJSONString();
        }
    }
    /**
    * 删除办件信息
    */
    @PostMapping(value="delete")
    public String delete(HttpServletRequest request, HttpServletResponse response, InformationForm form) {
        try{
            return super.delete(form);
        }catch(Exception e){
            log.error("删除办件信息错误",e);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            ret.put(KEY_RESULT_MSG, super.convertException(e));
            return ret.toJSONString();
        }
    }
    /**
    * 查看办件信息
    */
    @PostMapping(value="view")
    public String view(HttpServletRequest request, HttpServletResponse response, InformationForm form) {
        try{
            return super.view(form);
        }catch(Exception e){
            log.error("查看办件信息错误",e);
            JSONObject ret = new JSONObject();
            ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
            ret.put(KEY_RESULT_MSG, super.convertException(e));
            return ret.toJSONString();
        }
    }






}