From cdd77b303e20b210e976ac7637ab52857f6ae96a Mon Sep 17 00:00:00 2001 From: Paidax Date: Mon, 26 Aug 2024 11:51:06 +0800 Subject: [PATCH] commit --- .../review/StatisticsZpController.java | 250 +++++++++++++++--- .../impl/review/CommentPeoServiceImpl.java | 3 +- .../review/CommentStatisticsServiceImpl.java | 94 +++++++ .../service/review/CommentPeoService.java | 3 + .../review/CommentStatisticsService.java | 23 ++ .../service/review/CommentZbService.java | 2 - .../wakeshome/review/ReviewResult.vue | 2 +- .../platform/wakeshome/review/statistics.html | 60 +++-- 8 files changed, 364 insertions(+), 73 deletions(-) create mode 100644 src/main/java/io/v/nutz/wakershome/service/impl/review/CommentStatisticsServiceImpl.java create mode 100644 src/main/java/io/v/nutz/wakershome/service/review/CommentStatisticsService.java diff --git a/src/main/java/io/v/nutz/wakershome/controller/review/StatisticsZpController.java b/src/main/java/io/v/nutz/wakershome/controller/review/StatisticsZpController.java index 1f19667..9672d0d 100644 --- a/src/main/java/io/v/nutz/wakershome/controller/review/StatisticsZpController.java +++ b/src/main/java/io/v/nutz/wakershome/controller/review/StatisticsZpController.java @@ -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 list = new ArrayList<>(); - resultMap.put("schoolName", Globals.schoolName); - - CommentZb khzb = map.getAs("zbxx", CommentZb.class); - List nrs = khzb.getNrs(); - - nrs.forEach(v -> { - NutMap nutMap = NutMap.NEW(); - List bzs = v.getBzs(); - String nr = bzs.stream().sorted(Comparator.comparing(CommentBz::getContentNumber)).map(item -> { - return item.getContentNumber() + "." + item.getInspection() + "(" + item.getScore() + "分)"; - }).collect(Collectors.joining("
")); - - 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 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 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 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 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 peoList = commentPeoService.dao().query(CommentPeo.class, Cnd.where("zbId", "=", zbId)); + +// Map> collect = peoList.stream().collect(Collectors.groupingBy(CommentPeo::getUnionId)); + } } diff --git a/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentPeoServiceImpl.java b/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentPeoServiceImpl.java index ce84dd2..84ecaaa 100644 --- a/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentPeoServiceImpl.java +++ b/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentPeoServiceImpl.java @@ -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 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()); }); }); diff --git a/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentStatisticsServiceImpl.java b/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentStatisticsServiceImpl.java new file mode 100644 index 0000000..6daa6a5 --- /dev/null +++ b/src/main/java/io/v/nutz/wakershome/service/impl/review/CommentStatisticsServiceImpl.java @@ -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 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 list = new ArrayList<>(); + resultMap.put("schoolName", Globals.schoolName); + + CommentZb khzb = map.getAs("zbxx", CommentZb.class); + List nrs = khzb.getNrs(); + + nrs.forEach(v -> { + NutMap nutMap = NutMap.NEW(); + List 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(); + } + } +} diff --git a/src/main/java/io/v/nutz/wakershome/service/review/CommentPeoService.java b/src/main/java/io/v/nutz/wakershome/service/review/CommentPeoService.java index e98b392..1c968f4 100644 --- a/src/main/java/io/v/nutz/wakershome/service/review/CommentPeoService.java +++ b/src/main/java/io/v/nutz/wakershome/service/review/CommentPeoService.java @@ -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 { /** @@ -12,4 +14,5 @@ public interface CommentPeoService extends ViService { * @return */ NutMap getBzById(String peoId); + } diff --git a/src/main/java/io/v/nutz/wakershome/service/review/CommentStatisticsService.java b/src/main/java/io/v/nutz/wakershome/service/review/CommentStatisticsService.java new file mode 100644 index 0000000..c78fec9 --- /dev/null +++ b/src/main/java/io/v/nutz/wakershome/service/review/CommentStatisticsService.java @@ -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 { + + void exportWord(CommentPeo peo, OutputStream outputStream); + + + +} diff --git a/src/main/java/io/v/nutz/wakershome/service/review/CommentZbService.java b/src/main/java/io/v/nutz/wakershome/service/review/CommentZbService.java index 0c8619b..19f50c9 100644 --- a/src/main/java/io/v/nutz/wakershome/service/review/CommentZbService.java +++ b/src/main/java/io/v/nutz/wakershome/service/review/CommentZbService.java @@ -8,6 +8,4 @@ public interface CommentZbService extends ViService { CommentZb khzb(String zbid); - - } diff --git a/src/main/resources/static/components/wakeshome/review/ReviewResult.vue b/src/main/resources/static/components/wakeshome/review/ReviewResult.vue index c9b02d4..57b57e9 100644 --- a/src/main/resources/static/components/wakeshome/review/ReviewResult.vue +++ b/src/main/resources/static/components/wakeshome/review/ReviewResult.vue @@ -66,7 +66,7 @@ 备注 - diff --git a/src/main/resources/views/platform/wakeshome/review/statistics.html b/src/main/resources/views/platform/wakeshome/review/statistics.html index 7b020e2..d4d982a 100644 --- a/src/main/resources/views/platform/wakeshome/review/statistics.html +++ b/src/main/resources/views/platform/wakeshome/review/statistics.html @@ -5,7 +5,6 @@ layout("/layouts/platform.html"){
- 搜索 - + 搜索
- - - + :size="tableSize" v-loading="tableLoading" ref="table" class="vi-table"> + :index="indexMethod" label="序号" width="80px"> - @@ -160,13 +153,11 @@ layout("/layouts/platform.html"){ + label="操作" width="240px" fixed="right"> @@ -246,8 +237,23 @@ layout("/layouts/platform.html"){ 'wakes-home-review': httpVueLoader('/components/wakeshome/review/ReviewResult.vue?v=' + moment(new Date()).unix()), }, methods: { - doDownLoad(row){ - window.open(loc() + '/doDownLoad?zbId=' + this.pageForm.zbId + '&unionId=' + row.id) + doDownLoad(row,flag){ + if (flag) { + // 为true,自我评议 + window.open(loc() + '/doDownLoadSingleByUnionId?zbId=' + this.pageForm.zbId + '&unionId=' + row.id) + } else { + // false, 会员评议,导出压缩包 + window.open(loc() + '/doDownLoadZipByUnionId?zbId=' + this.pageForm.zbId + '&unionId=' + row.id) + } + }, + downloadFilesByUnion(row){ + window.open(loc() + '/exportFilesByUnionId?zbId=' + this.pageForm.zbId + '&unionId=' + row.id) + }, + downloadByPeoId(row){ + window.open(loc() + '/exportByPeoId?peoId=' + row.id) + }, + downloadFilesByPeoId(){ + window.open(loc() + '/exportFilesByPeoId?peoId=' + row.id) }, async getReviewResultNum(row) { const res = await $.post(loc() + "/getReviewResultNum", { @@ -313,7 +319,7 @@ layout("/layouts/platform.html"){ computed: { canDownload() { const data = this.zbList.find(v=> v.id === this.pageForm.zbId) - return data.commentTarget===3 && data.unionIds + return data.commentTarget===3 && data.unionIds && data.unionIds.length > 0 } }, async created() {