Commit 1d2544695b4af008558a2172c4e33ee6c5e8352c

Authored by jiangjiazhi
1 parent 48311fea51

updated

Showing 15 changed files with 567 additions and 149 deletions

platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java View file @ 1d25446
... ... @@ -11,16 +11,16 @@
11 11  
12 12 public class BasicConfigServiceTest {
13 13 public static void main(String[] args) {
14   - ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext_biz_patient.xml");
  14 + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext_biz_patient1.xml");
15 15 BasicConfigService basicConfigService = (BasicConfigService) applicationContext.getBean("basicConfigService");
  16 + System.out.println(basicConfigService.queryParentConfig());
16 17  
17   -
18   - for(int i = 6;i<10;i++){
  18 + for(int i = 6;i<7;i++){
19 19 BasicConfig obj = new BasicConfig();
20   - obj.setCode("xc"+i);
21   - obj.setName("哮喘"+i);
  20 + obj.setCode("xc123456"+i);
  21 + obj.setName("哮喘123456"+i);
22 22 obj.setYn(1);
23   - obj.setParentId("56e8cf6e24fdcc51d22a4f27");
  23 + obj.setParentId("56ea134c24fdaafbabbb0025");
24 24 basicConfigService.addBasicConfig(obj);
25 25 }
26 26 }
platform-biz-patient-service/src/main/java/com/lyms/platform/biz/service/BasicConfigService.java View file @ 1d25446
... ... @@ -2,6 +2,7 @@
2 2  
3 3 import java.util.List;
4 4  
  5 +import org.apache.commons.lang.StringUtils;
5 6 import org.springframework.beans.factory.annotation.Autowired;
6 7 import org.springframework.data.domain.Sort.Direction;
7 8 import org.springframework.stereotype.Service;
8 9  
9 10  
... ... @@ -9,11 +10,14 @@
9 10 import com.lyms.platform.biz.dal.IBasicConfigDao;
10 11 import com.lyms.platform.common.dao.operator.MongoCondition;
11 12 import com.lyms.platform.common.dao.operator.MongoOper;
  13 +import com.lyms.platform.common.dao.operator.MongoQuery;
12 14 import com.lyms.platform.common.dao.operator.Page;
13 15 import com.lyms.platform.pojo.BasicConfig;
  16 +import com.lyms.platform.pojo.BasicConfigQuery;
14 17  
15 18 @Service("basicConfigService")
16 19 public class BasicConfigService {
  20 +
17 21 @Autowired
18 22 private IBasicConfigDao basicConfigDao;
19 23  
20 24  
21 25  
22 26  
... ... @@ -25,19 +29,27 @@
25 29 basicConfigDao.updateBasicConfig(obj, obj.getId());
26 30 }
27 31  
28   - public List<BasicConfig> queryBasicConfig(int start, int end) {
29   - return basicConfigDao.queryBasicConfig(MongoCondition.newInstance().toMongoQuery().start(start).end(end)
30   - .addOrder(Direction.ASC, "id"));
  32 + public List<BasicConfig> queryBasicConfig(BasicConfigQuery basicConfigQuery) {
  33 + MongoQuery query = basicConfigQuery.convertToQuery();
  34 + if (StringUtils.isNotEmpty(basicConfigQuery.getNeed())) {
  35 + basicConfigQuery.mysqlBuild(basicConfigDao.queryBasicConfigCount(basicConfigQuery.convertToQuery()));
  36 + query.start(basicConfigQuery.getOffset()).end(basicConfigQuery.getLimit());
  37 + }
  38 +
  39 + return basicConfigDao.queryBasicConfig(query.addOrder(Direction.ASC, "id"));
31 40 }
32   -
33   - public List<BasicConfig> queryParentConfig(){
34   - return basicConfigDao.queryBasicConfig(MongoCondition.newInstance("parentId",null,MongoOper.IS).toMongoQuery().start(0).end(100)
  41 +
  42 + public List<BasicConfig> queryParentConfig() {
  43 + return basicConfigDao.queryBasicConfig(MongoCondition.newInstance("parentId", null, MongoOper.IS).toMongoQuery()
35 44 .addOrder(Direction.ASC, "id"));
36 45 }
37 46  
  47 + public List<BasicConfig> queryByParentId(String parentId) {
  48 + return basicConfigDao.queryBasicConfig(MongoCondition.newInstance("parentId", parentId, MongoOper.IS).toMongoQuery());
  49 + }
  50 +
38 51 public Page<BasicConfig> queryGuidesAndPage(int start, int end) {
39   - return basicConfigDao.findPage(MongoCondition.newInstance().toMongoQuery().start(start).end(end)
40   - .addOrder(Direction.ASC, "id"));
  52 + return basicConfigDao.findPage(MongoCondition.newInstance().toMongoQuery().start(start).end(end).addOrder(Direction.ASC, "id"));
41 53 }
42 54 }
platform-biz-patient-service/src/main/resources/spring/applicationContext_biz_patient1.xml View file @ 1d25446
... ... @@ -54,6 +54,6 @@
54 54 </bean>
55 55  
56 56 <!-- <bean id="messageResolver" class="com.lyms.platform.common.core.resolve.MessageResolver" /> -->
57   - <import resource="spring-mongodb.xml" />
  57 + <import resource="spring-mongodb1.xml" />
58 58 </beans>
platform-common/com/lyms/platform/common/dao/IBasicConfigDao.java View file @ 1d25446
1   -package com.lyms.biz.core.dao.mongo;
2   -
3   -import com.lyms.biz.core.model.BasicConfig;
4   -import com.lyms.platform.common.dao.operator.Page;
5   -import java.util.List;
6   -
7   -public interface IBasicConfigDao {
8   -public BasicConfig addBasicConfig(BasicConfig obj);
9   -public void updateBasicConfig(BasicConfig obj,String id);
10   -public void deleteBasicConfig (String id);
11   -public BasicConfig getBasicConfig (String id);
12   -public int queryBasicConfigCount (com.lyms.biz.core.dao.mongo.operator.MongoQuery query);
13   -public List<BasicConfig> queryBasicConfig (com.lyms.biz.core.dao.mongo.operator.MongoQuery query);
14   -public Page<BasicConfig> findPage(com.lyms.biz.core.dao.mongo.operator.MongoQuery query);
15   -}
platform-common/com/lyms/platform/common/dao/impl/BasicConfigDaoImpl.java View file @ 1d25446
1   -package com.lyms.biz.core.dao.mongo.impl;
2   -
3   -import com.lyms.biz.core.model.BasicConfig;
4   -import org.springframework.stereotype.Repository;
5   -import com.lyms.platform.common.dao.BaseMongoDAOImpl;
6   -import com.lyms.platform.common.dao.IBasicConfigDao;
7   -import java.util.List;
8   -import com.lyms.platform.common.dao.operator.MongoQuery;
9   -import com.lyms.platform.common.dao.operator.MongoCondition;
10   -import com.lyms.platform.common.dao.operator.MongoOper;
11   -import com.lyms.platform.common.dao.operator.Page;
12   -
13   -
14   -
15   -@Repository("basicConfigDao")
16   -public class BasicConfigDaoImpl extends BaseMongoDAOImpl<BasicConfig> implements IBasicConfigDao {
17   - public BasicConfig addBasicConfig(BasicConfig obj){
18   - return save(obj);
19   - }
20   - public void updateBasicConfig(BasicConfig obj,String id){
21   - update(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery(), obj);
22   - }
23   - public void deleteBasicConfig(String id){
24   - delete(new MongoQuery(new MongoCondition("id", id, MongoOper.IS)).convertToMongoQuery());
25   - }
26   - public BasicConfig getBasicConfig (String id){
27   - return findById(id);
28   - }
29   - public int queryBasicConfigCount(MongoQuery query){
30   - return (int)count(query.convertToMongoQuery());
31   - }
32   - public List<BasicConfig> queryBasicConfig(MongoQuery query){
33   - return find(query.convertToMongoQuery());
34   - }
35   - public Page<BasicConfig> findPage(MongoQuery query){
36   - return findPage(query.convertToMongoQuery());
37   -}
38   -}
platform-common/src/main/java/com/lyms/platform/common/GAllMysql.java View file @ 1d25446
... ... @@ -86,6 +86,8 @@
86 86  
87 87 FileUtils.writeStringToFile(new File(BASE_MONGO_DAO1 + "/impl/" + className
88 88 + "DaoImpl.java"), daoImpl.toString());
  89 +
  90 +// FileUtils.writeStringToFile(new File(baseDir+"model/"+className+"Query.java"), pojo.toString().replace("class " + className, "class " + className + "Query extends BaseQuery").replace("import java.util.Date;", "\n\nimport java.util.Date;\nimport com.lymsh.mommybaby.basecommon.base.BaseQuery;\n\n"));
89 91 } catch (IOException e) {
90 92 e.printStackTrace();
91 93 }
platform-common/src/main/java/com/lyms/platform/common/dao/BaseQuery.java View file @ 1d25446
  1 +package com.lyms.platform.common.dao;
  2 +
  3 +
  4 +import java.util.ArrayList;
  5 +import java.util.Date;
  6 +import java.util.List;
  7 +
  8 +public class BaseQuery {
  9 +
  10 + // 排序
  11 + private String sort;
  12 + // 是否分页
  13 + private String need;
  14 + // 当前页起始行数
  15 + private Integer offset = 0;
  16 + // 页面行数
  17 + private Integer limit = 15;
  18 + // 当前页
  19 + private int page = 1;
  20 + // 最后一页
  21 + private int lastPage = 0;
  22 + // 行数
  23 + private int count = 0;
  24 +
  25 + private boolean prev;
  26 +
  27 + private boolean next;
  28 +
  29 + private int[] range = new int[2];
  30 +
  31 + private List<Integer> pageNums = new ArrayList<Integer>();
  32 +
  33 + private int startNum;
  34 + private int endNum;
  35 +
  36 + private Date startTimeStart;
  37 + private Date startTimeEnd;
  38 + private Date endTimeStart;
  39 + private Date endTimeEnd;
  40 +
  41 +
  42 + public Date getStartTimeStart() {
  43 + return startTimeStart;
  44 + }
  45 +
  46 + public void setStartTimeStart(Date startTimeStart) {
  47 + this.startTimeStart = startTimeStart;
  48 + }
  49 +
  50 + public Date getStartTimeEnd() {
  51 + return startTimeEnd;
  52 + }
  53 +
  54 + public void setStartTimeEnd(Date startTimeEnd) {
  55 + this.startTimeEnd = startTimeEnd;
  56 + }
  57 +
  58 + public Date getEndTimeStart() {
  59 + return endTimeStart;
  60 + }
  61 +
  62 + public void setEndTimeStart(Date endTimeStart) {
  63 + this.endTimeStart = endTimeStart;
  64 + }
  65 +
  66 + public Date getEndTimeEnd() {
  67 + return endTimeEnd;
  68 + }
  69 +
  70 + public void setEndTimeEnd(Date endTimeEnd) {
  71 + this.endTimeEnd = endTimeEnd;
  72 + }
  73 +
  74 + public int getCount() {
  75 + return count;
  76 + }
  77 +
  78 + public void setCount(int count) {
  79 + this.count = count;
  80 + }
  81 +
  82 + public String getSort() {
  83 + return sort;
  84 + }
  85 +
  86 + public void setSort(String sort) {
  87 + this.sort = sort;
  88 + }
  89 +
  90 + public String getNeed() {
  91 + return need;
  92 + }
  93 +
  94 + public void setNeed(String need) {
  95 + this.need = need;
  96 + }
  97 +
  98 + public Integer getOffset() {
  99 + return offset;
  100 + }
  101 +
  102 + public void setOffset(Integer offset) {
  103 + this.offset = offset;
  104 + }
  105 +
  106 + public Integer getLimit() {
  107 + return limit;
  108 + }
  109 +
  110 + public void setLimit(Integer limit) {
  111 + if (limit != null && limit > 0) {
  112 + this.limit = limit;
  113 + }
  114 + }
  115 +
  116 + public int getPage() {
  117 + return page;
  118 + }
  119 +
  120 + public void setPage(int page) {
  121 + this.page = page;
  122 + }
  123 +
  124 + public int getLastPage() {
  125 + return lastPage;
  126 + }
  127 +
  128 + public void setLastPage(int lastPage) {
  129 + this.lastPage = lastPage;
  130 + }
  131 +
  132 + public void postgresqlBuild(int count) {
  133 + this.count = count;
  134 + lastPage = count / limit;
  135 + if (count % limit > 0) {
  136 + lastPage += 1;
  137 + }
  138 +// if (page > lastPage) {
  139 +// page = lastPage;
  140 +// }
  141 + if (page < 1) {
  142 + page = 1;
  143 + }
  144 + offset = page * limit - limit;
  145 +
  146 +
  147 + this.range[0] = (this.page - 1) * this.limit + 1;
  148 + this.range[1] = page * limit > count ? count : page * limit;
  149 + this.startNum = page / 5 * 5;
  150 + if (startNum < 0) {
  151 + startNum = 0;
  152 + }
  153 +
  154 + this.endNum = this.page / 5 * 5 + 5;
  155 + if (endNum > this.lastPage) {
  156 + endNum = this.lastPage;
  157 + }
  158 +
  159 + for (int i = 0; i < (endNum - startNum); i++) {
  160 + this.pageNums.add(startNum + i + 1);
  161 + }
  162 + if (this.page > 1) {
  163 + this.prev = this.page - 1 > 0 ? true : false;
  164 + }
  165 +
  166 + if (this.page < this.lastPage) {
  167 + this.next = this.page + 1 > 0 ? true : false;
  168 + }
  169 + }
  170 +
  171 + public void mysqlBuild(int count) {
  172 + this.count = count;
  173 + lastPage = count / limit;
  174 + if (count % limit > 0) {
  175 + lastPage += 1;
  176 + }
  177 +// if (page > lastPage) {
  178 +// page = lastPage;
  179 +// }
  180 + if (page < 1) {
  181 + page = 1;
  182 + }
  183 + offset = page * limit - limit;
  184 +
  185 +
  186 + this.range[0] = (this.page - 1) * this.limit + 1;
  187 + this.range[1] = page * limit > count ? count : page * limit;
  188 + this.startNum = page / 5 * 5;
  189 + if (startNum < 0) {
  190 + startNum = 0;
  191 + }
  192 +
  193 + this.endNum = this.page / 5 * 5 + 5;
  194 + if (endNum > this.lastPage) {
  195 + endNum = this.lastPage;
  196 + }
  197 +
  198 + for (int i = 0; i < (endNum - startNum); i++) {
  199 + this.pageNums.add(startNum + i + 1);
  200 + }
  201 + if (this.page > 1) {
  202 + this.prev = this.page - 1 > 0 ? true : false;
  203 + }
  204 +
  205 + if (this.page < this.lastPage) {
  206 + this.next = this.page + 1 > 0 ? true : false;
  207 + }
  208 + }
  209 +
  210 + public Integer prePage() {
  211 + return this.page - 1;
  212 + }
  213 +
  214 + public Integer nextPage() {
  215 + return this.page + 1;
  216 + }
  217 +
  218 + public int getStartNum() {
  219 + return startNum;
  220 + }
  221 +
  222 + public void setStartNum(int startNum) {
  223 + this.startNum = startNum;
  224 + }
  225 +
  226 + public int getEndNum() {
  227 + return endNum;
  228 + }
  229 +
  230 + public void setEndNum(int endNum) {
  231 + this.endNum = endNum;
  232 + }
  233 +
  234 + public boolean isPrev() {
  235 + return prev;
  236 + }
  237 +
  238 + public void setPrev(boolean prev) {
  239 + this.prev = prev;
  240 + }
  241 +
  242 + public boolean isNext() {
  243 + return next;
  244 + }
  245 +
  246 + public void setNext(boolean next) {
  247 + this.next = next;
  248 + }
  249 +
  250 + public int[] getRange() {
  251 + return range;
  252 + }
  253 +
  254 + public void setRange(int[] range) {
  255 + this.range = range;
  256 + }
  257 +
  258 + public List<Integer> getPageNums() {
  259 + return pageNums;
  260 + }
  261 +
  262 + public void setPageNums(List<Integer> pageNums) {
  263 + this.pageNums = pageNums;
  264 + }
  265 +}
platform-common/src/main/java/com/lyms/platform/common/dao/operator/MongoCondition.java View file @ 1d25446
... ... @@ -59,6 +59,7 @@
59 59 }
60 60  
61 61 public MongoCondition() {
  62 + criteria = new Criteria();
62 63 }
63 64  
64 65 /**
... ... @@ -73,9 +74,15 @@
73 74 * @return
74 75 */
75 76 public MongoCondition and(String key, Object obj, MongoOper oper) {
76   - Criteria criteria1 = criteria.and(key);
77   - set(oper, obj, criteria1);
78   - criteria = criteria1;
  77 + if(criteria ==null){
  78 + criteria = Criteria.where(key);
  79 + set(oper, obj, criteria);
  80 + }else{
  81 + Criteria criteria1 = criteria.and(key);
  82 + set(oper, obj, criteria1);
  83 + criteria = criteria1;
  84 + }
  85 +
79 86 return this;
80 87 }
81 88  
82 89  
... ... @@ -98,8 +105,35 @@
98 105 * @return
99 106 */
100 107 public MongoCondition orCondition(MongoCondition con) {
101   - criteria = criteria.orOperator(con.criteria);
  108 + if(null==criteria){
  109 + criteria= con.criteria;
  110 + }else{
  111 + criteria = criteria.orOperator(con.criteria);
  112 + }
102 113 return this;
  114 + }
  115 +
  116 + public MongoCondition orCondition(MongoCondition... con){
  117 + /* public Criteria orOperator(Criteria... criteria) {
  118 + BasicDBList bsonList = createCriteriaList(criteria);
  119 + return registerCriteriaChainElement(new Criteria("$or").is(bsonList));
  120 + }*/
  121 + Criteria[] list=new Criteria[con.length];
  122 + int index= 0;
  123 + for(MongoCondition c:con){
  124 + list[index++]=c.criteria;
  125 + }
  126 + if(null==criteria){
  127 + criteria=list[0];
  128 + if(con.length>1){
  129 + Criteria[] dest = new Criteria[con.length-1];
  130 + System.arraycopy(list, 1, dest, 0, dest.length);
  131 + criteria.orOperator(dest);
  132 + }
  133 + }else{
  134 + criteria.orOperator(list);
  135 + }
  136 + return this;
103 137 }
104 138  
105 139 /**
platform-common/src/main/java/com/lyms/platform/common/result/BaseResponse.java View file @ 1d25446
... ... @@ -15,13 +15,13 @@
15 15 private static final long serialVersionUID = 1L;
16 16  
17 17 protected String errormsg;
18   - protected String errorcode;
  18 + protected int errorcode;
19 19  
20 20 public BaseResponse() {
21 21 super();
22 22 }
23 23  
24   - public BaseResponse(String errormsg, String errorcode) {
  24 + public BaseResponse(String errormsg, int errorcode) {
25 25 super();
26 26 this.errormsg = errormsg;
27 27 this.errorcode = errorcode;
28 28  
... ... @@ -35,11 +35,11 @@
35 35 this.errormsg = errormsg;
36 36 }
37 37  
38   - public String getErrorcode() {
  38 + public int getErrorcode() {
39 39 return errorcode;
40 40 }
41 41  
42   - public void setErrorcode(String errorcode) {
  42 + public void setErrorcode(int errorcode) {
43 43 this.errorcode = errorcode;
44 44 }
45 45 }
platform-common/src/main/java/com/lyms/platform/common/utils/ResultUtils.java View file @ 1d25446
... ... @@ -4,7 +4,7 @@
4 4  
5 5 public final class ResultUtils {
6 6  
7   - public static BaseResponse buildBaseResponse(String msg, String errorcode) {
  7 + public static BaseResponse buildBaseResponse(String msg, int errorcode) {
8 8 return new BaseResponse(msg, errorcode);
9 9 }
10 10  
... ... @@ -20,7 +20,7 @@
20 20 * @return
21 21 */
22 22 public static <T extends BaseResponse> T buildResponse(String msg,
23   - String errorcode, T baseResponse) {
  23 + int errorcode, T baseResponse) {
24 24 baseResponse.setErrormsg(msg);
25 25 baseResponse.setErrorcode(errorcode);
26 26 return baseResponse;
platform-dal/src/main/java/com/lyms/platform/pojo/BasicConfigQuery.java View file @ 1d25446
  1 +package com.lyms.platform.pojo;
  2 +
  3 +import com.lyms.platform.common.dao.BaseQuery;
  4 +import com.lyms.platform.common.dao.operator.MongoCondition;
  5 +import com.lyms.platform.common.dao.operator.MongoOper;
  6 +import com.lyms.platform.common.dao.operator.MongoQuery;
  7 +
  8 +public class BasicConfigQuery extends BaseQuery {
  9 +
  10 + private String id;
  11 +
  12 + private String parentId;
  13 +
  14 + private String code;
  15 +
  16 + private String name;
  17 +
  18 + private String keyword;
  19 +
  20 + public MongoQuery convertToQuery() {
  21 +// MongoCondition condition = MongoCondition.newInstance("1","1",MongoOper.IS);
  22 + MongoCondition condition = MongoCondition.newInstance();
  23 + if (null != id) {
  24 + condition = condition.and("id", id, MongoOper.IS);
  25 + }
  26 +
  27 + if (null != code) {
  28 + condition = condition.and("code", code, MongoOper.IS);
  29 + }
  30 + if (null != name) {
  31 + condition = condition.and("name", name, MongoOper.IS);
  32 + }
  33 + if (null != parentId) {
  34 + condition = condition.and("parentId", parentId, MongoOper.IS);
  35 + }
  36 + if (null != keyword) {
  37 + MongoCondition con1= MongoCondition.newInstance("code", keyword, MongoOper.LIKE);
  38 + MongoCondition con = MongoCondition.newInstance("name", keyword, MongoOper.LIKE);
  39 + condition = condition.orCondition(new MongoCondition[]{con1,con});
  40 + }
  41 +
  42 + return condition.toMongoQuery();
  43 + }
  44 +
  45 + public String getKeyword() {
  46 + return keyword;
  47 + }
  48 +
  49 + public void setKeyword(String keyword) {
  50 + this.keyword = keyword;
  51 + }
  52 +
  53 + public String getName() {
  54 + return name;
  55 + }
  56 +
  57 + public void setName(String name) {
  58 + this.name = name;
  59 + }
  60 +
  61 + private int yn;
  62 +
  63 + public String getId() {
  64 + return id;
  65 + }
  66 +
  67 + public void setId(String id) {
  68 + this.id = id;
  69 + }
  70 +
  71 + public String getParentId() {
  72 + return parentId;
  73 + }
  74 +
  75 + public void setParentId(String parentId) {
  76 + this.parentId = parentId;
  77 + }
  78 +
  79 + public String getCode() {
  80 + return code;
  81 + }
  82 +
  83 + public void setCode(String code) {
  84 + this.code = code;
  85 + }
  86 +
  87 + public int getYn() {
  88 + return yn;
  89 + }
  90 +
  91 + public void setYn(int yn) {
  92 + this.yn = yn;
  93 + }
  94 +}
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/BasicConfigController.java View file @ 1d25446
... ... @@ -2,9 +2,7 @@
2 2  
3 3 import java.io.IOException;
4 4 import java.util.ArrayList;
5   -import java.util.HashMap;
6 5 import java.util.List;
7   -import java.util.Map;
8 6  
9 7 import javax.servlet.http.HttpServletRequest;
10 8  
11 9  
12 10  
13 11  
14 12  
15 13  
16 14  
17 15  
18 16  
19 17  
20 18  
21 19  
22 20  
23 21  
24 22  
25 23  
26 24  
27 25  
28 26  
29 27  
30 28  
31 29  
... ... @@ -14,128 +12,122 @@
14 12 import org.springframework.http.MediaType;
15 13 import org.springframework.stereotype.Controller;
16 14 import org.springframework.web.bind.annotation.PathVariable;
  15 +import org.springframework.web.bind.annotation.RequestBody;
17 16 import org.springframework.web.bind.annotation.RequestMapping;
18 17 import org.springframework.web.bind.annotation.RequestMethod;
19 18 import org.springframework.web.bind.annotation.RequestParam;
20 19 import org.springframework.web.bind.annotation.ResponseBody;
21 20  
22 21 import com.lyms.platform.biz.service.BasicConfigService;
  22 +import com.lyms.platform.common.constants.ErrorCodeConstants;
23 23 import com.lyms.platform.common.result.BaseListResponse;
24 24 import com.lyms.platform.common.result.BaseResponse;
25 25 import com.lyms.platform.common.utils.JsonUtil;
26 26 import com.lyms.platform.operate.web.request.BasicConfigRequest;
  27 +import com.lyms.platform.operate.web.result.TreeNode;
27 28 import com.lyms.platform.pojo.BasicConfig;
  29 +import com.lyms.platform.pojo.BasicConfigQuery;
28 30  
  31 +
  32 +/**
  33 + *
  34 + * 基础项配置接口
  35 + *
  36 + * @author Administrator
  37 + *
  38 + */
29 39 @Controller
30 40 public class BasicConfigController {
31 41 @Autowired
32 42 private BasicConfigService basicConfigService;
33 43  
34   - private static final String NODE = "child";
35   -
36 44 @RequestMapping(method = RequestMethod.GET, value = "/basicConfig")
37 45 @ResponseBody
38   - public BaseListResponse queryBasicConfig(@RequestParam(value="keywords",required=false)
39   - String keywords) {
40   - List<BasicConfig> data = basicConfigService.queryBasicConfig(0, 100);
  46 + public BaseListResponse queryBasicConfig(@RequestParam(value = "keywords", required = false)
  47 + String keywords,@RequestParam("page")int page,@RequestParam("limit")int limit) {
  48 + BasicConfigQuery basicConfigQuery = new BasicConfigQuery();
  49 + basicConfigQuery.setNeed("1");
  50 + basicConfigQuery.setPage(page);
  51 + basicConfigQuery.setLimit(limit);
  52 + basicConfigQuery.setKeyword(keywords);
  53 + List<BasicConfig> data = basicConfigService.queryBasicConfig(basicConfigQuery);
41 54 BaseListResponse baseListResponse = new BaseListResponse();
42 55 baseListResponse.setData(data);
43   - baseListResponse.setErrorcode("0");
  56 + baseListResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
44 57 baseListResponse.setErrormsg("成功");
45 58 return baseListResponse;
46 59 }
47 60  
48 61 @RequestMapping(method = RequestMethod.PUT, value = "/basicConfig/{id}")
49 62 @ResponseBody
50   - public BaseResponse updateBasicConfig(@PathVariable("id")String id,
51   - @RequestParam("title")String title,
52   - @RequestParam("code") String code) {
  63 + public BaseResponse updateBasicConfig(@PathVariable("id")
  64 + String id, @RequestParam("title")
  65 + String title, @RequestParam("code")
  66 + String code) {
53 67 BasicConfig obj = new BasicConfig();
54 68 obj.setId(id);
55 69 obj.setName(title);
56 70 obj.setCode(code);
57 71 basicConfigService.updateBasicConfig(obj);
58 72 BaseResponse baseResponse = new BaseResponse();
59   - baseResponse.setErrorcode("0");
  73 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
60 74 baseResponse.setErrormsg("成功");
61 75 return baseResponse;
62 76 }
  77 +
63 78 @RequestMapping(method = RequestMethod.DELETE, value = "/basicConfig/{id}")
64 79 @ResponseBody
65   - public BaseResponse updateBasicConfig(@PathVariable("id")String id){
66   - BasicConfig obj = new BasicConfig();
  80 + public BaseResponse updateBasicConfig(@PathVariable("id")
  81 + String id) {
  82 + BasicConfig obj = new BasicConfig();
67 83 obj.setId(id);
68 84 obj.setYn(0);
69 85 basicConfigService.updateBasicConfig(obj);
70   -
  86 +
71 87 BaseResponse baseResponse = new BaseResponse();
72   - baseResponse.setErrorcode("0");
  88 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
73 89 baseResponse.setErrormsg("成功");
74 90 return baseResponse;
75 91 }
76 92  
77   - private static List convertToTreeMap(List<BasicConfig> basicList) {
78   - List list = new ArrayList();
79   - // 存放模块名字和索引映射
80   - Map<String, Integer> nameToIndex = new HashMap<>();
81   - Map<String, BasicConfig> nameToIndex1 = new HashMap<>();
82   - for (BasicConfig b : basicList) {
83   - nameToIndex1.put(b.getId(), b);
  93 + public TreeNode recursiveTree(BasicConfig b) {
  94 + TreeNode node = converToNode(b);
  95 + List<BasicConfig> l2 = basicConfigService.queryByParentId(b.getId());
  96 + for (BasicConfig b1 : l2) {
  97 + TreeNode node1 = recursiveTree(b1);
  98 + if (null != node1) {
  99 + node.getNodes().add(node1);
  100 + }
84 101 }
  102 + return node;
  103 + }
85 104  
86   - int index = 0;
87   -
88   - for (BasicConfig config : basicList) {
89   - Map<String, Object> moduleMap = new HashMap<>();
90   - // 如果存在就加下一级节点
91   - moduleMap.put("id", config.getId());
92   - moduleMap.put("parentId", config.getParentId());
93   - moduleMap.put("name", config.getName());
94   -
95   - if (null == config.getParentId()) {
96   -
97   - } else {
98   - nameToIndex1.get(config.getParentId());
  105 + @RequestMapping(method = RequestMethod.GET, value = "/basicConfigTree")
  106 + @ResponseBody
  107 + public List<TreeNode> buildJson() {
  108 + List<TreeNode> list = new ArrayList<TreeNode>();
  109 + List<BasicConfig> l = basicConfigService.queryParentConfig();
  110 + for (BasicConfig b : l) {
  111 + TreeNode node = recursiveTree(b);
  112 + if (null != node) {
  113 + list.add(node);
99 114 }
100   -
101   - list.add(moduleMap);
102 115 }
103   - System.out.print(JsonUtil.array2JsonString(list));
104 116 return list;
105 117 }
106 118  
107   - public static void main(String[] args) {
108   - BasicConfig basicConfig = new BasicConfig();
109   - basicConfig.setId("1");
110   - basicConfig.setName("1");
111   -
112   - BasicConfig basicConfig1 = new BasicConfig();
113   - basicConfig1.setId("11");
114   - basicConfig1.setName("11");
115   - basicConfig1.setParentId("1");
116   -
117   - BasicConfig basicConfig2 = new BasicConfig();
118   - basicConfig2.setId("112");
119   - basicConfig2.setName("112");
120   - basicConfig2.setParentId("11");
121   -
122   - BasicConfig basicConfig3 = new BasicConfig();
123   - basicConfig3.setId("113");
124   - basicConfig3.setName("113");
125   - basicConfig3.setParentId("11");
126   -
127   - List<BasicConfig> list = new ArrayList<>();
128   - list.add(basicConfig);
129   - list.add(basicConfig1);
130   - list.add(basicConfig2);
131   - list.add(basicConfig3);
132   - System.out.println(convertToTreeMap(list));
  119 + private TreeNode converToNode(BasicConfig c) {
  120 + TreeNode node = new TreeNode();
  121 + node.setCid(c.getId());
  122 + node.setCname(c.getName());
  123 + node.setPid(c.getParentId());
  124 + return node;
133 125 }
134 126  
135   - @RequestMapping(method = RequestMethod.POST, value = "/basicConfig", consumes = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
  127 + @RequestMapping(method = RequestMethod.POST, value = "/basicConfig"/*, consumes = { MediaType.APPLICATION_OCTET_STREAM_VALUE }*/)
136 128 @ResponseBody
137   - public BaseResponse addBasicConfig(HttpServletRequest httpServletRequest) {
138   - String json = "";
  129 + public BaseResponse addBasicConfig(@RequestBody List<BasicConfigRequest> listReq) {
  130 + /* String json = "";
139 131 try {
140 132 json = IOUtils.toString(httpServletRequest.getInputStream(), "utf8");
141 133 } catch (IOException e) {
142 134  
143 135  
... ... @@ -147,9 +139,13 @@
147 139 for (BasicConfigRequest ba : li) {
148 140 basicConfigService.addBasicConfig(ba.convertToBasicConfig());
149 141 }
  142 + }*/
  143 + for (BasicConfigRequest ba : listReq) {
  144 + basicConfigService.addBasicConfig(ba.convertToBasicConfig());
150 145 }
  146 +
151 147 BaseResponse baseResponse = new BaseResponse();
152   - baseResponse.setErrorcode("0");
  148 + baseResponse.setErrorcode(ErrorCodeConstants.SUCCESS);
153 149 baseResponse.setErrormsg("成功");
154 150 return baseResponse;
155 151 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/request/BasicConfigRequest.java View file @ 1d25446
... ... @@ -2,10 +2,11 @@
2 2  
3 3 import org.hibernate.validator.constraints.NotEmpty;
4 4  
  5 +import com.lyms.platform.common.core.annotation.form.Form;
5 6 import com.lyms.platform.common.core.annotation.form.FormParam;
6 7 import com.lyms.platform.pojo.BasicConfig;
7 8  
8   -//@Form
  9 +@Form
9 10 public class BasicConfigRequest {
10 11 @FormParam
11 12 private String parentId;
platform-operate-api/src/main/java/com/lyms/platform/operate/web/result/TreeNode.java View file @ 1d25446
  1 +package com.lyms.platform.operate.web.result;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.ArrayList;
  5 +import java.util.List;
  6 +
  7 +public class TreeNode implements Serializable {
  8 + /**
  9 + *
  10 + */
  11 + private static final long serialVersionUID = 1L;
  12 +
  13 + /**
  14 + * 当前节点的id
  15 + */
  16 + private String cid;
  17 +
  18 + /**
  19 + * 当前节点的名称
  20 + */
  21 + private String cname;
  22 +
  23 + /**
  24 + * 父节点id
  25 + */
  26 + private String pid;
  27 +
  28 + /**
  29 + * 子节点
  30 + */
  31 + private List<TreeNode> nodes = new ArrayList<TreeNode>();
  32 +
  33 + public TreeNode() {
  34 + }
  35 +
  36 + public String getCid() {
  37 + return cid;
  38 + }
  39 +
  40 + public void setCid(String cid) {
  41 + this.cid = cid;
  42 + }
  43 +
  44 + public String getCname() {
  45 + return cname;
  46 + }
  47 +
  48 + public void setCname(String cname) {
  49 + this.cname = cname;
  50 + }
  51 +
  52 + public String getPid() {
  53 + return pid;
  54 + }
  55 +
  56 + public void setPid(String pid) {
  57 + this.pid = pid;
  58 + }
  59 +
  60 + public List<TreeNode> getNodes() {
  61 + return nodes;
  62 + }
  63 +
  64 + public void setNodes(List<TreeNode> nodes) {
  65 + this.nodes = nodes;
  66 + }
  67 +}
platform-operate-api/src/main/resources/database.properties View file @ 1d25446
1   -mongo.db.host=localhost
  1 +mongo.db.host=192.168.5.8
2 2 mongo.db.port=27017
3 3 mongo.db.dbname=platform