Commit c6ea911f authored by 查济's avatar 查济

Merge branch 'feature-zhaji' into 'develop'

"feature-zhaJi:新增商险附件上传功能"

See merge request fangxinjiang/yifu!173
parents a8d50a54 0beec024
package com.yifu.cloud.plus.v1.yifu.insurances.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yifu.cloud.plus.v1.yifu.common.mybatis.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
* 商险附件表
* @TableName t_insurance_enclosure
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("t_insurance_enclosure")
@Schema(description = "商险附件表")
public class TInsuranceEnclosure extends BaseEntity {
/**
*
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private Integer id;
/**
* 附件名
*/
@Schema(description = "附件名")
private String enclosureName;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 删除标识
*/
@Schema(description = "删除标识")
private Integer deleteFlag;
/**
* 附件地址
*/
@Schema(description = "附件地址")
private String enclosureAddress;
}
\ No newline at end of file
package com.yifu.cloud.plus.v1.yifu.insurances.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @author zhaji
* @description TODO
* @date 2022-08-23 11:50:53
*/
@Data
public class EnclosureUrlVo implements Serializable {
}
package com.yifu.cloud.plus.v1.yifu.insurances.vo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import java.io.Serializable;
/**
* @author zhaji
* @description 商险附件查询表
* @date 2022-08-23 10:29:33
*/
@Data
@Tag(name = "商险附件查询表")
public class InsuranceEnclosureParam implements Serializable {
/**
* 导入人
*/
private String createName;
/**
* 导入开始时间
*/
private String startTime;
/**
* 导入结束时间
*/
private String endTime;
/**
* 备注
*/
private String remark;
/**
* 文件名称
*/
private String enclosureName;
}
package com.yifu.cloud.plus.v1.yifu.insurances.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author zhaji
* @description 商险附件查询返回类
* @date 2022-08-23 10:37:30
*/
@Data
@Tag(name = "商险附件查询返回类")
public class InsuranceEnclosureVo implements Serializable {
/**
*
*/
@Schema(description = "主键")
private Integer id;
/**
* 附件名
*/
@Schema(description = "附件名")
private String enclosureName;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 创建者-姓名
*/
@Schema(description = "创建人-姓名")
private String createName;
/**
* 创建时间
*/
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
@Schema(description = "创建时间")
private LocalDateTime createTime;
}
package com.yifu.cloud.plus.v1.yifu.insurances.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure;
import com.yifu.cloud.plus.v1.yifu.insurances.service.TInsuranceEnclosureService;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureParam;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListParam;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO;
import com.yifu.cloud.plus.v1.yifu.salary.entity.TSalaryAtta;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URL;
/**
* @author zhaji
* @description 商险文件上传
* @date 2022-08-22 15:52:21
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/insuranceEnclosure")
@Tag(name = "商险文件上传")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
@Slf4j
public class TInsuranceEnclosureController {
@Resource
TInsuranceEnclosureService tInsuranceEnclosureService;
private final OSSUtil ossUtil;
/**
* 商险文件上传
*
* @param file 文件
* @param filePath 如: import 或 import/test/test..../test
* @return
* @throws IOException
* @Author zhaji
* @Date 2022-08-23
*/
@SysLog("商险文件上传")
@Schema(description = "商险文件上传")
@PostMapping(value = "/uploadInsuranceEnclosure")
public R uploadInsuranceEnclosure(@RequestBody MultipartFile file, String filePath,String remark) throws IOException {
return tInsuranceEnclosureService.uploadInsuranceEnclosure(file, filePath,remark);
}
/**
* 获取附件下载地址
*
* @param id
* @return
* @Author zhaji
* @Date 2022-08-23
**/
@Schema(description = "商险附件预览下载地址")
@SysLog("商险附件预览下载地址")
@GetMapping("/getInsuranceEnclosureUrl/{id}")
public R getInsuranceEnclosureUrl(@PathVariable String id) {
return tInsuranceEnclosureService.getInsuranceEnclosureUrl(id);
}
/**
* 删除商险附件
*
* @param id
* @return
* @Author zhaji
* @Date 2022-08-23
**/
@Schema(description = "删除商险附件")
@SysLog("删除商险附件")
@GetMapping("/deleteInsuranceEnclosure/{id}")
public R deleteInsuranceEnclosure(@PathVariable String id) {
return tInsuranceEnclosureService.deleteInsuranceEnclosure(id);
}
/**
* 商险附件列表分页查询
*
* @param page
* @param param
* @return
* @Author zhaji
* @Date 2022-08-23
**/
@Schema(description = "商险附件列表分页查询")
@SysLog("商险附件列表分页查询")
@GetMapping("/getInsuranceEnclosurePage")
public R getInsuranceEnclosurePage(Page<InsuranceEnclosureParam> page, @RequestBody InsuranceEnclosureParam param) {
return tInsuranceEnclosureService.getInsuranceEnclosurePage(page,param);
}
}
package com.yifu.cloud.plus.v1.yifu.insurances.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureParam;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* @author Administrator
* @description 针对表【t_insurance_enclosure】的数据库操作Mapper
* @createDate 2022-08-22 16:00:46
* @Entity generator.domain.TInsuranceEnclosure
*/
@Mapper
public interface TInsuranceEnclosureMapper extends BaseMapper<TInsuranceEnclosure> {
/**
* 查询商险附件列表
*
* @author zhaji
* @param page 分页参数
* @param param 查询参数
* @return {@link IPage< InsuranceEnclosureVo>}
*/
IPage<InsuranceEnclosureVo> getInsuranceEnclosurePage(Page<InsuranceEnclosureParam> page, @Param("param")InsuranceEnclosureParam param);
}
package com.yifu.cloud.plus.v1.yifu.insurances.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* @author Administrator
* @description 针对表【t_insurance_enclosure】的数据库操作Service
* @createDate 2022-08-22 16:00:46
*/
public interface TInsuranceEnclosureService extends IService<TInsuranceEnclosure> {
/**
* 上传商险附件
*
* @author zhaji
* @param file 文件
* @param filePath 文件路径
* @param remark 备注
* @return {@link R}
* @throws IOException
*/
R uploadInsuranceEnclosure(MultipartFile file, String filePath,String remark) throws IOException;
/**
* 获取附件列表
*
* @author zhaji
* @param page 分页参数
* @param param 查询参数
* @return {@link R}
*/
R getInsuranceEnclosurePage(Page<InsuranceEnclosureParam> page, InsuranceEnclosureParam param);
/**
* 获取商险附件地址
*
* @author zhaji
* @param id
* @return {@link R}
*/
R getInsuranceEnclosureUrl(String id);
/**
* 删除商险附件
*
* @author zhaji
* @param id
* @return {@link R}
*/
R deleteInsuranceEnclosure(String id);
}
package com.yifu.cloud.plus.v1.yifu.insurances.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.OSSUtil;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.FileVo;
import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure;
import com.yifu.cloud.plus.v1.yifu.insurances.mapper.TInsuranceEnclosureMapper;
import com.yifu.cloud.plus.v1.yifu.insurances.service.TInsuranceEnclosureService;
import com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
/**
* @author Administrator
* @description 针对表【t_insurance_enclosure】的数据库操作Service实现
* @createDate 2022-08-22 16:00:46
*/
@Service
@Slf4j
public class TInsuranceEnclosureServiceImpl extends ServiceImpl<TInsuranceEnclosureMapper, TInsuranceEnclosure> implements TInsuranceEnclosureService {
private final OSSUtil ossUtil;
public TInsuranceEnclosureServiceImpl(OSSUtil ossUtil) {
this.ossUtil = ossUtil;
}
/**
* 上传商险附件
*
* @author zhaji
* @param file 文件
* @param filePath 文件路径
* @param remark 备注
* @return {@link R}
* @throws IOException
*/
@Override
public R uploadInsuranceEnclosure(MultipartFile file, String filePath, String remark) throws IOException {
String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
String enclosureName = fileName.substring(0, fileName.lastIndexOf("."));
//filePath不传默认存储空间的根目录
//jpg,jpeg,png,bmp
String key = "";
if (!Common.isNotNull(filePath)) {
key = fileName;
} else {
key = filePath + "/" + fileName;
}
boolean flag = ossUtil.uploadFileByStream(file.getInputStream(), key, null);
FileVo fileVo;
TInsuranceEnclosure insuranceEnclosure = new TInsuranceEnclosure();
URL url = null;
if (flag) {
log.info("文件:" + fileName + "上传至存储空间" + ossUtil.getBucketName() + "成功!");
insuranceEnclosure.setDeleteFlag(CommonConstants.ZERO_INT);
insuranceEnclosure.setRemark(remark);
insuranceEnclosure.setEnclosureName(enclosureName);
insuranceEnclosure.setEnclosureAddress(key);
try {
this.save(insuranceEnclosure);
} catch (Exception e) {
log.error("OSS文件上传接口异常:" + e.getMessage());
ossUtil.deleteObject(null, key);
return R.failed("failed:" + e.getMessage());
}
url = ossUtil.getObjectUrl(null, insuranceEnclosure.getEnclosureAddress());
fileVo = new FileVo(insuranceEnclosure.getId().toString(), insuranceEnclosure.getEnclosureName(), url.toString());
return R.ok(fileVo);
} else {
return R.failed("failed:上传至存储空间失败");
}
}
/**
* 获取附件列表
*
* @author zhaji
* @param page 分页参数
* @param param 查询参数
* @return {@link R}
*/
@Override
public R getInsuranceEnclosurePage(Page<InsuranceEnclosureParam> page, InsuranceEnclosureParam param) {
return R.ok(this.baseMapper.getInsuranceEnclosurePage(page,param));
}
/**
* 获取商险附件地址
*
* @author zhaji
* @param id 附件id
* @return {@link R}
*/
@Override
public R getInsuranceEnclosureUrl(String id) {
TInsuranceEnclosure insuranceEnclosure = getById(id);
if (null == insuranceEnclosure) {
return R.failed("无对应附件信息");
}
String enclosureAddress = insuranceEnclosure.getEnclosureAddress();
log.info("key:"+enclosureAddress);
URL url = ossUtil.getObjectUrl(null, insuranceEnclosure.getEnclosureAddress());
return new R<>(url.toString());
}
/**
* 删除商险附件
*
* @author zhaji
* @param id 附件id
* @return {@link R}
*/
@Override
public R deleteInsuranceEnclosure(String id) {
try {
TInsuranceEnclosure insuranceEnclosure = getById(id);
if (null == insuranceEnclosure) {
return R.failed("无对应附件信息");
}
if (removeById(id)) {
ossUtil.deleteObject(null, insuranceEnclosure.getEnclosureAddress());
return R.ok("删除成功!");
}
} catch (Exception e) {
log.error("附件删除异常:" + e.getMessage());
return R.failed("附件删除异常!");
}
return R.ok("删除失败!");
}
}
<?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">
<mapper namespace="com.yifu.cloud.plus.v1.yifu.insurances.mapper.TInsuranceEnclosureMapper">
<resultMap id="BaseResultMap" type="com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceEnclosure">
<id property="id" column="ID" jdbcType="INTEGER"/>
<result property="enclosureName" column="ENCLOSURE_NAME" jdbcType="VARCHAR"/>
<result property="remark" column="REMARK" jdbcType="VARCHAR"/>
<result property="deleteFlag" column="DELETE_FLAG" jdbcType="VARCHAR"/>
<result property="enclosureAddress" column="ENCLOSURE_ADDRESS" jdbcType="VARCHAR"/>
<result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
<result property="createName" column="CREATE_NAME" jdbcType="VARCHAR"/>
<result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
<result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id,enclosure_name,create_name,
create_by,create_time,remark,
delete_flag,enclosure_address,
updateBy,updateTime
</sql>
<select id="getInsuranceEnclosurePage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceEnclosureVo">
select
e.ID as id,
e.ENCLOSURE_NAME as enclosureName,
e.CREATE_NAME as createName,
e.REMARK as remark,
e.CREATE_TIME as createTime
from
t_insurance_enclosure e
where
e.DELETE_FLAG = 0
<if test="param.createName != null and param.createName.trim() != ''">
and e.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
</if>
<if test="param.remark != null and param.remark.trim() != ''">
and e.REMARK like concat('%',replace(replace(#{param.remark},'_','\_'),'%','\%'),'%')
</if>
<if test="param.enclosureName != null and param.enclosureName.trim() != ''">
and e.ENCLOSURE_NAME like concat('%',replace(replace(#{param.enclosureName},'_','\_'),'%','\%'),'%')
</if>
<if test="param.startTime != null and param.startTime.trim() != '' ">
AND e.CREATE_TIME <![CDATA[ >= ]]> concat(#{param.startTime}, ' 00:00:00')
</if>
<if test="param.endTime != null and param.endTime.trim() != '' ">
AND e.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endTime}, ' 23:59:59')
</if>
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment