yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java
@@ -7,13 +7,19 @@
import javax.annotation.Resource;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import com.yeshi.fanli.entity.common.Config;
import com.yeshi.fanli.service.AdminUserService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import org.yeshi.utils.JsonUtil;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@Controller
@RequestMapping("admin/new/api/v1/config")
@@ -21,6 +27,10 @@
   
   @Resource
   private ConfigService configService;
   @Resource
   private AdminUserService adminUserService;
   
   @RequestMapping(value = "getConfigList", method = RequestMethod.POST)
   public void getConfigList(PrintWriter out){
@@ -47,4 +57,90 @@
      out.print(JsonUtil.loadTrueResult("修改成功"));
      return;
   }
   /**
    * 查询列表 - 新后台
    * @param callback
    * @param key 查询词  名称
    * @param pageIndex
    * @param out
    */
   @RequestMapping(value = "getNewConfigList")
   public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out){
      try {
         if (pageIndex == null || pageIndex < 0){
            pageIndex = 1;
         }
         List<Config> list =  configService.listObjects(key, pageIndex);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无更多数据"));
            return;
         }
         int pageSize = Constant.PAGE_SIZE;
         int count = configService.getCount(key, pageIndex);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
         JSONObject data = new JSONObject();
         data.put("pe", pe);
         data.put("result_list", list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    * 参数修改 - 新后台
    * @param callback
    * @param config
    * @param out
    */
   @RequestMapping(value = "saveModify")
   public void saveModify(String callback, Config config, PrintWriter out) {
      Long id = config.getId();
      if (id == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID不能为空"));
         return;
      }
      try {
         Config crentconfig = configService.getConfig(id);
         if (crentconfig == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作数据已不存在"));
            return;
         }
         if (StringUtil.isNullOrEmpty(config.getName()) || StringUtil.isNullOrEmpty(config.getValue())) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("说明、有效值不能为空"));
            return;
         }
         crentconfig.setName(config.getName());
         crentconfig.setValue(config.getValue());
         if (!StringUtil.isNullOrEmpty(config.getBeizhu())) {
            crentconfig.setBeizhu(config.getBeizhu());
         }
         configService.update(crentconfig);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("修改成功"));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("修改失败"));
         e.printStackTrace();
      }
   }
}