Ver código fonte

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

hefeng 5 anos atrás
pai
commit
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 16
 import com.chinaitop.depot.system.service.RoleFuncService;
17 17
 import com.chinaitop.depot.system.service.RoleInfoService;
18 18
 import com.chinaitop.depot.utils.DataSynchronization;
19
+import com.chinaitop.depot.utils.FileUtil;
19 20
 import com.fasterxml.jackson.core.JsonParseException;
20 21
 import com.fasterxml.jackson.databind.JsonMappingException;
21 22
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -29,6 +30,7 @@ import io.swagger.annotations.ApiOperation;
29 30
 
30 31
 import org.apache.commons.lang.ObjectUtils;
31 32
 import org.apache.commons.lang3.StringUtils;
33
+import org.springframework.beans.factory.annotation.Value;
32 34
 import org.springframework.web.bind.annotation.RequestMapping;
33 35
 import org.springframework.web.bind.annotation.RequestMethod;
34 36
 import org.springframework.web.bind.annotation.RestController;
@@ -70,6 +72,9 @@ public class OrgInfoController {
70 72
 	@Resource
71 73
 	private RoleButtonService roleButtonService;
72 74
 	
75
+	@Value("${web.upload-path}")
76
+	private String uploadPath;
77
+	
73 78
 	/**
74 79
 	 * 查找组织信息
75 80
 	 * @param pageNum 页码
@@ -145,6 +150,12 @@ public class OrgInfoController {
145 150
 		ObjectMapper mapper = new ObjectMapper();
146 151
 		OrgInfo orgInfo = (OrgInfo)mapper.readValue(orgInfoJson, OrgInfo.class);
147 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 159
 			orgInfoService.add(orgInfo);
149 160
 			//默认给新建的机构创建一个系统管理员角色
150 161
 			RoleInfo roleInfo = new RoleInfo();
@@ -161,6 +172,12 @@ public class OrgInfoController {
161 172
 			List<ButtonInfo> buttonList = buttonInfoService.queryByExample(exampleButton);
162 173
 			roleButtonService.saveForList(roleInfo.getRoleId(), buttonList);
163 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 181
 			orgInfoService.update(orgInfo);
165 182
 		}
166 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 303
    /* @RequestMapping("/getTreeAreaList")
265 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 59
     <result column="level_code" property="levelCode" jdbcType="VARCHAR" />
60 60
     <result column="updatetime" property="updateTime" jdbcType="VARCHAR" />
61 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 65
   <sql id="Example_Where_Clause" >
63 66
     <where >
64 67
       <foreach collection="oredCriteria" item="criteria" separator="or" >
@@ -175,7 +178,7 @@
175 178
       regist_number, bank_name, account_name, 
176 179
       account_number,total_assets,corporate_capacity,
177 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 182
     values (#{orgId,jdbcType=INTEGER}, #{orgName,jdbcType=VARCHAR}, #{shortName,jdbcType=VARCHAR}, 
180 183
       #{orgCode,jdbcType=VARCHAR}, #{orgClassId,jdbcType=INTEGER}, #{companyNature,jdbcType=INTEGER}, 
181 184
       #{busiType,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR}, 
@@ -194,7 +197,7 @@
194 197
       #{accountNumber,jdbcType=VARCHAR}, #{totalAssets,jdbcType=INTEGER}, #{corporateCapacity,jdbcType=VARCHAR}, 
195 198
       #{officePhone,jdbcType=VARCHAR}, #{registeredAddress,jdbcType=VARCHAR}, #{mailBox,jdbcType=VARCHAR}, 
196 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 201
   </insert>
199 202
   <insert id="insertSelective" parameterType="com.chinaitop.depot.system.model.OrgInfo" useGeneratedKeys="true" keyProperty="orgId">
200 203
     insert into org_info
@@ -334,6 +337,9 @@
334 337
       <if test="accountNumber != null" >
335 338
         account_number,
336 339
       </if>
340
+      <if test="wjl != null">
341
+        wjl,
342
+      </if>
337 343
     </trim>
338 344
     <trim prefix="values (" suffix=")" suffixOverrides="," >
339 345
       <if test="orgId != null" >
@@ -471,6 +477,9 @@
471 477
       <if test="accountNumber != null" >
472 478
         #{accountNumber,jdbcType=VARCHAR},
473 479
       </if>
480
+      <if test="wjl != null">
481
+        #{wjl,jdbcType=LONGVARCHAR},
482
+      </if>
474 483
     </trim>
475 484
   </insert>
476 485
   <select id="countByExample" parameterType="com.chinaitop.depot.system.model.OrgInfoExample" resultType="java.lang.Integer" >
@@ -620,6 +629,9 @@
620 629
       <if test="record.levelCode != null" >
621 630
         level_code = #{record.levelCode,jdbcType=VARCHAR},
622 631
       </if>
632
+      <if test="record.wjl != null">
633
+        wjl = #{record.wjl,jdbcType=LONGVARCHAR},
634
+      </if>
623 635
     </set>
624 636
     <if test="_parameter != null" >
625 637
       <include refid="Update_By_Example_Where_Clause" />
@@ -671,7 +683,8 @@
671 683
       regist_number = #{record.registNumber,jdbcType=VARCHAR},
672 684
       bank_name = #{record.bankName,jdbcType=VARCHAR},
673 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 688
     <if test="_parameter != null" >
676 689
       <include refid="Update_By_Example_Where_Clause" />
677 690
     </if>
@@ -841,6 +854,9 @@
841 854
       <if test="levelCode != null" >
842 855
         level_code = #{levelCode,jdbcType=VARCHAR},
843 856
       </if>
857
+      <if test="wjl != null">
858
+        wjl = #{wjl,jdbcType=LONGVARCHAR},
859
+      </if>
844 860
     </set>
845 861
     where org_id = #{orgId,jdbcType=INTEGER}
846 862
   </update>
@@ -899,7 +915,8 @@
899 915
       house_number = #{houseNumber,jdbcType=INTEGER},
900 916
       tank_number = #{tankNumber,jdbcType=INTEGER},
901 917
       depot_property = #{depotProperty,jdbcType=VARCHAR},
902
-      level_code = #{levelCode,jdbcType=VARCHAR}
918
+      level_code = #{levelCode,jdbcType=VARCHAR},
919
+      wjl = #{wjl,jdbcType=LONGVARCHAR}
903 920
     where org_id = #{orgId,jdbcType=INTEGER}
904 921
   </update>
905 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 124
     private Date updateTime;
125 125
 
126
+    private String wjl;
127
+
126 128
     public Integer getOrgId() {
127 129
         return orgId;
128 130
     }
@@ -578,5 +580,12 @@ public class OrgInfo implements Serializable {
578 580
 	public void setUpdateTime(Date updateTime) {
579 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
+}