合同管理
This commit is contained in:
parent
512b95fddd
commit
44191194b3
|
|
@ -8,6 +8,8 @@ import com.bonus.common.core.web.domain.AjaxResult;
|
|||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.book.domain.BookCarInfoDto;
|
||||
import com.bonus.material.contract.domain.BmContract;
|
||||
import com.bonus.material.contract.service.BmContractService;
|
||||
import com.bonus.material.order.domain.OrderDetailCostReliefDto;
|
||||
import com.bonus.material.order.domain.OrderDetailDto;
|
||||
import com.bonus.material.order.domain.OrderInfoDto;
|
||||
|
|
@ -16,19 +18,24 @@ import com.bonus.material.order.service.OrderService;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.IBodyElement;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -48,6 +55,9 @@ public class OrderController extends BaseController {
|
|||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private BmContractService bmContractService;
|
||||
|
||||
/**
|
||||
* 提交预约车到订单
|
||||
*/
|
||||
|
|
@ -154,51 +164,61 @@ public class OrderController extends BaseController {
|
|||
}
|
||||
|
||||
@ApiOperation(value = "租赁协议(查看)")
|
||||
@PostMapping("/leaseAgreement")
|
||||
public ResponseEntity<String> getleaseAgreement(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("orderId") String orderId,
|
||||
@RequestParam Map<String, String> replacements) {
|
||||
// 根据orderId获取订单信息
|
||||
@GetMapping("/leaseAgreement")
|
||||
public ResponseEntity<byte[]> getleaseAgreement(String orderId,
|
||||
Map<String, String> replacements) throws IOException {
|
||||
OrderInfoDto orderInfoDto = orderService.getAgreementByOrderId(orderId);
|
||||
try (XWPFDocument document = new XWPFDocument(file.getInputStream())) {
|
||||
// 准备替换的占位符及其对应值
|
||||
//订单日期
|
||||
replacements.put("${orderTime}", orderInfoDto.getOrderTime().toString());
|
||||
//装备所属公司
|
||||
replacements.put("${czcompanyName}", orderInfoDto.getCzcompanyName());
|
||||
//承租方所属公司
|
||||
replacements.put("${companyName}", orderInfoDto.getCompanyName());
|
||||
//订单金额
|
||||
replacements.put("${cost}", orderInfoDto.getCost().toString());
|
||||
BmContract bmContract = new BmContract();
|
||||
bmContract.setStatus(1);
|
||||
List<BmContract> list = bmContractService.list(bmContract);
|
||||
String wordUrl = list.get(0).getBmFileInfoList().get(0).getFileUrl();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
InputStream inputStream = restTemplate.getForObject(wordUrl, InputStream.class);
|
||||
|
||||
// 遍历文档中的段落,进行占位符替换
|
||||
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()) {
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
run.setText(text, 0);
|
||||
XWPFDocument document = new XWPFDocument(inputStream);
|
||||
//订单日期
|
||||
replacements.put("${orderTime}", orderInfoDto.getOrderTime().toString());
|
||||
//装备所属公司
|
||||
replacements.put("${czcompanyName}", orderInfoDto.getCzcompanyName());
|
||||
//承租方所属公司
|
||||
replacements.put("${companyName}", orderInfoDto.getCompanyName());
|
||||
//订单金额
|
||||
replacements.put("${cost}", orderInfoDto.getCost().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()) {
|
||||
text = text.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
run.setText(text, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将修改后的文档写入字节数组输出流
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
document.write(byteArrayOutputStream);
|
||||
|
||||
// 将字节数组转换为字符串(仅用于演示,实际应提供文件下载)
|
||||
String content = byteArrayOutputStream.toString("UTF-8");
|
||||
// 注意:对于大文件,不建议将内容作为字符串返回。应提供下载链接或二进制文件响应。
|
||||
|
||||
return ResponseEntity.ok(content);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing file");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
document.write(outputStream);
|
||||
byte[] wordBytes = outputStream.toByteArray();
|
||||
|
||||
// Convert Word to Image (simple example using BufferedImage)
|
||||
BufferedImage image = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.setPaint(Color.white);
|
||||
graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
|
||||
graphics.setPaint(Color.black);
|
||||
graphics.drawString(new String(wordBytes), 10, 20);
|
||||
graphics.dispose();
|
||||
|
||||
ByteArrayOutputStream imageOutputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png", imageOutputStream);
|
||||
byte[] imageBytes = imageOutputStream.toByteArray();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.IMAGE_PNG);
|
||||
return ResponseEntity.ok().headers(headers).body(imageBytes);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue