sinake
13 小时以前 64fe4241b5e764f91966878eff1720a3b14d6da8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java
@@ -9,6 +9,7 @@
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
@@ -59,11 +60,12 @@
    @Autowired
    private IServiceFundService serviceFundService;
    @Autowired
    private IServiceFundSharedService serviceFundSharedService;
    @Autowired
    private IServiceFunddetailService serviceFunddetailService;
    @Autowired
    private IServiceFundflowruleService serviceFundflowruleService;
    @Autowired
    private IServiceFundflowService serviceFundflowService;
    @Autowired
    private IServiceDonatebaseinfoService serviceDonatebaseinfoService;
@@ -71,20 +73,10 @@
    private IServiceReimbursementService serviceReimbursementService;
    @Autowired
    private IServiceSystemmessageService iServiceSystemmessageService;
    @Autowired
    private IServiceExternalpersonService externalpersonService;
    @Autowired
    private ISysPostService postService;
    @Autowired
    private DingTalkService dingTalkService;
    @Autowired
    private ISysUserService sysUserService;
    public ServiceFundController() {
        configuration = new Configuration();
@@ -118,13 +110,32 @@
    @PostMapping("/processlog")
    public AjaxResult processlog(@RequestBody ServiceProcessVO serviceProcessVO) {
        log.info("致远系统流程退回审批日志入参:{}", serviceProcessVO);
        if (serviceProcessVO.getBackCode() == null || StringUtils.isEmpty(serviceProcessVO.getApplytype())) {
        if (serviceProcessVO.getBackCode() == null && StringUtils.isEmpty(serviceProcessVO.getApplytype())) {
            return AjaxResult.error("入能为空,请检查入参!!");
        }
        Boolean processlog = serviceFundService.processlog(serviceProcessVO);
        if (!processlog) return AjaxResult.error("审批记录失败");
        return AjaxResult.success("审批记录成功");
    }
    /**
     * 修改编号与支付方式
     *
     * @param serviceCodeAndPyaWay
     * @return
     */
    @PostMapping("/updatecodepayway")
    public AjaxResult updatecodepay(@RequestBody ServiceCodeAndPyaWay serviceCodeAndPyaWay) {
        log.info("致远系统编号与支付方式入参:{}", serviceCodeAndPyaWay);
        if (StringUtils.isEmpty(serviceCodeAndPyaWay.getApplytype()) || StringUtils.isEmpty(serviceCodeAndPyaWay.getBh()) || StringUtils.isEmpty(serviceCodeAndPyaWay.getZffs())) {
            return AjaxResult.error("入能为空,请检查入参!!");
        }
        Boolean result = serviceFundService.updatecodepay(serviceCodeAndPyaWay);
        if (!result) return AjaxResult.error("修改失败");
        return AjaxResult.success("修改成功");
    }
@@ -136,11 +147,47 @@
    @GetMapping("/list")
    public TableDataInfo list(ServiceFund serviceFund) {
        startPage();
        //List<ServiceFund> list = serviceFundService.queryList(serviceFund);
        SysUser user = SecurityUtils.getLoginUser().getUser();
        serviceFund.setUsername(user.getNickName());
        // 2026-11-10:按角色划分可见范围(原实现一律只查"申请人=本人",管理员/组长看不到别人的单据)
        applyFundDataScope(serviceFund, user);
        List<ServiceFund> list = serviceFundService.selectServiceFundList(serviceFund);
        return getDataTable(list);
    }
    /**
     * 报销单列表数据范围:
     * 超管(user_id=1 或 role_id=1)→ 全部;
     * 业务组长(role_id=13)→ 本组(DeptmentNo = 登录人所属部门);
     * 其他(专职人员等)→ 本人(UserName = 登录人昵称)。
     */
    private void applyFundDataScope(ServiceFund serviceFund, SysUser user) {
        if (user == null) {
            return;
        }
        if (Long.valueOf(1L).equals(user.getUserId()) || hasRole(user, 1L)) {
            // 超管:不加任何过滤,看全部
            return;
        }
        if (hasRole(user, 13L) && user.getDeptId() != null) {
            // 业务组长:看本组
            serviceFund.setDeptmentno(String.valueOf(user.getDeptId()));
            return;
        }
        // 默认:只看本人
        serviceFund.setUsername(user.getNickName());
    }
    /** 判断登录人是否拥有指定角色 */
    private boolean hasRole(SysUser user, Long roleId) {
        if (user == null || user.getRoles() == null) {
            return false;
        }
        for (SysRole role : user.getRoles()) {
            if (role != null && roleId.equals(role.getRoleId())) {
                return true;
            }
        }
        return false;
    }
    @GetMapping("/listnew")
@@ -211,7 +258,7 @@
        Collections.sort(list, new Comparator<SpFinancialExpensesFundOut>() {
            @Override
            public int compare(SpFinancialExpensesFundOut o1, SpFinancialExpensesFundOut o2) {
                return o1.getApplyTime().compareTo(o2.getApplyTime());
                return o2.getApplyTime().compareTo(o1.getApplyTime());
            }
        });
        return getCustomDataTable(list, pageNum, pageSize);
@@ -308,8 +355,54 @@
    @RepeatSubmit
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public AjaxResult addOrUpdateNew(@RequestBody ServiceFundVO serviceFundVO) {
        // 2026-11-23:剔除 blob:/data: 这类浏览器临时附件地址,避免落库后无法预览
        int droppedAttach = sanitizeAttachments(serviceFundVO);
        AjaxResult result = AjaxResult.success(serviceFundService.addOrUpdateNew(serviceFundVO));
        if (droppedAttach > 0) {
            result.put("attachWarn",
                    "检测到 " + droppedAttach + " 个附件地址无效(浏览器临时地址),已自动剔除,请重新上传这些附件后再保存。");
        }
        return result;
    }
        return AjaxResult.success(serviceFundService.addOrUpdateNew(serviceFundVO));
    /**
     * 2026-11-23:清洗整单明细里的临时附件地址(blob:/data:/file:)。
     *
     * @return 被剔除的附件条数
     */
    private int sanitizeAttachments(ServiceFundVO serviceFundVO) {
        if (serviceFundVO == null || CollectionUtils.isEmpty(serviceFundVO.getServiceFunddetails())) {
            return 0;
        }
        int dropped = 0;
        for (ServiceFunddetailVO detail : serviceFundVO.getServiceFunddetails()) {
            if (detail == null) {
                continue;
            }
            dropped += com.ruoyi.project.common.AttachmentUrlSanitizer.sanitize(detail.getAnnexfilesList());
            dropped += com.ruoyi.project.common.AttachmentUrlSanitizer.sanitize(detail.getInvoicefilesList());
        }
        if (dropped > 0) {
            log.warn("报销单保存:剔除 {} 个临时附件地址(blob:/data:),单据 fundid={}", dropped, serviceFundVO.getId());
        }
        return dropped;
    }
    /**
     * 专家劳务费:保存前的费用控制校验(干跑,不落库)
     *
     * <p>供专家劳务费填报页在点“保存”前调用,把 9 条规则的校验结果
     * (errors 阻断 / warnings 提示)返回前端展示;真正的落库拦截在 addOrUpdateNew 中。
     */
    @ApiOperation("专家劳务费保存前校验")
    @PostMapping("/validateExpertFee")
    public AjaxResult validateExpertFee(@RequestBody ServiceFundVO serviceFundVO) {
        ExpertFeeCheckResult result = serviceFundService.validateExpertFee(serviceFundVO);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("errors", result.getErrors());
        ajaxResult.put("warnings", result.getWarnings());
        ajaxResult.put("blocked", result.hasError());
        return ajaxResult;
    }
@@ -323,7 +416,7 @@
    public AjaxResult checkFund(@RequestBody CheckFundVO checkFundVO) {
        log.info("serviceFundController---checkFund的入参值checkFundVO :{}", checkFundVO);
        LoginUser loginUser = getLoginUser();
        Map<String, String> map = serviceFundService.checkFund(checkFundVO,loginUser);
        Map<String, String> map = serviceFundService.checkFund(checkFundVO, loginUser);
        Set<String> keys = map.keySet();
        for (String s : keys) {
            if (!s.equals("200")) return AjaxResult.error(map.get(s));
@@ -345,6 +438,8 @@
        List<ServiceFund> infoByInfoIdList = serviceFundService.queryInfoById(serviceFund);
        log.info("修改费用申请,通过入参查询 serviceFundService.queryInfoById数据为空,入参:{}", infoByInfoIdList.size());
        if (CollectionUtils.isEmpty(infoByInfoIdList)) {
            // 2026-11-23:同样剔除临时附件地址(blob:/data:),避免落库后无法预览
            sanitizeAttachments(serviceFundVO);
            Long id = serviceFundService.addOrUpdateNew(serviceFundVO);
            serviceFund.setId(id);
        }
@@ -454,25 +549,27 @@
        }
        String newTime = String.valueOf(Calendar.getInstance().getTimeInMillis());
        String name = "专家劳务费发放申请单_" + dataMap.get("XM") + "_" + newTime;
        String newName = null;
        if (Objects.isNull(dataMap.get("XM"))) {
            newName = dataMap.get("XM").toString().trim();
        }
        String name = "专家劳务费发放申请单_" + newName + "_" + newTime;
        if (dataLW.equals("4")) {
            name = "办公费用申请单_" + dataMap.get("XM") + "_" + newTime;
            name = "办公费用申请单_" + newName + "_" + newTime;
        }
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -645,18 +742,16 @@
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -742,18 +837,16 @@
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -844,20 +937,16 @@
        }
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            log.error("FileNotFoundException报错信息是:{}", e1.getMessage());
//            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            log.error("TemplateException报错信自是:{}", e.getMessage());
            e.getMessage();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -1069,18 +1158,16 @@
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -1138,18 +1225,16 @@
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -1638,18 +1723,16 @@
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");
@@ -1727,18 +1810,16 @@
        //输出文档路径及名称
        File outFile = new File(RuoYiConfig.getProfile() + "/download/wordtemplate/" + name + ".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        if (t == null) {
            throw new ServiceException("模板加载失败,请检查模板文件是否存在", HttpStatus.NO_CONTENT);
        }
        try {
        // Writer 必须关闭/刷新:BufferedWriter 带缓冲,不关闭会造成文件句柄泄漏且内容可能不完整
        try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"))) {
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (TemplateException | IOException e) {
            log.error("生成模板文档失败, name={}", name, e);
            throw new ServiceException("生成文档失败", HttpStatus.ERROR);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("downloadUrl", "/profile/download/wordtemplate/" + name + ".doc");