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

重构简化

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