Просмотр исходного кода

机构编辑库区图片转二进制流

hefeng лет назад: 5
Родитель
Сommit
e6d349e1d2

+ 39 - 0
src/main/java/com/chinaitop/depot/system/controller/OrgInfoController.java

@@ -16,6 +16,7 @@ import com.chinaitop.depot.system.service.RoleButtonService;
16
 import com.chinaitop.depot.system.service.RoleFuncService;
16
 import com.chinaitop.depot.system.service.RoleFuncService;
17
 import com.chinaitop.depot.system.service.RoleInfoService;
17
 import com.chinaitop.depot.system.service.RoleInfoService;
18
 import com.chinaitop.depot.utils.DataSynchronization;
18
 import com.chinaitop.depot.utils.DataSynchronization;
19
+import com.chinaitop.depot.utils.FileUtil;
19
 import com.fasterxml.jackson.core.JsonParseException;
20
 import com.fasterxml.jackson.core.JsonParseException;
20
 import com.fasterxml.jackson.databind.JsonMappingException;
21
 import com.fasterxml.jackson.databind.JsonMappingException;
21
 import com.fasterxml.jackson.databind.ObjectMapper;
22
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -29,6 +30,7 @@ import io.swagger.annotations.ApiOperation;
29
 
30
 
30
 import org.apache.commons.lang.ObjectUtils;
31
 import org.apache.commons.lang.ObjectUtils;
31
 import org.apache.commons.lang3.StringUtils;
32
 import org.apache.commons.lang3.StringUtils;
33
+import org.springframework.beans.factory.annotation.Value;
32
 import org.springframework.web.bind.annotation.RequestMapping;
34
 import org.springframework.web.bind.annotation.RequestMapping;
33
 import org.springframework.web.bind.annotation.RequestMethod;
35
 import org.springframework.web.bind.annotation.RequestMethod;
34
 import org.springframework.web.bind.annotation.RestController;
36
 import org.springframework.web.bind.annotation.RestController;
@@ -70,6 +72,9 @@ public class OrgInfoController {
70
 	@Resource
72
 	@Resource
71
 	private RoleButtonService roleButtonService;
73
 	private RoleButtonService roleButtonService;
72
 	
74
 	
75
+	@Value("${web.upload-path}")
76
+	private String uploadPath;
77
+	
73
 	/**
78
 	/**
74
 	 * 查找组织信息
79
 	 * 查找组织信息
75
 	 * @param pageNum 页码
80
 	 * @param pageNum 页码
@@ -145,6 +150,12 @@ public class OrgInfoController {
145
 		ObjectMapper mapper = new ObjectMapper();
150
 		ObjectMapper mapper = new ObjectMapper();
146
 		OrgInfo orgInfo = (OrgInfo)mapper.readValue(orgInfoJson, OrgInfo.class);
151
 		OrgInfo orgInfo = (OrgInfo)mapper.readValue(orgInfoJson, OrgInfo.class);
147
         if (orgInfo.getOrgId() == null) {
152
         if (orgInfo.getOrgId() == null) {
153
+        	if(!ObjectUtils.toString(orgInfo.getBirdsEye()).isEmpty()) {
154
+        		String path = uploadPath+orgInfo.getBirdsEye();
155
+        		byte[] file2byte = FileUtil.file2byte(path);
156
+        		String hexString = FileUtil.toHexString(file2byte);
157
+        		orgInfo.setWjl(hexString);
158
+        	}
148
 			orgInfoService.add(orgInfo);
159
 			orgInfoService.add(orgInfo);
149
 			//默认给新建的机构创建一个系统管理员角色
160
 			//默认给新建的机构创建一个系统管理员角色
150
 			RoleInfo roleInfo = new RoleInfo();
161
 			RoleInfo roleInfo = new RoleInfo();
@@ -161,6 +172,12 @@ public class OrgInfoController {
161
 			List<ButtonInfo> buttonList = buttonInfoService.queryByExample(exampleButton);
172
 			List<ButtonInfo> buttonList = buttonInfoService.queryByExample(exampleButton);
162
 			roleButtonService.saveForList(roleInfo.getRoleId(), buttonList);
173
 			roleButtonService.saveForList(roleInfo.getRoleId(), buttonList);
163
 		} else {
174
 		} else {
175
+			if(!ObjectUtils.toString(orgInfo.getBirdsEye()).isEmpty()) {
176
+        		String path = uploadPath+orgInfo.getBirdsEye();
177
+        		byte[] file2byte = FileUtil.file2byte(path);
178
+        		String hexString = FileUtil.toHexString(file2byte);
179
+        		orgInfo.setWjl(hexString);
180
+        	}
164
 			orgInfoService.update(orgInfo);
181
 			orgInfoService.update(orgInfo);
165
 		}
182
 		}
166
         if(5318 == orgInfo.getOrgClassId()) {//粮食企业的级别是在上级行政单位的级别上加2位顺序码
183
         if(5318 == orgInfo.getOrgClassId()) {//粮食企业的级别是在上级行政单位的级别上加2位顺序码
@@ -260,6 +277,28 @@ public class OrgInfoController {
260
 		}
277
 		}
261
 	}
278
 	}
262
 	
279
 	
280
+	@RequestMapping("/updateWjl")
281
+	public Map<String, Object> updateWjl() {
282
+		Map<String, Object> modelMap = new HashMap<>();
283
+		OrgInfoExample example = new OrgInfoExample();
284
+		List<OrgInfo> list = orgInfoService.queryByExample(example);
285
+		for(OrgInfo orgInfo:list) {
286
+			if(!ObjectUtils.toString(orgInfo.getBirdsEye()).isEmpty()) {
287
+				try {
288
+					String path = uploadPath+orgInfo.getBirdsEye();
289
+					byte[] file2byte = FileUtil.file2byte(path);
290
+					String hexString = FileUtil.toHexString(file2byte);
291
+					orgInfo.setWjl(hexString);
292
+					orgInfoService.update(orgInfo);
293
+				} catch (Exception e) {
294
+					e.printStackTrace();
295
+				}
296
+        	}
297
+		}
298
+		modelMap.put("status", "success");
299
+		return modelMap;
300
+	}
301
+	
263
 	 //角色
302
 	 //角色
264
    /* @RequestMapping("/getTreeAreaList")
303
    /* @RequestMapping("/getTreeAreaList")
265
     public Map<String, Object> getTreeAreaList(HttpServletRequest request) {
304
     public Map<String, Object> getTreeAreaList(HttpServletRequest request) {

+ 21 - 4
src/main/java/com/chinaitop/depot/system/mapper/OrgInfoMapper.xml

@@ -59,6 +59,9 @@
59
     <result column="level_code" property="levelCode" jdbcType="VARCHAR" />
59
     <result column="level_code" property="levelCode" jdbcType="VARCHAR" />
60
     <result column="updatetime" property="updateTime" jdbcType="VARCHAR" />
60
     <result column="updatetime" property="updateTime" jdbcType="VARCHAR" />
61
   </resultMap>
61
   </resultMap>
62
+  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.chinaitop.depot.system.model.OrgInfo">
63
+    <result column="wjl" jdbcType="LONGVARCHAR" property="wjl" />
64
+  </resultMap>
62
   <sql id="Example_Where_Clause" >
65
   <sql id="Example_Where_Clause" >
63
     <where >
66
     <where >
64
       <foreach collection="oredCriteria" item="criteria" separator="or" >
67
       <foreach collection="oredCriteria" item="criteria" separator="or" >
@@ -175,7 +178,7 @@
175
       regist_number, bank_name, account_name, 
178
       regist_number, bank_name, account_name, 
176
       account_number,total_assets,corporate_capacity,
179
       account_number,total_assets,corporate_capacity,
177
       office_phone,registered_address,mail_box,official_website,
180
       office_phone,registered_address,mail_box,official_website,
178
-      house_number,tank_number,depot_property,level_code)
181
+      house_number,tank_number,depot_property,level_code,wjl)
179
     values (#{orgId,jdbcType=INTEGER}, #{orgName,jdbcType=VARCHAR}, #{shortName,jdbcType=VARCHAR}, 
182
     values (#{orgId,jdbcType=INTEGER}, #{orgName,jdbcType=VARCHAR}, #{shortName,jdbcType=VARCHAR}, 
180
       #{orgCode,jdbcType=VARCHAR}, #{orgClassId,jdbcType=INTEGER}, #{companyNature,jdbcType=INTEGER}, 
183
       #{orgCode,jdbcType=VARCHAR}, #{orgClassId,jdbcType=INTEGER}, #{companyNature,jdbcType=INTEGER}, 
181
       #{busiType,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR}, 
184
       #{busiType,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR}, 
@@ -194,7 +197,7 @@
194
       #{accountNumber,jdbcType=VARCHAR}, #{totalAssets,jdbcType=INTEGER}, #{corporateCapacity,jdbcType=VARCHAR}, 
197
       #{accountNumber,jdbcType=VARCHAR}, #{totalAssets,jdbcType=INTEGER}, #{corporateCapacity,jdbcType=VARCHAR}, 
195
       #{officePhone,jdbcType=VARCHAR}, #{registeredAddress,jdbcType=VARCHAR}, #{mailBox,jdbcType=VARCHAR}, 
198
       #{officePhone,jdbcType=VARCHAR}, #{registeredAddress,jdbcType=VARCHAR}, #{mailBox,jdbcType=VARCHAR}, 
196
       #{officialWebsite,jdbcType=VARCHAR}, #{houseNumber,jdbcType=INTEGER}, #{tankNumber,jdbcType=INTEGER}, 
199
       #{officialWebsite,jdbcType=VARCHAR}, #{houseNumber,jdbcType=INTEGER}, #{tankNumber,jdbcType=INTEGER}, 
197
-      #{depotProperty,jdbcType=VARCHAR}, #{levelCode,jdbcType=VARCHAR})
200
+      #{depotProperty,jdbcType=VARCHAR}, #{levelCode,jdbcType=VARCHAR}, #{wjl,jdbcType=LONGVARCHAR})
198
   </insert>
201
   </insert>
199
   <insert id="insertSelective" parameterType="com.chinaitop.depot.system.model.OrgInfo" useGeneratedKeys="true" keyProperty="orgId">
202
   <insert id="insertSelective" parameterType="com.chinaitop.depot.system.model.OrgInfo" useGeneratedKeys="true" keyProperty="orgId">
200
     insert into org_info
203
     insert into org_info
@@ -334,6 +337,9 @@
334
       <if test="accountNumber != null" >
337
       <if test="accountNumber != null" >
335
         account_number,
338
         account_number,
336
       </if>
339
       </if>
340
+      <if test="wjl != null">
341
+        wjl,
342
+      </if>
337
     </trim>
343
     </trim>
338
     <trim prefix="values (" suffix=")" suffixOverrides="," >
344
     <trim prefix="values (" suffix=")" suffixOverrides="," >
339
       <if test="orgId != null" >
345
       <if test="orgId != null" >
@@ -471,6 +477,9 @@
471
       <if test="accountNumber != null" >
477
       <if test="accountNumber != null" >
472
         #{accountNumber,jdbcType=VARCHAR},
478
         #{accountNumber,jdbcType=VARCHAR},
473
       </if>
479
       </if>
480
+      <if test="wjl != null">
481
+        #{wjl,jdbcType=LONGVARCHAR},
482
+      </if>
474
     </trim>
483
     </trim>
475
   </insert>
484
   </insert>
476
   <select id="countByExample" parameterType="com.chinaitop.depot.system.model.OrgInfoExample" resultType="java.lang.Integer" >
485
   <select id="countByExample" parameterType="com.chinaitop.depot.system.model.OrgInfoExample" resultType="java.lang.Integer" >
@@ -620,6 +629,9 @@
620
       <if test="record.levelCode != null" >
629
       <if test="record.levelCode != null" >
621
         level_code = #{record.levelCode,jdbcType=VARCHAR},
630
         level_code = #{record.levelCode,jdbcType=VARCHAR},
622
       </if>
631
       </if>
632
+      <if test="record.wjl != null">
633
+        wjl = #{record.wjl,jdbcType=LONGVARCHAR},
634
+      </if>
623
     </set>
635
     </set>
624
     <if test="_parameter != null" >
636
     <if test="_parameter != null" >
625
       <include refid="Update_By_Example_Where_Clause" />
637
       <include refid="Update_By_Example_Where_Clause" />
@@ -671,7 +683,8 @@
671
       regist_number = #{record.registNumber,jdbcType=VARCHAR},
683
       regist_number = #{record.registNumber,jdbcType=VARCHAR},
672
       bank_name = #{record.bankName,jdbcType=VARCHAR},
684
       bank_name = #{record.bankName,jdbcType=VARCHAR},
673
       account_name = #{record.accountName,jdbcType=VARCHAR},
685
       account_name = #{record.accountName,jdbcType=VARCHAR},
674
-      account_number = #{record.accountNumber,jdbcType=VARCHAR}
686
+      account_number = #{record.accountNumber,jdbcType=VARCHAR},
687
+      wjl = #{record.wjl,jdbcType=LONGVARCHAR}
675
     <if test="_parameter != null" >
688
     <if test="_parameter != null" >
676
       <include refid="Update_By_Example_Where_Clause" />
689
       <include refid="Update_By_Example_Where_Clause" />
677
     </if>
690
     </if>
@@ -841,6 +854,9 @@
841
       <if test="levelCode != null" >
854
       <if test="levelCode != null" >
842
         level_code = #{levelCode,jdbcType=VARCHAR},
855
         level_code = #{levelCode,jdbcType=VARCHAR},
843
       </if>
856
       </if>
857
+      <if test="wjl != null">
858
+        wjl = #{wjl,jdbcType=LONGVARCHAR},
859
+      </if>
844
     </set>
860
     </set>
845
     where org_id = #{orgId,jdbcType=INTEGER}
861
     where org_id = #{orgId,jdbcType=INTEGER}
846
   </update>
862
   </update>
@@ -899,7 +915,8 @@
899
       house_number = #{houseNumber,jdbcType=INTEGER},
915
       house_number = #{houseNumber,jdbcType=INTEGER},
900
       tank_number = #{tankNumber,jdbcType=INTEGER},
916
       tank_number = #{tankNumber,jdbcType=INTEGER},
901
       depot_property = #{depotProperty,jdbcType=VARCHAR},
917
       depot_property = #{depotProperty,jdbcType=VARCHAR},
902
-      level_code = #{levelCode,jdbcType=VARCHAR}
918
+      level_code = #{levelCode,jdbcType=VARCHAR},
919
+      wjl = #{wjl,jdbcType=LONGVARCHAR}
903
     where org_id = #{orgId,jdbcType=INTEGER}
920
     where org_id = #{orgId,jdbcType=INTEGER}
904
   </update>
921
   </update>
905
   <update id="updateOrgLevel" parameterType="map" statementType="CALLABLE" >
922
   <update id="updateOrgLevel" parameterType="map" statementType="CALLABLE" >

+ 9 - 0
src/main/java/com/chinaitop/depot/system/model/OrgInfo.java

@@ -123,6 +123,8 @@ public class OrgInfo implements Serializable {
123
     
123
     
124
     private Date updateTime;
124
     private Date updateTime;
125
 
125
 
126
+    private String wjl;
127
+
126
     public Integer getOrgId() {
128
     public Integer getOrgId() {
127
         return orgId;
129
         return orgId;
128
     }
130
     }
@@ -578,5 +580,12 @@ public class OrgInfo implements Serializable {
578
 	public void setUpdateTime(Date updateTime) {
580
 	public void setUpdateTime(Date updateTime) {
579
 		this.updateTime = updateTime;
581
 		this.updateTime = updateTime;
580
 	}
582
 	}
583
+
584
+	public String getWjl() {
585
+        return wjl;
586
+    }
581
 	
587
 	
588
+	public void setWjl(String wjl) {
589
+        this.wjl = wjl == null ? null : wjl.trim();
590
+    }
582
 }
591
 }

+ 55 - 0
src/main/java/com/chinaitop/depot/utils/FileUtil.java

@@ -0,0 +1,55 @@
1
+package com.chinaitop.depot.utils;
2
+
3
+import java.io.ByteArrayOutputStream;
4
+import java.io.File;
5
+import java.io.FileInputStream;
6
+import java.io.FileNotFoundException;
7
+import java.io.IOException;
8
+
9
+public class FileUtil {
10
+	/**
11
+	 * 根据文件路径将文件转为二进制数组
12
+	 * @param filePath:文件路径
13
+	 * @return
14
+	 */
15
+	public static byte[] file2byte(String filePath) {
16
+		byte[] buffer = null;
17
+		try {
18
+			File file = new File(filePath);
19
+			FileInputStream fis = new FileInputStream(file);
20
+			ByteArrayOutputStream bos = new ByteArrayOutputStream();
21
+			byte[] b = new byte[1024];
22
+			int n;
23
+			while ((n = fis.read(b)) != -1) {
24
+				bos.write(b, 0, n);
25
+			}
26
+			fis.close();
27
+			bos.close();
28
+			buffer = bos.toByteArray();
29
+		} catch (FileNotFoundException e) {
30
+			e.printStackTrace();
31
+		} catch (IOException e) {
32
+			e.printStackTrace();
33
+		}
34
+		return buffer;
35
+	}
36
+	
37
+	/**
38
+	 * 将二进制数组转为字符串
39
+	 * @param byteArray
40
+	 * @return
41
+	 */
42
+	public static String toHexString(byte[] byteArray) {
43
+		if (byteArray == null || byteArray.length < 1)
44
+			throw new IllegalArgumentException(
45
+					"this byteArray must not be null or empty");
46
+
47
+		final StringBuilder hexString = new StringBuilder();
48
+		for (int i = 0; i < byteArray.length; i++) {
49
+			if ((byteArray[i] & 0xff) < 0x10)// 0~F前面不零
50
+				hexString.append("0");
51
+			hexString.append(Integer.toHexString(0xFF & byteArray[i]));
52
+		}
53
+		return hexString.toString().toLowerCase();
54
+	}
55
+}