From 6f9f3bd1b4b4f656998779a429e4914278151c49 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 13 Nov 2025 17:49:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=85=B0=E9=97=AE=E7=94=B3=E8=AF=B7=E8=A1=A8?= =?UTF-8?q?=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CondolenceMineController.java | 242 +++++++++++++----- 1 file changed, 177 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/budwk/app/zhgh/staffbenefit/condolence/controller/CondolenceMineController.java b/src/main/java/com/budwk/app/zhgh/staffbenefit/condolence/controller/CondolenceMineController.java index 05ec07d..8f8506c 100644 --- a/src/main/java/com/budwk/app/zhgh/staffbenefit/condolence/controller/CondolenceMineController.java +++ b/src/main/java/com/budwk/app/zhgh/staffbenefit/condolence/controller/CondolenceMineController.java @@ -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,30 +67,39 @@ 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 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() {} + @At("/") + @Ok("beetl:/platform/zhgh/staffbenefit/condolence/mine/index.html") + @SaCheckPermission("condolence.mine") + public void index() { + } - @At("/h5") - @Ok("beetl:/platform/zhghh5/staffbenefit/condolence/mine/index.html") - @SaCheckPermission("h5.condolence.mine") - public void h5Index() {} + @At("/h5") + @Ok("beetl:/platform/zhghh5/staffbenefit/condolence/mine/index.html") + @SaCheckPermission("h5.condolence.mine") + public void h5Index() { + } - @At - @ApiOperation("分页查询") - @SaCheckPermission(value = {"condolence.mine", "h5.condolence.mine"}, mode = SaMode.OR) - public Result pageData(PageForm pageForm, - @Param(value = "year") Integer year, - @Param(value = "type") String type) { - Sql sql = Sqls.create(""" + @At + @ApiOperation("分页查询") + @SaCheckPermission(value = {"condolence.mine", "h5.condolence.mine"}, mode = SaMode.OR) + public Result pageData(PageForm pageForm, + @Param(value = "year") Integer year, + @Param(value = "type") String type) { + Sql sql = Sqls.create(""" SELECT info.*, type.name as typeName, @@ -104,59 +127,148 @@ public class CondolenceMineController { LEFT JOIN wf_process_task_actor ta ON ta.processTaskId = t.id $condition """); - Cnd cnd = Cnd.NEW(); - if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) { - SqlExpressionGroup seg = new SqlExpressionGroup(); - seg.or(Condolence::getHelpUserName, "like", "%" + pageForm.getSearchKeyword() + "%"); - seg.or(Condolence::getHelpLoginName, "like", "%" + pageForm.getSearchKeyword() + "%"); - cnd.and(seg); - } - cnd.andEX("year(info.createTime)", "=", year); - cnd.andEX("info.type", "=", type); - cnd.and("info.createdBy", "=", SecurityUtil.getUserId()); + Cnd cnd = Cnd.NEW(); + if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) { + SqlExpressionGroup seg = new SqlExpressionGroup(); + seg.or(Condolence::getHelpUserName, "like", "%" + pageForm.getSearchKeyword() + "%"); + seg.or(Condolence::getHelpLoginName, "like", "%" + pageForm.getSearchKeyword() + "%"); + cnd.and(seg); + } + cnd.andEX("year(info.createTime)", "=", year); + cnd.andEX("info.type", "=", type); + cnd.and("info.createdBy", "=", SecurityUtil.getUserId()); - if (StrUtil.isNotBlank(pageForm.getPageOrderName()) && StrUtil.isNotBlank(pageForm.getPageOrderBy())) { - cnd.orderBy(pageForm.getPageOrderName(), PageUtil.getOrder(pageForm.getPageOrderBy())); - } else { - cnd.desc("info.createTime"); - } + if (StrUtil.isNotBlank(pageForm.getPageOrderName()) && StrUtil.isNotBlank(pageForm.getPageOrderBy())) { + cnd.orderBy(pageForm.getPageOrderName(), PageUtil.getOrder(pageForm.getPageOrderBy())); + } else { + cnd.desc("info.createTime"); + } - sql.setCondition(cnd); - Pagination pagination = condolenceService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); - return Result.success(pagination); - } + sql.setCondition(cnd); + Pagination pagination = condolenceService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); + return Result.success(pagination); + } - @At - @ApiOperation("删除") - @Aop(TransAop.READ_COMMITTED) - @SaCheckPermission(value = {"condolence.mine", "h5.condolence.mine"}, mode = SaMode.OR) - @SLog(tag = "职工慰问系统-我的申请", msg = "删除职工慰问") - public Result delete(@Param("id") String id) { - condolenceService.delete(id); - flowEngine.processInstanceService().deleteProcessInstanceByBusinessKey(id); - return Result.success(); - } + @At + @ApiOperation("删除") + @Aop(TransAop.READ_COMMITTED) + @SaCheckPermission(value = {"condolence.mine", "h5.condolence.mine"}, mode = SaMode.OR) + @SLog(tag = "职工慰问系统-我的申请", msg = "删除职工慰问") + public Result delete(@Param("id") String id) { + condolenceService.delete(id); + flowEngine.processInstanceService().deleteProcessInstanceByBusinessKey(id); + return Result.success(); + } - @At - @ApiOperation("查询单个慰问申请信息") - @SaCheckPermission("condolence") - public Result info(String id) { - Condolence condolence = condolenceService.fetch(id); - CondolenceType type = condolenceService.dao().fetch(CondolenceType.class, Cnd.where(CondolenceType::getId, "=", condolence.getType())); - NutMap nutMap = Lang.obj2nutmap(condolence); - nutMap.put("typeName", type.getName()); - return Result.success(nutMap); - } + @At + @ApiOperation("查询单个慰问申请信息") + @SaCheckPermission("condolence") + public Result info(String id) { + Condolence condolence = condolenceService.fetch(id); + CondolenceType type = condolenceService.dao().fetch(CondolenceType.class, Cnd.where(CondolenceType::getId, "=", condolence.getType())); + NutMap nutMap = Lang.obj2nutmap(condolence); + nutMap.put("typeName", type.getName()); + return Result.success(nutMap); + } - @At - @ApiOperation("导出单个慰问申请信息") - @SaCheckPermission("condolence") - public void onExport(@Valid String id, HttpServletResponse response){ - Condolence condolence = condolenceService.fetch(id); + @At + @ApiOperation("导出单个慰问申请信息") + @SaCheckPermission("condolence") + public void onExport(@Valid String id, HttpServletResponse response) throws ParseException { + HashMap docData = new HashMap<>(); - String fileName; + 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 doneTaskVos = new ArrayList<>(); + List 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 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 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()); + } + + + } }