This commit is contained in:
许允枞 2024-11-27 17:54:20 +08:00
parent bc9302e9c3
commit 0c1e3bcd7e
6 changed files with 159 additions and 1 deletions

View File

@ -32,6 +32,16 @@
<version>2.1.0-jdk8-snapshot</version>
<scope>compile</scope>
</dependency>
<!--word-->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -1,16 +1,22 @@
package cn.iocoder.yudao.module.inspection.controller;
import java.util.List;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.inspection.entity.InspectionInfo;
import cn.iocoder.yudao.module.inspection.entity.InspectionWorkNode;
import cn.iocoder.yudao.module.inspection.service.AppInspectionPartnerService;
import cn.iocoder.yudao.module.inspection.service.IInspectionInfoService;
import cn.iocoder.yudao.module.inspection.service.IInspectionWorkNodeService;
import cn.iocoder.yudao.module.inspection.vo.InspectionInfoVo;
import cn.iocoder.yudao.util.ExcelUtil;
//import cn.iocoder.yudao.util.WordUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.security.access.prepost.PreAuthorize;
@ -32,6 +38,8 @@ public class InspectionInfoController extends BaseController {
@Autowired
private IInspectionWorkNodeService inspectionWorkNodeService;
@Autowired
private AppInspectionPartnerService partnerList;
/**
* 查询请填写功能名称列表
@ -267,4 +275,62 @@ public class InspectionInfoController extends BaseController {
public CommonResult isExamine(){
return success(inspectionInfoService.isExamine());
}
/**
* 判断当前登陆人是否有重检重审退办理的权限app
* @return
*/
@GetMapping("getRoleList")
public CommonResult getRoleList(){
return success(inspectionInfoService.getRoleList());
}
@GetMapping("getWordContent")
public CommonResult getWordContent(InspectionInfo inspectionInfo) {
//根据工单id查询工单信息
InspectionInfoVo inspectionInfoVo = partnerList.inspectionDetail(inspectionInfo.getId());
InspectionInfo inspectionInfos = inspectionInfoService.selectInspectionInfoById(inspectionInfo.getId());
Map<String, Object> map = new HashMap<>();
Date endTime = inspectionInfos.getEndTime();
// 创建 Calendar 实例并设置时间
Calendar calendar = Calendar.getInstance();
calendar.setTime(endTime);
// 获取年
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1; // 月份从0开始所以需要加1
int day = calendar.get(Calendar.DAY_OF_MONTH);
map.put("vin", inspectionInfos.getCarIdNo());
map.put("day", day);
map.put("one","");
map.put("two","");
map.put("three","");
map.put("four","");
map.put("month", month);
map.put("year", year);
map.put("carNum", inspectionInfoVo.getCarNum());
map.put("userName", inspectionInfos.getBuyName());
//TODO 还差编号和检验报告编号 告知书编号规则8位行政区划号码+2位年份号码+4位顺序号例如51132201240009 暂时写死
StringBuilder sb = new StringBuilder();
sb.append("51132201");
//获取年份第二位
DateTime now = DateUtil.date();
String yearStr = DateUtil.format(now, "yy");
sb.append(yearStr);
sb.append("0001");//顺序号 暂时写死
map.put("id", "1111111111");
map.put("reportId", sb);
return success(map);
}
/**
* 根据模板导出word
*/
@PostMapping("/exportWord")
public CommonResult exportWord(HttpServletRequest request, HttpServletResponse response,@RequestBody Map map){
String str = UUID.randomUUID().toString()+".docx";
String name = inspectionInfoService.easyPoiExport("template/word/四川省超标排放汽车维护修理告知书.docx", str, map, request, response);
return CommonResult.success(name);
}
}

View File

@ -2,11 +2,14 @@ package cn.iocoder.yudao.module.inspection.service;
import cn.iocoder.yudao.module.inspection.entity.InspectionWorkNode;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionWorkNodeVo;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.iocoder.yudao.module.inspection.entity.InspectionInfo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@ -109,4 +112,12 @@ public interface IInspectionInfoService extends IService<InspectionInfo>
* @return
*/
Boolean isExamine();
/**
* 获取当前登陆人的角色列表
* @return
*/
List<RoleDO> getRoleList();
String easyPoiExport(String templatePath, String filename, Map<String, Object> data, HttpServletRequest request, HttpServletResponse response);
}

View File

@ -1,5 +1,10 @@
package cn.iocoder.yudao.module.inspection.service.impl;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
@ -9,9 +14,12 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
@ -19,6 +27,7 @@ import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.appBase.controller.admin.InspectionSocket;
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.infra.service.file.FileService;
import cn.iocoder.yudao.module.inspection.vo.DlInspectionWorkNodeVo;
import cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo;
import cn.iocoder.yudao.module.partner.service.IPartnerCustomerInfoService;
@ -48,13 +57,20 @@ import cn.iocoder.yudao.module.payment.entity.OrderInfo;
import cn.iocoder.yudao.module.payment.entity.OrderInfoDetail;
import cn.iocoder.yudao.module.shop.entity.ShopMallPartners;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static cn.iocoder.yudao.framework.common.config.CommonStr.USER_TYPE_CUS;
@ -99,6 +115,8 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
private InspectionSocket inspectionSocket;
@Resource
private RoleMapper roleMapper;
@Autowired
private FileService fileService;
/**
* 查询请填写功能名称
@ -555,4 +573,55 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
}
return false;
}
/**
* 获取当前登陆人的角色列表
*
* @return
*/
@Override
public List<RoleDO> getRoleList() {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
//获取当前登陆人的所有角色
List<UserRoleDO> userRoles = roleService.getByUserId(loginUser.getId());
List<Long> userRoleIds = userRoles.stream().map(UserRoleDO::getRoleId).collect(Collectors.toList());
return roleService.getRoleList(userRoleIds);
}
/**
* EasyPoi 替换数据 导出 word
* @param templatePath word模板地址
* @param filename 文件名称
* @param data 替换参数
* @param request
* @param response
*/
public String easyPoiExport(String templatePath, String filename, Map<String, Object> data, HttpServletRequest request, HttpServletResponse response) {
Assert.notNull(templatePath, "模板路径不能为空");
Assert.notNull(filename, "文件名称不能为空");
Assert.isTrue(filename.endsWith(".docx"), "文件名称仅支持docx格式");
try {
String userAgent = request.getHeader("user-agent").toLowerCase();
if (userAgent.contains("msie") || userAgent.contains("like gecko")) {
filename = URLEncoder.encode(filename, "UTF-8");
} else {
filename = new String(filename.getBytes("utf-8"), "ISO-8859-1");
}
XWPFDocument document = WordExportUtil.exportWord07(templatePath, data);
MultipartFile files = convertXWPFDocumentToMultipartFile(document, filename);
filename = fileService.createFile(files.getOriginalFilename(), "", IoUtil.readBytes(files.getInputStream()));
} catch (Exception e) {
e.printStackTrace();
}
return filename;
}
public static MultipartFile convertXWPFDocumentToMultipartFile(XWPFDocument document, String filename) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
document.write(bos);
byte[] bytes = bos.toByteArray();
return new MockMultipartFile(filename, filename, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", bytes);
}
}

View File

@ -90,4 +90,6 @@ public class InspectionInfoVo {
List<InspectionWorkNode> workNodes;
@TableField(exist = false)
private Long leadManId;
@TableField(exist = false)
private String skuName;
}