瀏覽代碼

张丁 测试作业票流程5.0

zhangding 3 年之前
父節點
當前提交
648d5f0406

+ 0 - 200
master/src/main/java/com/ruoyi/project/invoice/controller/TInvoiceBookingworkticketController.java

@@ -378,27 +378,16 @@ public class TInvoiceBookingworkticketController extends BaseController
         tInvoiceBookingworkticket.setContact(sysUser.getNickName());
         tInvoiceBookingworkticket.setPhonenumber(sysUser.getPhonenumber());
         tInvoiceBookingworkticketService.insertTInvoiceBookingworkticket(tInvoiceBookingworkticket);
-
         Long didi=tInvoiceBookingworkticket.getId();
         List<TInvoiceWorkcontent>  w=tInvoiceBookingworkticket.gettInvoiceWorkcontentList();
-
         for(int i=0;i<w.size();i++){
              TInvoiceWorkcontent wt= w.get(i);
             wt.setBookingticketId(didi);
             //关联的票号
-
             tInvoiceBookingworkticketService.insertTInvoiceWorkcontent(wt);
             wt.setReservationNumber("Steam Cracker"+tInvoiceBookingworkticket.getId().toString()+"-"+wt.getId().toString());
             tInvoiceBookingworkticketService.updateTInvoiceWorkcontent(wt);
         }
-       /* try {
-            // 测试一下,先得到这个文件名 地址   在赋值插入 然后赋值 改文件名
-            String url=  PreView(tInvoiceBookingworkticket.getId());
-            tInvoiceBookingworkticket.setFilename(url);
-            tInvoiceBookingworkticketService.updateTInvoiceBookingworkticket(tInvoiceBookingworkticket);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }*/
 
         return AjaxResult.success(didi);
     }
@@ -438,193 +427,4 @@ public class TInvoiceBookingworkticketController extends BaseController
     {
         return toAjax(tInvoiceBookingworkticketService.deleteTInvoiceBookingworkticketByIds(ids));
     }
-
-
-
-    /**
-     *
-     * @param id   生成文件名
-     * @return
-     * @throws IOException
-     */
-    public String PreView(Long id) throws IOException {
-        TInvoiceBookingworkticket tInvoiceBookingworkticket= tInvoiceBookingworkticketService.selectTInvoiceBookingworkticketById(id);
-        String url = this.createBookingworkticketWord(tInvoiceBookingworkticket);
-        return url;
-    }
-
-    /**
-     * 生成word
-     */
-    public String createBookingworkticketWord(TInvoiceBookingworkticket invoiceBookingworkticket) throws IOException {
-        //生成word
-        //渲染文本
-        Map<String, Object> params = getWordData(invoiceBookingworkticket);
-        // 模板路径
-        String templatePath = "static/word/invoice/book.docx";
-        // 生成word的路径
-        String fileDir = RuoYiConfig.getProfile() + "/"+ "ticketWord";
-        // 生成word的文件名称
-        // 承包商+联系人+当前时间
-        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm"));
-        String fileName = invoiceBookingworkticket.getWorkUnit()+invoiceBookingworkticket.getContact() +time+".docx";
-        String wordPath = this.createWord(templatePath, fileDir, fileName, params);
-
-        return wordPath;
-    };
-
-
-    /**
-     * 获取word数据
-     */
-    public Map<String, Object> getWordData (TInvoiceBookingworkticket ticket){
-        Map<String, Object> params = new HashMap<>();
-        List<TInvoiceWorkcontent> tInvoiceWorkcontentList= tInvoiceBookingworkticketService.selectTInvoiceWorkcontentBybookingticketId(ticket.getId());
-        //字典查询
-        List<SysDictData> book_work_type = iSysDictTypeService.selectDictDataByType("book_work_type");
-        List<SysDictData> book_user_unit = iSysDictTypeService.selectDictDataByType("book_user_unit");
-        List<SysDictData> book_risk_level = iSysDictTypeService.selectDictDataByType("book_risk_level");
-        //构造模板的value
-        StringBuilder content=new StringBuilder();
-        StringBuilder contentUserUnit=new StringBuilder();
-        StringBuilder contentUserWorkType=new StringBuilder();
-        //关联的申请流程
-        TApproveReserveInvoice tApproveReserveInvoice= tApproveReserveInvoiceService.selectTApproveReserveInvoiceByinvoiceId(ticket.getId().toString());
-       for(int i =0;i<tInvoiceWorkcontentList.size();i++){
-           TInvoiceWorkcontent tInvoiceWorkcontent=tInvoiceWorkcontentList.get(i);
-           //不为空的字段进行拼接
-           if(tInvoiceWorkcontent.getRiskLevel()!=null){
-               for (SysDictData p : book_risk_level) {
-                   if (tInvoiceWorkcontent.getRiskLevel().toString().equals(p.getDictValue())) {
-                       content.append("具体工作内容:"+tInvoiceWorkcontent.getWorkDescription()+" 区域:"+ticket.getWorkArea());//装置名称
-                       content.append(" 风险提醒:"+p.getDictLabel());
-                   }
-               }
-           }
-           params.put("content"+i, Texts.of(content.toString()).fontSize(10).bold().create());
-           //用户单位
-           if(ticket.getUserUnit()!=null){
-               for (SysDictData p : book_user_unit) {
-                   if (ticket.getUserUnit().toString().equals(p.getDictValue())) {
-                       contentUserUnit.append(p.getDictLabel());//用户单位
-                   }
-               }
-               if(!params.containsKey("userUnit")){
-                   params.put("userUnit", Texts.of(contentUserUnit.toString()).fontSize(10).bold().create());
-               }
-           }
-           //用户主管
-           if(ticket.getUserMg()!=null){
-               SysUser sysUser =sysUserService.selectUserById(ticket.getUserMg());
-               if(!params.containsKey("userMg")){
-                   params.put("userMg", Texts.of(sysUser.getNickName()).fontSize(10).bold().create());
-               }
-               if(!params.containsKey("userMg")){
-                   params.put("userNumber", Texts.of(sysUser.getPhonenumber()).fontSize(10).bold().create());
-               }
-           }
-           //承包商
-           if(ticket.getWorkUnit()!=null) {
-               if (!params.containsKey("workUnit")) {
-                   params.put("workUnit", Texts.of(ticket.getWorkUnit()).fontSize(10).bold().create());
-               }
-           }
-           //申请人
-           if(ticket.getContact()!=null) {
-               if (!params.containsKey("userName")) {
-                   params.put("userName", Texts.of(ticket.getContact()).fontSize(10).bold().create());
-               }
-           }
-           //作业类型
-           if(tInvoiceWorkcontent.getWorkType()!=null){
-               for (SysDictData p : book_work_type) {
-                   if (tInvoiceWorkcontent.getWorkType().toString().equals(p.getDictValue())) {
-                       contentUserWorkType.append(p.getDictLabel());//作业类型
-                   }
-               }
-               params.put("workType"+i, Texts.of(contentUserWorkType.toString()).fontSize(10).bold().create());
-           }
-           //作业开始时间
-           if(ticket.getWorkStartTime()!=null){
-               params.put("workStartTime",Texts.of(DateUtils.dateTime(ticket.getWorkStartTime())).fontSize(10).bold().create());
-           }
-           //作业结束时间
-           if(ticket.getWorkEndTime()!=null){
-               params.put("workEndTime",Texts.of(DateUtils.dateTime(ticket.getWorkEndTime())).fontSize(10).bold().create());
-           }
-           //关联票号
-           if(tInvoiceWorkcontent.getReservationNumber()!=null){
-               params.put("associated"+i, Texts.of(tInvoiceWorkcontent.getReservationNumber()).fontSize(10).bold().create());
-           }
-           //申请单编号
-           if (!params.containsKey("application")) {
-               params.put("application"+i, Texts.of(DateUtils.dateTimeNow()).fontSize(10).bold().create());
-           }
-           //暂定的批准日期
-           if(tApproveReserveInvoice.getEnddate()!=null) {
-               if (!params.containsKey("applyDate")) {
-                   params.put("applyDate", Texts.of(DateUtils.dateTime(tApproveReserveInvoice.getEnddate())).fontSize(10).bold().create());
-               }
-           }
-           //装置批准人
-           if(tApproveReserveInvoice.getDevSupId()!=null) {
-               if (!params.containsKey("zzUser")&&!params.containsKey("zjNumber")) {
-                   SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getDevSupId());
-                   params.put("zzUser", Texts.of(sysUser.getNickName()).fontSize(10).bold().create());
-                   params.put("zjNumber", Texts.of(sysUser.getPhonenumber()).fontSize(10).bold().create());
-               }
-           }
-           //装置工程师  如果涉及
-           if(tApproveReserveInvoice.getDevEngineerId()!=null) {
-               if (!params.containsKey("zjgcs")) {
-                   SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getDevEngineerId());
-                   params.put("zjgcs",sysUser.getSignUrl());
-               }
-           }
-           //装置经理(副)  如果涉及
-           if(tApproveReserveInvoice.getManagerconId()!=null) {
-               if (!params.containsKey("zzjl")) {
-                   SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getManagerconId());
-                   params.put("zzjl",sysUser.getSignUrl());
-               }
-           }
-           content.delete(0, content.length());
-           contentUserWorkType.delete(0, contentUserWorkType.length());
-       }
-        // 渲染文本
-        return params;
-    };
-
-    /**
-     * @param templatePath word模板文件路径
-     * @param fileDir      生成的文件存放地址
-     * @param fileName     生成的文件名
-     * @param paramMap     参数集合
-     * @return 返回word生成的路径
-     */
-    public String createWord(String templatePath, String fileDir, String fileName, Map<String, Object> paramMap) throws IOException {
-        Assert.notNull(templatePath, "word模板文件路径不能为空");
-        Assert.notNull(fileDir, "生成的文件存放地址不能为空");
-        Assert.notNull(fileName, "生成的文件名不能为空");
-        File dir = new File(fileDir);
-        if (!dir.exists()) {
-            logger.info("目录不存在,创建文件夹{}!", fileDir);
-            dir.mkdirs();
-        }
-        String filePath = fileDir +"/"+ fileName;
-        logger.info("目录{}!", filePath);
-        // 读取模板渲染参数
-        InputStream is = getClass().getClassLoader().getResourceAsStream(templatePath);
-        XWPFTemplate template = XWPFTemplate.compile(is).render(paramMap);
-        try {
-            // 将模板参数写入路径
-            template.writeToFile(filePath);
-            template.close();
-        } catch (Exception e) {
-            logger.error("生成word异常{}", e.getMessage());
-            e.printStackTrace();
-        }
-        String pathFileName = FileUploadUtils.getPathFileName(RuoYiConfig.getFilePath("/"+ "ticketWord"), fileName);
-        return pathFileName;
-    }
 }

+ 15 - 5
master/src/main/java/com/ruoyi/project/listener/invoiceApprove/InvoiceEndSuccessListener.java

@@ -200,7 +200,9 @@ public class InvoiceEndSuccessListener implements Serializable, ExecutionListene
             if(ticket.getUserMg()!=null){
                 SysUser sysUser =sysUserService.selectUserById(ticket.getUserMg());
                 if(!params.containsKey("userMg")){
-                    params.put("userMg", Texts.of(sysUser.getNickName()).fontSize(10).bold().create());
+                    if(sysUser.getSignUrl()!=null){
+                        params.put("userMg", fileName(sysUser.getSignUrl()));
+                    }
                 }
                 if(!params.containsKey("userNumber")){
                     params.put("userNumber", Texts.of(sysUser.getPhonenumber()).fontSize(10).bold().create());
@@ -216,7 +218,9 @@ public class InvoiceEndSuccessListener implements Serializable, ExecutionListene
             if(tApproveReserveInvoice.getUserId()!=null) {
                 if (!params.containsKey("userName")) {
                     SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getUserId());
-                    params.put("userName",fileName(sysUser.getSignUrl()));
+            if(sysUser.getSignUrl()!=null){
+                params.put("userName",fileName(sysUser.getSignUrl()));
+            }
                 }
             }
             //联系单位
@@ -263,7 +267,9 @@ public class InvoiceEndSuccessListener implements Serializable, ExecutionListene
             if(tApproveReserveInvoice.getDevSupId()!=null) {
                 if (!params.containsKey("zzUser")&&!params.containsKey("zjNumber")) {
                     SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getDevSupId());
-                    params.put("zzUser", Texts.of(sysUser.getNickName()).fontSize(10).bold().create());
+                    if(sysUser.getSignUrl()!=null){
+                        params.put("zzUser", fileName(sysUser.getSignUrl()));
+                    }
                     params.put("zjNumber", Texts.of(sysUser.getPhonenumber()).fontSize(10).bold().create());
                 }
             }
@@ -271,14 +277,18 @@ public class InvoiceEndSuccessListener implements Serializable, ExecutionListene
             if(tApproveReserveInvoice.getDevEngineerId()!=null) {
                 if (!params.containsKey("zjgcs")) {
                     SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getDevEngineerId());
-                    params.put("zjgcs",fileName(sysUser.getSignUrl()));
+                    if(sysUser.getSignUrl()!=null){
+                        params.put("zjgcs",fileName(sysUser.getSignUrl()));
+                    }
                 }
             }
             //装置经理(副)  如果涉及
             if(tApproveReserveInvoice.getManagerconId()!=null) {
                 if (!params.containsKey("zzjl")) {
                     SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getManagerconId());
-                    params.put("zzjl",fileName(sysUser.getSignUrl()));
+                    if(sysUser.getSignUrl()!=null){
+                        params.put("zzjl",fileName(sysUser.getSignUrl()));
+                    }
                 }
             }
             content.delete(0, content.length());

二進制
master/src/main/resources/static/word/invoice/book.docx