From dd59c95e87ba585c4e3e2f059e218853784402e5 Mon Sep 17 00:00:00 2001 From: zhangfeng <1603559716@qq.com> Date: 星期三, 26 七月 2023 11:17:31 +0800 Subject: [PATCH] 附件上传接口 --- src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml | 5 src/main/java/com/gk/hotwork/Controller/AttachmentController.java | 223 +++++++++++ src/main/java/com/gk/hotwork/Domain/SafetySelfInspectionItem.java | 11 src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java | 212 +++------ src/main/java/com/gk/hotwork/Service/AttachmentService.java | 35 + src/main/resources/application-prod.yml | 47 + src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml | 41 ++ src/main/java/com/gk/hotwork/Mapper/mybatis/AttachmentInfoMapper.xml | 21 + src/main/java/com/gk/hotwork/Domain/InspectionHiddenDanger.java | 12 src/main/java/com/gk/hotwork/Service/ServiceImpl/ElementManagementImpl.java | 2 src/main/java/com/gk/hotwork/Controller/SafetySelfInspectionController.java | 2 src/main/java/com/gk/hotwork/Config/Cors/MyMvcConfigurer.java | 4 src/main/java/com/gk/hotwork/Mapper/AttachmentInfoMapper.java | 20 + src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java | 27 + src/main/java/com/gk/hotwork/Service/AttachmentInfoService.java | 33 + src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentInfoServiceImpl.java | 83 ++++ src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml | 3 src/main/resources/application-dev.yml | 47 + src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentServiceImpl.java | 327 ++++++++++++++++ src/main/java/com/gk/hotwork/Domain/SafetySelfInspection.java | 2 src/main/resources/application.yml | 6 21 files changed, 974 insertions(+), 189 deletions(-) diff --git a/src/main/java/com/gk/hotwork/Config/Cors/MyMvcConfigurer.java b/src/main/java/com/gk/hotwork/Config/Cors/MyMvcConfigurer.java index 8e6113b..e168a6c 100644 --- a/src/main/java/com/gk/hotwork/Config/Cors/MyMvcConfigurer.java +++ b/src/main/java/com/gk/hotwork/Config/Cors/MyMvcConfigurer.java @@ -1,5 +1,6 @@ package com.gk.hotwork.Config.Cors; +import com.gk.hotwork.Config.attachment.FilePathConfig; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; @@ -30,6 +31,8 @@ private String taskPath; @Value("${emergencyPlanPath}") private String emergencyPlanPath; + + @Override @@ -67,5 +70,6 @@ .addResourceLocations("file:" + taskPath); registry.addResourceHandler("/upload/emergencyPlan/**") .addResourceLocations("file:" + emergencyPlanPath); + } } diff --git a/src/main/java/com/gk/hotwork/Controller/AttachmentController.java b/src/main/java/com/gk/hotwork/Controller/AttachmentController.java new file mode 100644 index 0000000..d9cee31 --- /dev/null +++ b/src/main/java/com/gk/hotwork/Controller/AttachmentController.java @@ -0,0 +1,223 @@ +package com.gk.hotwork.Controller; +import com.gk.hotwork.Controller.Base.BaseController; +import com.gk.hotwork.Domain.AttachmentInfo; +import com.gk.hotwork.Domain.Utils.Msg; +import com.gk.hotwork.Service.AttachmentService; + +import com.gk.hotwork.common.FileProjectConstants; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2023/5/6 + * @time: 14:22 + */ +@Api(tags = "附件上传接口") +@RestController +@RequestMapping("/attachment") +public class AttachmentController extends BaseController { + + @Autowired + private AttachmentService attachmentService; + + + /** + * 根据标识查询文件具体信息 + * @param key + * @return + */ + @ApiOperation(value = "根据标识查询文件具体信息",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "key",value = "文件标识") + }) + @GetMapping("/get/key/{key}") + public Msg findByKey(@PathVariable String key) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("查询成功"); + AttachmentInfo byKey = attachmentService.findByKey(key); + msg.setResult(byKey); + return msg; + } + + /** + * 根据id获取文件 + * @param id + * @return + */ + @ApiOperation(value = "根据id获取文件",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "id",value = "文件id") + }) + @GetMapping("/get/id/{id}") + public Msg get(@PathVariable Long id) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("查询成功"); + AttachmentInfo byKey = attachmentService.findById(id); + msg.setResult(byKey); + return msg; + } + + /** + * 删除文件数据 + * @param id + * @return + */ + @ApiOperation(value = "删除文件数据",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "id",value = "文件id") + }) + @DeleteMapping("/delete/{id}") + public Msg delete(@PathVariable Long id) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("删除成功"); + attachmentService.delete(id,getUser()); + return msg; + + } + + /** + * 单个文件上传 + * @Description 上传文件(返回文件标识) + * @Param [file, module] + **/ + @ApiOperation(value = "上传文件(返回文件标识)-单个文件",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "file",value = "文件"), + @ApiImplicitParam(name = "module",value = "checkPath") + }) + @PostMapping("/upload/key") + public Msg uploadReturnKey(@RequestParam("file") MultipartFile + file, @RequestParam("module") String module) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("上传成功"); + Object returnStr = attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.KEY,getUser()); + msg.setResult(returnStr); + return msg; + } + + /** + * 单个文件 + * @Description 上传文件(返回文件信息) + * @Param [file, module] + **/ + @ApiOperation(value = "上传文件(返回文件信息)-单个文件",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "file",value = "文件"), + @ApiImplicitParam(name = "module",value = "模块(checkPath)") + }) + @PostMapping("/upload/detail") + public Msg uploadReturnDetail(@RequestParam("file") MultipartFile + file, @RequestParam("module") String module) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("上传成功"); + Object detail = attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.DETAIL,getUser()); + msg.setResult(detail); + return msg; + } + /** + * 单个文件 + * @Description 上传文件(返回访问路径) + * @Date 2021/4/20 19:28 + * @Param [file, module] + **/ + @ApiOperation(value = "上传文件(返回访问路径)-单个文件",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "file",value = "文件"), + @ApiImplicitParam(name = "module",value = "模块(checkPath)") + }) + @PostMapping("/upload/url") + public Msg uploadReturnUrl(@RequestParam("file") MultipartFile file, @RequestParam("module") String module) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("上传成功"); + Object returnStr = attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.URL,getUser()); + msg.setResult(returnStr); + return msg; + } + + /** + * 批量文件 + * @Description 上传文件(返回文件信息) + * @Param [file, module] + **/ + @ApiOperation(value = "上传文件(返回访问路径)-批量",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "file",value = "文件"), + @ApiImplicitParam(name = "module",value = "模块(checkPath)") + }) + @PostMapping("/upload/batch/detail") + public Msg uploadBatchReturnDetail(@RequestParam("file") MultipartFile[] + file, @RequestParam("module") String module) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("上传成功"); + Object detail = attachmentService.saveBatchFileToPath(file, module,getUser()); + msg.setResult(detail); + return msg; + } + + /** + * @return org.springframework.http.ResponseEntity<byte [ ]> + * @Description 获取下载文件流 + * @Param [key] + **/ + @ApiOperation(value = "获取下载文件流",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "key",value = "文件标识"), + }) + @GetMapping("/downloadFile/{key}") + public void download(@PathVariable String key, HttpServletResponse response) { + attachmentService.downloadForStream(response, key); + } + + /** + * @return void + * @Description 文件下载 + * @Param [key, response, request] + **/ + @ApiOperation(value = "文件下载",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "id",value = "文件id"), + }) + @RequestMapping(value = "/downloadFileById/{id}", method = {RequestMethod.POST, RequestMethod.GET}) + public void downloadFileByKey(@PathVariable Long id, HttpServletResponse response, HttpServletRequest + request) { + attachmentService.downloadById(response, request, id); + } + + /** + * @Description 获取下载文件路径 + * @Param [key] + **/ + @ApiOperation(value = "获取下载文件路径",response = Msg.class) + @ApiImplicitParams({ + @ApiImplicitParam(name = "key",value = "文件key"), + }) + @GetMapping("/downloadUrl/{key}") + public Msg downLoad( @PathVariable String key) { + Msg msg = new Msg(); + msg.setCode("200"); + msg.setMessage("查询成功"); + AttachmentInfo byKey = attachmentService.findByKey(key); + msg.setResult(byKey); + return msg; + } + + +} diff --git a/src/main/java/com/gk/hotwork/Controller/SafetySelfInspectionController.java b/src/main/java/com/gk/hotwork/Controller/SafetySelfInspectionController.java index 2c60902..c9a545c 100644 --- a/src/main/java/com/gk/hotwork/Controller/SafetySelfInspectionController.java +++ b/src/main/java/com/gk/hotwork/Controller/SafetySelfInspectionController.java @@ -38,7 +38,7 @@ @ApiImplicitParam(name = "pageSize",value = "每页行数"), @ApiImplicitParam(name = "inspectionName",value = "自查清单名称"), @ApiImplicitParam(name = "inspectorName",value = "检查人名称"), - @ApiImplicitParam(name = "checkedCompanyId",value = "被检查公司id"), + @ApiImplicitParam(name = "checkedCompanyName",value = "被检查公司名称"), @ApiImplicitParam(name = "inspectionStartTime",value = "开始时间"), @ApiImplicitParam(name = "inspectionEndTime",value = "结束时间"), @ApiImplicitParam(name = "status",value = "状态"), diff --git a/src/main/java/com/gk/hotwork/Domain/InspectionHiddenDanger.java b/src/main/java/com/gk/hotwork/Domain/InspectionHiddenDanger.java index 93674dd..c993701 100644 --- a/src/main/java/com/gk/hotwork/Domain/InspectionHiddenDanger.java +++ b/src/main/java/com/gk/hotwork/Domain/InspectionHiddenDanger.java @@ -5,6 +5,7 @@ import lombok.Data; import java.util.Date; +import java.util.List; /** * @email 1603559716@qq.com @@ -28,6 +29,9 @@ * 2重大 */ private Integer level; + /** + * 隐患附件 + */ private String url; private Boolean validFlag; /** @@ -36,16 +40,12 @@ private Long selfInspectionItemId; /** 创建时间 create_time **/ private Date createTime; - /** 创建人 create_by **/ private String createBy; - /** 最新更新时间 update_time **/ private Date updateTime; - /** 最后更新人 update_by **/ private String updateBy; - /** * 整改状态 0未整改,1已整改 */ @@ -54,7 +54,6 @@ * 整改描述 */ private String rectificationInfo; - /** * 整改附件 */ @@ -73,5 +72,8 @@ private String reviewMethod; @TableField(exist = false) private String veto; + //附件 + @TableField(exist = false) + private List<AttachmentInfo> attachmentList; } diff --git a/src/main/java/com/gk/hotwork/Domain/SafetySelfInspection.java b/src/main/java/com/gk/hotwork/Domain/SafetySelfInspection.java index bb541cc..c01ae2a 100644 --- a/src/main/java/com/gk/hotwork/Domain/SafetySelfInspection.java +++ b/src/main/java/com/gk/hotwork/Domain/SafetySelfInspection.java @@ -100,7 +100,7 @@ /** 检查单位 **/ private String checkUnit; - //检查标识 0自查,1监管检查 + //检查标识 2自查,1监管检查 private Byte flag; /** * 隐患总数 diff --git a/src/main/java/com/gk/hotwork/Domain/SafetySelfInspectionItem.java b/src/main/java/com/gk/hotwork/Domain/SafetySelfInspectionItem.java index a065214..548fc40 100644 --- a/src/main/java/com/gk/hotwork/Domain/SafetySelfInspectionItem.java +++ b/src/main/java/com/gk/hotwork/Domain/SafetySelfInspectionItem.java @@ -106,6 +106,17 @@ */ private String expertNames; + //附件 + @TableField(exist = false) + private List<AttachmentInfo> attachmentList; + + public List<AttachmentInfo> getAttachmentList() { + return attachmentList; + } + + public void setAttachmentList(List<AttachmentInfo> attachmentList) { + this.attachmentList = attachmentList; + } public String getExpertIds() { return expertIds; diff --git a/src/main/java/com/gk/hotwork/Mapper/AttachmentInfoMapper.java b/src/main/java/com/gk/hotwork/Mapper/AttachmentInfoMapper.java new file mode 100644 index 0000000..74fb4fb --- /dev/null +++ b/src/main/java/com/gk/hotwork/Mapper/AttachmentInfoMapper.java @@ -0,0 +1,20 @@ +package com.gk.hotwork.Mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.gk.hotwork.Domain.AttachmentInfo; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2023/7/24 + * @time: 13:49 + */ +@Repository +public interface AttachmentInfoMapper extends BaseMapper<AttachmentInfo> { + void saveBatch(List<AttachmentInfo> attachmentList); + + void updateBusinessIdBatch(List<AttachmentInfo> attachmentList); +} diff --git a/src/main/java/com/gk/hotwork/Mapper/mybatis/AttachmentInfoMapper.xml b/src/main/java/com/gk/hotwork/Mapper/mybatis/AttachmentInfoMapper.xml new file mode 100644 index 0000000..601c86e --- /dev/null +++ b/src/main/java/com/gk/hotwork/Mapper/mybatis/AttachmentInfoMapper.xml @@ -0,0 +1,21 @@ +<?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.gk.hotwork.Mapper.AttachmentInfoMapper" > + <insert id="saveBatch" useGeneratedKeys="true" keyProperty="id" > + insert into attachment (file_key,file_path,file_url,file_name,file_suffix,file_desc,file_size,file_type,module,del_flag, + create_uid,create_uname,create_time,update_uid,update_uname,update_time)values + <foreach collection="attachmentList" item="attachment" separator=","> + (#{attachment.fileKey},#{attachment.filePath},#{attachment.fileUrl},#{attachment.fileName},#{attachment.fileSuffix},#{attachment.fileDesc}, + #{attachment.fileSize},#{attachment.fileType},#{attachment.module},#{attachment.delFlag},#{attachment.createUid},#{attachment.createUname}, + #{attachment.createTime},#{attachment.updateUid},#{attachment.updateUname},#{attachment.updateTime}) + </foreach> + </insert> + <update id="updateBusinessIdBatch"> + <foreach collection="attachmentList" item="attachment"> + update attachment + set + business_id = #{attachment.id} + </foreach> + </update> + +</mapper> diff --git a/src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml b/src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml index 2ed110d..fc4038c 100644 --- a/src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml +++ b/src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml @@ -28,6 +28,7 @@ id,code,company, contactname, contactphone, ismain, province, city, area, town, community, isdel, createdby,createddate, lastmodifiedby, lastmodifieddate, longitude, latitude, isbanned </sql> +<!-- <select id="selectDataGrid" resultType="com.gk.hotwork.Domain.CompanyInfo"> select * from company @@ -60,6 +61,46 @@ </if> </where> </select> +--> + <select id="selectDataGrid" resultType="com.gk.hotwork.Domain.CompanyInfo"> + select c.* + from + (select * + from company + <where> + 1=1 + and isdel = 0 + <if test="condition.province != null and condition.province !=''"> + and province = #{condition.province} + </if> + <if test="condition.city != null and condition.city !=''"> + and city = #{condition.city} + </if> + <if test="condition.area != null and condition.area !=''"> + and area = #{condition.area} + </if> + </where> + union + select * + from company + <where>1=1 + and + isdel = 0 + and province is null + or province = '' + </where>) c + <where> + 1=1 + <if test="condition.company != null and condition.company !=''"> + and c.company like concat('%',#{condition.company},'%') + </if> + <if test="condition.companyid != null "> + and c.id = #{condition.companyid} + </if> + </where> + + </select> + <select id="selectExistByName" resultType="com.gk.hotwork.Domain.CompanyInfo"> select * from company diff --git a/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml b/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml index cfbc11c..735e914 100644 --- a/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml +++ b/src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml @@ -30,6 +30,9 @@ <if test="params.inspectionName != null and params.inspectionName != ''"> and s.inspection_name like concat("%",#{params.inspectionName},"%") </if> + <if test="params.checkedCompanyId != null and params.checkedCompanyId != ''"> + and s.checked_company_id like concat("%",#{params.checkedCompanyId},"%") + </if> <if test="params.checkedCompanyName != null and params.checkedCompanyName != ''"> and s.checked_company_name like concat("%",#{params.checkedCompanyName},"%") </if> diff --git a/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml b/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml index 7048d62..ec4215d 100644 --- a/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml +++ b/src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml @@ -27,7 +27,7 @@ LEFT JOIN userroles as c on b.id = c.userid left join company as co on a.checked_company_id = co.id where a.valid_flag = 1 - <if test="params.flag != null and params.flag != '' "> + <if test="params.flag != null and params.flag != '' "> and a.flag = #{params.flag} </if> <if test="params.inspectionName != null and params.inspectionName != ''"> @@ -36,6 +36,9 @@ <if test="params.checkedCompanyId != null"> and a.checked_company_id = #{params.checkedCompanyId} </if> + <if test="params.checkedCompanyName != null and params.checkedCompanyName != ''"> + and a.checked_company_name like concat("%",#{params.checkedCompanyName},"%") + </if> <if test="params.roleid != null "> and c.roleid = #{params.roleid} </if> diff --git a/src/main/java/com/gk/hotwork/Service/AttachmentInfoService.java b/src/main/java/com/gk/hotwork/Service/AttachmentInfoService.java new file mode 100644 index 0000000..e365859 --- /dev/null +++ b/src/main/java/com/gk/hotwork/Service/AttachmentInfoService.java @@ -0,0 +1,33 @@ +package com.gk.hotwork.Service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gk.hotwork.Domain.AttachmentInfo; +import com.gk.hotwork.Domain.UserInfo; + +import java.util.List; + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2023/7/24 + * @time: 13:51 + */ +public interface AttachmentInfoService extends IService<AttachmentInfo> { + AttachmentInfo findByKey(String key); + + AttachmentInfo findById(Long id); + + List<AttachmentInfo> findByBusinessId(Long businessId); + + List<AttachmentInfo> findByIds(List<Long> ids); + + + void delete(Long id, UserInfo userInfo); + + AttachmentInfo saveOne(AttachmentInfo attachmentInfo); + + List<AttachmentInfo> saveBatchAttachment(List<AttachmentInfo> attachmentInfoList); + + void updateBusinessIdBatch(List<AttachmentInfo> attachmentList); + +} diff --git a/src/main/java/com/gk/hotwork/Service/AttachmentService.java b/src/main/java/com/gk/hotwork/Service/AttachmentService.java new file mode 100644 index 0000000..5886c21 --- /dev/null +++ b/src/main/java/com/gk/hotwork/Service/AttachmentService.java @@ -0,0 +1,35 @@ +package com.gk.hotwork.Service; + +import com.gk.hotwork.Domain.AttachmentInfo; +import com.gk.hotwork.Domain.Exception.BusinessException; +import com.gk.hotwork.Domain.UserInfo; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2023/7/24 + * @time: 13:53 + */ +public interface AttachmentService { + AttachmentInfo findByKey(String key); + + AttachmentInfo findById(Long id); + List<AttachmentInfo> findByIds(List<Long> ids); + List<AttachmentInfo> findByBusinessId(Long businessId); + + void delete(Long id, UserInfo userInfo); + + Object saveFileToPath(MultipartFile file, String module, int type, UserInfo user); + + Object saveBatchFileToPath(MultipartFile[] file, String module, UserInfo user); + + void downloadForStream(HttpServletResponse response, String key); + + void downloadById(HttpServletResponse response, HttpServletRequest request, Long id); +} diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentInfoServiceImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentInfoServiceImpl.java new file mode 100644 index 0000000..4692a03 --- /dev/null +++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentInfoServiceImpl.java @@ -0,0 +1,83 @@ +package com.gk.hotwork.Service.ServiceImpl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gk.hotwork.Domain.AttachmentInfo; +import com.gk.hotwork.Domain.UserInfo; +import com.gk.hotwork.Mapper.AttachmentInfoMapper; +import com.gk.hotwork.Service.AttachmentInfoService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2023/7/24 + * @time: 13:48 + */ +@Service +public class AttachmentInfoServiceImpl extends ServiceImpl<AttachmentInfoMapper, AttachmentInfo> implements AttachmentInfoService { + @Autowired + private AttachmentInfoMapper attachmentInfoMapper; + + @Override + public AttachmentInfo findByKey(String key) { + AttachmentInfo attachmentInfo = attachmentInfoMapper.selectOne(new LambdaQueryWrapper<AttachmentInfo>() + .eq(AttachmentInfo::getDelFlag,0) + .eq(AttachmentInfo::getFileKey,key)); + return attachmentInfo; + } + @Override + public AttachmentInfo findById(Long id) { + AttachmentInfo attachmentInfo = attachmentInfoMapper.selectOne(new LambdaQueryWrapper<AttachmentInfo>() + .eq(AttachmentInfo::getDelFlag,0) + .eq(AttachmentInfo::getId,id)); + return attachmentInfo; + } + @Override + public List<AttachmentInfo> findByBusinessId(Long businessId) { + List<AttachmentInfo> attachmentInfoList = attachmentInfoMapper.selectList(new LambdaQueryWrapper<AttachmentInfo>() + .eq(AttachmentInfo::getDelFlag,0) + .eq(AttachmentInfo::getBusinessId,businessId)); + return attachmentInfoList; + } + + @Override + public List<AttachmentInfo> findByIds(List<Long> ids) { + return attachmentInfoMapper.selectList(new LambdaQueryWrapper<AttachmentInfo>() + .in(AttachmentInfo::getBusinessId,ids) + .eq(AttachmentInfo::getDelFlag,0)); + } + + @Override + public void delete(Long id, UserInfo userInfo) { + AttachmentInfo attachmentInfo = new AttachmentInfo(); + attachmentInfo.setId(id); + attachmentInfo.setUpdateTime(new Date()); + attachmentInfo.setUpdateUid(userInfo.getId()); + attachmentInfo.setUpdateUname(userInfo.getRealname()); + attachmentInfo.setDelFlag(1); + attachmentInfoMapper.updateById(attachmentInfo); + } + + @Override + public AttachmentInfo saveOne(AttachmentInfo attachmentInfo) { + attachmentInfoMapper.insert(attachmentInfo); + return attachmentInfoMapper.selectById(attachmentInfo.getId()); + } + + @Override + public List<AttachmentInfo> saveBatchAttachment(List<AttachmentInfo> attachmentInfoList) { + attachmentInfoMapper.saveBatch(attachmentInfoList); + return attachmentInfoList; + } + + @Override + public void updateBusinessIdBatch(List<AttachmentInfo> attachmentList) { + attachmentInfoMapper.updateBusinessIdBatch(attachmentList); + } +} + diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentServiceImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentServiceImpl.java new file mode 100644 index 0000000..eeb77a0 --- /dev/null +++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/AttachmentServiceImpl.java @@ -0,0 +1,327 @@ +package com.gk.hotwork.Service.ServiceImpl; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.servlet.ServletUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.gk.hotwork.Config.attachment.FilePathConfig; +import com.gk.hotwork.Domain.AttachmentInfo; +import com.gk.hotwork.Domain.Enum.ResultCodes; +import com.gk.hotwork.Domain.Exception.BusinessException; +import com.gk.hotwork.Domain.UserInfo; +import com.gk.hotwork.Domain.Utils.StringUtils; +import com.gk.hotwork.Mapper.AttachmentInfoMapper; +import com.gk.hotwork.Service.AttachmentInfoService; +import com.gk.hotwork.Service.AttachmentService; +import com.gk.hotwork.common.FileProjectConstants; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import static cn.hutool.core.io.FileTypeUtil.getType; + +/** + * @email 1603559716@qq.com + * @author: zf + * @date: 2023/7/24 + * @time: 13:54 + */ +@Service +public class AttachmentServiceImpl implements AttachmentService { + + @Autowired + private AttachmentInfoService attachmentInfoService; + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + /** + * 错误信息格式 + */ + private static final String ERROR_FORMATTER = "{}:{}"; + + @Resource + private FilePathConfig filePathConfig; + @Override + public AttachmentInfo findByKey(String key) { + if (StringUtils.isBlank(key)){ + throw new BusinessException("文件标识为空"); + } + return attachmentInfoService.findByKey(key); + } + @Override + public AttachmentInfo findById(Long id) { + if (id == null){ + throw new BusinessException("文件主键为空"); + } + return attachmentInfoService.findById(id); + } + @Override + public List<AttachmentInfo> findByIds(List<Long> ids) { + if (CollectionUtils.isEmpty(ids)){ + throw new BusinessException("文件主键为空"); + } + return attachmentInfoService.findByIds(ids); + } + @Override + public List<AttachmentInfo> findByBusinessId(Long businessId) { + if (businessId == null){ + throw new BusinessException("业务主键为空"); + } + return attachmentInfoService.findByBusinessId(businessId); + } + + @Override + public void delete(Long id, UserInfo userInfo) { + if (id == null){ + throw new BusinessException("文件主键为空"); + } + attachmentInfoService.delete(id,userInfo); + } + + @Override + public Object saveFileToPath(MultipartFile file, String module, int type, UserInfo user) { + //获取对应模块路径 + String path; + //获取对应模块根路径 + String dcPath; + path = filePathConfig.getModule().get(module); + dcPath = filePathConfig.getDcPath(); + + String originalFilename = file.getOriginalFilename(); + if (com.alibaba.druid.util.StringUtils.isEmpty(originalFilename)) { + logger.error(ERROR_FORMATTER,module, ResultCodes.PATH_NOT_EXISIST.getDesc()); + throw new BusinessException(ResultCodes.FILE_NOT_EXISIST); + } + if (com.alibaba.druid.util.StringUtils.isEmpty(path)) { + logger.error(ERROR_FORMATTER, module, ResultCodes.PATH_NOT_EXISIST.getDesc()); + throw new BusinessException(ResultCodes.PATH_NOT_EXISIST); + } + assert originalFilename != null; + LocalDateTime now = LocalDateTime.now(); + File newFile = null; + try { + //文件标识 UUID 如4d6873609b144945935ae84442711fd6 + String key = ""; + String suffix = ""; + if (originalFilename.contains(".mp3")) { + key = originalFilename; + suffix = ""; + } else { + key = UUID.randomUUID().toString().replace("-", ""); + //文件后缀 包含. + suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase(); + } + + path = path.replace("/", File.separator); + //文件模块路径 如 2021/base/build/0421 + String modulePath = now.getYear() + path + now.format(DateTimeFormatter.ofPattern("MMdd")); + //文件路径 如 2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀 + String newFilePath = modulePath + File.separator + key + suffix; + //文件绝对路径 如 /home/img/2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀 + String localPath = dcPath + newFilePath; + //文件访问路径 如 /upload/2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀 + String url = filePathConfig.getUrlRootPath() + newFilePath.replace(File.separator, "/"); + newFile = new File(localPath); + if (!newFile.exists() && !newFile.mkdirs()) { + logger.error(ERROR_FORMATTER, newFilePath, ResultCodes.FILE_UPLOAD_FAIL.getDesc()); + throw new BusinessException(ResultCodes.FILE_UPLOAD_FAIL); + } + file.transferTo(newFile); + //创建文件信息 + AttachmentInfo attachmentInfo = new AttachmentInfo(); + attachmentInfo.setDelFlag(0); + attachmentInfo.setFileKey(key); + attachmentInfo.setFileSuffix(suffix); + attachmentInfo.setFilePath(localPath); + attachmentInfo.setFileUrl(url); + attachmentInfo.setFileName(file.getOriginalFilename()); + attachmentInfo.setFileSize(file.getSize()); + attachmentInfo.setModule(module); + attachmentInfo.setFileType(getType(suffix)); + attachmentInfo.setCreateUid(user.getId()); + attachmentInfo.setCreateUname(user.getRealname()); + attachmentInfo.setUpdateUid(user.getId()); + attachmentInfo.setUpdateUname(user.getRealname()); + attachmentInfo.setUpdateTime(new Date()); + attachmentInfo.setCreateTime(new Date()); + AttachmentInfo attachment = attachmentInfoService.saveOne(attachmentInfo); + switch (type) { + case FileProjectConstants.ReturnType.URL: + return url; + case FileProjectConstants.ReturnType.KEY: + return key; + case FileProjectConstants.ReturnType.DETAIL: + return attachment; + default: + return null; + } + } catch (IOException e) { + if (newFile != null && newFile.exists()) { + newFile.delete(); + } + logger.error(ERROR_FORMATTER, ResultCodes.FILE_UPLOAD_FAIL, e.getMessage()); + throw new BusinessException(ResultCodes.FILE_UPLOAD_FAIL); + } + } + + @Override + public Object saveBatchFileToPath(MultipartFile[] fileList, String module, UserInfo user) { + //获取对应模块路径 + String path; + //获取对应模块根路径 + String dcPath; + path = filePathConfig.getModule().get(module); + dcPath = filePathConfig.getDcPath(); + List<AttachmentInfo> attachmentInfoList = new ArrayList<>(); + for (MultipartFile file : fileList) { + String originalFilename = file.getOriginalFilename(); + if (com.alibaba.druid.util.StringUtils.isEmpty(originalFilename)) { + logger.error(ERROR_FORMATTER,module, ResultCodes.PATH_NOT_EXISIST.getDesc()); + throw new BusinessException(ResultCodes.FILE_NOT_EXISIST); + } + if (com.alibaba.druid.util.StringUtils.isEmpty(path)) { + logger.error(ERROR_FORMATTER, module, ResultCodes.PATH_NOT_EXISIST.getDesc()); + throw new BusinessException(ResultCodes.PATH_NOT_EXISIST); + } + assert originalFilename != null; + LocalDateTime now = LocalDateTime.now(); + File newFile = null; + try { + //文件标识 UUID 如4d6873609b144945935ae84442711fd6 + String key = ""; + String suffix = ""; + if (originalFilename.contains(".mp3")) { + key = originalFilename; + suffix = ""; + } else { + key = UUID.randomUUID().toString().replace("-", ""); + //文件后缀 包含. + suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase(); + } + + path = path.replace("/", File.separator); + //文件模块路径 如 2021/base/build/0421 + String modulePath = now.getYear() + path + now.format(DateTimeFormatter.ofPattern("MMdd")); + //文件路径 如 2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀 + String newFilePath = modulePath + File.separator + key + suffix; + //文件绝对路径 如 /home/img/2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀 + String localPath = dcPath + newFilePath; + //文件访问路径 如 /upload/2021/base/build/0421/4d6873609b144945935ae84442711fd6.后缀 + String url = filePathConfig.getUrlRootPath() + newFilePath.replace(File.separator, "/"); + newFile = new File(localPath); + if (!newFile.exists() && !newFile.mkdirs()) { + logger.error(ERROR_FORMATTER, newFilePath, ResultCodes.FILE_UPLOAD_FAIL.getDesc()); + throw new BusinessException(ResultCodes.FILE_UPLOAD_FAIL); + } + //上传文件 + file.transferTo(newFile); + //创建文件信息 + AttachmentInfo attachmentInfo = new AttachmentInfo(); + attachmentInfo.setDelFlag(0); + attachmentInfo.setFileKey(key); + attachmentInfo.setFileSuffix(suffix); + attachmentInfo.setFilePath(localPath); + attachmentInfo.setFileUrl(url); + attachmentInfo.setFileName(file.getOriginalFilename()); + attachmentInfo.setFileSize(file.getSize()); + attachmentInfo.setModule(module); + attachmentInfo.setFileType(getType(suffix)); + attachmentInfo.setCreateUid(user.getId()); + attachmentInfo.setCreateUname(user.getRealname()); + attachmentInfo.setUpdateUid(user.getId()); + attachmentInfo.setUpdateUname(user.getRealname()); + attachmentInfo.setUpdateTime(new Date()); + attachmentInfo.setCreateTime(new Date()); + attachmentInfoList.add(attachmentInfo); + + } catch (IOException e) { + if (newFile != null && newFile.exists()) { + newFile.delete(); + } + logger.error(ERROR_FORMATTER, ResultCodes.FILE_UPLOAD_FAIL, e.getMessage()); + throw new BusinessException(ResultCodes.FILE_UPLOAD_FAIL); + } + } + List<AttachmentInfo> detailList = attachmentInfoService.saveBatchAttachment(attachmentInfoList); + + return detailList; + } + + @Override + public void downloadForStream(HttpServletResponse response, String key) { + AttachmentInfo byKey = findByKey(key); + File file; + try { + response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode(byKey.getFileName(), StandardCharsets.UTF_8.name())); + response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); + file = new File(byKey.getFilePath()); + if (!file.exists()) { + logger.error(ERROR_FORMATTER, key, ResultCodes.FILE_NOT_EXISIST.getDesc()); + throw new BusinessException(ResultCodes.FILE_NOT_EXISIST); + } + OutputStream outputStream = response.getOutputStream(); + FileInputStream inputStream = new FileInputStream(file); + IoUtil.copy(inputStream, outputStream); + outputStream.close(); + } catch (IOException e) { + logger.error(e.getMessage()); + throw new BusinessException(ResultCodes.FILE_DOWNLOAD_EXPERTION); + } + } + @Override + public void downloadById(HttpServletResponse response, HttpServletRequest request, Long id) { + Assert.isTrue(id == null, "文件key未知异常"); + AttachmentInfo byId = findById(id); + downloadByEntity(response, request, byId); + } + + + public void downloadByEntity(HttpServletResponse response, HttpServletRequest request, AttachmentInfo attachmentInfo) { + if (ObjectUtil.isNotNull(attachmentInfo)) { + String type = attachmentInfo.getFileType(); + if (StrUtil.isBlank(type)) { + type = "application/octet-stream"; + } + type = type + ";charset=utf-8"; + String fileName = attachmentInfo.getFileName(); + response.setContentType("multipart/form-data;charset=utf-8"); + ServletUtil.setHeader(response, "Access-Control-Expose-Headers", "Content-Disposition"); + //本地文件下载 + File file = FileUtil.file(attachmentInfo.getFilePath()); + if (!FileUtil.exist(file)) { + throw new BusinessException(attachmentInfo.getFileKey() + "文件不存在"); + } + InputStream is = null; + try { + is = IoUtil.toStream(file); + ServletUtil.write(response, is, type, fileName); + } catch (Exception e) { + throw new BusinessException(ResultCodes.FILE_DOWNLOAD_EXPERTION); + } finally { + IoUtil.close(is); + } + } else { + throw new BusinessException(ResultCodes.FILE_NOT_EXISIST); + } + } +} diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/ElementManagementImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/ElementManagementImpl.java index d36b43c..e7741f2 100644 --- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/ElementManagementImpl.java +++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/ElementManagementImpl.java @@ -193,7 +193,7 @@ List<ElementTree> returnTree = new ArrayList<>(); List<Map<String,Object>> list = elementManagementMapper.getElementTree(); //读取元素配置 for (Map<String, Object> map : list) { - if(map.get("value") == parentId){ //一级要素,MenuType2 + if(map.get("value").equals(parentId)){ //一级要素 ElementTree elementTree=new ElementTree(); elementTree.setType(Integer.valueOf(map.get("type").toString())); elementTree.setLabel(map.get("label").toString()); diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java index 311197d..ff755c1 100644 --- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java +++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java @@ -4,17 +4,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gk.hotwork.Domain.*; import com.gk.hotwork.Domain.Do.SafetySelfInspectionItemQualifiedCountDO; import com.gk.hotwork.Domain.Exception.BusinessException; -import com.gk.hotwork.Domain.InspectionExpert; -import com.gk.hotwork.Domain.InspectionHiddenDanger; -import com.gk.hotwork.Domain.SafetySelfInspection; -import com.gk.hotwork.Domain.UserInfo; import com.gk.hotwork.Domain.Utils.PageInfo; import com.gk.hotwork.Domain.Utils.StringUtils; import com.gk.hotwork.Domain.dto.resp.InspectionHiddenDangerRespDTO; import com.gk.hotwork.Mapper.InspectionExpertMapper; import com.gk.hotwork.Mapper.InspectionHiddenDangerMapper; +import com.gk.hotwork.Service.AttachmentInfoService; import com.gk.hotwork.Service.InspectionExpertService; import com.gk.hotwork.Service.InspectionHiddenDangerService; import org.apache.commons.collections4.CollectionUtils; @@ -41,6 +39,9 @@ @Autowired private InspectionHiddenDangerMapper inspectionHiddenDangerMapper; + @Autowired + private AttachmentInfoService attachmentInfoService; + /** * 修改 * @param inspectionHiddenDanger @@ -49,9 +50,26 @@ @Override public void mod(InspectionHiddenDanger inspectionHiddenDanger, UserInfo userInfo) { modrequiredVerification(inspectionHiddenDanger); + + StringBuffer stringBuffer = new StringBuffer(); + //附件 + if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + attachmentInfo.setBusinessId(inspectionHiddenDanger.getId()); + stringBuffer.append(attachmentInfo.getId().toString()).append(","); + } + stringBuffer = stringBuffer.deleteCharAt(stringBuffer.length()-1); + } + inspectionHiddenDanger.setUpdateTime(new Date()); inspectionHiddenDanger.setUpdateBy(userInfo.getRealname()); + inspectionHiddenDanger.setUrl(stringBuffer.toString()); inspectionHiddenDangerMapper.updateById(inspectionHiddenDanger); + //更新附件 + if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){ + attachmentInfoService.updateBusinessIdBatch(inspectionHiddenDanger.getAttachmentList()); + + } } /** @@ -163,7 +181,6 @@ if(danger.getStatus().equals((byte) 1)){ throw new BusinessException("已整改不可再修改"); } - if (StringUtils.isBlank(inspectionHiddenDanger.getInfo())) throw new BusinessException("请填写隐患描述"); if (inspectionHiddenDanger.getLevel() == null) throw new BusinessException("请选择隐患等级"); if (inspectionHiddenDanger.getStatus() == null) throw new BusinessException("整改状态不可为空"); } diff --git a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java index b8e40f0..eeab821 100644 --- a/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java +++ b/src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java @@ -53,9 +53,11 @@ private InspectionExpertService expertService; @Autowired private InspectionHiddenDangerService dangerService; + @Autowired + private AttachmentInfoService attachmentInfoService; /** - * @Description: 分页 + * @Description: 自查分页 */ @Override public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) { @@ -72,7 +74,7 @@ filter.put("city",user.getCity()); filter.put("area",user.getCounty()); } - filter.put("flag",0); + filter.put("flag",(byte)2); IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter); List<SafetySelfInspection> records = res.getRecords(); @@ -97,7 +99,7 @@ } /** - * @Description: 分页 + * @Description: 监管检查分页 */ @Override public IPage<SafetySelfInspection> selectSupervisePage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) { @@ -114,7 +116,7 @@ filter.put("city",user.getCity()); filter.put("area",user.getCounty()); } - filter.put("flag",1); + filter.put("flag",(byte)1); IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter); List<SafetySelfInspection> records = res.getRecords(); @@ -137,119 +139,7 @@ } return res; } - /* @Override - public IPage<SafetySelfInspection> selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user) { - Integer type = user.getType(); - //普通用户 - if (type.equals(3)) { - Long companyid = user.getCompanyid(); - filter.put("companyid",companyid); - } - //监管用户 - if (type.equals(2)) { - Long companyid = user.getCompanyid(); - //获取企业信息 - CompanyInfo companyInfo = companyService.getById(companyid); - filter.put("province",companyInfo.getProvince()); - filter.put("city",companyInfo.getCity()); - filter.put("area",companyInfo.getArea()); - } - IPage<SafetySelfInspection> res = safetySelfInspectionMapper.selectPages(page, filter); - List<SafetySelfInspection> records = res.getRecords(); - if (CollectionUtils.isNotEmpty(records)){ - DecimalFormat df = new DecimalFormat("0.00%"); - records = records.stream().map((safetySelfInspection) -> { - //总分 - Integer totalScore = 0; - //扣分 - Integer delScore =0; - - Long id = safetySelfInspection.getId(); - SafetySelfInspectionItemQualifiedCountDO countDO = safetySelfInspectionItemMapper.countQualifiedDataById(id); - safetySelfInspection.setUnqualifiedItem(countDO.getItemSum() - countDO.getQualifiedItem()); - if (countDO != null && countDO.getItemSum() != 0 && countDO.getItemSum() != null) { - BigDecimal rate = new BigDecimal(countDO.getQualifiedItem()) - .divide(new BigDecimal(countDO.getItemSum()), 4, BigDecimal.ROUND_HALF_UP); - String qualifiedRate = df.format(rate); - safetySelfInspection.setQualifiedRate(qualifiedRate); - safetySelfInspection.setItemSum(countDO.getItemSum()); - } - //计算总分以及得分 - //获取要素 - List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id); - //获取检查项 - List<SafetySelfInspectionItem> safetySelfInspectionItemList = safetySelfInspectionItemMapper.getBySafetySelfInspectionId2(id); - //循环要素 - for(SafetyInspectionElementA elementA : inspectionElementAList){ - //获取该要素的树 - List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA()); - //二级要素 - if (CollectionUtils.isNotEmpty(elementTree)) { - List<ElementTree> elementBList = elementTree.get(0).getChildren(); - for(ElementTree stree : elementBList){ - //三级要素为空 - if(CollectionUtils.isEmpty(stree.getChildren())){ - //总分累计 - totalScore += stree.getPoint(); - //无三级要素过滤出二级要素检查内容 - List<SafetySelfInspectionItem> sItemList = safetySelfInspectionItemList - .stream() - .filter(item -> item.getElementC() == null && item.getElementB().equals(stree.getValue())) - .collect(Collectors.toList()); - //判断是否有否决项 - List<SafetySelfInspectionItem> rejectList = sItemList - .stream() - .filter(item -> item.getSafetyInspectionItemResult().equals(0)) - .collect(Collectors.toList()); - - if(rejectList.size() > 0){ - delScore += stree.getPoint(); - }else { - //计算出不合格扣分 - delScore += unqualifiedItemDelScore(sItemList); - } - - } else { - List<ElementTree> elementCList = stree.getChildren(); - for(ElementTree ttree : elementCList){ - //计算总分 - totalScore += ttree.getPoint(); - //过滤该三级要素检查项目 - List<SafetySelfInspectionItem> tItemList = safetySelfInspectionItemList - .stream() - .filter(item -> item.getElementC() != null && item.getElementC().equals(ttree.getValue())) - .collect(Collectors.toList()); - //判断是否有被否决 - List<SafetySelfInspectionItem> rejectList = tItemList - .stream() - .filter(item -> item.getSafetyInspectionItemResult().equals(0)) - .collect(Collectors.toList()); - if(rejectList.size() > 0){ - delScore += ttree.getPoint(); - }else { - //计算出不合格扣分 - totalScore += unqualifiedItemDelScore(tItemList); - } - } - - } - } - - } - - - } - //得分 - Integer score = totalScore - delScore; - safetySelfInspection.setTotalScore(totalScore.toString()); - safetySelfInspection.setScore(score.toString()); - return safetySelfInspection; - }).collect(Collectors.toList()); - res.setRecords(records); - } - return res; - }*/ //累计过出不合格扣分 private Integer unqualifiedItemDelScore(List<SafetySelfInspectionItem> itemList){ int delScore = 0; @@ -283,7 +173,7 @@ Date date = new Date(); String username = user.getRealname(); param.setValidFlag(Boolean.TRUE); - param.setFlag((byte) 0); + param.setFlag((byte) 2); param.setUpdateBy(username); param.setCreateBy(username); param.setUpdateTime(date); @@ -521,25 +411,23 @@ BeanUtils.copyProperties(safetySelfInspection,safetySelfInspectionRespDTO); //获取所有检查项 List<SafetySelfInspectionItem> itemList= safetySelfInspectionItemMapper.getDetailBySafetySelfInspectionId(id,unqualified); - //获取关联要素 - List<SafetyInspectionElementA> inspectionElementAList = safetyInspectionElementAService.getBySafetySelfInspectionId(id); + //获取要素树 + List<ElementTree> elementTreeList = elementManagementService.getMenuType1Tree(); List<SafetySelfInspectionElementRespDTO> arespDTOList = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(inspectionElementAList)) { - for (SafetyInspectionElementA elementA : inspectionElementAList) { - //获取该要素的树 - List<ElementTree> elementTree = elementManagementService.getElementTreeByParentId(elementA.getElementA()); - if (CollectionUtils.isNotEmpty(elementTree)) { - //一级要素 - ElementTree otree = elementTree.get(0); + if (CollectionUtils.isNotEmpty(elementTreeList)) { + for (ElementTree elementA : elementTreeList) { + + List<SafetySelfInspectionItem> selectElementList = itemList.stream().filter(item -> item.getElementA().equals(elementA.getValue())).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(selectElementList)) { SafetySelfInspectionElementRespDTO elementARespDTO = new SafetySelfInspectionElementRespDTO(); - elementARespDTO.setElementId(otree.getValue()); - elementARespDTO.setElementName(otree.getLabel()); - elementARespDTO.setType(otree.getType()); + elementARespDTO.setElementId(elementA.getValue()); + elementARespDTO.setElementName(elementA.getLabel()); + elementARespDTO.setType(elementA.getType()); List<SafetySelfInspectionElementRespDTO> brespDTOList = new ArrayList<>(); //二级要素 - List<ElementTree> elementBList = otree.getChildren(); + List<ElementTree> elementBList = elementA.getChildren(); if(CollectionUtils.isNotEmpty(elementBList)){ for (ElementTree stree : elementBList) { SafetySelfInspectionElementRespDTO elementBRespDTO = new SafetySelfInspectionElementRespDTO(); @@ -669,6 +557,7 @@ SafetySelfInspectionItem safetySelfInspectionItem = safetySelfInspectionItemMapper.getDetailById(id); List<SafetySelfInspectionItemDeduction> selfDeductionList = safetySelfInspectionItemDeductionMapper.getBySafetySelfInspectionItemId(safetySelfInspectionItem.getId()); List<InspectionHiddenDanger> inspectionHiddenDangerList = dangerService.getBySafetySelfInspectionItemId(id); + List<AttachmentInfo> byBusinessId = attachmentInfoService.findByBusinessId(id); if (CollectionUtils.isNotEmpty(selfDeductionList)){ safetySelfInspectionItem.setSelfDeductionList(selfDeductionList); @@ -689,6 +578,20 @@ safetySelfInspectionItem.setSelfDeductionList(new ArrayList<>()); } } + for (InspectionHiddenDanger inspectionHiddenDanger : inspectionHiddenDangerList) { + if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){ + List<Long> attachmentIds = new ArrayList<>(); + String[] split = inspectionHiddenDanger.getUrl().split(","); + for (String s : split) { + attachmentIds.add(Long.valueOf(s)); + } + + List<AttachmentInfo> dangerAttachList = attachmentInfoService.findByIds(attachmentIds); + inspectionHiddenDanger.setAttachmentList(dangerAttachList); + } + + } + safetySelfInspectionItem.setAttachmentList(byBusinessId); safetySelfInspectionItem.setDangerList(inspectionHiddenDangerList); return safetySelfInspectionItem; } @@ -705,6 +608,15 @@ param.setUpdateTime(date); param.setUpdateBy(username); safetySelfInspectionItemMapper.updateById(param); + //附件 + List<AttachmentInfo> attachmentInfoList = new ArrayList<>(); + if(CollectionUtils.isNotEmpty(param.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : param.getAttachmentList()) { + attachmentInfo.setBusinessId(param.getId()); + attachmentInfoList.add(attachmentInfo); + } + } + if (param.getSafetyInspectionItemResult()==0 || param.getSafetyInspectionItemResult() == 2){ //否决 合格--删除扣分记录 safetySelfInspectionItemDeductionMapper.delBySafetySelfInspectionItemId(param.getId(),username,date); @@ -747,6 +659,15 @@ dangerService.delByIds(idList); } for (InspectionHiddenDanger inspectionHiddenDanger : param.getDangerList()) { + StringBuffer stringBuffer = new StringBuffer(); + //附件 + if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + stringBuffer.append(attachmentInfo.getId().toString()).append(","); + } + stringBuffer = stringBuffer.deleteCharAt(stringBuffer.length()-1); + } + if(inspectionHiddenDanger.getId() == null){ inspectionHiddenDanger.setCreateBy(user.getRealname()); inspectionHiddenDanger.setCreateTime(new Date()); @@ -756,14 +677,35 @@ inspectionHiddenDanger.setValidFlag(true); inspectionHiddenDanger.setSelfInspectionId(param.getSafetySelfInspectionId()); inspectionHiddenDanger.setSelfInspectionItemId(param.getId()); + inspectionHiddenDanger.setUrl(stringBuffer.toString()); dangerService.save(inspectionHiddenDanger); + //附件 + if(StringUtils.isNotBlank(inspectionHiddenDanger.getUrl())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + attachmentInfo.setBusinessId(inspectionHiddenDanger.getId()); + attachmentInfoList.add(attachmentInfo); + } + } }else { inspectionHiddenDanger.setUpdateBy(user.getRealname()); inspectionHiddenDanger.setUpdateTime(new Date()); + inspectionHiddenDanger.setUrl(stringBuffer.toString()); dangerService.updateById(inspectionHiddenDanger); + //附件 + if(CollectionUtils.isNotEmpty(inspectionHiddenDanger.getAttachmentList())){ + for (AttachmentInfo attachmentInfo : inspectionHiddenDanger.getAttachmentList()) { + attachmentInfo.setBusinessId(inspectionHiddenDanger.getId()); + attachmentInfoList.add(attachmentInfo); + } + } } } } + + } + //附件信息更新 + if(CollectionUtils.isNotEmpty(attachmentInfoList)){ + attachmentInfoService.updateBusinessIdBatch(attachmentInfoList); } } @@ -844,13 +786,7 @@ if (param.getCheckedCompanyId() == null){ throw new BusinessException("请选择被检查公司"); } - if(CollectionUtils.isEmpty(param.getElementAList())){ - throw new BusinessException("请选择A检查要素"); - } - for(SafetyInspectionElementA elementA : param.getElementAList()){ - if(elementA.getElementA() == null){ - throw new BusinessException("请选择A检查要素"); - } - } } + + } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index e815830..0d5847e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -35,63 +35,63 @@ -host: http://localhost:8006 +host: http://localhost:8016 filePath: d:/uploads/ -fileurl: http://localhost:8006/upload/ +fileurl: http://localhost:8016/upload/ socketport: 504 sqlPath: /home/dbback/ -sqlurl: http://nmy.sinanoaq.cn:8006/dbback/ +sqlurl: http://nmy.sinanoaq.cn:8016/dbback/ enterprisePath: /home/uploads/enterprise/ -enterpriseUrl: http://nmy.sinanoaq.cn:8006/upload/enterprise/ +enterpriseUrl: http://nmy.sinanoaq.cn:8016/upload/enterprise/ enterprise: enterprise/ transportCertificatePath: /home/uploads/transportCertificate/ -transportCertificateUrl: http://nmy.sinanoaq.cn:8006/upload/transportCertificate/ +transportCertificateUrl: http://nmy.sinanoaq.cn:8016/upload/transportCertificate/ transportCertificate: transportCertificate/ hiddenDangerPath: /home/uploads/hiddenDanger/ -hiddenDangerUrl: http://nmy.sinanoaq.cn:8006/upload/hiddenDanger/ +hiddenDangerUrl: http://nmy.sinanoaq.cn:8016/upload/hiddenDanger/ hiddenDanger: hiddenDanger/ standardPath: /home/uploads/standard/ -standardUrl: http://nmy.sinanoaq.cn:8006/upload/standard/ +standardUrl: http://nmy.sinanoaq.cn:8016/upload/standard/ standard: standard/ contractPath: /home/uploads/contract/ -contractUrl: http://nmy.sinanoaq.cn:8006/upload/contract/ +contractUrl: http://nmy.sinanoaq.cn:8016/upload/contract/ contract: contract/ patrolPath: /home/uploads/patrol/ -patrolUrl: http://nmy.sinanoaq.cn:8006/upload/patrol/ +patrolUrl: http://nmy.sinanoaq.cn:8016/upload/patrol/ appPath: /home/uploads/app/ app: app/ -appUrl: http://nmy.sinanoaq.cn:8006/upload/app/ +appUrl: http://nmy.sinanoaq.cn:8016/upload/app/ productPath: /home/uploads/product/ -productUrl: http://nmy.sinanoaq.cn:8006/upload/product/ +productUrl: http://nmy.sinanoaq.cn:8016/upload/product/ assessApplyPath: /home/uploads/assessApply/ -assessApplytUrl: http://nmy.sinanoaq.cn:8006/upload/assessApply/ +assessApplytUrl: http://nmy.sinanoaq.cn:8016/upload/assessApply/ assessApply: assessApply/ workCertPath: /home/uploads/workCert/ -workCertUrl: http://nmy.sinanoaq.cn:8006/upload/workCert/ +workCertUrl: http://nmy.sinanoaq.cn:8016/upload/workCert/ workCert: workCert/ -nanowebUrl: http://nmy.sinanoaq.cn:8006/nanoweb/api/register +nanowebUrl: http://nmy.sinanoaq.cn:8016/nanoweb/api/register nanowebEnable: true taskPath: d:/uploads/task/ taskPathPrefix: d:/uploads/ -taskUrl: http://localhost:8006/upload/task/ +taskUrl: http://localhost:8016/upload/task/ task: task/ emergencyPlanPath: /home/uploads/emergencyPlan/ -emergencyPlanUrl: http://localhost:8006/upload/emergencyPlan/ +emergencyPlanUrl: http://localhost:8016/upload/emergencyPlan/ emergencyPlan : emergencyPlan/ safecheckExecImagePath : /home/uploads/safecheck/ @@ -115,3 +115,18 @@ name: ali key: url: +#windous测试 +file: + path: + #基础路径 + dcPath: E:\file\gkhy\test\ + urlRootPath: /uploadfile/ + module: + #用户模块 + accountPath: /account/user/ + #排查模块 + checkPath: /check/ + +# swagger生产环境中禁止显示 +swagger: + show: false \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 31290d4..1879bb0 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -17,7 +17,7 @@ #redis redis: - database: 0 + database: 14 host: 127.0.0.1 port: 6379 password: akj78avauba789a @@ -33,63 +33,63 @@ # enabled: true enabled: false -host: http://localhost:8006/zhongtai +host: http://localhost:8016 filePath: /home/uploads/ -fileurl: http://nmy.sinanoaq.cn:8006/upload/ +fileurl: http://nmy.sinanoaq.cn:8016/upload/ socketport: 504 sqlPath: /home/dbback/ -sqlurl: http://nmy.sinanoaq.cn:8006/dbback/ +sqlurl: http://nmy.sinanoaq.cn:8016/dbback/ enterprisePath: /home/uploads/enterprise/ -enterpriseUrl: http://nmy.sinanoaq.cn:8006/upload/enterprise/ +enterpriseUrl: http://nmy.sinanoaq.cn:8016/upload/enterprise/ enterprise: enterprise/ transportCertificatePath: /home/uploads/transportCertificate/ -transportCertificateUrl: http://nmy.sinanoaq.cn:8006/upload/transportCertificate/ +transportCertificateUrl: http://nmy.sinanoaq.cn:8016/upload/transportCertificate/ transportCertificate: transportCertificate/ hiddenDangerPath: /home/uploads/hiddenDanger/ -hiddenDangerUrl: http://nmy.sinanoaq.cn:8006/upload/hiddenDanger/ +hiddenDangerUrl: http://nmy.sinanoaq.cn:8016/upload/hiddenDanger/ hiddenDanger: hiddenDanger/ standardPath: /home/uploads/standard/ -standardUrl: http://nmy.sinanoaq.cn:8006/upload/standard/ +standardUrl: http://nmy.sinanoaq.cn:8016/upload/standard/ standard: standard/ contractPath: /home/uploads/contract/ -contractUrl: http://nmy.sinanoaq.cn:8006/upload/contract/ +contractUrl: http://nmy.sinanoaq.cn:8016/upload/contract/ contract: contract/ patrolPath: /home/uploads/patrol/ -patrolUrl: http://nmy.sinanoaq.cn:8006/upload/patrol/ +patrolUrl: http://nmy.sinanoaq.cn:8016/upload/patrol/ appPath: /home/uploads/app/ app: app/ -appUrl: http://nmy.sinanoaq.cn:8006/upload/app/ +appUrl: http://nmy.sinanoaq.cn:8016/upload/app/ productPath: /home/uploads/product/ -productUrl: http://nmy.sinanoaq.cn:8006/upload/product/ +productUrl: http://nmy.sinanoaq.cn:8016/upload/product/ assessApplyPath: /home/uploads/assessApply/ -assessApplytUrl: http://nmy.sinanoaq.cn:8006/upload/assessApply/ +assessApplytUrl: http://nmy.sinanoaq.cn:8016/upload/assessApply/ assessApply: assessApply/ workCertPath: /home/uploads/workCert/ -workCertUrl: http://nmy.sinanoaq.cn:8006/upload/workCert/ +workCertUrl: http://nmy.sinanoaq.cn:8016/upload/workCert/ workCert: workCert/ -nanowebUrl: http://nmy.sinanoaq.cn:8006/nanoweb/api/register +nanowebUrl: http://nmy.sinanoaq.cn:8016/nanoweb/api/register nanowebEnable: true taskPath: /home/uploads/task/ taskPathPrefix: /home/uploads/ -taskUrl: http://nmy.sinanoaq.cn:8006/upload/task/ +taskUrl: http://nmy.sinanoaq.cn:8016/upload/task/ task: task/ emergencyPlanPath: /home/uploads/emergencyPlan/ -emergencyPlanUrl: http://localhost:8006/upload/emergencyPlan/ +emergencyPlanUrl: http://localhost:8016/upload/emergencyPlan/ emergencyPlan : emergencyPlan/ safecheckExecImagePath : /home/uploads/safecheck/ @@ -119,3 +119,16 @@ key: url: +file: + path: + #基础路径 + dcPath: /home/upload/hazardInvestigation/ + urlRootPath: /uploadfile/ + module: + #用户模块 + accountPath: /account/user/ + #排查模块 + checkPath: /check/ +# swagger生产环境中禁止显示 +swagger: + show: false diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 428a5d4..b70fc9d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,12 +1,10 @@ -# swagger生产环境中禁止显示 -swagger: - show: false + # mysql 多数据源 spring: application: # 环境 dev|prod|online profiles: - active: prod + active: dev # active: prod # active: test # active: online -- Gitblit v1.9.2