This commit is contained in:
@jyuhsin
2025-06-11 17:35:30 +08:00
parent 77d9aef4c5
commit c243daddec
2 changed files with 97 additions and 175 deletions
@@ -2,17 +2,22 @@ package io.v.nutz.zhgh.lxy.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.policy.HackLoopTableRenderPolicy;
import io.v.nutz.base.annontation.ViReturn;
import io.v.nutz.base.utils.MsgApi;
import io.v.nutz.base.utils.OfficeTemplateUtil;
import io.v.nutz.base.utils.Vi;
import io.v.nutz.zhgh.lxy.model.Lxy_bm;
import io.v.nutz.zhgh.lxy.model.Lxy_hd;
import io.v.nutz.zhgh.lxy.service.LxyGrxxService;
import io.v.nutz.zhgh.lxy.service.LxyHdService;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Record;
import org.nutz.dao.sql.Sql;
@@ -29,6 +34,7 @@ import org.nutz.mvc.annotation.Param;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
@@ -45,19 +51,16 @@ public class LxyHdTjController {
@Inject
private LxyHdService lxyHdService;
@Inject
private LxyGrxxService lxyGrxxService;
@Inject
private Vi vi;
@Inject
private OfficeTemplateUtil officeTemplateUtil;
@Inject
private MsgApi msgApi;
@Inject
private Dao dao;
@At("")
@Ok("beetl:/platform/zgfw/lxy/HdTj.html")
@@ -73,9 +76,24 @@ public class LxyHdTjController {
@Param(value = "searchKey", required = false) String searchKey,
@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize) {
Cnd cnd = Cnd.NEW();
Sql sql = Sqls.create("SELECT gr.* ,u.unionname,u.unioncode,u.unitname unitname,u.unitcode FROM `lxy_grxx` gr \n" +
"LEFT JOIN lxy_bm bm ON bm.userid = gr.userid \n" +
"LEFT JOIN `user` u ON u.id=bm.userid $condition");
Sql sql = Sqls.create("""
SELECT
gr.*,
u.unionname,
u.unioncode,
u.unitname,
u.unitcode,
bm.zyhj,
bm.bz,
bm.talent,
bm.nation,
bm.bmzt
FROM
lxy_grxx gr
LEFT JOIN lxy_bm bm ON bm.userid = gr.userid
LEFT JOIN `user` u ON u.id = bm.userid
$condition
""");
cnd.and(new Static("bm.bmzt = 5"));
cnd.and("gr.hdid", "=", hdid);
@@ -108,56 +126,44 @@ public class LxyHdTjController {
Cnd cnd = Cnd.NEW();
Sql sql = Sqls.create("""
SELECT
gr.*,
bm.unionname,
gr.username as uName,
bm.unitname,
gr.sex,
bm.nation,
bm.zyhj,
bm.bz
bm.idcard,
bm.mobile,
bm.talent
FROM
`lxy_grxx` gr
LEFT JOIN lxy_bm bm ON bm.userid = gr.userid
LEFT JOIN `user` u ON u.id = bm.userid
$condition
""");
cnd.and(new Static("bm.bmzt = 5"));
cnd.and("bm.bmzt", "=", 5);
cnd.and("gr.hdid", "=", hdid);
if (Strings.isNotBlank(ghid)) {
cnd.and("gr.ghid", "=", ghid);
}
cnd.andEX("gr.ghid", "=", ghid);
cnd.groupBy("bm.userid");
cnd.asc("bm.unionname").asc("bm.unitname").asc("gr.age");
cnd.asc("u.unioncode");
sql.setCondition(cnd);
List<Record> list = lxyGrxxService.list(sql);
int i = 1;
for (Record r : list) {
r.set("index", i);
List<NutMap> chry = Json.fromJsonAsList(NutMap.class, r.getString("chry"));
for (NutMap map : chry) {
r.set("rych", (r.getString("rych") == null ? "" : r.getString("rych")) + " " + map.getString("shry"));
}
i++;
for (int i = 0; i < list.size(); i++) {
list.get(i).set("index", i + 1);
}
// HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
// Configure config = Configure.newBuilder().bind("list", policy).build();
HashMap<String, Object> map = new HashMap<>();
map.put("hdmc", hdname);
map.put("mapList", list);
String fileName = "疗休养人员名单汇总表.xls";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1"));
// TemplateExportParams params = new TemplateExportParams("C:\\Users\\mayn\\Desktop\\lxyrymd.xls");
TemplateExportParams params = new TemplateExportParams(officeTemplateUtil.getPath("lxy_lxyrymd"));
// Workbook workbook = ExcelExportUtil.exportExcel(params, map);
// workbook.write(response.getOutputStream());
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
}
NutMap map = new NutMap();
map.put("list", list);
HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
Configure config = Configure.builder().bind("list", policy).build();
String fileName = "疗休养人员名单汇总表.docx";
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(StandardCharsets.UTF_8), "ISO8859-1"));
XWPFTemplate.compile(officeTemplateUtil.getPath("lxy_lxyrymd"), config).render(map).write(response.getOutputStream());
response.getOutputStream().close();
}
@At
@RequiresPermissions("zgfw.lxy.hdtj")