From 153b891aea3fab7528d497e2ededf294fa016c3a Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Sun, 24 Dec 2017 21:51:38 +0800
Subject: [PATCH] Merge branch 'master' of ssh://blit.7drlb.com:29418/screen_api_v2
---
src/main/java/com/moral/service/DeviceVersionService.java | 8
src/main/java/com/moral/service/impl/DeviceVersionServiceImpl.java | 10 +
src/main/java/com/moral/controller/MobileController.java | 4
src/main/java/com/moral/common/util/MyBatisBaseMapUtil.java | 31 +++
src/main/java/com/moral/common/util/StringUtils.java | 85 +++++++++
src/main/java/com/moral/entity/DeviceVersion.java | 1
src/main/java/com/moral/common/util/ExampleUtil.java | 115 ++++++++++++
src/main/java/com/moral/entity/DeviceVersion.java.1 | 55 ++++++
src/main/java/com/moral/controller/DeviceVersionController.java | 18 +
src/main/java/com/moral/entity/DeviceVersion.java.3 | 55 ++++++
src/main/java/com/moral/common/bean/PageBean.java | 5
src/main/java/com/moral/entity/DeviceVersion.java.2 | 55 ++++++
src/main/java/com/moral/entity/DeviceVersion.java.4 | 55 ++++++
13 files changed, 489 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/moral/common/bean/PageBean.java b/src/main/java/com/moral/common/bean/PageBean.java
index 13fa623..60900df 100644
--- a/src/main/java/com/moral/common/bean/PageBean.java
+++ b/src/main/java/com/moral/common/bean/PageBean.java
@@ -1,6 +1,7 @@
package com.moral.common.bean;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.List;
import com.github.pagehelper.Page;
@@ -23,13 +24,13 @@
private Integer pageIndex; // ���������
private Integer pageSize; // ���������������
private Integer pages; // ���������
+ private String queryParams;
private Integer size; // ������������������ <= pageSize������������������ArrayList���size������
/**
* ������Page���������������������������Page������������JSON���������������������������������������List������������
* ������������������������
* @param list page������
- * @param navigatePages ������������
*/
public PageBean(List<T> list) {
super();
@@ -39,7 +40,7 @@
this.pageSize = page.getPageSize();
this.total = page.getTotal();
this.pages = page.getPages();
- this.data = page;
+ this.data= new ArrayList<>(list);
this.size = page.size();
}
}
diff --git a/src/main/java/com/moral/common/util/ExampleUtil.java b/src/main/java/com/moral/common/util/ExampleUtil.java
new file mode 100644
index 0000000..d50d02a
--- /dev/null
+++ b/src/main/java/com/moral/common/util/ExampleUtil.java
@@ -0,0 +1,115 @@
+package com.moral.common.util;
+
+import lombok.extern.log4j.Log4j;
+import tk.mybatis.mapper.entity.Example;
+import java.beans.PropertyDescriptor;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Log4j
+public class ExampleUtil {
+ private final static String OR_SPLIT = "or\\|";
+ private final static String CRITERIA_SPLIT = "\\|\\|\\|";
+ private final static String CONDITION_SPLIT = "\\|\\|";
+ private static Map<String, Method> criteriaMethodMap = null;
+
+ public static Example generateExample(Class clzz, String params) {
+ Example example = new Example(clzz);
+ try {
+ params = URLDecoder.decode(params, "UTF-8");
+ if (!StringUtils.isNullOrEmpty(params) && params.startsWith("or|")) {
+ String[] criteria = params.trim().split(OR_SPLIT);
+ Example.Criteria criteriaOfExample = example.or();
+ for (String criterion : criteria) {
+ if (!StringUtils.isNullOrEmpty(criterion)) {
+ String[] conditions = criterion.trim().split(CRITERIA_SPLIT);
+ for (String condition : conditions) {
+ if (!StringUtils.isNullOrEmpty(condition)) {
+ String[] conditionItems = condition.split(CONDITION_SPLIT);
+ if (conditionItems != null && conditionItems.length > 1) {
+ //���������
+ String methodName = conditionItems[0];
+ //���������
+ String propertyName = conditionItems[1];
+ Method method = getMethod(methodName);
+ if (method != null && isPropertyOfClass(clzz, propertyName)) {
+ List values = new ArrayList<Object>();
+ if (conditionItems.length > 2) {
+ //���������������
+ Class<?> valutType = new PropertyDescriptor(propertyName, clzz).getPropertyType();
+ for (int index = 2; index < conditionItems.length; index++) {
+ values.add(StringUtils.stringToObject4Type(valutType, conditionItems[index]));
+ }
+ }
+ invokeMethod(criteriaOfExample,method,propertyName,values);
+ }
+
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception ex) {
+ log.error(ex.getMessage());
+ ex.printStackTrace();
+ }
+ return example;
+ }
+
+ private static void invokeMethod(Object obj, Method method,String propertyName,List values) throws InvocationTargetException, IllegalAccessException {
+ int len = values.size();
+ switch (len) {
+ case 0:
+ if(method.getParameterCount()==1) {
+ method.invoke(obj, propertyName);
+ }
+ break;
+ case 1:
+
+ if(method.getParameterCount()==2){
+ method.invoke(obj,propertyName,values.get(0));
+ }
+ break;
+ //between ������
+ case 2:
+ if(method.getParameterCount()==3){
+ method.invoke(obj,propertyName,values.toArray());
+ }
+ break;
+ //in ������
+ default:
+ if(method.getParameterCount()==2){
+ method.invoke(obj,propertyName,values);
+ }
+ break;
+ }
+ }
+
+ ;
+
+ private static boolean isPropertyOfClass(Class clzz, String propertyName) throws NoSuchFieldException {
+ return clzz.getDeclaredField(propertyName) != null;
+ }
+
+ private static Method getMethod(String methodName) {
+ if (criteriaMethodMap == null) {
+ criteriaMethodMap = new HashMap<>();
+ Method[] methods = Example.Criteria.class.getMethods();
+ for (Method m : methods) {
+ Method method = criteriaMethodMap.get(m.getName());
+ //���������������������������������
+ if (method==null||m.getParameterTypes().length>method.getParameterTypes().length){
+ criteriaMethodMap.put(m.getName(),m);
+ }
+ }
+ }
+ return criteriaMethodMap.get(methodName);
+ }
+}
diff --git a/src/main/java/com/moral/common/util/MyBatisBaseMapUtil.java b/src/main/java/com/moral/common/util/MyBatisBaseMapUtil.java
new file mode 100644
index 0000000..c306d46
--- /dev/null
+++ b/src/main/java/com/moral/common/util/MyBatisBaseMapUtil.java
@@ -0,0 +1,31 @@
+package com.moral.common.util;
+
+import com.github.pagehelper.PageHelper;
+import com.moral.common.bean.PageBean;
+import com.moral.common.mapper.BaseMapper;
+import com.moral.entity.Account;
+import lombok.extern.log4j.Log4j;
+import tk.mybatis.mapper.entity.Example;
+import tk.mybatis.mapper.mapperhelper.MapperHelper;
+import tk.mybatis.mapper.mapperhelper.MapperTemplate;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Type;
+import java.util.List;
+
+@Log4j
+public class MyBatisBaseMapUtil {
+ public static PageBean queryPage(BaseMapper baseMapper, PageBean pageBean,Class clazz){
+ List page = null;
+ try {
+ Example example = ExampleUtil.generateExample(clazz,pageBean.getQueryParams());
+ PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
+ page = baseMapper.selectByExample(example);
+
+ }catch (Exception ex){
+ log.error(ex.getMessage());
+ ex.printStackTrace();
+ }
+ return new PageBean(page);
+ }
+}
diff --git a/src/main/java/com/moral/common/util/StringUtils.java b/src/main/java/com/moral/common/util/StringUtils.java
new file mode 100644
index 0000000..4b2791b
--- /dev/null
+++ b/src/main/java/com/moral/common/util/StringUtils.java
@@ -0,0 +1,85 @@
+package com.moral.common.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class StringUtils {
+ public static final char UNDERLINE = '_';
+
+ /**
+ * ������������������������������������������������������
+ *
+ * @param param
+ * @return
+ */
+ public static String camelToUnderline(String param) {
+ if (param == null || "".equals(param.trim())) {
+ return "";
+ }
+ int len = param.length();
+ StringBuilder sb = new StringBuilder(len);
+ for (int i = 0; i < len; i++) {
+ char c = param.charAt(i);
+ if (Character.isUpperCase(c)) {
+ sb.append(UNDERLINE);
+ sb.append(Character.toLowerCase(c));
+ } else {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * //������������������
+ *
+ * @param s
+ * @return
+ */
+ public static String toUpperCaseFirstOne(String s){
+ StringBuilder sb = new StringBuilder(s);
+ sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+ return sb.toString();
+ }
+ public static boolean isNullOrEmpty(String toTest) {
+ return toTest == null || toTest.length() == 0;
+ }
+ public static Object stringToObject4Type(Class<?> type,String value) throws Exception{
+ Object result = value;
+
+ if (type == double.class || type == Double.class) {
+ result = Double.parseDouble(value);
+ } else if (type == float.class || type == Float.class) {
+ result = Float.parseFloat(value);
+ } else if (type == long.class || type == Long.class) {
+ result = Long.parseLong(value);
+ } else if (type == int.class || type == Integer.class) {
+ result = Integer.parseInt(value);
+ } else if (type == short.class || type == Short.class) {
+ result = Short.parseShort(value);
+ } else if (type == boolean.class || type == Boolean.class) {
+ result = Boolean.parseBoolean(value);
+ } else if (type == Date.class) {
+ value = value.replace("T", " ");
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ try {
+ result = df.parse(value);
+ } catch (Exception e) {
+ df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+ try {
+ result = df.parse(value);
+ } catch (ParseException e1) {
+ df = new SimpleDateFormat("yyyy-MM-dd");
+ try {
+ result = df.parse(value);
+ } catch (ParseException e2) {
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+}
diff --git a/src/main/java/com/moral/controller/DeviceVersionController.java b/src/main/java/com/moral/controller/DeviceVersionController.java
index 14bf960..e9c750b 100644
--- a/src/main/java/com/moral/controller/DeviceVersionController.java
+++ b/src/main/java/com/moral/controller/DeviceVersionController.java
@@ -1,12 +1,24 @@
package com.moral.controller;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.moral.common.bean.PageBean;
+import com.moral.common.bean.PageResult;
+import com.moral.entity.DeviceVersion;
+import com.moral.service.DeviceVersionService;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.io.UnsupportedEncodingException;
@RestController
@RequestMapping("device-version")
@CrossOrigin(origins = "*", maxAge = 3600)
public class DeviceVersionController {
+ @Resource
+ private DeviceVersionService deviceVersionService;
+
+ @GetMapping("page-list")
+ public PageBean<DeviceVersion> pageList(PageBean pageBean) throws NoSuchMethodException, UnsupportedEncodingException {
+ return deviceVersionService.queryByPageBean(pageBean);
+ }
}
diff --git a/src/main/java/com/moral/controller/MobileController.java b/src/main/java/com/moral/controller/MobileController.java
index ff56619..1f4e182 100644
--- a/src/main/java/com/moral/controller/MobileController.java
+++ b/src/main/java/com/moral/controller/MobileController.java
@@ -117,7 +117,7 @@
/**
* Gets the monitor points by area name.
*
- * @param areaName the area name
+ * @param request the area name
* @return the monitor points by area name
*/
@GetMapping("getMpointsByAreaName")
@@ -130,7 +130,7 @@
/**
* Gets the organizations by area name.
*
- * @param areaName the area name
+ * @param request the area name
* @return the organizations by area name
*/
@GetMapping("getOrgsByAreaName")
diff --git a/src/main/java/com/moral/entity/DeviceVersion.java b/src/main/java/com/moral/entity/DeviceVersion.java
index f11b731..8485a13 100644
--- a/src/main/java/com/moral/entity/DeviceVersion.java
+++ b/src/main/java/com/moral/entity/DeviceVersion.java
@@ -5,7 +5,6 @@
import javax.persistence.Id;
import java.util.Date;
-
@Data
public class DeviceVersion {
@Id
diff --git a/src/main/java/com/moral/entity/DeviceVersion.java.1 b/src/main/java/com/moral/entity/DeviceVersion.java.1
new file mode 100644
index 0000000..d8633f0
--- /dev/null
+++ b/src/main/java/com/moral/entity/DeviceVersion.java.1
@@ -0,0 +1,55 @@
+package com.moral.entity;
+
+import java.util.Date;
+
+public class DeviceVersion {
+ private Integer id;
+
+ private String name;
+
+ private Integer version;
+
+ private Date createTime;
+
+ private String description;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name == null ? null : name.trim();
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description == null ? null : description.trim();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/entity/DeviceVersion.java.2 b/src/main/java/com/moral/entity/DeviceVersion.java.2
new file mode 100644
index 0000000..d8633f0
--- /dev/null
+++ b/src/main/java/com/moral/entity/DeviceVersion.java.2
@@ -0,0 +1,55 @@
+package com.moral.entity;
+
+import java.util.Date;
+
+public class DeviceVersion {
+ private Integer id;
+
+ private String name;
+
+ private Integer version;
+
+ private Date createTime;
+
+ private String description;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name == null ? null : name.trim();
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description == null ? null : description.trim();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/entity/DeviceVersion.java.3 b/src/main/java/com/moral/entity/DeviceVersion.java.3
new file mode 100644
index 0000000..d8633f0
--- /dev/null
+++ b/src/main/java/com/moral/entity/DeviceVersion.java.3
@@ -0,0 +1,55 @@
+package com.moral.entity;
+
+import java.util.Date;
+
+public class DeviceVersion {
+ private Integer id;
+
+ private String name;
+
+ private Integer version;
+
+ private Date createTime;
+
+ private String description;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name == null ? null : name.trim();
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description == null ? null : description.trim();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/entity/DeviceVersion.java.4 b/src/main/java/com/moral/entity/DeviceVersion.java.4
new file mode 100644
index 0000000..d8633f0
--- /dev/null
+++ b/src/main/java/com/moral/entity/DeviceVersion.java.4
@@ -0,0 +1,55 @@
+package com.moral.entity;
+
+import java.util.Date;
+
+public class DeviceVersion {
+ private Integer id;
+
+ private String name;
+
+ private Integer version;
+
+ private Date createTime;
+
+ private String description;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name == null ? null : name.trim();
+ }
+
+ public Integer getVersion() {
+ return version;
+ }
+
+ public void setVersion(Integer version) {
+ this.version = version;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description == null ? null : description.trim();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/moral/service/DeviceVersionService.java b/src/main/java/com/moral/service/DeviceVersionService.java
index d8d4209..7193821 100644
--- a/src/main/java/com/moral/service/DeviceVersionService.java
+++ b/src/main/java/com/moral/service/DeviceVersionService.java
@@ -1,4 +1,12 @@
package com.moral.service;
+import com.moral.common.bean.PageBean;
+import com.moral.entity.DeviceVersion;
+
+import java.io.UnsupportedEncodingException;
+
public interface DeviceVersionService {
+
+ public PageBean queryByPageBean(PageBean pageBean);
+
}
diff --git a/src/main/java/com/moral/service/impl/DeviceVersionServiceImpl.java b/src/main/java/com/moral/service/impl/DeviceVersionServiceImpl.java
index c53e102..e5aaa1e 100644
--- a/src/main/java/com/moral/service/impl/DeviceVersionServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/DeviceVersionServiceImpl.java
@@ -1,13 +1,23 @@
package com.moral.service.impl;
+import com.moral.common.bean.PageBean;
+import com.moral.common.util.ExampleUtil;
+import com.moral.common.util.MyBatisBaseMapUtil;
+import com.moral.entity.DeviceVersion;
import com.moral.mapper.DeviceVersionMapper;
import com.moral.service.DeviceVersionService;
import org.springframework.stereotype.Service;
+import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
+import java.io.UnsupportedEncodingException;
@Service
public class DeviceVersionServiceImpl implements DeviceVersionService {
@Resource
private DeviceVersionMapper deviceVersionMapper;
+ private static Class ENTITY_CLASS = DeviceVersion.class;
+ public PageBean queryByPageBean(PageBean pageBean){
+ return MyBatisBaseMapUtil.queryPage(deviceVersionMapper,pageBean,ENTITY_CLASS);
+ }
}
--
Gitblit v1.8.0