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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseJsonBodyController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.feign.base.pdu.DeptPdu;
import com.mortals.xhx.feign.base.pdu.SitePdu;
import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.module.home.pdu.BasicSettingsPdu;
import com.mortals.xhx.module.home.pdu.HomeQueryPdu;
import org.springframework.beans.factory.annotation.Autowired;
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.*;

@RestController
@RequestMapping("setting")
public class BasicSettingsController extends BaseJsonBodyController {

    @Autowired
    private ParamService paramService;

    @PostMapping({"info"})
    public Rest<Object> list() {
        IUser user = this.getCurUser();
        if(user==null){
            throw new AppException("用户未登录");
        }
        Rest<Object> ret = new Rest();
        Map<String, Object> model = new HashMap();
        String busiDesc = "查询基础设置" ;

        int code=1;
        try {
            model.put("hotWords", paramService.getHotWords());
            model.put("printDisplay", paramService.getPrintDisplayQuantity());
            model.put("message_info", busiDesc + "成功");
            this.recordSysLog(this.request, busiDesc + " 【成功】");
        } catch (Exception var9) {
            code = -1;
            this.doException(this.request, busiDesc, model, var9);
        }

        ret.setCode(code);
        ret.setData(model);
        ret.setDict(model.get("dict"));
        ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
        return ret;
    }

    @PostMapping({"save"})
    public Rest<Object> deptList(@RequestBody BasicSettingsPdu queryPdu) {
        IUser user = this.getCurUser();
        if(user==null){
            throw new AppException("用户未登录");
        }
        Rest<Object> ret = new Rest();
        Map<String, Object> model = new HashMap();
        String busiDesc = "保存基础设置" ;

        int code=1;
        try {
            paramService.setHotWords(queryPdu.getHotWords());
            paramService.setPrintDisplayQuantity(queryPdu.getPrintDisplay());
            model.put("message_info", busiDesc + "成功");
            this.recordSysLog(this.request, busiDesc + " 【成功】");
        } catch (Exception var9) {
            code = -1;
            this.doException(this.request, busiDesc, model, var9);
        }

        ret.setCode(code);
        ret.setData(model);
        ret.setDict(model.get("dict"));
        ret.setMsg(model.get("message_info") == null ? "" : model.remove("message_info").toString());
        return ret;
    }
}
