魏超 před 6 roky
rodič
revize
d23ead3f61

+ 13
- 22
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/ImageController.java Zobrazit soubor

@@ -1,14 +1,16 @@
1 1
 package com.community.huiju.controller;
2 2
 
3
-import com.aliyun.oss.OSSClient;
4
-import io.swagger.annotations.*;
3
+import com.community.huiju.service.ImageServiceI;
4
+import io.swagger.annotations.Api;
5
+import io.swagger.annotations.ApiOperation;
6
+import io.swagger.annotations.ApiParam;
7
+import org.springframework.beans.factory.annotation.Autowired;
5 8
 import org.springframework.cloud.context.config.annotation.RefreshScope;
6
-import org.springframework.web.bind.annotation.*;
9
+import org.springframework.web.bind.annotation.PostMapping;
10
+import org.springframework.web.bind.annotation.RequestMapping;
11
+import org.springframework.web.bind.annotation.RestController;
7 12
 import org.springframework.web.multipart.MultipartFile;
8 13
 
9
-import java.io.ByteArrayInputStream;
10
-import java.util.Date;
11
-
12 14
 /**
13 15
  * @author weichaochao
14 16
  * @Title: ImageController
@@ -21,27 +23,16 @@ import java.util.Date;
21 23
 @Api(value = "图片操作API", description = "图片操作API")
22 24
 public class ImageController {
23 25
 
24
-    private static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
25
-    private static String accessKeyId = "LTAIiG6xeHbVzTXC";
26
-    private static String accessKeySecret = "YUci8oBtm5WzobH6SP2eyZUbjCBKBo";
27
-    private static String bucketName = "imgurlspace";
26
+
27
+
28
+    @Autowired
29
+    private ImageServiceI imageService;
28 30
 
29 31
     @ApiOperation(value = "图片上传以及获取url", notes = "图片上传以及获取url")
30 32
     @PostMapping(value = "/getUrl", consumes = "multipart/*", headers = "content-type=multipart/form-data")
31 33
     public String uploadImgAndGetUrl(@ApiParam(value = "file" ,required = true) MultipartFile uploadFile) throws Exception {
32 34
 
33
-        String imgName = System.currentTimeMillis() + ".png";
34
-        // 创建OSSClient实例
35
-        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
36
-        // 上传
37
-        long time = System.currentTimeMillis();
38
-
39
-        ossClient.putObject(bucketName, imgName, new ByteArrayInputStream(uploadFile.getBytes()));
40
-
41
-        // 关闭client
42
-        ossClient.shutdown();
43
-        Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
44
-        String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
35
+        String url = imageService.getImageUrl(uploadFile);
45 36
         return url;
46 37
     }
47 38
 }

+ 6
- 7
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/SocialController.java Zobrazit soubor

@@ -8,15 +8,14 @@ import com.community.huiju.model.TpAnnouncement;
8 8
 import com.community.huiju.model.TpTicket;
9 9
 import com.community.huiju.model.TpTransaction;
10 10
 import com.community.huiju.service.SocialServiceI;
11
-import io.swagger.annotations.Api;
12
-import io.swagger.annotations.ApiImplicitParam;
13
-import io.swagger.annotations.ApiImplicitParams;
14
-import io.swagger.annotations.ApiOperation;
11
+import io.swagger.annotations.*;
15 12
 import org.springframework.beans.factory.annotation.Autowired;
16 13
 import org.springframework.cloud.context.config.annotation.RefreshScope;
17 14
 import org.springframework.web.bind.annotation.*;
15
+import org.springframework.web.multipart.MultipartFile;
18 16
 
19 17
 import javax.servlet.http.HttpSession;
18
+import java.io.IOException;
20 19
 import java.util.List;
21 20
 
22 21
 /**
@@ -163,13 +162,13 @@ public class SocialController {
163 162
                     "title:小区标题,content:小区类容, type"),
164 163
             @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token")
165 164
     })
166
-    @RequestMapping(value = "/addTransaction", method = RequestMethod.POST)
165
+    @PostMapping(value = "/addTransaction", consumes = "multipart/*", headers = "content-type=multipart/form-data")
167 166
     @ResponseBody
168
-    public ResponseBean addTransaction(@RequestBody String paramets, HttpSession session) {
167
+    public ResponseBean addTransaction(@RequestBody String paramets, @ApiParam(value = "file" ,required = true) MultipartFile uploadFile, HttpSession session) throws IOException {
169 168
         ResponseBean responseBean = new ResponseBean();
170 169
         UserElement userElement = (UserElement) session.getAttribute(Constant.APP_USER_SESSION);
171 170
         Integer userId = userElement.getId();
172
-        ResponseBean response = socialServiceI.addAllTransaction(userId, paramets);
171
+        ResponseBean response = socialServiceI.addAllTransaction(userId, paramets, uploadFile);
173 172
         return response;
174 173
     }
175 174
 

+ 19
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TdImagesMapper.java Zobrazit soubor

@@ -0,0 +1,19 @@
1
+package com.community.huiju.dao;
2
+
3
+import com.community.huiju.model.TdImages;
4
+import org.apache.ibatis.annotations.Mapper;
5
+
6
+@Mapper
7
+public interface TdImagesMapper {
8
+    int deleteByPrimaryKey(Integer id);
9
+
10
+    int insert(TdImages record);
11
+
12
+    int insertSelective(TdImages record);
13
+
14
+    TdImages selectByPrimaryKey(Integer id);
15
+
16
+    int updateByPrimaryKeySelective(TdImages record);
17
+
18
+    int updateByPrimaryKey(TdImages record);
19
+}

+ 65
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/model/TdImages.java Zobrazit soubor

@@ -0,0 +1,65 @@
1
+package com.community.huiju.model;
2
+
3
+import java.util.Date;
4
+
5
+public class TdImages {
6
+    private Integer id;
7
+
8
+    private String imageUrl;
9
+
10
+    private Integer uuid;
11
+
12
+    private String type;
13
+
14
+    private Integer createUser;
15
+
16
+    private Date createTime;
17
+
18
+    public Integer getId() {
19
+        return id;
20
+    }
21
+
22
+    public void setId(Integer id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public String getImageUrl() {
27
+        return imageUrl;
28
+    }
29
+
30
+    public void setImageUrl(String imageUrl) {
31
+        this.imageUrl = imageUrl == null ? null : imageUrl.trim();
32
+    }
33
+
34
+    public Integer getUuid() {
35
+        return uuid;
36
+    }
37
+
38
+    public void setUuid(Integer uuid) {
39
+        this.uuid = uuid;
40
+    }
41
+
42
+    public String getType() {
43
+        return type;
44
+    }
45
+
46
+    public void setType(String type) {
47
+        this.type = type == null ? null : type.trim();
48
+    }
49
+
50
+    public Integer getCreateUser() {
51
+        return createUser;
52
+    }
53
+
54
+    public void setCreateUser(Integer createUser) {
55
+        this.createUser = createUser;
56
+    }
57
+
58
+    public Date getCreateTime() {
59
+        return createTime;
60
+    }
61
+
62
+    public void setCreateTime(Date createTime) {
63
+        this.createTime = createTime;
64
+    }
65
+}

+ 15
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/ImageServiceI.java Zobrazit soubor

@@ -0,0 +1,15 @@
1
+package com.community.huiju.service;
2
+
3
+import org.springframework.web.multipart.MultipartFile;
4
+
5
+import java.io.IOException;
6
+
7
+/**
8
+ * @author admin
9
+ * @Title: ImageServiceI
10
+ * @Description: TODO
11
+ * @date 2018/11/5
12
+ */
13
+public interface ImageServiceI {
14
+    String getImageUrl(MultipartFile uploadFile) throws IOException;
15
+}

+ 3
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/SocialServiceI.java Zobrazit soubor

@@ -2,7 +2,9 @@ package com.community.huiju.service;
2 2
 
3 3
 import com.community.commom.mode.ResponseBean;
4 4
 import com.community.huiju.model.*;
5
+import org.springframework.web.multipart.MultipartFile;
5 6
 
7
+import java.io.IOException;
6 8
 import java.util.List;
7 9
 
8 10
 /**
@@ -69,7 +71,7 @@ public interface SocialServiceI {
69 71
 	/**
70 72
 	 * 添加二手租赁帖子
71 73
 	 */
72
-    ResponseBean addAllTransaction(Integer userId, String paramets);
74
+    ResponseBean addAllTransaction(Integer userId, String paramets, MultipartFile uploadFile) throws IOException;
73 75
 
74 76
 	/**
75 77
 	 * 获取当前用户所有的帖子

+ 43
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/ImageServiceimpl.java Zobrazit soubor

@@ -0,0 +1,43 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.aliyun.oss.OSSClient;
4
+import com.community.huiju.service.ImageServiceI;
5
+import org.springframework.stereotype.Service;
6
+import org.springframework.web.multipart.MultipartFile;
7
+
8
+import java.io.ByteArrayInputStream;
9
+import java.io.IOException;
10
+import java.util.Date;
11
+
12
+/**
13
+ * @author weichaochao
14
+ * @Title: ImageServiceimpl
15
+ * @Description: 获取图片地址实现类
16
+ * @date 2018/11/5
17
+ */
18
+@Service("ImageService")
19
+public class ImageServiceimpl implements ImageServiceI {
20
+
21
+    private static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
22
+    private static String accessKeyId = "LTAIiG6xeHbVzTXC";
23
+    private static String accessKeySecret = "YUci8oBtm5WzobH6SP2eyZUbjCBKBo";
24
+    private static String bucketName = "imgurlspace";
25
+
26
+    @Override
27
+    public String getImageUrl(MultipartFile uploadFile) throws IOException {
28
+
29
+        String imgName = System.currentTimeMillis() + ".png";
30
+        // 创建OSSClient实例
31
+        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
32
+        // 上传
33
+        long time = System.currentTimeMillis();
34
+
35
+        ossClient.putObject(bucketName, imgName, new ByteArrayInputStream(uploadFile.getBytes()));
36
+
37
+        // 关闭client
38
+        ossClient.shutdown();
39
+        Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
40
+        String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
41
+        return url;
42
+    }
43
+}

+ 24
- 4
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/SocialServiceImpl.java Zobrazit soubor

@@ -5,14 +5,15 @@ import com.community.commom.constant.Constant;
5 5
 import com.community.commom.mode.ResponseBean;
6 6
 import com.community.huiju.dao.*;
7 7
 import com.community.huiju.model.*;
8
+import com.community.huiju.service.ImageServiceI;
8 9
 import com.community.huiju.service.SocialServiceI;
9 10
 import com.github.pagehelper.PageHelper;
10
-import com.netflix.discovery.converters.Auto;
11 11
 import org.springframework.beans.factory.annotation.Autowired;
12 12
 import org.springframework.stereotype.Service;
13 13
 import org.springframework.transaction.annotation.Transactional;
14
+import org.springframework.web.multipart.MultipartFile;
14 15
 
15
-import java.text.SimpleDateFormat;
16
+import java.io.IOException;
16 17
 import java.util.Date;
17 18
 import java.util.List;
18 19
 
@@ -57,6 +58,12 @@ public class SocialServiceImpl implements SocialServiceI {
57 58
     @Autowired
58 59
     private TpTicketMapper tpTicketMapper;
59 60
 
61
+    @Autowired
62
+    private TdImagesMapper tdImagesMapper;
63
+
64
+    @Autowired
65
+    private ImageServiceI imageServiceI;
66
+
60 67
     @Override
61 68
     @Transactional
62 69
     public TpAnnouncement findAnnouncementDetail(Integer id, Integer communityId, Integer userId) {
@@ -221,7 +228,7 @@ public class SocialServiceImpl implements SocialServiceI {
221 228
 
222 229
     @Transactional
223 230
     @Override
224
-    public ResponseBean addAllTransaction(Integer userId, String paramets) {
231
+    public ResponseBean addAllTransaction(Integer userId, String paramets, MultipartFile uploadFile) throws IOException {
225 232
 
226 233
         ResponseBean response = new ResponseBean();
227 234
 
@@ -231,7 +238,7 @@ public class SocialServiceImpl implements SocialServiceI {
231 238
         String  type= (String) jsonObject.get("type");
232 239
 
233 240
         TaUser user=taUserMapper.selectByPrimaryKey(userId);
234
-        TpTransaction tpTransaction=new TpTransaction();
241
+        TpTransaction tpTransaction = new TpTransaction();
235 242
         tpTransaction.setTransactionTitle(transactionTitle);
236 243
         tpTransaction.setTransactionContent(transactionContent);
237 244
         tpTransaction.setType(type);
@@ -266,6 +273,8 @@ public class SocialServiceImpl implements SocialServiceI {
266 273
                 || Constant.TENANT.equals(sysRole.getRoleName())
267 274
                 || Constant.OWNER.equals(sysRole.getRoleName())){
268 275
             tpTransactionMapper.insertSelective(tpTransaction);
276
+            insertTdImage(tpTransaction, uploadFile, type, userId);
277
+
269 278
             TpTransaction tpTransaction1=tpTransactionMapper.getById(tpTransaction.getId());
270 279
             response.addSuccess(tpTransaction1);
271 280
         }
@@ -274,6 +283,17 @@ public class SocialServiceImpl implements SocialServiceI {
274 283
 
275 284
     }
276 285
 
286
+    private void insertTdImage(TpTransaction tpTransaction, MultipartFile uploadFile, String type, Integer userId) throws IOException {
287
+        TdImages tdImages = new TdImages();
288
+        Integer uuId = tpTransaction.getId();
289
+        String imageUrl = imageServiceI.getImageUrl(uploadFile);
290
+        tdImages.setImageUrl(imageUrl);
291
+        tdImages.setType(type);
292
+        tdImages.setUuid(uuId);
293
+        tdImages.setCreateUser(userId);
294
+        tdImages.setCreateTime(new Date());
295
+        tdImagesMapper.insertSelective(tdImages);
296
+    }
277 297
     @Override
278 298
     public ResponseBean selectAllTransaction(Integer userId,Integer pageNum,Integer paeSize) {
279 299
         ResponseBean responseBean = new ResponseBean();

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/TaVistorServiceImpl.java Zobrazit soubor

@@ -56,12 +56,12 @@ public class TaVistorServiceImpl implements TaVistorServiceI {
56 56
             taVisitorMapper.insertSelective(taVisitor);
57 57
         }
58 58
 
59
-
60 59
     }
61 60
 
62 61
     @Override
63 62
     public List<TaVisitor> invateHis(Integer communityId, Integer userId) {
64 63
         List<TaVisitor> taVisitors = taVisitorMapper.findAllVistors(communityId, userId);
64
+
65 65
         for (TaVisitor taVisitor : taVisitors){
66 66
             if (Constant.EFFECTIVE.equals(taVisitor.getDrivingStatus())){
67 67
                 List<Integer> taVisitorLicenses = taVisitorLicenseMapper.findTaVistorLicenseById(taVisitor.getId());

+ 106
- 0
CODE/smart-community/app-api/src/main/resources/mapper/TdImagesMapper.xml Zobrazit soubor

@@ -0,0 +1,106 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="com.community.huiju.dao.TdImagesMapper" >
4
+  <resultMap id="BaseResultMap" type="com.community.huiju.model.TdImages" >
5
+    <id column="id" property="id" jdbcType="INTEGER" />
6
+    <result column="image_url" property="imageUrl" jdbcType="VARCHAR" />
7
+    <result column="uuid" property="uuid" jdbcType="INTEGER" />
8
+    <result column="type" property="type" jdbcType="CHAR" />
9
+    <result column="create_user" property="createUser" jdbcType="INTEGER" />
10
+    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
11
+  </resultMap>
12
+  <sql id="Base_Column_List" >
13
+    id, image_url, uuid, type, create_user, create_time
14
+  </sql>
15
+  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
16
+    select 
17
+    <include refid="Base_Column_List" />
18
+    from td_images
19
+    where id = #{id,jdbcType=INTEGER}
20
+  </select>
21
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
22
+    delete from td_images
23
+    where id = #{id,jdbcType=INTEGER}
24
+  </delete>
25
+  <insert id="insert" parameterType="com.community.huiju.model.TdImages" >
26
+    insert into td_images (id, image_url, uuid, 
27
+      type, create_user, create_time
28
+      )
29
+    values (#{id,jdbcType=INTEGER}, #{imageUrl,jdbcType=VARCHAR}, #{uuid,jdbcType=INTEGER}, 
30
+      #{type,jdbcType=CHAR}, #{createUser,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}
31
+      )
32
+  </insert>
33
+  <insert id="insertSelective" parameterType="com.community.huiju.model.TdImages" >
34
+    insert into td_images
35
+    <trim prefix="(" suffix=")" suffixOverrides="," >
36
+      <if test="id != null" >
37
+        id,
38
+      </if>
39
+      <if test="imageUrl != null" >
40
+        image_url,
41
+      </if>
42
+      <if test="uuid != null" >
43
+        uuid,
44
+      </if>
45
+      <if test="type != null" >
46
+        type,
47
+      </if>
48
+      <if test="createUser != null" >
49
+        create_user,
50
+      </if>
51
+      <if test="createTime != null" >
52
+        create_time,
53
+      </if>
54
+    </trim>
55
+    <trim prefix="values (" suffix=")" suffixOverrides="," >
56
+      <if test="id != null" >
57
+        #{id,jdbcType=INTEGER},
58
+      </if>
59
+      <if test="imageUrl != null" >
60
+        #{imageUrl,jdbcType=VARCHAR},
61
+      </if>
62
+      <if test="uuid != null" >
63
+        #{uuid,jdbcType=INTEGER},
64
+      </if>
65
+      <if test="type != null" >
66
+        #{type,jdbcType=CHAR},
67
+      </if>
68
+      <if test="createUser != null" >
69
+        #{createUser,jdbcType=INTEGER},
70
+      </if>
71
+      <if test="createTime != null" >
72
+        #{createTime,jdbcType=TIMESTAMP},
73
+      </if>
74
+    </trim>
75
+  </insert>
76
+  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TdImages" >
77
+    update td_images
78
+    <set >
79
+      <if test="imageUrl != null" >
80
+        image_url = #{imageUrl,jdbcType=VARCHAR},
81
+      </if>
82
+      <if test="uuid != null" >
83
+        uuid = #{uuid,jdbcType=INTEGER},
84
+      </if>
85
+      <if test="type != null" >
86
+        type = #{type,jdbcType=CHAR},
87
+      </if>
88
+      <if test="createUser != null" >
89
+        create_user = #{createUser,jdbcType=INTEGER},
90
+      </if>
91
+      <if test="createTime != null" >
92
+        create_time = #{createTime,jdbcType=TIMESTAMP},
93
+      </if>
94
+    </set>
95
+    where id = #{id,jdbcType=INTEGER}
96
+  </update>
97
+  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TdImages" >
98
+    update td_images
99
+    set image_url = #{imageUrl,jdbcType=VARCHAR},
100
+      uuid = #{uuid,jdbcType=INTEGER},
101
+      type = #{type,jdbcType=CHAR},
102
+      create_user = #{createUser,jdbcType=INTEGER},
103
+      create_time = #{createTime,jdbcType=TIMESTAMP}
104
+    where id = #{id,jdbcType=INTEGER}
105
+  </update>
106
+</mapper>