|
|
package com.ui.ctrl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ui.contants.HttpUriContants;
|
|
|
import com.ui.http.HttpRestClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
/**
|
|
|
* Created by fruwei on 2016/6/16.
|
|
|
*/
|
|
|
@Controller
|
|
|
@RequestMapping("type")
|
|
|
public class TypeCtrl {
|
|
|
Logger logger = LoggerFactory.getLogger(TypeCtrl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private HttpRestClient httpClient;
|
|
|
|
|
|
@RequestMapping("/all")
|
|
|
@ResponseBody
|
|
|
public String getAllType() {
|
|
|
String strType = "";
|
|
|
|
|
|
logger.debug("get all type");
|
|
|
|
|
|
strType = httpClient.defaultGet(HttpUriContants.TYPE_GET_ALL, String.class);
|
|
|
|
|
|
logger.info("all type: {}", strType);
|
|
|
|
|
|
return strType;
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/add")
|
|
|
@ResponseBody
|
|
|
public String addType(@RequestParam String name, @RequestParam int pid, @RequestParam int isleaf) {
|
|
|
|
|
|
String rel;
|
|
|
logger.info("add type name:{},pid:{},isLeaf{}", name, pid, isleaf);
|
|
|
|
|
|
JSONObject req=new JSONObject();
|
|
|
req.put("typeName",name);
|
|
|
req.put("typeParentId",pid);
|
|
|
req.put("typeIsLeaf",isleaf);
|
|
|
|
|
|
rel = httpClient.defaultPost(HttpUriContants.TYPE_ADD, req,String.class);
|
|
|
|
|
|
logger.info("all type: {}", rel);
|
|
|
|
|
|
|
|
|
|
|
|
return rel;
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/del")
|
|
|
@ResponseBody
|
|
|
public String delType(@RequestParam int id) {
|
|
|
String rel = "";
|
|
|
logger.info("update type id {} ", id);
|
|
|
rel = httpClient.defaultGet(HttpUriContants.TYPE_DEL+"/"+id,String.class);
|
|
|
logger.info("update type: {}", rel);
|
|
|
return "ok";
|
|
|
}
|
|
|
|
|
|
|
|
|
@RequestMapping("/update")
|
|
|
@ResponseBody
|
|
|
public String updateType(@RequestParam int id, @RequestParam String name) {
|
|
|
String rel = "";
|
|
|
|
|
|
logger.info("update type id {} ,name {}", id, name);
|
|
|
|
|
|
JSONObject req=new JSONObject();
|
|
|
|
|
|
req.put("typeId",id);
|
|
|
req.put("typeName",name);
|
|
|
|
|
|
rel = httpClient.defaultPost(HttpUriContants.TYPE_UPDATE, req,String.class);
|
|
|
logger.info("update type: {}", rel);
|
|
|
|
|
|
return rel;
|
|
|
}
|
|
|
|
|
|
} |