Browse Source

nsy 随身帮

ningsy 3 years ago
parent
commit
3979c9c75d

+ 74 - 0
suishenbang-common/src/main/java/com/dgtly/common/utils/StringUtils.java

@@ -1,5 +1,7 @@
 package com.dgtly.common.utils;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Map;
 import com.dgtly.common.core.text.StrFormatter;
@@ -395,4 +397,76 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
         }
         return sb.toString();
     }
+
+    /**
+     * 去掉bean中所有属性为字符串的前后空格
+     * @param bean
+     * @throws Exception
+     */
+    public static void beanAttributeValueTrim(Object bean) throws Exception {
+        if(bean!=null){
+            //获取所有的字段包括public,private,protected,private
+            Field[] fields = bean.getClass().getDeclaredFields();
+            for (int i = 0; i < fields.length; i++) {
+                Field f = fields[i];
+                if (f.getType().getName().equals("java.lang.String")) {
+                    String key = f.getName();//获取字段名
+                    Object value = getFieldValue(bean, key);
+
+                    if (value == null)
+                        continue;
+
+                    setFieldValue(bean, key, value.toString().trim());
+                }
+            }
+        }
+    }
+
+    /**
+     * 利用反射通过get方法获取bean中字段fieldName的值
+     * @param bean
+     * @param fieldName
+     * @return
+     * @throws Exception
+     */
+    private static Object getFieldValue(Object bean, String fieldName)
+            throws Exception {
+        StringBuffer result = new StringBuffer();
+        String methodName = result.append("get")
+                .append(fieldName.substring(0, 1).toUpperCase())
+                .append(fieldName.substring(1)).toString();
+
+        Object rObject = null;
+        Method method = null;
+
+        @SuppressWarnings("rawtypes")
+        Class[] classArr = new Class[0];
+        method = bean.getClass().getMethod(methodName, classArr);
+        rObject = method.invoke(bean, new Object[0]);
+
+        return rObject;
+    }
+
+    /**
+     * 利用发射调用bean.set方法将value设置到字段
+     * @param bean
+     * @param fieldName
+     * @param value
+     * @throws Exception
+     */
+    private static void setFieldValue(Object bean, String fieldName, Object value)
+            throws Exception {
+        StringBuffer result = new StringBuffer();
+        String methodName = result.append("set")
+                .append(fieldName.substring(0, 1).toUpperCase())
+                .append(fieldName.substring(1)).toString();
+
+        /**
+         * 利用发射调用bean.set方法将value设置到字段
+         */
+        Class[] classArr = new Class[1];
+        classArr[0]="java.lang.String".getClass();
+        Method method=bean.getClass().getMethod(methodName,classArr);
+        method.invoke(bean,value);
+    }
 }

+ 0 - 1
suishenbang-order/src/main/java/com/dgtly/order/controller/DiysalesorgStartController.java

@@ -3,7 +3,6 @@ package com.dgtly.order.controller;
 import java.util.List;
 
 import com.dgtly.order.domain.DiySalesorgtree;
-import com.dgtly.order.domain.OrderCustomers;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;

+ 0 - 2
suishenbang-order/src/main/java/com/dgtly/order/controller/OrderSalesGroupController.java

@@ -13,8 +13,6 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
-import com.dgtly.common.annotation.Log;
-import com.dgtly.common.enums.BusinessType;
 import com.dgtly.common.core.controller.BaseController;
 import com.dgtly.common.core.domain.AjaxResult;
 import com.dgtly.common.utils.poi.ExcelUtil;

+ 6 - 1
suishenbang-order/src/main/java/com/dgtly/order/service/impl/CustomersStartServiceImpl.java

@@ -2,8 +2,8 @@ package com.dgtly.order.service.impl;
 
 import java.util.List;
 
+import com.dgtly.common.utils.StringUtils;
 import com.dgtly.order.domain.OrderCustomers;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.dgtly.order.mapper.CustomersStartMapper;
 import com.dgtly.order.domain.CustomersStart;
@@ -105,6 +105,11 @@ public class CustomersStartServiceImpl implements ICustomersStartService
      */
     @Override
     public List<OrderCustomers> selectcustomersList(OrderCustomers customers) {
+        try {
+            StringUtils.beanAttributeValueTrim(customers);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return customersStartMapper.selectcustomersList(customers);
     }
 

+ 6 - 3
suishenbang-order/src/main/java/com/dgtly/order/service/impl/DiysalesorgStartServiceImpl.java

@@ -2,10 +2,8 @@ package com.dgtly.order.service.impl;
 
 import java.util.List;
 
-import com.dgtly.order.domain.CustomersStart;
+import com.dgtly.common.utils.StringUtils;
 import com.dgtly.order.domain.DiySalesorgtree;
-import com.dgtly.order.domain.OrderCustomers;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.dgtly.order.mapper.DiysalesorgStartMapper;
 import com.dgtly.order.domain.DiysalesorgStart;
@@ -105,6 +103,11 @@ public class DiysalesorgStartServiceImpl implements IDiysalesorgStartService
      */
     @Override
     public List<DiySalesorgtree> findSalesOrgList(DiySalesorgtree salesorgtree) {
+        try {
+            StringUtils.beanAttributeValueTrim(salesorgtree);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return diysalesorgStartMapper.selectSalesOrgList(salesorgtree);
     }
 

+ 1 - 1
suishenbang-order/src/main/resources/mapper/order/CustomersStartMapper.xml

@@ -36,7 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="chainsName != null and chainsName != ''">
             AND chains_name like concat('%', #{chainsName}, '%')
         </if>
-        GROUP BY chains_code
+        GROUP BY chains_code,chains_name
     </select>
     <select id="selectCustomersById" resultType="com.dgtly.order.domain.OrderCustomers" parameterType="Long">
          select id, chains_name as chainsName, chains_code as chainsCode, state_name as stateName, city_name as cityName

+ 1 - 1
suishenbang-order/src/main/resources/mapper/order/DiysalesorgStartMapper.xml

@@ -61,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="org5name != null  and org5name != ''"> and Org5name like concat('%', #{org5name}, '%')</if>
         <if test="org6code != null  and org6code != ''"> and Org6code like concat('%', #{org6code}, '%')</if>
         <if test="org6name != null  and org6name != ''"> and Org6name like concat('%', #{org6name}, '%')</if>
-
+        GROUP BY Org6code,Org6name
     </select>
 
     <insert id="insertDiysalesorgStart" parameterType="com.dgtly.order.domain.DiysalesorgStart">

+ 2 - 2
suishenbang-order/src/main/resources/templates/order/salesorgStart/add.html

@@ -12,10 +12,10 @@
                 <div class="select-list">
                     <ul>
                         <li>
-                            公司名称:<input type="text" name="org3name"/>
+                            公司名称&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="org3name"/>
                         </li>
                         <li>
-                            大区名称:<input type="text" name="org4name"/>
+                            &nbsp;&nbsp;&nbsp;大区名称&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="org4name"/>
                         </li>
                         <li>
                             销售部名称:<input type="text" name="org5name"/>