|
|
@@ -11,6 +11,7 @@ import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.bean.BeanValidators;
|
|
|
+import com.ruoyi.common.utils.file.FileUtils;
|
|
|
import com.ruoyi.project.bo.MyMonthDays;
|
|
|
import com.ruoyi.project.bo.ProjectStaffRecordInput;
|
|
|
import com.ruoyi.project.bo.ProjectStaffRecordOut;
|
|
|
@@ -25,18 +26,25 @@ import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
import com.ruoyi.system.service.impl.SysConfigServiceImpl;
|
|
|
import com.ruoyi.weChat.service.WeChatService;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Validator;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.time.Duration;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
@Service
|
|
|
public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService {
|
|
|
@@ -176,6 +184,63 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
|
|
|
return AjaxResult.success(projectStaffRecordLogMapper.selectByPsrId(in.getPsrId()));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void downloadFiles(String ids, HttpServletResponse response) {
|
|
|
+ String downloadFileName = "";
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ ZipOutputStream zip = new ZipOutputStream(outputStream);
|
|
|
+ downloadFileName="项目打卡数据_"+DateUtils.dateTimeNow()+".zip";
|
|
|
+ String[] idList = ids.split(",");
|
|
|
+ for (String id : idList) {
|
|
|
+ ProjectStaffRecord psr = projectStaffRecordMapper.selectByPrimaryKey(Long.valueOf(id));
|
|
|
+ if (psr != null) {
|
|
|
+ ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(psr.getPid());
|
|
|
+ String annexUrl = psr.getAnnexUrl();
|
|
|
+ String[] split = annexUrl.split(",");
|
|
|
+ if (split.length>0){
|
|
|
+ String recordTimes=DateUtils.parseDateToStr(DateUtils.YYYYMMDD,psr.getRecordTime());
|
|
|
+ int index =0;
|
|
|
+ for (String s : split) {
|
|
|
+ if (StringUtils.isNotEmpty(s)){
|
|
|
+ index++;
|
|
|
+ String url=s.replace("/profile/upload","");
|
|
|
+ url=RuoYiConfig.getUploadPath()+url;
|
|
|
+ System.out.println(url);
|
|
|
+ File file = new File(url);
|
|
|
+ if (file.exists()){
|
|
|
+ try {
|
|
|
+ String suffix = s.substring(s.indexOf("."), s.length());
|
|
|
+ String fileName=projectTask.getName()+"_"+psr.getName()+"_"+recordTimes+"_"+index+suffix;
|
|
|
+ ZipEntry e = new ZipEntry(fileName);
|
|
|
+ zip.putNextEntry(e);
|
|
|
+ IOUtils.write(FileUtils.getBytes(file),zip);
|
|
|
+ zip.closeEntry();
|
|
|
+ zip.flush();
|
|
|
+ } catch (IOException e){
|
|
|
+ throw new ServiceException("文件写入压缩失败:"+e.getLocalizedMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ IOUtils.closeQuietly(zip);
|
|
|
+ try {
|
|
|
+ byte[] data = outputStream.toByteArray();
|
|
|
+ response.reset();
|
|
|
+ response.addHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + java.net.URLEncoder.encode(downloadFileName, "utf-8").replaceAll("\\+", "%20") + "\"");
|
|
|
+ response.addHeader("Content-Length", "" + data.length);
|
|
|
+ response.setContentType("application/octet-stream; charset=UTF-8");
|
|
|
+ IOUtils.write(data,response.getOutputStream());
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
* @param date 当前时间
|