慰问申请表导出

This commit is contained in:
=
2025-11-13 17:49:54 +08:00
parent 384cd4f4c7
commit 6f9f3bd1b4
@@ -3,6 +3,8 @@ package com.budwk.app.zhgh.staffbenefit.condolence.controller;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import com.budwk.app.base.annotation.SLog;
import com.budwk.app.base.constant.RoleConstant;
@@ -11,18 +13,26 @@ import com.budwk.app.base.param.PageForm;
import com.budwk.app.base.result.Result;
import com.budwk.app.base.utils.CommonDownloadUtil;
import com.budwk.app.base.utils.PageUtil;
import com.budwk.app.base.utils.SysOfficeTemplateUtil;
import com.budwk.app.flow.engine.FlowEngine;
import com.budwk.app.flow.entity.ProcessTask;
import com.budwk.app.flow.vo.ProcessTaskVO;
import com.budwk.app.sys.views.View_user;
import com.budwk.app.web.commons.auth.utils.AuthUtil;
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
import com.budwk.app.web.commons.base.Globals;
import com.budwk.app.zhgh.democratic.proposal.models.ProposalInfo;
import com.budwk.app.zhgh.staffbenefit.condolence.model.Condolence;
import com.budwk.app.zhgh.staffbenefit.condolence.model.CondolenceType;
import com.budwk.app.zhgh.staffbenefit.condolence.service.CondolenceService;
import com.deepoove.poi.XWPFTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.boot.starter.ftp.FtpService;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.FieldFilter;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
@@ -41,6 +51,10 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
/**
* @ClassName CondolenceApplyController
@@ -53,22 +67,31 @@ import java.io.IOException;
@At("/platform/condolence/mine")
@Api("职工慰问我的")
@Ok("json:full")
@Slf4j
public class CondolenceMineController {
@Inject
private CondolenceService condolenceService;
@Inject
private FlowEngine flowEngine;
@Inject
private FtpService ftpService;
@Inject
private Dao dao;
@Inject
private SysOfficeTemplateUtil sysOfficeTemplateUtil;
@At("/")
@Ok("beetl:/platform/zhgh/staffbenefit/condolence/mine/index.html")
@SaCheckPermission("condolence.mine")
public void index() {}
public void index() {
}
@At("/h5")
@Ok("beetl:/platform/zhghh5/staffbenefit/condolence/mine/index.html")
@SaCheckPermission("h5.condolence.mine")
public void h5Index() {}
public void h5Index() {
}
@At
@ApiOperation("分页查询")
@@ -151,11 +174,100 @@ public class CondolenceMineController {
@At
@ApiOperation("导出单个慰问申请信息")
@SaCheckPermission("condolence")
public void onExport(@Valid String id, HttpServletResponse response){
Condolence condolence = condolenceService.fetch(id);
public void onExport(@Valid String id, HttpServletResponse response) throws ParseException {
HashMap<String, Object> docData = new HashMap<>();
Sql sql = Sqls.create("""
SELECT
info.*,
ins.id AS instanceId
FROM
`condolence` info
LEFT JOIN wf_process_instance ins ON ins.businessNo = info.id
WHERE
info.id = @id
""").setParam("id", id);
sql.setCallback(Sqls.callback.map());
dao.execute(sql);
NutMap info = (NutMap) sql.getResult();
// 根据慰问类型选择不同的模板和文件名
String type = info.getString("type");
String templateName;
String fileName;
if ("a6be188e586e4df091d0fcc37b5ecfd0".equals(type)) {
templateName = "zzjzgqs_table";
fileName = "河北地质大学在职教职工去世慰问金额申请表" + ".docx";
} else {
templateName = "zzjzgfmqs_table";
fileName = "河北地质大学在职教职工父母去世慰问金额申请表" + ".docx";
}
// 添加日期格式化处理
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (info.get("createTime") != null) {
if (info.get("createTime") instanceof String) {
String createTimeStr = (String) info.get("createTime");
Date date = inputFormat.parse(createTimeStr);
info.put("createTime", sdf.format(date));
}
}
if (StrUtil.isNotBlank(info.getString("signature"))) {
info.put("signature", sysOfficeTemplateUtil.createPictureRenderData(info.getString("signature")));
}
docData.put("schoolName", Globals.AppName);
docData.put("info", info);
List<ProcessTaskVO> doneTaskVos = new ArrayList<>();
List<ProcessTask> doneTaskList = flowEngine.processTaskService().getDoneTaskList(info.getLong("instanceId"), null);
for (ProcessTask doneTask : doneTaskList) {
ProcessTaskVO taskVO = flowEngine.processTaskService().findById(doneTask.getId());
doneTaskVos.add(taskVO);
}
// 各审批节点处理
doneTaskVos.stream().filter(task -> "分工会审核".equals(task.getDisplayName()))
.max(Comparator.comparing(ProcessTaskVO::getCreatedAt))
.ifPresent(v -> {
Dict taskFormData = v.getTaskFormData();
HashMap<String, Object> approval = new HashMap<>();
approval.put("date", DateUtil.format(v.getFinishTime(), "yyyy年MM月dd日"));
approval.put("user", taskFormData.getStr("tf_userName"));
if (StrUtil.isNotBlank(taskFormData.getStr("tf_userSign"))) {
approval.put("sign", sysOfficeTemplateUtil.createPictureRenderData(taskFormData.getStr("tf_userSign")));
}
approval.put("opinion", taskFormData.getStr("tf_opinion"));
docData.put("fgh", approval);
});
doneTaskVos.stream().filter(task -> "校工会审核".equals(task.getDisplayName()))
.max(Comparator.comparing(ProcessTaskVO::getCreatedAt))
.ifPresent(v -> {
Dict taskFormData = v.getTaskFormData();
HashMap<String, Object> approval = new HashMap<>();
approval.put("date", DateUtil.format(v.getFinishTime(), "yyyy年MM月dd日"));
approval.put("user", taskFormData.getStr("tf_userName"));
if (StrUtil.isNotBlank(taskFormData.getStr("tf_userSign"))) {
approval.put("sign", sysOfficeTemplateUtil.createPictureRenderData(taskFormData.getStr("tf_userSign")));
}
approval.put("opinion", taskFormData.getStr("tf_opinion"));
docData.put("xgh", approval);
});
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
XWPFTemplate.compile(sysOfficeTemplateUtil.getTemplate(templateName)).render(docData).writeAndClose(byteArrayOutputStream);
CommonDownloadUtil.download(fileName, byteArrayOutputStream.toByteArray(), response);
} catch (IOException e) {
log.error("河北地质大学教在职职工去世/在职教职工父母去世慰问金额申请表导出失败,id:{},错误信息:{}", id, e.getMessage());
}
}