Browse Source

LY poi-tl

ly 3 years ago
parent
commit
b189608403

+ 1 - 1
master/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

@@ -140,7 +140,7 @@ public class FileUploadUtils
         return desc;
     }
 
-    private static final String getPathFileName(String uploadDir, String fileName) throws IOException
+    public static final String getPathFileName(String uploadDir, String fileName) throws IOException
     {
         int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
         String currentDir = StringUtils.substring(uploadDir, dirLastIndex);

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

@@ -1,16 +1,26 @@
 package com.ruoyi.project.invoice.controller;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.data.Texts;
 import com.ruoyi.common.utils.ServletUtils;
+import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.framework.config.RuoYiConfig;
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.framework.security.service.TokenService;
 import com.ruoyi.project.invoice.domain.TInvoiceContractor;
 import com.ruoyi.project.invoice.domain.TInvoiceWorkcontent;
 import com.ruoyi.project.invoice.service.ITInvoiceContractorService;
 import com.ruoyi.project.invoice.service.ITInvoiceWorkcontentService;
+import io.jsonwebtoken.lang.Assert;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -157,4 +167,50 @@ public class TInvoiceBookingworkticketController extends BaseController
     {
         return toAjax(tInvoiceBookingworkticketService.deleteTInvoiceBookingworkticketByIds(ids));
     }
+
+
+    /**
+     * 获取word数据
+     */
+    public Map<String, Object> getWordData (TInvoiceBookingworkticket ticket){
+        Map<String, Object> params = new HashMap<>();
+        // 渲染文本
+        params.put("contact", Texts.of(ticket.getContact().toString()).fontSize(12).bold().create());
+
+        return params;
+    };
+
+    /**
+     * @author lsc
+     * @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;
+    }
 }

+ 19 - 7
master/src/main/java/com/ruoyi/project/plant/controller/TStaffmgrController.java

@@ -495,13 +495,25 @@ public class TStaffmgrController extends BaseController
         if (!tStaffmgr.getTeam().equals("18")) {
             //非W班组人员
             TWorklicense tWorklicense = tWorklicenseService.selectTWorklicenseByEmployeeid(tStaffmgr.getStaffid());
-            tWorklicense.setPlantCode(tStaffmgr.getPlantCode());
-            tWorklicense.setClasses(tStaffmgr.getTeam());
-            tWorklicense.setName(tStaffmgr.getName());
-            tWorklicense.setEmployeeid(tStaffmgr.getStaffid());
-            tWorklicense.setPost(tStaffmgr.getActualpost());
-            tWorklicense.setDeptId(tStaffmgr.getDeptId());
-            tWorklicenseService.updateTWorklicense(tWorklicense);
+            if (tWorklicense == null){
+                TWorklicense newWorklicense = new TWorklicense();
+                newWorklicense.setPlantCode(tStaffmgr.getPlantCode());
+                newWorklicense.setClasses(tStaffmgr.getTeam());
+                newWorklicense.setName(tStaffmgr.getName());
+                newWorklicense.setEmployeeid(tStaffmgr.getStaffid());
+                newWorklicense.setPost(tStaffmgr.getActualpost());
+                newWorklicense.setDeptId(tStaffmgr.getDeptId());
+                tWorklicenseService.insertTWorklicense(newWorklicense);
+            }else {
+                tWorklicense.setPlantCode(tStaffmgr.getPlantCode());
+                tWorklicense.setClasses(tStaffmgr.getTeam());
+                tWorklicense.setName(tStaffmgr.getName());
+                tWorklicense.setEmployeeid(tStaffmgr.getStaffid());
+                tWorklicense.setPost(tStaffmgr.getActualpost());
+                tWorklicense.setDeptId(tStaffmgr.getDeptId());
+                tWorklicenseService.updateTWorklicense(tWorklicense);
+            }
+
         }
         return toAjax(tStaffmgrService.updateTStaffmgr(tStaffmgr));
     }

+ 1 - 1
master/src/main/resources/mybatis/plant/TStaffmgrMapper.xml

@@ -124,7 +124,7 @@
         </where>
         <!-- 数据范围过滤 -->
         ${params.dataScope}
-        ORDER BY s0.DICT_SORT, s1.DICT_SORT ,s.DICT_SORT
+        ORDER BY s0.DICT_SORT, s1.DICT_SORT ,s.DICT_SORT , d.staffid
     </select>
 
     <select id="selectAllTStaffmgrList" parameterType="TStaffmgr" resultMap="TStaffmgrResult">

+ 2 - 1
ui/src/views/plant/organization/index.vue

@@ -319,7 +319,8 @@ export default {
         }
 
         this.list1 = this.listToTree(this.list2)
-        // console.log(JSON.stringify(this.list1))
+        console.log(this.list1)
+        console.log(JSON.stringify(this.list1))
       })
     },
     listToTree(list) {