|
@@ -17,6 +17,7 @@ import com.deepoove.poi.data.Texts;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
|
+import com.ruoyi.common.utils.SpringContextUtils;
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
import com.ruoyi.framework.config.RuoYiConfig;
|
|
import com.ruoyi.framework.config.RuoYiConfig;
|
|
@@ -382,6 +383,28 @@ public class TInvoiceBookingworkticketController extends BaseController
|
|
return AjaxResult.success(t);
|
|
return AjaxResult.success(t);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 票号生成文件
|
|
|
|
+ */
|
|
|
|
+ @GetMapping(value = "/assion{id}")
|
|
|
|
+ public AjaxResult assion(@PathVariable("id") Long id)
|
|
|
|
+ {
|
|
|
|
+ TInvoiceBookingworkticket tInvoiceBookingworkticket =tInvoiceBookingworkticketService.selectTInvoiceBookingworkticketById(id);
|
|
|
|
+ String url= null;
|
|
|
|
+ try {
|
|
|
|
+ url = PreView(id);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tInvoiceBookingworkticket.setFilename(url);
|
|
|
|
+ tInvoiceBookingworkticketService.updateTInvoiceBookingworkticket(tInvoiceBookingworkticket);
|
|
|
|
+ return AjaxResult.success(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 新增预约作业票台账
|
|
* 新增预约作业票台账
|
|
*/
|
|
*/
|
|
@@ -446,4 +469,248 @@ public class TInvoiceBookingworkticketController extends BaseController
|
|
{
|
|
{
|
|
return toAjax(tInvoiceBookingworkticketService.deleteTInvoiceBookingworkticketByIds(ids));
|
|
return toAjax(tInvoiceBookingworkticketService.deleteTInvoiceBookingworkticketByIds(ids));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param id 生成文件名
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String PreView(Long id) throws IOException {
|
|
|
|
+ ITInvoiceBookingworkticketService tInvoiceBookingworkticketService = (ITInvoiceBookingworkticketService) SpringContextUtils.getBean("tInvoiceBookingworkticketService");
|
|
|
|
+ //根据ID查询并生成
|
|
|
|
+ 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<>();
|
|
|
|
+ ITApproveReserveInvoiceService tApproveReserveInvoiceService = (ITApproveReserveInvoiceService) SpringContextUtils.getBean("tApproveReserveInvoiceService");
|
|
|
|
+ ISysUserService sysUserService = (ISysUserService) SpringContextUtils.getBean("sysUserService");
|
|
|
|
+ ISysDictTypeService iSysDictTypeService = (ISysDictTypeService) SpringContextUtils.getBean("sysDictTypeService");
|
|
|
|
+ ITInvoiceBookingworkticketService tInvoiceBookingworkticketService = (ITInvoiceBookingworkticketService) SpringContextUtils.getBean("tInvoiceBookingworkticketService");
|
|
|
|
+ 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(ticket.getWorkArea()+","+tInvoiceWorkcontent.getWorkDescription());//装置名称
|
|
|
|
+ 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")){
|
|
|
|
+ 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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //承包商
|
|
|
|
+ if(ticket.getWorkUnit()!=null) {
|
|
|
|
+ if (!params.containsKey("workUnit")) {
|
|
|
|
+ params.put("workUnit", Texts.of(ticket.getWorkUnit()).fontSize(10).bold().create());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //申请人签名
|
|
|
|
+ if(tApproveReserveInvoice.getUserId()!=null) {
|
|
|
|
+ if (!params.containsKey("userName")) {
|
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getUserId());
|
|
|
|
+ if(sysUser.getSignUrl()!=null){
|
|
|
|
+ params.put("userName",fileName(sysUser.getSignUrl()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //联系电话
|
|
|
|
+ if(tApproveReserveInvoice.getUserId()!=null) {
|
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getUserId());
|
|
|
|
+ String dName= sysUser.getPhonenumber();
|
|
|
|
+ //如果没有添加过 找到用户所属的部门添加进去
|
|
|
|
+ if (!params.containsKey("conUnit")) {
|
|
|
|
+ params.put("conUnit",Texts.of(dName).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", Texts.of(DateUtils.dateTimeNow()).fontSize(10).color("FF0000").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")) {
|
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getDevSupId());
|
|
|
|
+ if(sysUser.getSignUrl()!=null){
|
|
|
|
+ params.put("zzUser", fileName(sysUser.getSignUrl()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //装置批准人的电话
|
|
|
|
+ if (!params.containsKey("zjNumber")) {
|
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getDevSupId());
|
|
|
|
+ if(sysUser.getPhonenumber()!=null){
|
|
|
|
+ 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());
|
|
|
|
+ if(sysUser.getSignUrl()!=null){
|
|
|
|
+ params.put("zjgcs",fileName(sysUser.getSignUrl()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //批准日期
|
|
|
|
+ if (!params.containsKey("DateOne")) {
|
|
|
|
+ if(tApproveReserveInvoice.getEnddate()!=null) {
|
|
|
|
+ params.put("DateOne", Texts.of(DateUtils.dateTime(tApproveReserveInvoice.getEnddate())).fontSize(10).bold().create());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //装置经理(副) 如果涉及
|
|
|
|
+ if(tApproveReserveInvoice.getManagerconId()!=null) {
|
|
|
|
+ if (!params.containsKey("zzjl")) {
|
|
|
|
+ SysUser sysUser = sysUserService.selectUserById(tApproveReserveInvoice.getManagerconId());
|
|
|
|
+ if(sysUser.getSignUrl()!=null){
|
|
|
|
+ params.put("zzjl",fileName(sysUser.getSignUrl()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!params.containsKey("DateTwo")) {
|
|
|
|
+ if(tApproveReserveInvoice.getEnddate()!=null) {
|
|
|
|
+ params.put("DateTwo", Texts.of(DateUtils.dateTime(tApproveReserveInvoice.getEnddate())).fontSize(10).bold().create());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param
|
|
|
|
+ * @return 映射签名的文件名
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ public String fileName(String filepath) {
|
|
|
|
+ String newFilePath=filepath.replace("/profile","");
|
|
|
|
+ String pathName=RuoYiConfig.getProfile()+newFilePath;
|
|
|
|
+ return pathName;
|
|
|
|
+ }
|
|
}
|
|
}
|