领用申请下载文档
This commit is contained in:
parent
21c0c50a92
commit
bbb6cc4a9a
|
|
@ -263,4 +263,6 @@ public class LeaseApplyInfo extends BaseEntity{
|
|||
@ApiModelProperty(value = "供应地点")
|
||||
private String supplierPlace;
|
||||
|
||||
@ApiModelProperty(value = "公司名称")
|
||||
private String companyName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,22 +11,44 @@ import com.bonus.common.log.annotation.SysLog;
|
|||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||
import com.bonus.material.common.annotation.PreventRepeatSubmit;
|
||||
import com.bonus.material.lease.domain.LeaseApplyDetails;
|
||||
import com.bonus.material.lease.domain.vo.LeaseApplyRequestVo;
|
||||
import com.bonus.material.lease.service.ILeaseApplyInfoService;
|
||||
import com.bonus.material.lease.service.ILeaseTaskService;
|
||||
import com.bonus.material.ma.domain.Type;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeVo;
|
||||
import com.bonus.material.ma.domain.vo.StandardConfigDetailsVo;
|
||||
import com.bonus.system.api.RemoteFileService;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
|
||||
import feign.Param;
|
||||
import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
|
||||
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.awt.Font;
|
||||
|
||||
/**
|
||||
* @author hay
|
||||
|
|
@ -41,6 +63,9 @@ public class LeaseTaskController extends BaseController {
|
|||
@Resource
|
||||
private ILeaseTaskService service;
|
||||
|
||||
@Resource
|
||||
private RemoteFileService sysFileService;
|
||||
|
||||
/**
|
||||
* 新增领用任务
|
||||
*/
|
||||
|
|
@ -195,4 +220,228 @@ public class LeaseTaskController extends BaseController {
|
|||
List<Type> listByMaType = service.getEquipmentThreeTypes();
|
||||
return success(listByMaType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 业务联系单pdf
|
||||
*/
|
||||
@ApiOperation(value = "业务联系单pdf")
|
||||
@GetMapping("/getCodePDF/{taskId}")
|
||||
public AjaxResult getCodePDF(@PathVariable("taskId") Long taskId, Map<String, String> replacements) throws IOException, ParseException {
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("template/yewu.docx");
|
||||
XWPFDocument document = new XWPFDocument(in);
|
||||
|
||||
LeaseApplyInfo info = service.getApplyInfo(taskId);
|
||||
|
||||
//订单日期
|
||||
replacements.put("${createTime}", String.valueOf(info.getCreateTime()));
|
||||
|
||||
//合同编号
|
||||
replacements.put("${createBy}", String.valueOf(info.getCreateBy()));
|
||||
|
||||
replacements.put("${unitName}", String.valueOf(info.getUnitName()));
|
||||
|
||||
// replacements.put("${leasePerson}", String.valueOf(info.getLeasePerson()));
|
||||
|
||||
replacements.put("${companyName}", String.valueOf(info.getCompanyName()));
|
||||
|
||||
replacements.put("${projectName}", String.valueOf(info.getProjectName()));
|
||||
|
||||
replacements.put("${phone}", String.valueOf(info.getPhone()));
|
||||
|
||||
replacements.put("${code}", String.valueOf(info.getCode()));
|
||||
|
||||
// 假设 info.getCreateTime() 返回的是 String 类型的日期时间
|
||||
SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
|
||||
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date1 = inputFormat.parse(String.valueOf(info.getCreateTime()));
|
||||
String startTime = outputFormat.format(date1);
|
||||
// 将 startTime 字符串转换为 LocalDate 对象
|
||||
LocalDate localDate = LocalDate.parse(startTime);
|
||||
// 提取年、月、日
|
||||
int year = localDate.getYear();
|
||||
int month = localDate.getMonthValue();
|
||||
int day = localDate.getDayOfMonth();
|
||||
|
||||
replacements.put("${year}", String.valueOf(year));
|
||||
|
||||
replacements.put("${month}", String.valueOf(month));
|
||||
|
||||
replacements.put("${day}", String.valueOf(day));
|
||||
|
||||
//填充订单详情到表格
|
||||
fillOrderTable(document, info);
|
||||
|
||||
//获取附件详情
|
||||
List<LeaseApplyDetails> details = service.getApplyDetails(taskId);
|
||||
|
||||
|
||||
//填充订单详情到表格
|
||||
fillOrderTableTwo(document, details);
|
||||
|
||||
// 将拼接的字符串放入替换的map中
|
||||
// replacements.put("${orderTable}", orderDetail.toString());
|
||||
|
||||
for (IBodyElement element : document.getBodyElements()) {
|
||||
if (element instanceof XWPFParagraph) {
|
||||
XWPFParagraph paragraph = (XWPFParagraph) element;
|
||||
for (XWPFRun run : paragraph.getRuns()) {
|
||||
String text = run.getText(0);
|
||||
if (text != null) {
|
||||
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
String entryValue = entry.getValue();
|
||||
if (entryValue == null) {continue;}
|
||||
text = text.replace(entry.getKey(), entryValue);
|
||||
}
|
||||
run.setText(text, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
document.write(outputStream);
|
||||
byte[] wordBytes = outputStream.toByteArray();
|
||||
// // 将 DOCX 转换为 PDF
|
||||
// ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();
|
||||
// try (XWPFDocument docxDocument = new XWPFDocument(new java.io.ByteArrayInputStream(wordBytes))) {
|
||||
// PdfOptions options = PdfOptions.create();
|
||||
// PdfConverter.getInstance().convert(docxDocument, pdfOutputStream, options);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// // 处理异常
|
||||
// }
|
||||
// byte[] pdfBytes = pdfOutputStream.toByteArray();
|
||||
|
||||
MultipartFile file = new MockMultipartFile("contract", "contract.docx", MediaType.APPLICATION_OCTET_STREAM_VALUE, wordBytes);
|
||||
// MultipartFile file = new MockMultipartFile("contract", "contract.pdf", MediaType.APPLICATION_PDF_VALUE, pdfBytes);
|
||||
|
||||
|
||||
return sysFileService.upload(file);
|
||||
}
|
||||
|
||||
private static void fillOrderTable(XWPFDocument document, LeaseApplyInfo info) {
|
||||
XWPFTable table = null;
|
||||
int headerRowIndex = 0; // 表头行索引
|
||||
int footerRowIndex = 0; // 合计行索引
|
||||
int cellCount = 0;
|
||||
try {
|
||||
// 获取第一个表格(假设模板中只有一个表格)
|
||||
table = document.getTables().get(0);
|
||||
Map<String, String> replacements = new HashMap<>();
|
||||
// 假设 info.getCreateTime() 返回的是 String 类型的日期时间
|
||||
SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
|
||||
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date1 = inputFormat.parse(String.valueOf(info.getCreateTime()));
|
||||
String startTime = outputFormat.format(date1);
|
||||
// 将 startTime 字符串转换为 LocalDate 对象
|
||||
LocalDate localDate = LocalDate.parse(startTime);
|
||||
// 提取年、月、日
|
||||
int year = localDate.getYear();
|
||||
int month = localDate.getMonthValue();
|
||||
int day = localDate.getDayOfMonth();
|
||||
|
||||
replacements.put("${year}", String.valueOf(year));
|
||||
|
||||
replacements.put("${month}", String.valueOf(month));
|
||||
|
||||
replacements.put("${day}", String.valueOf(day));
|
||||
replacements.put("${companyName}", String.valueOf(info.getCompanyName()));
|
||||
replacements.put("${leasePerson}", String.valueOf(info.getLeasePerson()));
|
||||
replacements.put("${unitName}", String.valueOf(info.getUnitName()));
|
||||
replacements.put("${projectName}", String.valueOf(info.getProjectName()));
|
||||
replacements.put("${phone}", String.valueOf(info.getPhone()));
|
||||
replacements.put("${code}", String.valueOf(info.getCode()));
|
||||
replacements.put("${createTime}", String.valueOf(info.getCreateTime()));
|
||||
replacements.put("${createBy}", String.valueOf(info.getCreateBy()));
|
||||
|
||||
// 遍历表格的每一行
|
||||
for (int i = 0; i < table.getNumberOfRows(); i++) {
|
||||
XWPFTableRow row = table.getRow(i);
|
||||
// 遍历行中的每个单元格
|
||||
for (int j = 0; j < row.getTableCells().size(); j++) {
|
||||
XWPFTableCell cell = row.getCell(j);
|
||||
// 遍历单元格中的每个段落
|
||||
for (XWPFParagraph paragraph : cell.getParagraphs()) {
|
||||
// 遍历段落中的每个运行对象
|
||||
for (XWPFRun run : paragraph.getRuns()) {
|
||||
String text = run.getText(0);
|
||||
if (text != null) {
|
||||
// 遍历替换映射
|
||||
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
String placeholder = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
if (text.contains(placeholder)) {
|
||||
// 替换占位符为实际值
|
||||
text = text.replace(placeholder, value);
|
||||
run.setText(text, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new RuntimeException("模板表处理异常,请检查合同信息");
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void fillOrderTableTwo(XWPFDocument document, List<LeaseApplyDetails> orderDetails) {
|
||||
XWPFTable table = null;
|
||||
int headerRowIndex = 0; // 表头行索引
|
||||
int footerRowIndex = 0; // 合计行索引
|
||||
int cellCount = 0;
|
||||
try {
|
||||
// 获取第一个表格(假设模板中只有一个表格)
|
||||
table = document.getTables().get(1);
|
||||
|
||||
// 保留第一行(表头)和最后一行(合计行),仅在中间插入数据行
|
||||
headerRowIndex = 0;
|
||||
footerRowIndex = table.getRows().size();
|
||||
|
||||
// 删除中间的所有行(如果有的话)
|
||||
for (int i = table.getRows().size() - 2; i > headerRowIndex; i--) {
|
||||
table.removeRow(i);
|
||||
}
|
||||
// 获取表头行的单元格数量
|
||||
cellCount = table.getRow(headerRowIndex).getTableCells().size();
|
||||
|
||||
// 遍历订单详情并动态插入数据行
|
||||
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new RuntimeException("模板表处理异常,请检查合同信息");
|
||||
}
|
||||
int num = orderDetails.size();
|
||||
for (LeaseApplyDetails detail : orderDetails) {
|
||||
XWPFTableRow newRow = table.insertNewTableRow(headerRowIndex + 1);
|
||||
|
||||
// 确保新行有足够数量的单元格
|
||||
while (newRow.getTableCells().size() < cellCount) {
|
||||
newRow.createCell();
|
||||
}
|
||||
int cellIndex = 0;
|
||||
// 序号
|
||||
newRow.getCell(cellIndex++).setText(String.valueOf(num));
|
||||
num--;
|
||||
|
||||
// 机具名称
|
||||
newRow.getCell(cellIndex++).setText(detail.getMaTypeName());
|
||||
String typeName = detail.getTypeName();
|
||||
// 规格型号
|
||||
newRow.getCell(cellIndex++).setText(typeName);
|
||||
// 单位
|
||||
newRow.getCell(cellIndex++).setText(detail.getUnitName());
|
||||
// 数量
|
||||
newRow.getCell(cellIndex++).setText(String.valueOf(detail.getPreNum()));
|
||||
// 备注
|
||||
newRow.getCell(cellIndex++).setText(detail.getRemark() );
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class LeaseDeptInfo extends BaseEntity {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 部门 */
|
||||
private Long dept_id;
|
||||
private Long deptId;
|
||||
|
||||
/** 父级id */
|
||||
@ApiModelProperty(value = "父级id")
|
||||
|
|
|
|||
|
|
@ -94,4 +94,8 @@ public interface LeaseTaskMapper {
|
|||
List<MaTypeVo> getListByTypeName(@Param("typeId") Long typeId);
|
||||
|
||||
void updateLeaseTaskStatus(@Param("taskId") Long taskId, @Param("taskStatus") int taskStatus);
|
||||
|
||||
LeaseApplyInfo getApplyInfo(Long taskId);
|
||||
|
||||
List<LeaseApplyDetails> getApplyDetails(Long taskId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.bonus.material.lease.service;
|
|||
|
||||
import com.bonus.common.biz.domain.lease.LeaseApplyInfo;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.lease.domain.LeaseApplyDetails;
|
||||
import com.bonus.material.lease.domain.vo.LeaseApplyRequestVo;
|
||||
import com.bonus.material.lease.domain.vo.LeaseDeptInfo;
|
||||
import com.bonus.material.ma.domain.Type;
|
||||
|
|
@ -87,5 +88,11 @@ public interface ILeaseTaskService {
|
|||
List<Type> getEquipmentThreeTypes();
|
||||
|
||||
List<MaTypeVo> getListByParentId(Long typeId);
|
||||
|
||||
|
||||
LeaseApplyInfo getApplyInfo(Long taskId);
|
||||
|
||||
|
||||
List<LeaseApplyDetails> getApplyDetails(Long taskId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,27 @@ public class LeaseTaskServiceImpl implements ILeaseTaskService {
|
|||
}
|
||||
leaseApplyRequestVo.getLeaseApplyInfo().setCreateTime(DateUtils.getNowDate());
|
||||
leaseApplyRequestVo.getLeaseApplyInfo().setCreateBy(SecurityUtils.getUsername());
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long deptId = mapper.getDeptIdByUserId(userId);
|
||||
LeaseDeptInfo leaseDeptInfo = new LeaseDeptInfo();
|
||||
leaseDeptInfo = mapper.getDeptIdByParentId(deptId);
|
||||
Long parentIdTemp = leaseDeptInfo.getParentId();
|
||||
String deptName = "";
|
||||
while (leaseDeptInfo != null) {
|
||||
parentIdTemp = leaseDeptInfo.getParentId();
|
||||
String ancestors = leaseDeptInfo.getAncestors();
|
||||
if (ancestors != null && StringUtils.countMatches(ancestors, ",") < 1) {
|
||||
break;
|
||||
}
|
||||
if (ancestors != null && StringUtils.countMatches(ancestors, ",") == 1) {
|
||||
deptName = leaseDeptInfo.getDeptName();
|
||||
break;
|
||||
}
|
||||
leaseDeptInfo = mapper.getDeptIdByParentId(parentIdTemp);
|
||||
}
|
||||
if(!deptName.equals("")){
|
||||
leaseApplyRequestVo.getLeaseApplyInfo().setCompanyId(leaseDeptInfo.getDeptId());
|
||||
}
|
||||
try {
|
||||
Integer statusFlag = leaseApplyRequestVo.getStatusFlag();
|
||||
// 根据状态标志选择合适的状态
|
||||
|
|
@ -479,4 +500,43 @@ public class LeaseTaskServiceImpl implements ILeaseTaskService {
|
|||
public List<MaTypeVo> getListByParentId(Long typeId) {
|
||||
return mapper.getListByTypeName(typeId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id查询领用任务信息
|
||||
*
|
||||
* @param taskId
|
||||
* @return 领用任务
|
||||
*/
|
||||
@Override
|
||||
public LeaseApplyInfo getApplyInfo(Long taskId) {
|
||||
try {
|
||||
LeaseApplyInfo leaseApplyInfo = new LeaseApplyInfo();
|
||||
leaseApplyInfo = mapper.getApplyInfo(taskId);
|
||||
return leaseApplyInfo;
|
||||
} catch (Exception e) {
|
||||
// 记录异常日志
|
||||
System.err.println("查看失败" + e.getMessage());
|
||||
throw new RuntimeException("失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
*
|
||||
* @param taskId
|
||||
* @return 领用任务
|
||||
*/
|
||||
@Override
|
||||
public List<LeaseApplyDetails> getApplyDetails(Long taskId) {
|
||||
try {
|
||||
|
||||
List<LeaseApplyDetails> list = mapper.getApplyDetails(taskId);
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
// 记录异常日志
|
||||
System.err.println("查看失败" + e.getMessage());
|
||||
throw new RuntimeException("失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -640,4 +640,29 @@
|
|||
</trim>
|
||||
where task_Id = #{taskId}
|
||||
</update>
|
||||
|
||||
<select id="getApplyInfo" resultType="com.bonus.common.biz.domain.lease.LeaseApplyInfo">
|
||||
select
|
||||
lai.code as code,lai.lease_person as leasePerson,lai.phone as phone,lai.create_by as createBy,
|
||||
lai.create_time as createTime,lai.supplier_time as supplierTime,lai.supplier_place as supplierPlace,
|
||||
bu.unit_name as unitName,bp.pro_name as projectName,lai.company_id as companyId,sd.dept_name as companyName
|
||||
|
||||
from lease_apply_info lai
|
||||
left join bm_unit bu on lai.unit_id = bu.unit_id
|
||||
left join bm_project bp on lai.project_id = bp.pro_id
|
||||
left join sys_dept sd on lai.company_id = sd.dept_id and sd.del_flag = 0
|
||||
where task_id = #{taskId} and bu.del_flag = 0 and bp.del_flag = 0
|
||||
</select>
|
||||
|
||||
<select id="getApplyDetails" resultType="com.bonus.material.lease.domain.LeaseApplyDetails">
|
||||
select
|
||||
lad.pre_num as preNum,lad.remark as remark,ma1.unit_name as unitName,ma1.type_name as typeName,
|
||||
ma2.type_name as maTypeName
|
||||
|
||||
from lease_apply_details lad
|
||||
left join lease_apply_info lai on lad.parent_id = lai.id
|
||||
left join ma_type ma1 on lad.type_id = ma1.type_id
|
||||
left join ma_type ma2 on ma1.parent_id = ma2.type_id
|
||||
where lai.task_id = #{taskId} and ma1.del_flag = 0 and ma2.del_flag = 0
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Binary file not shown.
27
pom.xml
27
pom.xml
|
|
@ -240,6 +240,7 @@
|
|||
<artifactId>bonus-api-system</artifactId>
|
||||
<version>${bonus.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
@ -255,6 +256,32 @@
|
|||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.3.22</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml-schemas</artifactId>
|
||||
<version>4.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-scratchpad</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.opensagres.xdocreport</groupId>
|
||||
<artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
|||
Loading…
Reference in New Issue