admin
2022-05-12 fa705507ba574c857b1667553737d23b1b7ff495
src/main/resources/code/service/app/src/main/java/com/ks/app/controller/admin/config/SystemConfigAdminController.java
@@ -2,8 +2,12 @@
import com.google.gson.*;
import com.ks.app.entity.config.SystemConfig;
import com.ks.app.entity.config.SystemConfigKey;
import com.ks.app.entity.config.SystemConfigType;
import com.ks.app.service.inter.config.SystemConfigService;
import com.ks.app.service.query.config.SystemConfigQuery;
import com.ks.app.vo.AcceptAdminData;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -25,15 +29,15 @@
    private SystemConfigService systemConfigService;
    private String loadPrint(String callback, String root){
          return root;
    private String loadPrint(String callback, String root) {
        return root;
    }
    @ResponseBody
    @RequestMapping("list")
    public String list(SystemConfigQuery query, int page, int limit, String callback) {
        List<SystemConfig> list = systemConfigService.list(query,page,limit);
        long count = systemConfigService.count(query);
        List<SystemConfig> list = systemConfigService.listByType(query.getType() == null ? SystemConfigType.common : query.getType());
        long count = list.size();
        JSONObject data = new JSONObject();
        Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@@ -50,11 +54,12 @@
    @ResponseBody
    @RequestMapping("add")
    public String add(SystemConfig bean, HttpSession session, String callback) {
        try{
    public String add(SystemConfig bean, AcceptAdminData acceptAdminData, String callback) {
        try {
            bean.setSystem(acceptAdminData.getSystem());
            systemConfigService.add(bean);
            return loadPrint(callback, JsonUtil.loadTrueResult(""));
        }catch(Exception e){
        } catch (Exception e) {
            return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage()));
        }
    }
@@ -63,7 +68,7 @@
    @RequestMapping("get")
    public String get(String id, HttpSession session, String callback) {
        SystemConfig entity = systemConfigService.get(id);
        if (entity !=null){
        if (entity != null) {
            return loadPrint(callback, JsonUtil.loadTrueResult(entity));
        } else {
            return loadPrint(callback, JsonUtil.loadFalseResult("ID不存在"));
@@ -73,17 +78,33 @@
    @ResponseBody
    @RequestMapping("update")
    public String update(SystemConfig bean, HttpSession session,String callback) {
    public String update(SystemConfig bean, HttpSession session, String callback) {
        if (bean.getId() == null) {
            return loadPrint(callback, JsonUtil.loadFalseResult("ID不能为空"));
        }
        try{
        try {
            systemConfigService.update(bean);
        }catch(Exception e){
        } catch (Exception e) {
            return loadPrint(callback, JsonUtil.loadFalseResult(e.getMessage()));
        }
        return loadPrint(callback, JsonUtil.loadTrueResult(""));
    }
    @ResponseBody
    @RequestMapping("getKeyList")
    public String getKeyList(SystemConfigType type) {
        JSONArray array = new JSONArray();
        for (SystemConfigKey key : SystemConfigKey.values()) {
            if (key.getType() == (type == null ? SystemConfigType.common : type)) {
                JSONObject data = new JSONObject();
                data.put("key", key.name());
                data.put("value", key.getDesc());
                array.add(data);
            }
        }
        return JsonUtil.loadTrueResult(array);
    }
}