| | |
| | | package com.ruoyi.manage.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.deepoove.poi.config.ConfigureBuilder; |
| | | import com.deepoove.poi.data.Pictures; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.framework.exception.ErrorException; |
| | | import com.ruoyi.manage.dto.ClientSatisfactionDto; |
| | | import com.ruoyi.manage.mapper.ClientSatisfactionAnalyseFileMapper; |
| | | import com.ruoyi.manage.mapper.ClientSatisfactionAttachmentMapper; |
| | | import com.ruoyi.manage.mapper.ClientSatisfactionMapper; |
| | | import com.ruoyi.manage.pojo.ClientSatisfaction; |
| | | import com.ruoyi.manage.pojo.ClientSatisfactionAnalyseFile; |
| | | import com.ruoyi.manage.pojo.ClientSatisfactionAttachment; |
| | | import com.ruoyi.manage.service.ClientSatisfactionService; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private ClientSatisfactionAnalyseFileMapper clientSatisfactionAnalyseFileMapper; |
| | | |
| | | @Resource |
| | | private ClientSatisfactionAttachmentMapper clientSatisfactionAttachmentMapper; |
| | | |
| | | @Resource |
| | | private UserMapper userMapper; |
| | |
| | | clientSatisfaction.setConfirmStatus(1); |
| | | baseMapper.updateById(clientSatisfaction); |
| | | } |
| | | |
| | | /** |
| | | * 查询满意度附件 |
| | | * |
| | | * @param clientSatisfactionId 满意度记录id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<ClientSatisfactionAttachment> selectAttachments(Integer clientSatisfactionId) { |
| | | return clientSatisfactionAttachmentMapper.selectList(new QueryWrapper<ClientSatisfactionAttachment>().lambda() |
| | | .eq(ClientSatisfactionAttachment::getClientSatisfactionId, clientSatisfactionId) |
| | | .orderByAsc(ClientSatisfactionAttachment::getSort, ClientSatisfactionAttachment::getId)); |
| | | } |
| | | |
| | | /** |
| | | * 上传满意度附件 |
| | | * |
| | | * @param clientSatisfactionId 满意度记录id |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ClientSatisfactionAttachment uploadAttachment(Integer clientSatisfactionId, MultipartFile file) { |
| | | if (baseMapper.selectById(clientSatisfactionId) == null) { |
| | | throw new BaseException("客户满意度调查不存在"); |
| | | } |
| | | if (file == null || file.isEmpty()) { |
| | | throw new BaseException("附件不能为空"); |
| | | } |
| | | // 系统全局上传上限为200MB,这里提前给出友好提示 |
| | | if (file.getSize() > 200L * 1024 * 1024) { |
| | | throw new BaseException("附件不能超过200MB"); |
| | | } |
| | | String originalName = file.getOriginalFilename(); |
| | | if (originalName == null || originalName.trim().isEmpty()) { |
| | | originalName = "未命名文件"; |
| | | } |
| | | // 个别浏览器可能带上路径前缀,只保留文件名本身 |
| | | originalName = originalName.replaceAll(".*[/\\\\]", ""); |
| | | try { |
| | | // 图片放图片目录(/img 静态路径),其余任意格式放 word 目录(/word 静态路径) |
| | | boolean image = originalName.matches("(?i).+\\.(jpg|jpeg|png|gif)$"); |
| | | File directory = new File(image ? imgUrl : wordUrl); |
| | | if (!directory.exists()) { |
| | | directory.mkdirs(); |
| | | } |
| | | String fileUrl = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmssSSS")) + "-" + originalName; |
| | | file.transferTo(new File(directory, fileUrl)); |
| | | ClientSatisfactionAttachment attachment = new ClientSatisfactionAttachment(); |
| | | attachment.setClientSatisfactionId(clientSatisfactionId); |
| | | attachment.setFileName(originalName); |
| | | attachment.setFileUrl(fileUrl); |
| | | attachment.setSort(selectAttachments(clientSatisfactionId).size()); |
| | | clientSatisfactionAttachmentMapper.insert(attachment); |
| | | return attachment; |
| | | } catch (IOException e) { |
| | | throw new BaseException("附件上传失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除满意度附件 |
| | | * |
| | | * @param id 附件id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean deleteAttachment(Long id) { |
| | | return clientSatisfactionAttachmentMapper.deleteById(id) > 0; |
| | | } |
| | | } |
| | | |