Ver código fonte

年平均周温度

lvzhikai 4 anos atrás
pai
commit
0d4fef313d

+ 2 - 1
src/main/java/com/chinaitop/depot/DatePermissionInterceptor.java

@@ -61,7 +61,8 @@ public class DatePermissionInterceptor implements Interceptor {
61 61
 		String bouString = boundSql.getSql();// 获取执行sql 
62 62
 		
63 63
 		//sql是查询的才进行权限过滤
64
-	    if(mappedStatement.getSqlCommandType().toString().equals("select".toUpperCase())) {
64
+	    if(mappedStatement.getSqlCommandType().toString().equals("select".toUpperCase())&&
65
+				!"com.chinaitop.depot.supervise.mapper.TestDatasMapper.selectByYear".equals(mappedStatement.getId())) {
65 66
 	    
66 67
 			//通过本地线程获取库id
67 68
 			Object threadLocalObj = DataPolicyEngine.get();

+ 18 - 2
src/main/java/com/chinaitop/depot/supervise/controller/GrainConditionController.java

@@ -82,6 +82,22 @@ public class GrainConditionController {
82 82
     }
83 83
 
84 84
     /**
85
+     * 通过cfbh获取当年的三温数据
86
+     * @param orgId 库id
87
+     * @param barnNumber 仓房编号
88
+     * @return
89
+     */
90
+    @RequestMapping(value = "/getThreeConditionYear", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
91
+    @ApiOperation(value="当年的三温数据", notes = "通过cfbh获取当年的三温数据")
92
+    @ApiImplicitParams({
93
+            @ApiImplicitParam(name = "orgId", value = "组织机构id", paramType = "query"),
94
+            @ApiImplicitParam(name = "barnNumber", value = "仓房编号", paramType = "query")
95
+    })
96
+    public List<Map<String, Object>> getThreeConditionYear(Integer orgId,String barnNumber) {
97
+        return grainConditionService.getThreeConditionYear(orgId,barnNumber);
98
+    }
99
+
100
+    /**
85 101
      * 通过cfbh获取当天的三温数据,查询当天的列表数据,按时间排序--首页用到
86 102
      * @param orgId 库id
87 103
      * @param barnNumber 仓房编号
@@ -102,11 +118,11 @@ public class GrainConditionController {
102 118
     }
103 119
 
104 120
     /**
105
-     *根据仓房编号查询对应测温数据
121
+     *根据仓房id查询品种,性质
106 122
      * 传入仓id
107 123
      */
108 124
     @RequestMapping(value = "/getTempByHouseNo", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
109
-    @ApiOperation(value="测温数据", notes = "根据仓房编号查询对应测温数据")
125
+    @ApiOperation(value="仓房数据", notes = "根据仓房编号查询品种,性质")
110 126
     @ApiImplicitParams({
111 127
             @ApiImplicitParam(name = "houseNo", value = "仓房ID", paramType = "query"),
112 128
             @ApiImplicitParam(name = "orgId", value = "组织机构id", paramType = "query"),

+ 1 - 2
src/main/java/com/chinaitop/depot/supervise/mapper/TestDatasMapper.java

@@ -11,8 +11,6 @@ public interface TestDatasMapper {
11 11
 
12 12
     //根据仓房编号获取仓房温度数据
13 13
     Map<String,Object> getTempByHouseNo(Map<String,String> map);
14
-    Map<String,Object> getYGTempByHouseNo(Map<String,String> map);
15
-
16 14
     //获取仓温列表
17 15
     List<Map<String,Object>> getDataList(Map<String,String> map);
18 16
 
@@ -22,6 +20,7 @@ public interface TestDatasMapper {
22 20
     //获取指定仓房的三温
23 21
     List<Map<String,Object>> selectByDays(Map<String,Object> map);
24 22
     List<Map<String,Object>> selectYGByDays(Map<String,Object> map);
23
+    List<Map<String,Object>> selectByYear(Map<String,Object> map);
25 24
 
26 25
     //给pad端提供的三温图的接口
27 26
     List<Map<String,Object>> getThreeConditionForPad(Map<String,Object> map);

+ 22 - 90
src/main/java/com/chinaitop/depot/supervise/mapper/TestDatasMapper.xml

@@ -3,98 +3,14 @@
3 3
 <mapper namespace="com.chinaitop.depot.supervise.mapper.TestDatasMapper">
4 4
     
5 5
     <select id="getTempByHouseNo" resultType="java.util.Map" parameterType="java.util.Map">
6
-        SELECT t2.id,
7
-               si.storehouse_name HouseNo,
8
-               si.storehouse_id   house,
9
-               t2.time            TestDate,
10
-               t2.inTemp _InT,
11
-                t2.outTemp OutT,
12
-                t2.inH InH,
13
-                t2.OutH OutH,
14
-                t2.avg AvgT,
15
-                t2.min MinT,
16
-                t2.max MaxT,
17
-                kcsw.pz sub_type,
18
-                kcsw.hwxz quality
19
-        FROM
20
-            basic_storehouse si
21
-            LEFT JOIN (
22
-            SELECT
23
-            id,
24
-            time,
25
-            inTemp,
26
-            outTemp,
27
-            inH,
28
-            OutH,
29
-            avg,
30
-            min,
31
-            max,
32
-            storehouse
33
-            FROM
34
-            t_testdata
35
-            WHERE
36
-            iLq_yq = 0
37
-            AND org_id = #{orgId,jdbcType=VARCHAR}
38
-            AND storehouse = #{houseCode,jdbcType=VARCHAR}
39
-            ORDER BY
40
-            time DESC
41
-            LIMIT 1
42
-            ) t2
43
-        ON t2.storehouse = si.storehouse_code
44
-            LEFT JOIN lsreport_ts.data_kcgl_kcsw_default kcsw ON si.storehouse_id = kcsw.ch
45
-        WHERE
46
-            si.org_id = #{orgId,jdbcType=VARCHAR}
47
-          AND si.storehouse_id = #{houseId,jdbcType=VARCHAR}
48
-    </select>
49
-
50
-    <select id="getYGTempByHouseNo" resultType="java.util.Map" parameterType="java.util.Map">
51 6
         SELECT
52
-        t2.id,
53
-        tank.storageTank_name HouseNo,
54
-        tank.id house,
55
-        t2.time TestDate,
56
-        t2.inTemp _InT,
57
-        t2.outTemp OutT,
58
-        t2.inH InH,
59
-        t2.OutH OutH,
60
-        t2.avg AvgT,
61
-        t2.min MinT,
62
-        t2.max MaxT,
63
-        foodbasic.record_unite,
64
-        foodbasic.sub_type,
65
-        foodbasic.quality
7
+            pz sub_type,
8
+            hwxz quality
66 9
         FROM
67
-        (
68
-        SELECT
69
-        t.*
70
-        FROM
71
-        (
72
-        SELECT
73
-        *
74
-        FROM
75
-        t_testdata
76
-        WHERE iLq_yq = 0
77
-        <if test="orgId != null" >
78
-            AND org_id = #{orgId,jdbcType=VARCHAR}
79
-        </if>
80
-        ORDER BY time DESC
81
-        ) t
82
-        GROUP BY t.storehouse
83
-        ) t2
84
-        LEFT JOIN basic_tank tank ON t2.storehouse = tank.storageTank_code
85
-        <if test="orgId != null" >
86
-            AND tank.org_id = #{orgId,jdbcType=VARCHAR}
87
-        </if>
88
-        LEFT JOIN storage_foodbasicinfo foodbasic ON tank.id = foodbasic.house_id AND foodbasic.history_status = 0
89
-        <if test="orgId != null" >
90
-            AND foodbasic.org_id = #{orgId,jdbcType=VARCHAR}
91
-        </if>
92
-        WHERE t2.storehouse = tank.storageTank_code
93
-        <if test="houseId != null" >
94
-            AND tank.id=#{houseId,jdbcType=VARCHAR}
95
-        </if>
96
-        ORDER BY t2.storehouse
97
-        LIMIT 1
10
+            lsreport_ts.data_kcgl_kcsw_default
11
+        WHERE
12
+            UnitID = #{orgId,jdbcType=VARCHAR}
13
+          AND ch = #{houseId,jdbcType=VARCHAR}
98 14
     </select>
99 15
 
100 16
   <select id="getDataList" resultType="java.util.Map" parameterType="java.util.Map">
@@ -229,6 +145,22 @@
229 145
             DATE_FORMAT(t.time, '%Y-%m-%d');
230 146
   </select>
231 147
 
148
+  <select id="selectByYear" resultType="java.util.Map" parameterType="java.util.Map" >
149
+      SELECT
150
+          WEEKOFYEAR(time) djz,
151
+          cast(AVG(`avg`) as decimal(20,2)) lswd,
152
+          cast(AVG(`inTemp`) as decimal(20,2)) cnwd,
153
+          cast(AVG(`outTemp`) as decimal(20,2)) cwwd
154
+      FROM
155
+          t_testdata
156
+      WHERE
157
+              org_id = #{orgid,jdbcType=VARCHAR}
158
+          AND storehouse = #{houseCode,jdbcType=VARCHAR}
159
+          AND YEAR (time) = YEAR (CURDATE())
160
+      GROUP BY
161
+          WEEKOFYEAR(time)
162
+  </select>
163
+
232 164
     <select id="selectByHours" resultType="java.util.Map" parameterType="java.util.Map" >
233 165
         SELECT
234 166
             Max(DATE_FORMAT(t.time, '%Y-%m-%d')) check_date,

+ 1 - 0
src/main/java/com/chinaitop/depot/supervise/service/GrainConditionService.java

@@ -10,6 +10,7 @@ public interface GrainConditionService {
10 10
     List<Map<String,Object>> getDataList(String houseNo, String orgId);
11 11
 
12 12
     List<Map<String,Object>> getThreeCondition(Map<String,Object> example);
13
+    List<Map<String,Object>> getThreeConditionYear(Integer orgId,String barnNumber);
13 14
 
14 15
     List<Map<String,Object>> getThreeConditionHomePage(Map<String,Object> example);
15 16
 

+ 46 - 6
src/main/java/com/chinaitop/depot/supervise/service/impl/GrainConditionServiceImpl.java

@@ -1,7 +1,10 @@
1 1
 package com.chinaitop.depot.supervise.service.impl;
2 2
 
3 3
 
4
+import com.chinaitop.depot.supervise.mapper.TTestdataYearMapper;
4 5
 import com.chinaitop.depot.supervise.mapper.TestDatasMapper;
6
+import com.chinaitop.depot.supervise.model.TTestdataYear;
7
+import com.chinaitop.depot.supervise.model.TTestdataYearExample;
5 8
 import com.chinaitop.depot.supervise.service.GrainConditionService;
6 9
 import com.chinaitop.utils.ParameterUtil;
7 10
 import com.chinaitop.utils.activiti.StringUtils;
@@ -18,6 +21,8 @@ public class GrainConditionServiceImpl implements GrainConditionService {
18 21
 
19 22
     @Resource
20 23
     private TestDatasMapper testDatasMapper;
24
+    @Resource
25
+    private TTestdataYearMapper tTestdataYearMapper;
21 26
 
22 27
     /**
23 28
      * 获取最新仓房温度列表
@@ -35,7 +40,7 @@ public class GrainConditionServiceImpl implements GrainConditionService {
35 40
     }
36 41
 
37 42
     /**
38
-     * 根据仓房id查询对应仓房温度
43
+     * 根据仓房id查询品种,性质
39 44
      * @param houseId
40 45
      * @return
41 46
      */
@@ -45,11 +50,7 @@ public class GrainConditionServiceImpl implements GrainConditionService {
45 50
         map.put("houseId",houseId);
46 51
         map.put("orgId",orgId);
47 52
         map.put("houseCode",houseCode);
48
-        if(ParameterUtil.isnotnull(houseId) && ParameterUtil.isequal("YG",houseId.substring(0,2))){
49
-            return testDatasMapper.getYGTempByHouseNo(map);
50
-        }else{
51
-            return testDatasMapper.getTempByHouseNo(map);
52
-        }
53
+        return testDatasMapper.getTempByHouseNo(map);
53 54
     }
54 55
 
55 56
     /**
@@ -66,6 +67,45 @@ public class GrainConditionServiceImpl implements GrainConditionService {
66 67
         }
67 68
     }
68 69
 
70
+    @Override
71
+    public List<Map<String,Object>> getThreeConditionYear(Integer orgId,String barnNumber) {
72
+        List<Map<String, Object>> testYear = new ArrayList<Map<String,Object>>();
73
+        Map<String, Object> byMonth = new HashMap<String, Object>();//基础信息
74
+        TTestdataYearExample example = new TTestdataYearExample();
75
+        TTestdataYearExample.Criteria criteria = example.createCriteria();
76
+
77
+        //添加查询条件
78
+        byMonth.put("orgid", orgId);
79
+        criteria.andOrgIdEqualTo(orgId.toString());
80
+        byMonth.put("houseCode", barnNumber);
81
+        criteria.andStorehouseEqualTo(barnNumber);
82
+
83
+        //判断年粮情表是否有数据
84
+        //如果没有数据则重新查询并存储到年粮情表,以便下回使用
85
+        //有数据,并且数据和查询时间在同一周就直接用
86
+        //否则就,查询最新数据,并存储到年粮情表,以便下回使用
87
+        List<TTestdataYear> tTestdataYears = tTestdataYearMapper.selectByExample(example);
88
+        if (ParameterUtil.isequal(0, tTestdataYears.size())) {
89
+            testYear = testDatasMapper.selectByYear(byMonth);
90
+            TTestdataYear tTestdataYear = new TTestdataYear();
91
+            tTestdataYear.setOrgId(orgId.toString());
92
+            tTestdataYear.setStorehouse(barnNumber);
93
+            tTestdataYear.setQueryTime(new Date());
94
+            tTestdataYear.setTemperatureData(ParameterUtil.ListToString(testYear));
95
+
96
+            tTestdataYearMapper.insert(tTestdataYear);
97
+        } else if (ParameterUtil.isSameDate(tTestdataYears.get(0).getQueryTime(), new Date())) {
98
+            testYear = ParameterUtil.StringToList(tTestdataYears.get(0).getTemperatureData());
99
+        } else {
100
+            testYear = testDatasMapper.selectByYear(byMonth);
101
+            tTestdataYears.get(0).setQueryTime(new Date());
102
+            tTestdataYears.get(0).setTemperatureData(ParameterUtil.ListToString(testYear));
103
+            tTestdataYearMapper.updateByPrimaryKeySelective(tTestdataYears.get(0));
104
+        }
105
+
106
+        return testYear;
107
+    }
108
+
69 109
     /**
70 110
      * 根据仓房BH获取三温曲线图--首页用到
71 111
      * @param example

+ 200 - 46
src/main/java/com/chinaitop/utils/ParameterUtil.java

@@ -4,39 +4,36 @@ import java.io.BufferedInputStream;
4 4
 import java.io.InputStream;
5 5
 import java.text.ParseException;
6 6
 import java.text.SimpleDateFormat;
7
-import java.util.Calendar;
8
-import java.util.Date;
9
-import java.util.List;
10
-import java.util.Properties;
7
+import java.util.*;
11 8
 
12 9
 public class ParameterUtil {
13 10
 
14
-    public static String getSysDateTime(){
15
-        String temp_str="";
11
+    public static String getSysDateTime() {
12
+        String temp_str = "";
16 13
         Date dt = new Date();
17 14
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
18
-        temp_str=sdf.format(dt);
19
-        System.out.println("获取当前时间"+temp_str);
15
+        temp_str = sdf.format(dt);
16
+        System.out.println("获取当前时间" + temp_str);
20 17
         return temp_str;
21 18
     }
22
-    
19
+
23 20
     public static String getDateYMDHMS(Date date) {
24
-    	String str = "";
21
+        String str = "";
25 22
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
26
-        str=sdf.format(date);
27
-        System.out.println("获取当前时间"+str);
23
+        str = sdf.format(date);
24
+        System.out.println("获取当前时间" + str);
28 25
         return str;
29 26
     }
30
-    
31
-    public static String getSysDate(){
32
-        String temp_str="";
27
+
28
+    public static String getSysDate() {
29
+        String temp_str = "";
33 30
         Date dt = new Date();
34 31
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
35
-        temp_str=sdf.format(dt);
32
+        temp_str = sdf.format(dt);
36 33
         return temp_str;
37 34
     }
38 35
 
39
-    public static Date string2datetime(String dateTime){
36
+    public static Date string2datetime(String dateTime) {
40 37
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
41 38
         Date date = null;
42 39
         try {
@@ -46,7 +43,8 @@ public class ParameterUtil {
46 43
         }
47 44
         return date;
48 45
     }
49
-    public static Date string2date(String dateTime){
46
+
47
+    public static Date string2date(String dateTime) {
50 48
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
51 49
         Date date = null;
52 50
         try {
@@ -57,20 +55,21 @@ public class ParameterUtil {
57 55
         return date;
58 56
     }
59 57
 
60
-    public static String date2string(Date date){
61
-        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
62
-        String str=sdf.format(date);
58
+    public static String date2string(Date date) {
59
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
60
+        String str = sdf.format(date);
63 61
         return str;
64 62
     }
65 63
 
66 64
     /**
67 65
      * 获取指定时间的时间戳
66
+     *
68 67
      * @param datatime
69 68
      * @return
70 69
      */
71
-    public static String getTimeStamp(String datatime){
70
+    public static String getTimeStamp(String datatime) {
72 71
         long timeStamp = 0;
73
-        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
72
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
74 73
         try {
75 74
             Date date = format.parse(datatime);
76 75
             timeStamp = date.getTime();
@@ -83,7 +82,7 @@ public class ParameterUtil {
83 82
     /*
84 83
      * 将时间戳转换为时间
85 84
      */
86
-    public static String stampToDate(String s){
85
+    public static String stampToDate(String s) {
87 86
         String res;
88 87
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
89 88
         long lt = new Long(s);
@@ -92,34 +91,34 @@ public class ParameterUtil {
92 91
         return res;
93 92
     }
94 93
 
95
-//    public static void main(String[] args) {
94
+    //    public static void main(String[] args) {
96 95
 //        System.out.println(stampToDate("1504689208643"));
97 96
 //        System.out.println(getTimeStamp(getSysDateTime()));
98 97
 //    }
99
-    public static String getBHS(String BHS){
98
+    public static String getBHS(String BHS) {
100 99
         String[] str = BHS.split(",");
101 100
         StringBuffer sb = new StringBuffer();
102
-        for(int i=0;i<str.length;i++){
101
+        for (int i = 0; i < str.length; i++) {
103 102
             sb.append("'").append(str[i]).append("'").append(",");
104 103
         }
105
-        String s=sb.toString();
106
-        String t=s.substring(0,s.length()-1);
104
+        String s = sb.toString();
105
+        String t = s.substring(0, s.length() - 1);
107 106
         return t;
108 107
     }
109 108
 
110 109
     //判断字段值是为空 不为空返回ture
111
-    public static boolean isnotnull(Object name){
112
-        return (null!=name&&!"".equals(name) && !"null".equals(name) && "null" != name);
110
+    public static boolean isnotnull(Object name) {
111
+        return (null != name && !"".equals(name) && !"null".equals(name) && "null" != name);
113 112
     }
114
-    
113
+
115 114
     //判断字段值是为空,为空返回ture
116
-    public static boolean isnull(Object name){
117
-        return (null==name || "".equals(name) || "null".equals(name) || "null" == name);
115
+    public static boolean isnull(Object name) {
116
+        return (null == name || "".equals(name) || "null".equals(name) || "null" == name);
118 117
     }
119 118
 
120 119
     //判断字段值是相等  相等返回ture
121
-    public static boolean isequal(Object name,Object value){
122
-        if(name==value||name.equals(value)){
120
+    public static boolean isequal(Object name, Object value) {
121
+        if (name == value || name.equals(value)) {
123 122
             return true;
124 123
         }
125 124
         return false;
@@ -127,14 +126,15 @@ public class ParameterUtil {
127 126
 
128 127
     /**
129 128
      * 判断list和str数组是否全等
129
+     *
130 130
      * @param list
131 131
      * @param str
132 132
      * @return
133 133
      */
134
-    public static boolean isAllequal(List<String> list,String[] str){
134
+    public static boolean isAllequal(List<String> list, String[] str) {
135 135
         boolean isbz = true;
136
-        for(int z=0;z<str.length;z++){
137
-            if(!isequal(list.get(z),str[z])){
136
+        for (int z = 0; z < str.length; z++) {
137
+            if (!isequal(list.get(z), str[z])) {
138 138
                 isbz = false;
139 139
                 break;
140 140
             }
@@ -143,9 +143,9 @@ public class ParameterUtil {
143 143
     }
144 144
 
145 145
     //判断字段值是否在某个集合里  在返回ture
146
-    public static boolean isallequal(Object name,String[] value){
147
-        for(int i=0;i<value.length;i++){
148
-            if(name==value[i]||name.equals(value[i])){
146
+    public static boolean isallequal(Object name, String[] value) {
147
+        for (int i = 0; i < value.length; i++) {
148
+            if (name == value[i] || name.equals(value[i])) {
149 149
                 return true;
150 150
             }
151 151
         }
@@ -154,6 +154,7 @@ public class ParameterUtil {
154 154
 
155 155
     /**
156 156
      * 从properties得到路径
157
+     *
157 158
      * @param filePath
158 159
      * @return
159 160
      */
@@ -168,15 +169,14 @@ public class ParameterUtil {
168 169
         return props;
169 170
     }
170 171
 
171
-    public static String dellOneDay(String time)
172
-    {
172
+    public static String dellOneDay(String time) {
173 173
         String add = null;
174 174
         try {
175 175
             SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
176 176
             java.util.Date timeNow = df.parse(time);
177
-            Calendar begin=Calendar.getInstance();
177
+            Calendar begin = Calendar.getInstance();
178 178
             begin.setTime(timeNow);
179
-            begin.add(Calendar.DAY_OF_MONTH,-1);
179
+            begin.add(Calendar.DAY_OF_MONTH, -1);
180 180
             add = df.format(begin.getTime());
181 181
         } catch (Exception e) {
182 182
             e.printStackTrace();
@@ -184,4 +184,158 @@ public class ParameterUtil {
184 184
         return add;
185 185
     }
186 186
 
187
+    //判断两个时间是否是同一周
188
+    public static boolean isSameDate(Date d1, Date d2) {
189
+        Calendar cal1 = Calendar.getInstance();
190
+        Calendar cal2 = Calendar.getInstance();
191
+        cal1.setTime(d1);
192
+        cal2.setTime(d2);
193
+        int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
194
+        //subYear==0,说明是同一年
195
+        if (subYear == 0) {
196
+            if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
197
+                return true;
198
+        }
199
+        //例子:cal1是"2005-1-1",cal2是"2004-12-25"
200
+        //java对"2004-12-25"处理成第52周
201
+        // "2004-12-26"它处理成了第1周,和"2005-1-1"相同了
202
+        //大家可以查一下自己的日历
203
+        //处理的比较好
204
+        //说明:java的一月用"0"标识,那么12月用"11"
205
+        else if (subYear == 1 && cal2.get(Calendar.MONTH) == 11) {
206
+            if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
207
+                return true;
208
+        }
209
+        //例子:cal1是"2004-12-31",cal2是"2005-1-1"
210
+        else if (subYear == -1 && cal1.get(Calendar.MONTH) == 11) {
211
+            if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))
212
+                return true;
213
+        }
214
+        return false;
215
+    }
216
+
217
+    /**
218
+     * List转换String
219
+     *
220
+     * @param list :需要转换的List
221
+     * @return String转换后的字符串
222
+     */
223
+    public static String ListToString(List<?> list) {
224
+        StringBuffer sb = new StringBuffer();
225
+        if (list != null && list.size() > 0) {
226
+            for (int i = 0; i < list.size(); i++) {
227
+                if (list.get(i) == null || list.get(i) == "") {
228
+                    continue;
229
+                }
230
+                // 如果值是list类型则调用自己
231
+                if (list.get(i) instanceof List) {
232
+                    sb.append(ListToString((List<?>) list.get(i)));
233
+                    sb.append(",");
234
+                } else if (list.get(i) instanceof Map) {
235
+                    sb.append(MapToString((Map<?, ?>) list.get(i)));
236
+                    sb.append(",");
237
+                } else {
238
+                    sb.append(list.get(i));
239
+                    sb.append(",");
240
+                }
241
+            }
242
+        }
243
+        return "L" + sb.toString();
244
+    }
245
+
246
+    /**
247
+     * Map转换String
248
+     *
249
+     * @param map :需要转换的Map
250
+     * @return String转换后的字符串
251
+     */
252
+    public static String MapToString(Map<?, ?> map) {
253
+        StringBuffer sb = new StringBuffer();
254
+        // 遍历map
255
+        for (Object obj : map.keySet()) {
256
+            if (obj == null) {
257
+                continue;
258
+            }
259
+            Object key = obj;
260
+            Object value = map.get(key);
261
+            if (value instanceof List<?>) {
262
+                sb.append(key.toString() + "," + ListToString((List<?>) value));
263
+                sb.append("|");
264
+            } else if (value instanceof Map<?, ?>) {
265
+                sb.append(key.toString() + "," + MapToString((Map<?, ?>) value));
266
+                sb.append("|");
267
+            } else {
268
+                sb.append(key.toString() + "=" + value.toString());
269
+                sb.append("|");
270
+            }
271
+        }
272
+        return "M" + sb.toString();
273
+    }
274
+
275
+    /**
276
+     * String转换List
277
+     *
278
+     * @param listText
279
+     *            :需要转换的文本
280
+     * @return List<?>
281
+     */
282
+    public static List<Map<String,Object>> StringToList(String listText) {
283
+        if (listText == null || listText.equals("")) {
284
+            return null;
285
+        }
286
+        listText = listText.substring(1);
287
+
288
+        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
289
+        String[] text = listText.split("\\" + ",");
290
+        String listStr = "";
291
+        boolean flag = false;
292
+        for (String str : text) {
293
+            if (!str.equals("")) {
294
+                if (str.charAt(0) == 'M') {
295
+                    Map<String,Object> map = StringToMap(str);
296
+                    list.add(map);
297
+                } else if (str.charAt(0) == 'L' || flag) {
298
+                    flag = true;
299
+                    listStr += str + ",";
300
+                }
301
+            }
302
+        }
303
+        return list;
304
+    }
305
+
306
+    /**
307
+     * String转换Map
308
+     *
309
+     * @param mapText
310
+     *            :需要转换的字符串
311
+     * @return Map<?,?>
312
+     */
313
+    public static Map<String, Object> StringToMap(String mapText) {
314
+
315
+        if (mapText == null || mapText.equals("")) {
316
+            return null;
317
+        }
318
+        mapText = mapText.substring(1);
319
+
320
+        Map<String, Object> map = new HashMap<String, Object>();
321
+        String[] text = mapText.split("\\" + "|"); // 转换为数组
322
+        for (String str : text) {
323
+            String[] keyText = str.split("="); // 转换key与value的数组
324
+            if (keyText.length < 1) {
325
+                continue;
326
+            }
327
+            String key = keyText[0]; // key
328
+            String value = keyText[1]; // value
329
+            if (value.charAt(0) == 'M') {
330
+                Map<?, ?> map1 = StringToMap(value);
331
+                map.put(key, map1);
332
+            } else if (value.charAt(0) == 'L') {
333
+                List<?> list = StringToList(value);
334
+                map.put(key, list);
335
+            } else {
336
+                map.put(key, value);
337
+            }
338
+        }
339
+        return map;
340
+    }
187 341
 }