This commit is contained in:
Paidax
2024-08-26 11:51:06 +08:00
parent aa444a21ae
commit cdd77b303e
8 changed files with 364 additions and 73 deletions
@@ -8,16 +8,21 @@ import com.deepoove.poi.policy.HackLoopTableRenderPolicy;
import io.v.nutz.annontation.ViReturn;
import io.v.nutz.base.utils.Vi;
import io.v.nutz.modules.models.PageForm;
import io.v.nutz.sys.models.Sys_file;
import io.v.nutz.util.ShiroUtil;
import io.v.nutz.wakershome.model.review.CommentBz;
import io.v.nutz.wakershome.model.review.CommentNr;
import io.v.nutz.wakershome.model.review.CommentPeo;
import io.v.nutz.wakershome.model.review.CommentZb;
import io.v.nutz.wakershome.service.review.CommentPeoService;
import io.v.nutz.wakershome.service.review.CommentStatisticsService;
import io.v.nutz.wakershome.service.review.CommentZbService;
import io.v.nutz.web.commons.base.Globals;
import io.v.nutz.web.commons.utils.FileUtil;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.ddr.poi.html.HtmlRenderPolicy;
import org.nutz.boot.starter.ftp.FtpService;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
@@ -26,17 +31,22 @@ import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.lang.random.R;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @ClassName statisticsController
@@ -49,12 +59,18 @@ import java.util.stream.Collectors;
@IocBean
public class StatisticsZpController {
@Inject
private FtpService ftpService;
@Inject
private CommentZbService commentZbService;
@Inject
private CommentPeoService commentPeoService;
@Inject
private CommentStatisticsService commentStatisticsService;
@At("")
@Ok("beetl:/platform/wakeshome/review/statistics.html")
@@ -159,57 +175,207 @@ public class StatisticsZpController {
}
/**
* 分工会自评导出(单个)
*
* @param zbId
* @param unionId
* @param response
*/
@At
@Ok("void")
public void doDownLoad(String zbId, String unionId, HttpServletResponse response) {
@RequiresPermissions("wakeshome.review.statistics")
public void doDownLoadSingleByUnionId(String zbId, String unionId, HttpServletResponse response) {
CommentPeo peo = commentZbService.dao().fetch(CommentPeo.class, Cnd.where("unionId", "=", unionId).and("zbId", "=", zbId));
NutMap map = commentPeoService.getBzById(peo.getId());
//最后的导出表
NutMap resultMap = NutMap.NEW();
List<NutMap> list = new ArrayList<>();
resultMap.put("schoolName", Globals.schoolName);
CommentZb khzb = map.getAs("zbxx", CommentZb.class);
List<CommentNr> nrs = khzb.getNrs();
nrs.forEach(v -> {
NutMap nutMap = NutMap.NEW();
List<CommentBz> bzs = v.getBzs();
String nr = bzs.stream().sorted(Comparator.comparing(CommentBz::getContentNumber)).map(item -> {
return item.getContentNumber() + "." + item.getInspection() + "(" + item.getScore() + "分)";
}).collect(Collectors.joining("<br/>"));
int jf = bzs.stream().mapToInt(item -> Integer.parseInt(item.getScore())).sum();
int zpf = bzs.stream().mapToInt(item -> Integer.parseInt(item.getResultScore())).sum();
CommentBz commentBz = bzs.stream().findFirst().orElse(new CommentBz());
nutMap.put("xh", Convert.numberToChinese(Double.parseDouble(v.getContentNumber()), false));
nutMap.put("zb", v.getContent());
nutMap.put("nr", nr);
nutMap.put("jf", jf);
nutMap.put("zpf", zpf);
nutMap.put("bz", commentBz.getOptions());
list.add(nutMap);
});
HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
htmlRenderPolicy.getConfig().setShowDefaultTableBorderInTableCell(true);
Configure config = Configure.newBuilder().bind("list", policy)
.bind("list.nr", htmlRenderPolicy).build();
resultMap.put("list", list);
String fileName = Globals.schoolName + "“模范教工小家”评分标准";
String fileName = peo.getUnionName() + "(" + peo.getUserName() + ")“模范教工小家”评议结果";
try {
response.addHeader("Content-Type", "application/octet-stream");
response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("UTF-8"), "ISO-8859-1") + "\".docx");
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("docTemplate/WakesHome.docx");
XWPFTemplate.compile(inputStream, config).render(resultMap, response.getOutputStream());
inputStream.close();
commentStatisticsService.exportWord(peo, response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 分工会下所有测评结果导出(多个)压缩包
* @param zbId
* @param unionId
* @param response
*/
@At
@Ok("void")
@RequiresPermissions("wakeshome.review.statistics")
public void doDownLoadZipByUnionId(String zbId, String unionId, HttpServletResponse response) {
try {
List<CommentPeo> peoList = commentPeoService.dao().query(CommentPeo.class, Cnd.where("unionId", "=", unionId).and("zbId", "=", zbId));
CommentPeo commentPeo = peoList.stream().findFirst().orElse(new CommentPeo());
String zipName = commentPeo.getUnionName() + "评议结果.zip";
response.setContentType("application/octet-stream");
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(zipName, "UTF-8"));
ZipOutputStream zipOutputStream = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
for (CommentPeo peo : peoList) {
String fileName = peo.getUnionName() + "(" + peo.getUserName() + ")“模范教工小家”评议结果.docx";
zipOutputStream.putNextEntry(new ZipEntry(fileName));
commentStatisticsService.exportWord(peo, zipOutputStream);
zipOutputStream.closeEntry();
response.flushBuffer();
}
zipOutputStream.flush();
zipOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 分工会导出附件
* @param zbId
* @param unionId
* @param response
*/
@At
@Ok("void")
@RequiresPermissions("wakeshome.review.statistics")
public void exportFilesByUnionId(String zbId, String unionId, HttpServletResponse response) {
List<CommentPeo> peoList = commentPeoService.dao().query(CommentPeo.class, Cnd.where("unionId", "=", unionId).and("zbId", "=", zbId));
CommentPeo commentPeo = peoList.stream().findFirst().orElse(new CommentPeo());
response.reset();
response.setContentType("application/x-msdownload;charset=utf-8");
String tmpPath = "tmp/" + R.UU32();
File tmpDir = new File(tmpPath + "/附件信息");
tmpDir.mkdirs();
try {
for (CommentPeo peo : peoList) {
String fileName = peo.getUnionName() + "(" + peo.getUserName() + ")";
List<Sys_file> files = peo.getFiles();
File tDir = new File(tmpDir + "/" + fileName);
tDir.mkdirs();
if (Lang.isNotEmpty(files)) {
for (Sys_file file : files) {
if(Lang.isNotEmpty(file)) {
FileOutputStream outputStream = new FileOutputStream(tDir.getPath() + "/" + file.getFilename());
ftpService.download(file.getFilepath(), outputStream);
outputStream.close();
}
}
}
}
String aimsDir = "zipTmp/" + R.UU32();
String aimsName = commentPeo.getUnionName() + "评议信息.zip";
String aimsPath = aimsDir + "/" + aimsName;
FileUtil.compressToZip(tmpDir.getPath(), aimsDir, aimsName);
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(aimsName, "UTF-8"));
File aimsFile = new File(aimsPath);
FileInputStream inputStream = new FileInputStream(aimsFile);
IOUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
aimsFile.delete();
FileUtil.deleteDir(new File(tmpPath));
FileUtil.deleteDir(new File(aimsDir));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 个人上传附件导出
*
* @param peoId
* @param response
*/
@At
@Ok("void")
@RequiresPermissions("wakeshome.review.statistics")
public void exportFilesByPeoId(String peoId, HttpServletResponse response) {
CommentPeo peo = commentPeoService.dao().fetch(CommentPeo.class, peoId);
List<Sys_file> files = peo.getFiles();
response.reset();
response.setContentType("application/x-msdownload;charset=utf-8");
String tmpPath = "tmp/" + R.UU32();
File tmpDir = new File(tmpPath + "/个人附件信息");
tmpDir.mkdirs();
try {
for (Sys_file file : files) {
if (Lang.isNotEmpty(files)) {
FileOutputStream out = new FileOutputStream(tmpDir.getPath() + "/" + file.getFilename());
ftpService.download(file.getFilepath(), out);
out.close();
}
}
String aimsDir = "zipTmp/" + R.UU32();
String aimsName = peo.getUnionName() + "(" + peo.getUserName() + ")个人附件信息.zip";
String aimsPath = aimsDir + "/" + aimsName;
FileUtil.compressToZip(tmpDir.getPath(), aimsDir, aimsName);
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(aimsName, "UTF-8"));
File aimsFile = new File(aimsPath);
FileInputStream inputStream = new FileInputStream(aimsFile);
IOUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
aimsFile.delete();
FileUtil.deleteDir(new File(tmpPath));
FileUtil.deleteDir(new File(aimsDir));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 个人评议结果导出(得分)
*
* @param peoId
* @param response
*/
@At
@Ok("void")
@RequiresPermissions("wakeshome.review.statistics")
public void exportByPeoId(String peoId, HttpServletResponse response) {
CommentPeo peo = commentPeoService.dao().fetch(CommentPeo.class, peoId);
String fileName = peo.getUnionName() + "(" + peo.getUserName() + ")“模范教工小家”评议结果";
try {
response.addHeader("Content-Type", "application/octet-stream");
response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.getBytes("UTF-8"), "ISO-8859-1") + "\".docx");
commentStatisticsService.exportWord(peo, response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 导出所有分工会评议结果和附件信息
*
* @param zbId
* @param response
*/
@At
@Ok("void")
@RequiresPermissions("wakeshome.review.statistics")
public void exportAllUnions(String zbId, HttpServletResponse response) {
// List<CommentPeo> peoList = commentPeoService.dao().query(CommentPeo.class, Cnd.where("zbId", "=", zbId));
// Map<String, List<CommentPeo>> collect = peoList.stream().collect(Collectors.groupingBy(CommentPeo::getUnionId));
}
}
@@ -1,6 +1,7 @@
package io.v.nutz.wakershome.service.impl.review;
import cn.hutool.core.util.StrUtil;
import cn.wizzer.framework.base.service.BaseService;
import io.v.nutz.service.impl.ViServiceImpl;
import io.v.nutz.wakershome.model.review.CommentNr;
@@ -48,7 +49,7 @@ public class CommentPeoServiceImpl extends ViServiceImpl<CommentPeo> implements
v.getBzs().forEach(o->{
//赋值测评结果
CommentResult result = commentResultMap.get(o.getId());
o.setOptions(result.getRecommendation());
o.setOptions(StrUtil.isNotBlank(result.getRecommendation()) ? result.getRecommendation() : "未填写备注");
o.setResultScore(result.getAssessResult());
});
});
@@ -0,0 +1,94 @@
package io.v.nutz.wakershome.service.impl.review;
import cn.hutool.core.convert.Convert;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.policy.HackLoopTableRenderPolicy;
import io.v.nutz.base.service.impl.BaseServiceImpl;
import io.v.nutz.wakershome.model.review.CommentBz;
import io.v.nutz.wakershome.model.review.CommentNr;
import io.v.nutz.wakershome.model.review.CommentPeo;
import io.v.nutz.wakershome.model.review.CommentZb;
import io.v.nutz.wakershome.service.review.CommentPeoService;
import io.v.nutz.wakershome.service.review.CommentStatisticsService;
import io.v.nutz.web.commons.base.Globals;
import org.ddr.poi.html.HtmlRenderPolicy;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* @version 1.0
* @Author zzr
* @name:CommentStatisticsServiceImpl
* @Date 2024/8/26 9:48
* @注释
*/
@IocBean(args = {"refer:dao"})
public class CommentStatisticsServiceImpl extends BaseServiceImpl<CommentPeo> implements CommentStatisticsService {
public CommentStatisticsServiceImpl(Dao dao) {
super(dao);
}
@Inject
private CommentPeoService commentPeoService;
@Override
public void exportWord(CommentPeo peo, OutputStream outputStream) {
NutMap map = commentPeoService.getBzById(peo.getId());
//最后的导出表
NutMap resultMap = NutMap.NEW();
List<NutMap> list = new ArrayList<>();
resultMap.put("schoolName", Globals.schoolName);
CommentZb khzb = map.getAs("zbxx", CommentZb.class);
List<CommentNr> nrs = khzb.getNrs();
nrs.forEach(v -> {
NutMap nutMap = NutMap.NEW();
List<CommentBz> bzs = v.getBzs();
String nr = bzs.stream().sorted(Comparator.comparing(CommentBz::getContentNumber)).map(item -> {
return item.getContentNumber() + "." + item.getInspection() + "(" + item.getScore() + "分)";
}).collect(Collectors.joining("\n"));
int jf = bzs.stream().mapToInt(item -> Integer.parseInt(item.getScore())).sum();
int zpf = bzs.stream().mapToInt(item -> Integer.parseInt(item.getResultScore())).sum();
CommentBz commentBz = bzs.stream().findFirst().orElse(new CommentBz());
nutMap.put("xh", Convert.numberToChinese(Double.parseDouble(v.getContentNumber()), false));
nutMap.put("zb", v.getContent());
nutMap.put("nr", nr);
nutMap.put("jf", jf);
nutMap.put("zpf", zpf);
nutMap.put("bz", commentBz.getOptions());
list.add(nutMap);
});
HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
htmlRenderPolicy.getConfig().setShowDefaultTableBorderInTableCell(true);
Configure config = Configure.newBuilder().bind("list", policy)
.bind("list.nr", htmlRenderPolicy).build();
resultMap.put("list", list);
try {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("docTemplate/WakesHome.docx");
XWPFTemplate.compile(inputStream, config).render(resultMap, outputStream);
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -4,6 +4,8 @@ import io.v.nutz.service.ViService;
import io.v.nutz.wakershome.model.review.CommentPeo;
import org.nutz.lang.util.NutMap;
import java.io.InputStream;
public interface CommentPeoService extends ViService<CommentPeo> {
/**
@@ -12,4 +14,5 @@ public interface CommentPeoService extends ViService<CommentPeo> {
* @return
*/
NutMap getBzById(String peoId);
}
@@ -0,0 +1,23 @@
package io.v.nutz.wakershome.service.review;
import io.v.nutz.base.service.BaseService;
import io.v.nutz.wakershome.model.review.CommentPeo;
import org.nutz.lang.util.NutMap;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
/**
* @version 1.0
* @Author zzr
* @name:CommentStatisticsService
* @Date 2024/8/26 9:47
* @注释
*/
public interface CommentStatisticsService extends BaseService<CommentPeo> {
void exportWord(CommentPeo peo, OutputStream outputStream);
}
@@ -8,6 +8,4 @@ public interface CommentZbService extends ViService<CommentZb> {
CommentZb khzb(String zbid);
}