瀏覽代碼

机构资料备注

Aslee 3 年之前
父節點
當前提交
3a860294f1

+ 18 - 0
backup.sql

@@ -55,4 +55,22 @@ CREATE TABLE `cm_svip_history`(
 ALTER TABLE `cm_split_account` ADD COLUMN `vipPackageId` INT NULL COMMENT '超级会员套餐id' AFTER `shopId`;
 ALTER TABLE `cm_split_account` ADD COLUMN `vipPackageId` INT NULL COMMENT '超级会员套餐id' AFTER `shopId`;
 
 
 
 
+CREATE TABLE `cm_club_remarks` (
+        `id` INT NOT NULL AUTO_INCREMENT,
+        `clubId` INT NULL COMMENT '机构id',
+        `serviceProviderId` INT NULL COMMENT '协销id',
+        `remarks` TEXT NULL COMMENT '文字备注',
+        `addTime` DATETIME NULL COMMENT '添加时间',
+        PRIMARY KEY (`id`))
+    COMMENT = '机构资料备注';
+
+CREATE TABLE `caimei`.`cm_club_remarks_file` (
+                                                 `id` INT NOT NULL AUTO_INCREMENT,
+                                                 `remarksId` INT NULL COMMENT '机构备注id',
+                                                 `fileType` INT NULL COMMENT '文件类型:1图片,2文件',
+                                                 `fileName` VARCHAR(100) NULL COMMENT '文件名称',
+                                                 `ossName` VARCHAR(45) NULL COMMENT 'oss名称',
+                                                 `imageUrl` TEXT NULL COMMENT '图片路径',
+                                                 PRIMARY KEY (`id`))
+    COMMENT = '机构资料备注文件';
 -- ================================== 2021年9月 超级会员S_VIP end ==================================
 -- ================================== 2021年9月 超级会员S_VIP end ==================================

+ 7 - 0
pom.xml

@@ -149,6 +149,13 @@
 			<artifactId>reactor-test</artifactId>
 			<artifactId>reactor-test</artifactId>
 			<scope>test</scope>
 			<scope>test</scope>
 		</dependency>
 		</dependency>
+
+        <!--对象存储oss-->
+        <dependency>
+            <groupId>com.aliyun.oss</groupId>
+            <artifactId>aliyun-sdk-oss</artifactId>
+            <version>3.12.0</version>
+        </dependency>
     </dependencies>
     </dependencies>
 
 
     <profiles>
     <profiles>

+ 52 - 0
src/main/java/com/caimei365/user/controller/ClubApi.java

@@ -1,9 +1,14 @@
 package com.caimei365.user.controller;
 package com.caimei365.user.controller;
 
 
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.dto.ClubRemarksDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.DeductionDto;
 import com.caimei365.user.model.dto.DeductionDto;
+import com.caimei365.user.model.dto.JsonParamsDto;
 import com.caimei365.user.model.vo.BeansHistoryVo;
 import com.caimei365.user.model.vo.BeansHistoryVo;
+import com.caimei365.user.model.vo.OperationVo;
+import com.caimei365.user.model.vo.PaginationVo;
+import com.caimei365.user.model.vo.RemarksVo;
 import com.caimei365.user.service.ClubService;
 import com.caimei365.user.service.ClubService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParam;
@@ -140,4 +145,51 @@ public class ClubApi {
         }
         }
         return clubService.archiveDeduction(userId, archiveId);
         return clubService.archiveDeduction(userId, archiveId);
     }
     }
+
+    @ApiOperation("机构资料备注列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = true, name = "clubId", value = "机构Id"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+    })
+    @GetMapping("/remarks/list")
+    public ResponseJson<PaginationVo<RemarksVo>> getRemarksList(Integer clubId,
+                                                             @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                             @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        return clubService.getRemarksList(clubId, pageNum, pageSize);
+    }
+
+    @ApiOperation("机构资料备注详情")
+    @ApiImplicitParam(required = true, name = "remarksId", value = "机构id")
+    @GetMapping("/remarks/detail")
+    public ResponseJson<RemarksVo> getRemarksDetail(Integer remarksId) {
+        return clubService.getRemarksDetail(remarksId);
+    }
+
+    /**
+     * @param jsonParamsDto:{
+     *                     remarksId:           备注id,
+     *                     机构id:               机构id,
+     *                     serviceProviderId:   协销id,
+     *                     remarks:             文字备注,
+     *                     fileList:    [{fileName:"文件名称",ossName:"oss文件名称"},{fileName:"文件名称",ossName:"oss文件名称"}...]
+     *                     imageList:   ["图片","图片",...]
+     *                    }
+     * @return
+     */
+    @ApiOperation("保存机构资料备注")
+    @PostMapping("/remarks/save")
+    public ResponseJson saveClubRemarks(JsonParamsDto jsonParamsDto) {
+        return clubService.saveClubRemarks(jsonParamsDto);
+    }
+
+    @ApiOperation("删除机构资料备注")
+    @ApiImplicitParam(required = true, name = "remarksId", value = "机构id")
+    @PostMapping("/remarks/delete")
+    public ResponseJson deleteClubRemarks(ClubRemarksDto clubRemarksDto) {
+        return clubService.deleteClubRemarks(clubRemarksDto.getRemarksId());
+    }
+
+
+
 }
 }

+ 77 - 3
src/main/java/com/caimei365/user/mapper/ClubMapper.java

@@ -1,10 +1,9 @@
 package com.caimei365.user.mapper;
 package com.caimei365.user.mapper;
 
 
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
+import com.caimei365.user.model.po.ClubRemarksPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.po.UserPo;
-import com.caimei365.user.model.vo.BeansHistoryVo;
-import com.caimei365.user.model.vo.ClubVo;
-import com.caimei365.user.model.vo.OrderCountVo;
+import com.caimei365.user.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
@@ -131,4 +130,79 @@ public interface ClubMapper {
      * @return
      * @return
      */
      */
     Integer getBeansNumByUserId(Integer userId);
     Integer getBeansNumByUserId(Integer userId);
+
+    /**
+     * 新增资料备注
+     * @param clubRemarksPo
+     */
+    void insertRemarks(ClubRemarksPo clubRemarksPo);
+
+    /**
+     * 修改资料备注
+     * @param clubRemarksPo
+     */
+    void updateRemarks(ClubRemarksPo clubRemarksPo);
+
+    /**
+     * 清除资料备注文件
+     * @param remarksId
+     */
+    void clearRearksFiles(Integer remarksId);
+
+    /**
+     * 添加资料备注图片
+     *
+     * @param remarksId 备注id
+     * @param imageUrl  图片路径
+     */
+    void insertRemarksImage(@Param("remarksId") Integer remarksId, @Param("imageUrl") String imageUrl);
+
+    /**
+     * 添加资料备注文件
+     *
+     * @param remarksId 备注id
+     * @param fileName  文件名称
+     * @param ossName   oss名称
+     */
+    void insertRemarksFile(@Param("remarksId") Integer remarksId, @Param("fileName") String fileName, @Param("ossName") String ossName);
+
+    /**
+     * 获取资料备注列表
+     * @param clubId   机构id
+     * @return
+     */
+    List<RemarksVo> getRemarksList(Integer clubId);
+
+    /**
+     * 获取资料备注详情
+     * @param remarksId 备注id
+     * @return
+     */
+    RemarksVo getRemarks(Integer remarksId);
+
+    /**
+     * 获取资料备注图片
+     * @param remarksId 备注id
+     * @return
+     */
+    List<String> getRemarksImageList(Integer remarksId);
+
+    /**
+     * 获取资料备注文件
+     * @param remarksId     备注id
+     * @return
+     */
+    List<RemarksFileVo> getRemarksFileList(Integer remarksId);
+
+    /**
+     * 删除资料备注
+     * @param remarksId 备注id
+     */
+    void deleteRemarks(Integer remarksId);
+
+    /**
+     * 删除资料备注包含的文件
+     * @param remarksId  备注id
+     */
+    void deleteRemarksFiles(Integer remarksId);
 }
 }

+ 38 - 0
src/main/java/com/caimei365/user/model/dto/ClubRemarksDto.java

@@ -0,0 +1,38 @@
+package com.caimei365.user.model.dto;
+
+import com.caimei365.user.model.po.RemarksFilePo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/9/26
+ */
+@ApiModel("机构资料备注")
+@Data
+public class ClubRemarksDto implements Serializable {
+    @ApiModelProperty("备注id")
+    private Integer remarksId;
+
+    @ApiModelProperty("机构id")
+    private Integer clubId;
+
+    @ApiModelProperty("协销id")
+    private Integer serviceProviderId;
+
+    @ApiModelProperty("文字备注")
+    private String remarks;
+
+    @ApiModelProperty("图片列表")
+    private List<String> imageList;
+
+    @ApiModelProperty("文件列表")
+    private List<RemarksFilePo> fileList;
+}

+ 27 - 0
src/main/java/com/caimei365/user/model/dto/JsonParamsDto.java

@@ -0,0 +1,27 @@
+package com.caimei365.user.model.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/8/12
+ */
+@Data
+public class JsonParamsDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty("JSON字符串参数")
+    private String params;
+
+    @Override
+    public String toString() {
+        return "JsonParamsDto{" +
+                "params='" + params + '\'' +
+                '}';
+    }
+}

+ 29 - 0
src/main/java/com/caimei365/user/model/po/ClubRemarksPo.java

@@ -0,0 +1,29 @@
+package com.caimei365.user.model.po;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/9/26
+ */
+@ApiModel("机构资料备注")
+@Data
+public class ClubRemarksPo implements Serializable {
+    @ApiModelProperty("备注id")
+    private Integer remarksId;
+
+    @ApiModelProperty("机构id")
+    private Integer clubId;
+
+    @ApiModelProperty("协销id")
+    private Integer serviceProviderId;
+
+    @ApiModelProperty("文字备注")
+    private String remarks;
+}

+ 26 - 0
src/main/java/com/caimei365/user/model/po/RemarksFilePo.java

@@ -0,0 +1,26 @@
+package com.caimei365.user.model.po;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/9/26
+ */
+@Data
+public class RemarksFilePo implements Serializable {
+    /**
+     * 文件名称
+     */
+    private String fileName;
+
+    /**
+     * oss名称
+     */
+    private String ossName;
+}

+ 29 - 0
src/main/java/com/caimei365/user/model/vo/RemarksFileVo.java

@@ -0,0 +1,29 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/9/26
+ */
+@Data
+public class RemarksFileVo implements Serializable {
+    /**
+     * 文件名称
+     */
+    private String fileName;
+
+    /**
+     * oss名称
+     */
+    private String ossName;
+
+    /**
+     * 文件链接
+     */
+    private String fileUrl;
+}

+ 42 - 0
src/main/java/com/caimei365/user/model/vo/RemarksVo.java

@@ -0,0 +1,42 @@
+package com.caimei365.user.model.vo;
+
+import com.caimei365.user.model.po.RemarksFilePo;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/9/26
+ */
+@Data
+public class RemarksVo implements Serializable {
+    /**
+     * 备注id
+     */
+    private Integer remarksId;
+    /**
+     * 文字备注
+     */
+    private String remarks;
+    /**
+     * 添加时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date addTime;
+
+    /**
+     * 图片列表
+     */
+    private List<String> imageList;
+
+    /**
+     * 文件列表
+     */
+    private List<RemarksFileVo> fileList;
+}

+ 42 - 0
src/main/java/com/caimei365/user/service/ClubService.java

@@ -1,8 +1,12 @@
 package com.caimei365.user.service;
 package com.caimei365.user.service;
 
 
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.dto.ClubRemarksDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
+import com.caimei365.user.model.dto.JsonParamsDto;
 import com.caimei365.user.model.vo.BeansHistoryVo;
 import com.caimei365.user.model.vo.BeansHistoryVo;
+import com.caimei365.user.model.vo.PaginationVo;
+import com.caimei365.user.model.vo.RemarksVo;
 
 
 import java.util.Map;
 import java.util.Map;
 
 
@@ -87,4 +91,42 @@ public interface ClubService {
      * @return
      * @return
      */
      */
     ResponseJson archiveDeduction(Integer userId, Integer archiveId);
     ResponseJson archiveDeduction(Integer userId, Integer archiveId);
+
+    /**
+     * 保存机构资料备注
+     * @param jsonParamsDto:{
+     *                     remarksId:           备注id,
+     *                     机构id:               机构id,
+     *                     serviceProviderId:   协销id,
+     *                     remarks:             文字备注,
+     *                     fileList:    [{fileName:"文件名称",ossName:"oss文件名称"},{fileName:"文件名称",ossName:"oss文件名称"}...]
+     *                     imageList:   ["图片","图片",...]
+     *                    }
+     * @return
+     * @return
+     */
+    ResponseJson saveClubRemarks(JsonParamsDto jsonParamsDto);
+
+    /**
+     * 获取机构资料备注列表
+     * @param clubId    机构id
+     * @param pageNum   页码
+     * @param pageSize  每页数量
+     * @return
+     */
+    ResponseJson<PaginationVo<RemarksVo>> getRemarksList(Integer clubId, int pageNum, int pageSize);
+
+    /**
+     * 获取机构资料备注详情
+     * @param remarksId     备注id
+     * @return
+     */
+    ResponseJson<RemarksVo> getRemarksDetail(Integer remarksId);
+
+    /**
+     * 删除机构资料备注
+     * @param remarksId     备注id
+     * @return
+     */
+    ResponseJson deleteClubRemarks(Integer remarksId);
 }
 }

+ 127 - 0
src/main/java/com/caimei365/user/service/impl/ClubServiceImpl.java

@@ -1,27 +1,40 @@
 package com.caimei365.user.service.impl;
 package com.caimei365.user.service.impl;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
 import com.caimei365.user.mapper.BaseMapper;
 import com.caimei365.user.mapper.BaseMapper;
 import com.caimei365.user.mapper.ClubMapper;
 import com.caimei365.user.mapper.ClubMapper;
 import com.caimei365.user.mapper.RegisterMapper;
 import com.caimei365.user.mapper.RegisterMapper;
 import com.caimei365.user.mapper.SuperVipMapper;
 import com.caimei365.user.mapper.SuperVipMapper;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.ResponseJson;
+import com.caimei365.user.model.dto.ClubRemarksDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.ClubUpdateDto;
 import com.caimei365.user.model.dto.SuperVipDto;
 import com.caimei365.user.model.dto.SuperVipDto;
 import com.caimei365.user.model.po.SuperVipPo;
 import com.caimei365.user.model.po.SuperVipPo;
+import com.caimei365.user.model.dto.JsonParamsDto;
+import com.caimei365.user.model.po.RemarksFilePo;
+import com.caimei365.user.model.po.ClubRemarksPo;
 import com.caimei365.user.model.po.UserBeansHistoryPo;
 import com.caimei365.user.model.po.UserBeansHistoryPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.ClubService;
 import com.caimei365.user.service.ClubService;
+import com.caimei365.user.utils.OssUtil;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 
 
+import static com.alibaba.fastjson.JSON.parseArray;
+import static com.alibaba.fastjson.JSON.parseObject;
+
 /**
 /**
  * Description
  * Description
  *
  *
@@ -339,4 +352,118 @@ public class ClubServiceImpl implements ClubService {
         clubMapper.updateUserBeans(userId, beansNum);
         clubMapper.updateUserBeans(userId, beansNum);
         return ResponseJson.success("抵扣成功");
         return ResponseJson.success("抵扣成功");
     }
     }
+
+    /**
+     * 保存机构资料备注
+     * @param jsonParamsDto:{
+     *                     remarksId:           备注id,
+     *                     机构id:               机构id,
+     *                     serviceProviderId:   协销id,
+     *                     remarks:             文字备注,
+     *                     fileList:    [{fileName:"文件名称",ossName:"oss文件名称"},{fileName:"文件名称",ossName:"oss文件名称"}...]
+     *                     imageList:   ["图片","图片",...]
+     *                    }
+     * @return
+     */
+    @Override
+    public ResponseJson saveClubRemarks(JsonParamsDto jsonParamsDto) {
+        try {
+            JSONObject jsonObject = parseObject(jsonParamsDto.getParams());
+            Integer clubId = jsonObject.getInteger("clubId");
+            Integer remarksId = jsonObject.getInteger("remarksId");
+            Integer serviceProviderId = jsonObject.getInteger("serviceProviderId");
+            String remarks = jsonObject.getString("remarks");
+            if (null == clubId) {
+                return ResponseJson.error("参数异常,机构id不能为空");
+            }
+            if (null == serviceProviderId) {
+                return ResponseJson.error("参数异常,协销id不能为空");
+            }
+            // 是否新增备注
+            boolean newRemarks = null == remarksId;
+            ClubRemarksPo clubRemarksPo = new ClubRemarksPo();
+            clubRemarksPo.setRemarksId(remarksId);
+            clubRemarksPo.setClubId(clubId);
+            clubRemarksPo.setServiceProviderId(serviceProviderId);
+            clubRemarksPo.setRemarks(remarks);
+            if (newRemarks) {
+                // 新增备注
+                clubMapper.insertRemarks(clubRemarksPo);
+            } else {
+                // 修改备注
+                clubMapper.updateRemarks(clubRemarksPo);
+                // 删除旧的备注图片和文件
+                clubMapper.clearRearksFiles(remarksId);
+            }
+            JSONArray filesArray = jsonObject.getJSONArray("fileList");
+            JSONArray imagesArray = jsonObject.getJSONArray("imageList");
+            remarksId = clubRemarksPo.getRemarksId();
+            //保存图片
+            if (!imagesArray.isEmpty()) {
+                for (Object imageObj: imagesArray) {
+                    String image = String.valueOf(imageObj);
+                    // 保存资质图片
+                    clubMapper.insertRemarksImage(remarksId, image);
+                }
+            }
+            //保存文件
+            if (!filesArray.isEmpty()) {
+                for (Object fileObj: filesArray) {
+                    JSONObject file = (JSONObject) fileObj;
+                    String fileName = file.getString("fileName");
+                    String ossName = file.getString("ossName");
+                    // 保存资质文件
+                    clubMapper.insertRemarksFile(remarksId, fileName, ossName);
+                }
+            }
+            return ResponseJson.success("保存资料备注成功");
+        } catch (Exception e) {
+            log.info("保存机构资料备注参数:" + jsonParamsDto.toString());
+            log.error("【保存机构资料备注】>>>参数解析异常try-catch:", e);
+            return ResponseJson.error("保存机构资料备注参数解析异常!", null);
+        }
+
+    }
+
+    @Override
+    public ResponseJson<PaginationVo<RemarksVo>> getRemarksList(Integer clubId, int pageNum, int pageSize) {
+        if (null == clubId) {
+            return ResponseJson.error("参数异常,机构id不能为空", null);
+        }
+        PageHelper.startPage(pageNum, pageSize);
+        List<RemarksVo> remarksList = clubMapper.getRemarksList(clubId);
+        return ResponseJson.success(new PaginationVo<>(remarksList));
+    }
+
+    @Override
+    public ResponseJson<RemarksVo> getRemarksDetail(Integer remarksId) {
+        if (null == remarksId) {
+            return ResponseJson.error("参数异常,备注id不能为空", null);
+        }
+        RemarksVo remarksVo = clubMapper.getRemarks(remarksId);
+        List<String> imageList = clubMapper.getRemarksImageList(remarksId);
+        List<RemarksFileVo> fileList = clubMapper.getRemarksFileList(remarksId);
+        fileList.forEach(file->{
+            file.setFileUrl(OssUtil.getOssUrl(file.getOssName())); ;
+        });
+        remarksVo.setImageList(imageList);
+        remarksVo.setFileList(fileList);
+        return ResponseJson.success(remarksVo);
+    }
+
+    @Override
+    public ResponseJson deleteClubRemarks(Integer remarksId) {
+        if (null == remarksId) {
+            return ResponseJson.error("参数异常,备注id不能为空");
+        }
+        clubMapper.deleteRemarks(remarksId);
+        //删除oss服务器上的文件
+        List<RemarksFileVo> fileList = clubMapper.getRemarksFileList(remarksId);
+        fileList.forEach(file->{
+            OssUtil.deleteSingleFile(file.getOssName());
+        });
+        //删除备注包含的文件
+        clubMapper.deleteRemarksFiles(remarksId);
+        return ResponseJson.success("删除成功");
+    }
 }
 }

+ 187 - 0
src/main/java/com/caimei365/user/utils/OssUtil.java

@@ -0,0 +1,187 @@
+package com.caimei365.user.utils;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.aliyun.oss.model.GetObjectRequest;
+import com.aliyun.oss.model.ObjectMetadata;
+import com.aliyun.oss.model.UploadFileRequest;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.UUID;
+
+
+/**
+ * 文件的上传下载
+ *
+ * @author Administrator
+ */
+@Component
+public class OssUtil {
+    private static final String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
+    private static final String accessKeyId = "LTAI4GBL3o4YkWnbKYgf2Xia";
+    private static final String accessKeySecret = "dBjAXqbYiEPP6Ukuk2ZsXQeET7FVkK";
+    private static final String privateBucket = "caimei-oss";
+
+    private static String active;
+
+    @Value("${spring.cloud.config.profile}")
+    public void setActive(String actives) {
+        active = actives;
+    }
+
+
+
+    public static String ossUpload(String fileName, File file, String contentType) {
+        String url = null;
+        try {
+            OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+            ObjectMetadata meta = new ObjectMetadata();
+            meta.setContentType(contentType);
+            fileName = active + "/" + fileName;
+            UploadFileRequest uploadFileRequest = new UploadFileRequest(privateBucket, fileName);
+            // 指定上传的本地文件。
+            uploadFileRequest.setUploadFile(file.toString());
+            // 指定上传并发线程数,默认为1。
+            uploadFileRequest.setTaskNum(10);
+            // 指定上传的分片大小,范围为100KB~5GB,默认为文件大小/10000。
+            uploadFileRequest.setPartSize(1024 * 1024);
+            // 开启断点续传,默认关闭。
+            uploadFileRequest.setEnableCheckpoint(true);
+            uploadFileRequest.setCheckpointFile(file.getAbsolutePath() + "uploadFile.ucp");
+            // 文件的元数据。
+            uploadFileRequest.setObjectMetadata(meta);
+            // 设置上传成功回调,参数为Callback类型。
+            //uploadFileRequest.setCallback("<yourCallbackEvent>");
+            //断点续传上传。
+            ossClient.uploadFile(uploadFileRequest);
+            Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000);
+            url = ossClient.generatePresignedUrl(privateBucket, fileName, expiration).toString();
+            // 关闭OSSClient。
+            ossClient.shutdown();
+        } catch (Throwable e) {
+            e.printStackTrace();
+        }
+        return url;
+    }
+
+
+    /**
+     * 通过文件名判断并获取OSS服务文件上传时文件的contentType
+     */
+    public static String getContentType(String fileName) {
+        String fileExtension = fileName.substring(fileName.lastIndexOf("."));
+        if (".bmp".equalsIgnoreCase(fileExtension)) {
+            return "image/bmp";
+        }
+        if (".gif".equalsIgnoreCase(fileExtension)) {
+            return "image/gif";
+        }
+        if (".jpeg".equalsIgnoreCase(fileExtension)) {
+            return "image/jpeg";
+        }
+        if (".jpg".equalsIgnoreCase(fileExtension)) {
+            return "image/jpg";
+        }
+        if (".png".equalsIgnoreCase(fileExtension)) {
+            return "image/png";
+        }
+        if (".html".equalsIgnoreCase(fileExtension)) {
+            return "text/html";
+        }
+        if (".txt".equalsIgnoreCase(fileExtension)) {
+            return "text/plain";
+        }
+        if (".vsd".equalsIgnoreCase(fileExtension)) {
+            return "application/vnd.visio";
+        }
+        if (".ppt".equalsIgnoreCase(fileExtension) || "pptx".equalsIgnoreCase(fileExtension)) {
+            return "application/vnd.ms-powerpoint";
+        }
+        if (".doc".equalsIgnoreCase(fileExtension) || "docx".equalsIgnoreCase(fileExtension)) {
+            return "application/msword";
+        }
+        if (".xml".equalsIgnoreCase(fileExtension)) {
+            return "text/xml";
+        }
+        if (".mp4".equalsIgnoreCase(fileExtension)) {
+            return "video/mp4";
+        }
+        if (".mp3".equalsIgnoreCase(fileExtension)) {
+            return "audio/mp3";
+        }
+        if (".pdf".equalsIgnoreCase(fileExtension)) {
+            return "application/pdf";
+        }
+        return "text/html";
+    }
+
+    public static void deleteFile(File... files) {
+        for (File file : files) {
+            //logger.info("File:[{}]",file.getAbsolutePath());
+            if (file.exists()) {
+                file.delete();
+            }
+        }
+    }
+
+    public static File ossUpload(MultipartFile file) throws IOException {
+        // 获取文件名
+        String fileName = file.getOriginalFilename();
+        // 获取文件后缀
+        String prefix = fileName.substring(fileName.lastIndexOf("."));
+        // 用uuid作为文件名,防止生成的临时文件重复
+        File excelFile = File.createTempFile(UUID.randomUUID().toString(), prefix);
+        // MultipartFile to File
+        file.transferTo(excelFile);
+        //程序结束时,删除临时文件
+        return excelFile;
+    }
+
+    /**
+     * 授权生成签名URL临时访问
+     *
+     * @param fileName 文件名称
+     */
+    public static String getOssUrl(String fileName) {
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        // 设置URL过期时间为1个小时
+        Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000);
+        String url = ossClient.generatePresignedUrl(privateBucket, active + "/" + fileName, expiration).toString();
+        // 关闭OSSClient。
+        ossClient.shutdown();
+        return url;
+    }
+
+    /**
+     * oss单个文件删除
+     *
+     * @param fileName 文件名称或文件夹名称
+     */
+    public static void deleteSingleFile(String fileName) {
+        // 创建OSSClient实例。
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        // 删除文件。如需删除文件夹,请将ObjectName设置为对应的文件夹名称。
+        // 如果文件夹非空,则需要将文件夹下的所有object删除后才能删除该文件夹。
+        fileName = active + "/" + fileName;
+        ossClient.deleteObject(privateBucket, fileName);
+        // 关闭OSSClient。
+        ossClient.shutdown();
+    }
+
+    /**
+     * oss单个文件下载
+     */
+    public static void downFile(String ossName, String fileName) {
+        // 创建OSSClient实例。
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
+        ossClient.getObject(new GetObjectRequest(privateBucket, ossName), new File("./" + fileName));
+        // 关闭OSSClient。
+        ossClient.shutdown();
+    }
+}

+ 49 - 0
src/main/resources/mapper/ClubMapper.xml

@@ -1,6 +1,18 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.user.mapper.ClubMapper">
 <mapper namespace="com.caimei365.user.mapper.ClubMapper">
+    <insert id="insertRemarks" parameterType="com.caimei365.user.model.po.ClubRemarksPo" keyProperty="remarksId" useGeneratedKeys="true">
+        insert into cm_club_remarks(clubId, serviceProviderId, remarks, addTime)
+        values (#{clubId}, #{serviceProviderId}, #{remarks}, now())
+    </insert>
+    <insert id="insertRemarksImage">
+        insert into cm_club_remarks_file(remarksId, fileType, imageUrl)
+        values (#{remarksId}, 1, #{imageUrl})
+    </insert>
+    <insert id="insertRemarksFile">
+        insert into cm_club_remarks_file(remarksId, fileType, fileName, ossName)
+        values (#{remarksId}, 2, #{fileName}, #{ossName})
+    </insert>
 
 
     <update id="updateClubUserByUpdateInfo">
     <update id="updateClubUserByUpdateInfo">
         update user set
         update user set
@@ -54,6 +66,15 @@
         lastModify = NOW()
         lastModify = NOW()
         where clubID = #{clubId}
         where clubID = #{clubId}
     </update>
     </update>
+    <delete id="clearRearksFiles">
+        delete from cm_club_remarks where id = #{remarksId}
+    </delete>
+    <delete id="deleteRemarks">
+        delete from cm_club_remarks where id = #{remarksId}
+    </delete>
+    <delete id="deleteRemarksFiles">
+        delete from cm_club_remarks_file where remarksId = #{remarksId}
+    </delete>
     <select id="getClubById" resultType="com.caimei365.user.model.vo.ClubVo">
     <select id="getClubById" resultType="com.caimei365.user.model.vo.ClubVo">
         select clubID as clubId, userID as userId, name, sname as shortName, contractMobile, contractEmail1 as contractEmail,
         select clubID as clubId, userID as userId, name, sname as shortName, contractMobile, contractEmail1 as contractEmail,
                contractPhone, linkMan, provinceID as proviceId, cityID as cityId, townID as townId,
                contractPhone, linkMan, provinceID as proviceId, cityID as cityId, townID as townId,
@@ -116,6 +137,11 @@
     <update id="updatePushStatus">
     <update id="updatePushStatus">
         UPDATE user_beans_history SET pushStatus = 1 WHERE userId = #{userId}
         UPDATE user_beans_history SET pushStatus = 1 WHERE userId = #{userId}
     </update>
     </update>
+    <update id="updateRemarks">
+        update cm_club_remarks
+        set remarks = #{remarks}
+        where id = #{remarksId}
+    </update>
 
 
     <select id="findAllBeansHistory" resultType="com.caimei365.user.model.vo.BeansHistoryVo">
     <select id="findAllBeansHistory" resultType="com.caimei365.user.model.vo.BeansHistoryVo">
         SELECT
         SELECT
@@ -170,4 +196,27 @@
         from user
         from user
         where userID = #{userId}
         where userID = #{userId}
     </select>
     </select>
+    <select id="getRemarksList" resultType="com.caimei365.user.model.vo.RemarksVo">
+        select id as remarksId, remarks, addTime
+        from cm_club_remarks
+        where clubId = #{clubId}
+        order by addTime desc
+    </select>
+    <select id="getRemarks" resultType="com.caimei365.user.model.vo.RemarksVo">
+        select id as remarksId, remarks, addTime
+        from cm_club_remarks
+        where id = #{remarksId}
+    </select>
+    <select id="getRemarksImageList" resultType="java.lang.String">
+        select imageUrl
+        from cm_club_remarks_file
+        where remarksId = #{remarksId}
+          and fileType = 1
+    </select>
+    <select id="getRemarksFileList" resultType="com.caimei365.user.model.vo.RemarksFileVo">
+        select fileName, ossName
+        from cm_club_remarks_file
+        where remarksId = #{remarksId}
+          and fileType = 2
+    </select>
 </mapper>
 </mapper>