Commit 78717895 authored by zhangwanglin's avatar zhangwanglin

补卡列表附件下载

parent c5a0d709
package com.hungraim.ltc.account.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Data
@ConfigurationProperties(prefix = "auditing.role")
public class AuditingRoleConfig {
private List<String> roleId;
}
...@@ -167,6 +167,8 @@ public class AccountController { ...@@ -167,6 +167,8 @@ public class AccountController {
if(srvOrganId != 0) { if(srvOrganId != 0) {
srvTaskReqVO.setSrvOrganId(srvOrganId); srvTaskReqVO.setSrvOrganId(srvOrganId);
} }
Integer userId = TokenParsingUtil.TokenParsing(token, "userId");
srvTaskReqVO.setUserId(userId);
return Result.success(accountService.getSrvTaskCardList(srvTaskReqVO)); return Result.success(accountService.getSrvTaskCardList(srvTaskReqVO));
} }
......
...@@ -7,6 +7,7 @@ import com.hungraim.ltc.pojo.vo.account.SrvTaskReqVO; ...@@ -7,6 +7,7 @@ import com.hungraim.ltc.pojo.vo.account.SrvTaskReqVO;
import com.hungraim.ltc.pojo.vo.account.SrvTaskRespVO; import com.hungraim.ltc.pojo.vo.account.SrvTaskRespVO;
import com.hungraim.ltc.pojo.vo.disable.PlaceOtherVO; import com.hungraim.ltc.pojo.vo.disable.PlaceOtherVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -35,4 +36,6 @@ public interface ChSrvTaskDetailMapper extends BaseMapper<ChSrvTaskDetail> { ...@@ -35,4 +36,6 @@ public interface ChSrvTaskDetailMapper extends BaseMapper<ChSrvTaskDetail> {
List<PlaceOtherVO> placeOtherTaskQuery(); List<PlaceOtherVO> placeOtherTaskQuery();
int getRoleByUserId(@Param("userId") Integer userId, @Param("roleIds") List<String> roleIds );
} }
\ No newline at end of file
...@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSON; ...@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hungraim.ltc.account.config.AuditingRoleConfig;
import com.hungraim.ltc.account.dao.*; import com.hungraim.ltc.account.dao.*;
import com.hungraim.ltc.account.service.AccountService; import com.hungraim.ltc.account.service.AccountService;
import com.hungraim.ltc.account.service.BaseAccountService; import com.hungraim.ltc.account.service.BaseAccountService;
...@@ -28,6 +29,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -28,6 +29,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -58,6 +60,8 @@ public class AccountServiceImpl extends ServiceImpl<ChDisabAccountsMapper, ChDis ...@@ -58,6 +60,8 @@ public class AccountServiceImpl extends ServiceImpl<ChDisabAccountsMapper, ChDis
private final ChSrvPlanMapper chSrvPlanMapper; private final ChSrvPlanMapper chSrvPlanMapper;
@Autowired
private AuditingRoleConfig auditingRoleConfig;
private final ChSrvTaskDetailMapper chSrvTaskDetailMapper; private final ChSrvTaskDetailMapper chSrvTaskDetailMapper;
private final ChSrvTaskFinishItemMapper chSrvTaskFinishItemMapper;; private final ChSrvTaskFinishItemMapper chSrvTaskFinishItemMapper;;
...@@ -720,6 +724,17 @@ public class AccountServiceImpl extends ServiceImpl<ChDisabAccountsMapper, ChDis ...@@ -720,6 +724,17 @@ public class AccountServiceImpl extends ServiceImpl<ChDisabAccountsMapper, ChDis
@Override @Override
public Page<SrvTaskRespVO> getSrvTaskCardList(SrvTaskReqVO srvTaskReqVO){ public Page<SrvTaskRespVO> getSrvTaskCardList(SrvTaskReqVO srvTaskReqVO){
Page<SrvTaskRespVO> srvTaskList = taskDetailMapper.getSrvTaskCardList(new Page<>(srvTaskReqVO.getPageNum(), srvTaskReqVO.getPageSize()), srvTaskReqVO); Page<SrvTaskRespVO> srvTaskList = taskDetailMapper.getSrvTaskCardList(new Page<>(srvTaskReqVO.getPageNum(), srvTaskReqVO.getPageSize()), srvTaskReqVO);
List<String> roleIds = auditingRoleConfig.getRoleId();
log.info("==========getSrvTaskCardList====roleIds:{}",roleIds);
// 有审核的权限就配置,根据配置的审核角色查询是否满足条件,如果查到返回给前端1 可以审核,为2不展示审核按钮
int count = taskDetailMapper.getRoleByUserId(srvTaskReqVO.getUserId(), roleIds);
List<SrvTaskRespVO> records = srvTaskList.getRecords();
for (SrvTaskRespVO record : records) {
if(count>0){
record.setAuditFlag(true);
}
}
return srvTaskList; return srvTaskList;
} }
......
...@@ -181,6 +181,14 @@ ...@@ -181,6 +181,14 @@
</update> </update>
<select id="getRoleByUserId" resultType="java.lang.Integer">
select count(*) from LTC_USER_ROLE r where r.user_id = #{userId}
<if test="roleIds != null">
and r.role_id in
<foreach collection="roleIds" item="roleIds" open="(" close=")" separator=",">
#{roleIds}
</foreach>
</if>
</select>
</mapper> </mapper>
...@@ -22,4 +22,6 @@ public class SrvTaskReqVO extends BaseReq { ...@@ -22,4 +22,6 @@ public class SrvTaskReqVO extends BaseReq {
private String srvOrganName; private String srvOrganName;
private Long srvOrganId; private Long srvOrganId;
private Integer userId;
} }
...@@ -50,5 +50,7 @@ public class SrvTaskRespVO { ...@@ -50,5 +50,7 @@ public class SrvTaskRespVO {
private String auditRemark; private String auditRemark;
private boolean auditFlag;
} }
\ No newline at end of file
...@@ -2,11 +2,14 @@ package com.hungraim.ltc.util; ...@@ -2,11 +2,14 @@ package com.hungraim.ltc.util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.IOUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.*;
import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
...@@ -80,4 +83,97 @@ public class FileUtils { ...@@ -80,4 +83,97 @@ public class FileUtils {
} }
} }
public static void downloadPathFile(String path,String fileName, HttpServletRequest request, HttpServletResponse response) {
//设置文件路径
File file = new File(path);
//判断文件是否存在
if (file.exists()) {
FileInputStream fis = null;
OutputStream os = null;
try {
// 取得输出流
os = response.getOutputStream();
// 清空输出流
response.reset();
//response.setContentType("application/force-download");// 设置强制下载不打开
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));
fis = new FileInputStream(file);
IOUtils.copy(fis, os);
response.getOutputStream().flush();
/* bis = new BufferedInputStream(fis);
OutputStream os = response.getOutputStream();
int i = bis.read(buffer);
while (i != -1) {
os.write(buffer, 0, i);
i = bis.read(buffer);
}*/
log.info("=========下载成功:{}",fileName);
} catch (Exception e) {
log.error("=====error1:{}",e);
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
// logger.error(ExceptionUtils.getFullStackTrace(e));
}
try {
if (os != null) {
os.close();
}
} catch (IOException e) {
//logger.error(ExceptionUtils.getFullStackTrace(e));
}
}
}
}
/**
* 文件下载
*
* @param fileName
* @return
* @author 小辰哥哥
*/
public static byte[] downloadFile(String path,String fileName, HttpServletResponse response) {
// 关联文件
File file = new File(path);
byte[] fileBytes = null;
FileInputStream fileInputStream = null;
ByteArrayOutputStream bos = null;
//设置响应头类型,这里可以根据文件类型设置,text/plain、application/vnd.ms-excel等
response.setHeader("content-type", "text/plain;charset=UTF-8");
response.setContentType("application/octet-stream;charset=UTF-8");
//如果不设置响应头大小,可能报错:“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”
response.addHeader("Content-Length", String.valueOf(file.length()));
try {
response.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8"));
fileInputStream = new FileInputStream(file);
bos = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int len ;
while ((len = fileInputStream.read(bytes)) != -1) {
bos.write(bytes, 0, len);
}
fileBytes = bos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fileInputStream.close();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return fileBytes;
}
} }
...@@ -12,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -12,7 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
import java.util.Objects;
@RestController @RestController
@RequestMapping("/api.system/resource") @RequestMapping("/api.system/resource")
...@@ -88,4 +91,17 @@ public class FileUploadController { ...@@ -88,4 +91,17 @@ public class FileUploadController {
List<ChFndAttach> chFndAttaches = attachService.selectAttachs(ctrlId, attachType); List<ChFndAttach> chFndAttaches = attachService.selectAttachs(ctrlId, attachType);
return Result.success(chFndAttaches); return Result.success(chFndAttaches);
} }
@GetMapping ("/download")
public void download(Long attachId, HttpServletRequest request, HttpServletResponse response) {
ChFndAttach chFndAttach = attachService.selectById(attachId);
if(Objects.nonNull(chFndAttach)){
String filePath = chFndAttach.getFilePath();
String fileName = chFndAttach.getFileName();
FileUtils.downloadPathFile(filePath, fileName,request,response);
}
}
} }
...@@ -35,4 +35,6 @@ public interface AttachService { ...@@ -35,4 +35,6 @@ public interface AttachService {
* @return 返回对应的数据列表 * @return 返回对应的数据列表
*/ */
List<ChFndAttach> selectAttachs(Long ctrlId, Short attachType); List<ChFndAttach> selectAttachs(Long ctrlId, Short attachType);
ChFndAttach selectById(Long attachId);
} }
...@@ -11,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -11,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
@Service @Service
public class AttachServiceImpl implements AttachService { public class AttachServiceImpl implements AttachService {
...@@ -103,4 +104,11 @@ public class AttachServiceImpl implements AttachService { ...@@ -103,4 +104,11 @@ public class AttachServiceImpl implements AttachService {
public List<ChFndAttach> selectAttachs(Long ctrlId, Short attachType) { public List<ChFndAttach> selectAttachs(Long ctrlId, Short attachType) {
return this.getChFndAttaches(ctrlId, attachType); return this.getChFndAttaches(ctrlId, attachType);
} }
@Override
public ChFndAttach selectById(Long attachId){
ChFndAttach chFndAttach = chFndAttachMapper.selectById(attachId);
return chFndAttach;
}
} }
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