Commit 46da17a7 authored by 曲欣亮's avatar 曲欣亮

重构简化

parent 000d52f4
......@@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSON;
import com.egolm.common.GsonUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.lang.bean.T_lang_tree;
import com.egolm.lang.config.XException;
import com.egolm.lang.model.ContentArgs;
import com.egolm.lang.service.LanguageService;
......@@ -52,15 +53,13 @@ public class LanguageController {
})
public Object menus(String sParentLink) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
String sParentID = service.getNodeIDByLink(sParentLink);
if(sParentID != null) {
Map<String, Object> nodeMap = service.getNodeMapByID(sParentID);
String sTopID = (String)nodeMap.get("sTopID");
list = service.getListByTopID(sTopID);
T_lang_tree node = service.getNodeByLink(sParentLink);
if(node != null) {
list = service.getListByTopID(node.getsTopID());
} else {
list = service.getListAll();
}
return Rjx.jsonOk().setData(this.toNodesTree(list, sParentID, sParentLink == null ? new ArrayList<String>() : Arrays.asList(sParentLink)));
return Rjx.jsonOk().setData(this.toNodesTree(list, node == null ? null : node.getsNodeID(), sParentLink == null ? new ArrayList<String>() : Arrays.asList(sParentLink)));
}
private List<Map<String, Object>> toNodesTree(List<Map<String, Object>> list, String sParentID, List<String> sParentLink) {
......@@ -100,8 +99,8 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object append(String sLink) {
service.append(sLink);
return Rjx.jsonOk();
T_lang_tree node = service.getNodeByLink(sLink, true);
return Rjx.jsonOk().setData(node);
}
@ResponseBody
......@@ -112,8 +111,8 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object delete(String sLink) {
String sNodeID = service.getNodeIDByLink(sLink);
service.delete(sNodeID);
T_lang_tree node = service.getNodeByLink(sLink);
service.delete(node.getsNodeID());
return Rjx.jsonOk();
}
......@@ -125,9 +124,9 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object move(String sLink, String sParentLink) {
String sNodeID = service.getNodeIDByLink(sLink);
String sParentID = service.getNodeIDByLink(sParentLink);
service.move(sNodeID, sParentID);
T_lang_tree node = service.getNodeByLink(sLink);
T_lang_tree parent = service.getNodeByLink(sParentLink);
service.move(node.getsNodeID(), parent.getsNodeID());
return Rjx.jsonOk();
}
......@@ -139,8 +138,8 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object rename(String sLink, String sNodeNO) {
String sNodeID = service.getNodeIDByLink(sLink);
service.rename(sNodeID, sNodeNO);
T_lang_tree node = service.getNodeByLink(sLink);
service.rename(node.getsNodeID(), sNodeNO);
return Rjx.jsonOk();
}
......@@ -152,7 +151,7 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object update(String sLink, String sContentText) {
String sNodeID = service.getNodeIDByLink(sLink, true);
T_lang_tree node = service.getNodeByLink(sLink, true);
Map<String, Object> contentMap = GsonUtil.toMap(sContentText);
Map<String, Object> tmp = new HashMap<String, Object>();
String sCaption = (String)contentMap.get("sCaption");
......@@ -178,7 +177,7 @@ public class LanguageController {
if(StringUtil.isNotBlank(sCaption)) {
tmp.put("sCaption", sCaption);
}
service.update(sNodeID, JSON.toJSONString(tmp, true));
service.update(node.getsNodeID(), JSON.toJSONString(tmp, true));
return Rjx.jsonOk();
}
......@@ -190,8 +189,8 @@ public class LanguageController {
@ApiImplicitParam(paramType = "header", name = "sig", dataType = "string", required = false, value = "sig"),
})
public Object queryByLink(String sLink) {
String sNodeID = service.getNodeIDByLink(sLink);
return Rjx.jsonOk().setData(service.getNodeMapByID(sNodeID));
T_lang_tree node = service.getNodeByLink(sLink);
return Rjx.jsonOk().setData(node);
}
@ResponseBody
......@@ -203,10 +202,8 @@ public class LanguageController {
@ApiImplicitParam(paramType = "query", name = "sLink", dataType = "string", required = true, value = "要查询文档树的目录")
})
public Object getDocumentsByLink(String sLink) {
String sNodeID = service.getNodeIDByLink(sLink);
Map<String, Object> map = service.getNodeMapByID(sNodeID);
String sContentText = (String)map.get("sContentText");
Map<String, Object> contentMap = GsonUtil.toMap(sContentText);
T_lang_tree node = service.getNodeByLink(sLink);
Map<String, Object> contentMap = GsonUtil.toMap(node.getsContentText());
List<?> ary = (List<?>)contentMap.get("sDocuments");
Map<String, String> result = new HashMap<String, String>();
if(ary != null && ary.size() > 0) {
......@@ -233,16 +230,11 @@ public class LanguageController {
@ApiImplicitParam(paramType = "query", name = "sTopLink", dataType = "string", required = false, value = "要查询文档树的根[最上层]目录")
})
public Object getTreeByLink(String sTopLink) {
String sTopID = service.getNodeIDByLink(sTopLink);
if(StringUtil.isBlank(sTopID)) {
T_lang_tree node = service.getNodeByLink(sTopLink);
if(node == null) {
throw new XException("找不到节点[" + sTopLink + "]");
}
List<Map<String, Object>> list = null;
if(sTopID == null) {
list = service.getListAll();
} else {
list = service.getListByTopID(sTopID);
}
List<Map<String, Object>> list = service.getListByTopID(node.getsTopID());
return Rjx.jsonOk().setData(this.toDoc(list, null));
}
......@@ -293,10 +285,8 @@ public class LanguageController {
tmp.add(map);
}
}
String sNodeID = service.getNodeIDByLink(sLink, true);
Map<String, Object> nodeMap = service.getNodeMapByID(sNodeID);
String sContentText = (String)nodeMap.get("sContentText");
Map<String, Object> textMap = GsonUtil.toMap(sContentText);
T_lang_tree node = service.getNodeByLink(sLink);
Map<String, Object> textMap = GsonUtil.toMap(node.getsContentText());
String caption = (String)textMap.get("sCaption");
List<?> list = (List<?>)textMap.get("sDocuments");
if(list != null && list.size() > 0) {
......@@ -327,7 +317,7 @@ public class LanguageController {
map.put("sCaption", caption);
map.put("sDocuments", tmp);
if(isUpdate) {
service.update(sNodeID, JSON.toJSONString(map, true));
service.update(node.getsNodeID(), JSON.toJSONString(map, true));
}
Map<String, String> result = new HashMap<String, String>();
result.put("Caption", caption);
......@@ -358,10 +348,8 @@ public class LanguageController {
@ApiImplicitParam(paramType = "query", name = "sDocument", dataType = "string", required = false, value = "sDocument")
})
public Object translate(String sLink, String sDocument) {
String sNodeID = service.getNodeIDByLink(sLink, true);
Map<String, Object> nodeMap = service.getNodeMapByID(sNodeID);
String sContentText = (String)nodeMap.get("sContentText");
Map<String, Object> textMap = GsonUtil.toMap(sContentText);
T_lang_tree node = service.getNodeByLink(sLink);
Map<String, Object> textMap = GsonUtil.toMap(node.getsContentText());
String sCaption = (String)textMap.get("sCaption");
List<?> objList = (List<?>)textMap.get("sDocuments");
List<Object> list = objList == null ? new ArrayList<Object>() : new ArrayList<Object>(objList);
......@@ -389,7 +377,7 @@ public class LanguageController {
Map<String, Object> tmp = new HashMap<String, Object>();
tmp.put("sCaption", sCaption);
tmp.put("sDocuments", list);
service.update(sNodeID, JSON.toJSONString(tmp, true));
service.update(node.getsNodeID(), JSON.toJSONString(tmp, true));
}
return Rjx.jsonOk().setData(dst);
}
......
......@@ -3,12 +3,14 @@ package com.egolm.lang.bean;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@Entity(name="t_lang_tree")
public class T_lang_tree implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String sNodeID;
private String sNodeNO;
private String sParentID;
......
......@@ -3,13 +3,13 @@ package com.egolm.lang.service;
import java.util.List;
import java.util.Map;
public interface LanguageService {
import com.egolm.lang.bean.T_lang_tree;
public String getNodeIDByLink(String sLink);
public interface LanguageService {
public String getNodeIDByLink(String sLink, boolean ifNullCreate);
public T_lang_tree getNodeByLink(String sLink);
public Map<String, Object> getNodeMapByID(String sNodeID);
public T_lang_tree getNodeByLink(String sLink, boolean ifNullCreate);
public void update(String sNodeID, String sContentText);
......@@ -19,8 +19,6 @@ public interface LanguageService {
public void delete(String sNodeID);
public void append(String sLink);
public List<Map<String, Object>> getListByTopID(String sTopID);
public List<Map<String, Object>> getListAll();
......
......@@ -28,17 +28,16 @@ public class LanguageServiceImpl implements LanguageService {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public String getNodeIDByLink(String sLink) {
return this.getNodeIDByLink(sLink, false);
public T_lang_tree getNodeByLink(String sLink) {
return this.getNodeByLink(sLink, false);
}
@Override
public String getNodeIDByLink(String sLink, boolean ifNullCreate) {
String sNodeID = null;
String sTopID = null;
public T_lang_tree getNodeByLink(String sLink, boolean ifNullCreate) {
T_lang_tree node = null;
if(sLink != null) {
for(String sNodeNO : sLink.split("[/]+")) {
String sNodeID = node == null ? null : node.getsNodeID();
String sTopID = node == null ? null : node.getsTopID();
List<String> args = new ArrayList<String>();
List<Object> objs = new ArrayList<Object>();
args.add("sNodeNO = ?");
......@@ -50,35 +49,27 @@ public class LanguageServiceImpl implements LanguageService {
objs.add(sNodeID);
}
String sql = "select sNodeID, sTopID from t_lang_tree" + StringUtil.join(" and ", " where ", args);
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, objs.toArray());
List<T_lang_tree> list = jdbcTemplate.queryForBeans(sql, T_lang_tree.class, objs.toArray());
if(list.size() == 0) {
if(ifNullCreate) {
T_lang_tree node = new T_lang_tree();
node = new T_lang_tree();
node.setsNodeID(StringUtil.getUid());
node.setsParentID(sNodeID);
node.setsTopID(sTopID == null ? node.getsNodeID() : sTopID);
node.setnDelFlag(0);
node.setsNodeNO(sNodeNO);
jdbcTemplate.save(node);
sNodeID = node.getsNodeID();
sTopID = node.getsTopID();
} else {
return null;
}
} else if(list.size() == 1) {
sNodeID = (String)list.get(0).get("sNodeID");
sTopID = (String)list.get(0).get("sTopID");
node = list.get(0);
} else {
throw new XException("节点编号重复[" + sNodeNO + "]");
}
}
}
return sNodeID;
}
@Override
public Map<String, Object> getNodeMapByID(String sNodeID) {
return jdbcTemplate.queryForMap("select * from t_lang_tree where sNodeID = ?", sNodeID);
return node;
}
@Override
......@@ -101,11 +92,6 @@ public class LanguageServiceImpl implements LanguageService {
jdbcTemplate.executeUpdate("delete from t_lang_tree where sNodeID = ?", sNodeID);
}
@Override
public void append(String sLink) {
this.getNodeIDByLink(sLink, true);
}
@Override
public List<Map<String, Object>> getListByTopID(String sTopID) {
String sql = "select * from t_lang_tree where sTopID = ? and nDelFlag = ?";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment