|
@@ -0,0 +1,276 @@
|
|
|
+package cn.hnthyy.thmz.controller.mz;
|
|
|
+
|
|
|
+import cn.hnthyy.thmz.comment.UserLoginToken;
|
|
|
+import cn.hnthyy.thmz.entity.his.mz.YpZdClass;
|
|
|
+import cn.hnthyy.thmz.service.his.mz.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+public class YpZdClassController {
|
|
|
+ @Autowired
|
|
|
+ private YpZdClassService ypZdClassService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有药品、检验、检查的分类
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @UserLoginToken
|
|
|
+ @RequestMapping(value = "/getYpZdClasses", method = {RequestMethod.GET})
|
|
|
+ public Map<String, Object> getYpZdClasses() {
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ try {
|
|
|
+ List<YpZdClass> ypZdClasses = ypZdClassService.queryYpZdClasses();
|
|
|
+ List<Map<String, Object>> treeList = null;
|
|
|
+ if (ypZdClasses == null || ypZdClasses.size() == 0) {
|
|
|
+ log.info("未查询到药品分类");
|
|
|
+ } else {
|
|
|
+ treeList = getYpZdClassTreeList(ypZdClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> jyZdClasses = ypZdClassService.queryJyZdClasses();
|
|
|
+ List<Map<String, Object>> jyTreeList = null;
|
|
|
+ if (ypZdClasses == null || ypZdClasses.size() == 0) {
|
|
|
+ log.info("未查询到检验分类");
|
|
|
+ } else {
|
|
|
+ jyTreeList = getJyZdClassTreeList(jyZdClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> jcZdClasses = ypZdClassService.queryJcZdClasses();
|
|
|
+ List<Map<String, Object>> jcTreeList = null;
|
|
|
+ if (jcZdClasses == null || jcZdClasses.size() == 0) {
|
|
|
+ log.info("未查询到检查分类");
|
|
|
+ } else {
|
|
|
+ jcTreeList = getJcZdClassTreeList(jcZdClasses);
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> fullTree = new ArrayList<>();
|
|
|
+ if(treeList!=null){
|
|
|
+ Map<String, Object> parentMap = new HashMap<>();
|
|
|
+ fullTree.add(parentMap);
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ parentMap.put("isParent", true);
|
|
|
+ parentMap.put("id", 1);
|
|
|
+ parentMap.put("name", "西成药");
|
|
|
+ parentMap.put("children", treeList);
|
|
|
+ }
|
|
|
+ if(jyTreeList!=null){
|
|
|
+ Map<String, Object> parentMap = new HashMap<>();
|
|
|
+ fullTree.add(parentMap);
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ parentMap.put("isParent", true);
|
|
|
+ parentMap.put("id", 2);
|
|
|
+ parentMap.put("name", "检验项目");
|
|
|
+ parentMap.put("children", jyTreeList);
|
|
|
+ }
|
|
|
+ if(jcTreeList!=null){
|
|
|
+ Map<String, Object> parentMap = new HashMap<>();
|
|
|
+ fullTree.add(parentMap);
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ parentMap.put("isParent", true);
|
|
|
+ parentMap.put("id", 3);
|
|
|
+ parentMap.put("name", "检查项目");
|
|
|
+ parentMap.put("children", jcTreeList);
|
|
|
+ }
|
|
|
+ resultMap.put("code", 0);
|
|
|
+ resultMap.put("message", "查询所有的分类成功");
|
|
|
+ resultMap.put("data", fullTree);
|
|
|
+ return resultMap;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("查询所有药品、检验、检查的分类失败,错误信息{}", e.getMessage());
|
|
|
+ resultMap.put("code", -1);
|
|
|
+ resultMap.put("message", "查询所有药品、检验、检查的分类失败,错误原因【" + e.getMessage() + "】");
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取药品字典树
|
|
|
+ *
|
|
|
+ * @param ypZdClasses
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> getYpZdClassTreeList(List<YpZdClass> ypZdClasses) {
|
|
|
+ List<Map<String, Object>> treeList = new ArrayList<>();
|
|
|
+ //当前一级父节点
|
|
|
+ Map<String, Object> grandParentMap = null;
|
|
|
+ //当前二级父节点
|
|
|
+ Map<String, Object> parentMap = null;
|
|
|
+ for (YpZdClass ypZdClass : ypZdClasses) {
|
|
|
+ if (ypZdClass.getCode().endsWith("0000")) {
|
|
|
+ grandParentMap = new HashMap<>();
|
|
|
+ treeList.add(grandParentMap);
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ grandParentMap.put("isParent", false);
|
|
|
+ grandParentMap.put("id", ypZdClass.getCode());
|
|
|
+ grandParentMap.put("name", ypZdClass.getName());
|
|
|
+ } else if (ypZdClass.getCode().endsWith("00")) {
|
|
|
+ //此时已经有子节点,设置成父节点
|
|
|
+ grandParentMap.put("isParent", true);
|
|
|
+ Map<String, Object> temMap = new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ temMap.put("isParent", false);
|
|
|
+ temMap.put("id", ypZdClass.getCode());
|
|
|
+ temMap.put("name", ypZdClass.getName());
|
|
|
+ List<Map<String, Object>> children = (List<Map<String, Object>>) grandParentMap.get("children");
|
|
|
+ if (children == null) {
|
|
|
+ children = new ArrayList<>();
|
|
|
+ grandParentMap.put("children", children);
|
|
|
+ }
|
|
|
+ children.add(temMap);
|
|
|
+ parentMap = temMap;
|
|
|
+ } else {
|
|
|
+ parentMap.put("isParent", true);
|
|
|
+ Map<String, Object> temMap = new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ temMap.put("isParent", false);
|
|
|
+ temMap.put("id", ypZdClass.getCode());
|
|
|
+ temMap.put("name", ypZdClass.getName());
|
|
|
+ List<Map<String, Object>> children = (List<Map<String, Object>>) parentMap.get("children");
|
|
|
+ if (children == null) {
|
|
|
+ children = new ArrayList<>();
|
|
|
+ parentMap.put("children", children);
|
|
|
+ }
|
|
|
+ children.add(temMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有检验分类字典树
|
|
|
+ *
|
|
|
+ * @param jyZdClasses
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> getJyZdClassTreeList(List<Map<String, Object>> jyZdClasses) {
|
|
|
+ List<Map<String, Object>> treeList = new ArrayList<>();
|
|
|
+ //父节点
|
|
|
+ Map<String, Object> parentMap = null;
|
|
|
+ //上一条数据的父编码
|
|
|
+ String prevDlCode = null;
|
|
|
+ for (Map<String, Object> jyZdClass : jyZdClasses) {
|
|
|
+ String xlCode = (String) jyZdClass.get("xl_code");
|
|
|
+ if(StringUtils.isBlank(xlCode)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String dlCode = (String) jyZdClass.get("dl_code");
|
|
|
+ String dlName = (String) jyZdClass.get("dl_name");
|
|
|
+ String xlName = (String) jyZdClass.get("xl_name");
|
|
|
+ if(prevDlCode==null || !prevDlCode.equals(dlCode)){
|
|
|
+ parentMap = new HashMap<>();
|
|
|
+ treeList.add(parentMap);
|
|
|
+ parentMap.put("isParent", true);
|
|
|
+ parentMap.put("id", dlCode);
|
|
|
+ parentMap.put("name", dlName);
|
|
|
+ List<Map<String, Object>> children = new ArrayList<>();
|
|
|
+ parentMap.put("children", children);
|
|
|
+ Map<String, Object> temMap = new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ temMap.put("isParent", false);
|
|
|
+ temMap.put("id", xlCode);
|
|
|
+ temMap.put("name", xlName);
|
|
|
+ children.add(temMap);
|
|
|
+ }else {
|
|
|
+ List<Map<String, Object>> children = (List<Map<String, Object>>) parentMap.get("children");
|
|
|
+ Map<String, Object> temMap = new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ temMap.put("isParent", false);
|
|
|
+ temMap.put("id", xlCode);
|
|
|
+ temMap.put("name", xlName);
|
|
|
+ children.add(temMap);
|
|
|
+ }
|
|
|
+ prevDlCode=dlCode;
|
|
|
+ }
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有检查分类字典树
|
|
|
+ *
|
|
|
+ * @param jyZcClasses
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> getJcZdClassTreeList(List<Map<String, Object>> jyZcClasses) {
|
|
|
+ List<Map<String, Object>> treeList = new ArrayList<>();
|
|
|
+ //当前一级父节点
|
|
|
+ Map<String, Object> grandParentMap = null;
|
|
|
+ //当前二级父节点
|
|
|
+ Map<String, Object> parentMap = null;
|
|
|
+ //当前数据的祖父编码
|
|
|
+ String currentGrandParentDlCode = null;
|
|
|
+ //当前数据的父编码
|
|
|
+ String currentParentDlCode = null;
|
|
|
+ for (Map<String, Object> jcZdClass : jyZcClasses) {
|
|
|
+ String dlCode = (String) jcZdClass.get("dl_code");
|
|
|
+ if(StringUtils.isBlank(dlCode)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String dlName = (String) jcZdClass.get("dl_name");
|
|
|
+ String xlCode = (String) jcZdClass.get("xl_code");
|
|
|
+ String xlName = (String) jcZdClass.get("xl_name");
|
|
|
+ //父编码是2位数 说明是一级树
|
|
|
+ if(dlCode.length()==2){
|
|
|
+ grandParentMap = new HashMap<>();
|
|
|
+ treeList.add(grandParentMap);
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ grandParentMap.put("isParent", false);
|
|
|
+ grandParentMap.put("id", dlCode);
|
|
|
+ grandParentMap.put("name", dlName);
|
|
|
+ currentGrandParentDlCode=dlCode;
|
|
|
+ if(StringUtils.isNotBlank(xlCode)){
|
|
|
+ grandParentMap.put("isParent", true);
|
|
|
+ List<Map<String, Object>> children = new ArrayList<>();
|
|
|
+ grandParentMap.put("children", children);
|
|
|
+ Map<String, Object> temMap = new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ temMap.put("isParent", false);
|
|
|
+ temMap.put("id", xlCode);
|
|
|
+ temMap.put("name", xlName);
|
|
|
+ children.add(temMap);
|
|
|
+ }
|
|
|
+ //以当前的祖父节点的编码做为编码起始,说明示二级菜单
|
|
|
+ }else if(dlCode.startsWith(currentGrandParentDlCode)){
|
|
|
+ //此时已经有子节点,设置成父节点
|
|
|
+ grandParentMap.put("isParent", true);
|
|
|
+ List<Map<String, Object>> children = (List<Map<String, Object>>) grandParentMap.get("children");
|
|
|
+ if (children == null) {
|
|
|
+ children = new ArrayList<>();
|
|
|
+ grandParentMap.put("children", children);
|
|
|
+ }
|
|
|
+ if(parentMap==null || !currentParentDlCode.equals(dlCode)){
|
|
|
+ parentMap=new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ parentMap.put("isParent", false);
|
|
|
+ parentMap.put("id", dlCode);
|
|
|
+ parentMap.put("name", dlName.substring(dlName.indexOf(" ")+1));
|
|
|
+ children.add(parentMap);
|
|
|
+ currentParentDlCode=dlCode;
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(xlCode)){
|
|
|
+ parentMap.put("isParent", true);
|
|
|
+ List<Map<String, Object>> grandchildren = (List<Map<String, Object>>) parentMap.get("children");
|
|
|
+ if (grandchildren == null) {
|
|
|
+ grandchildren = new ArrayList<>();
|
|
|
+ parentMap.put("children", grandchildren);
|
|
|
+ }
|
|
|
+ parentMap.put("children", grandchildren);
|
|
|
+ Map<String, Object> temMap = new HashMap<>();
|
|
|
+ //初始化时不知道自己有子节点,所以设置为非父节点
|
|
|
+ temMap.put("isParent", false);
|
|
|
+ temMap.put("id", xlCode);
|
|
|
+ temMap.put("name", xlName);
|
|
|
+ grandchildren.add(temMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+}
|