合同管理
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.core.web.page.TableDataInfo;
|
||||||
import com.bonus.common.security.utils.SecurityUtils;
|
import com.bonus.common.security.utils.SecurityUtils;
|
||||||
import com.bonus.material.book.domain.BookCarInfoDto;
|
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.OrderDetailCostReliefDto;
|
||||||
import com.bonus.material.order.domain.OrderDetailDto;
|
import com.bonus.material.order.domain.OrderDetailDto;
|
||||||
import com.bonus.material.order.domain.OrderInfoDto;
|
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.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.xwpf.usermodel.IBodyElement;
|
import org.apache.poi.xwpf.usermodel.*;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -48,6 +55,9 @@ public class OrderController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private OrderMapper orderMapper;
|
private OrderMapper orderMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BmContractService bmContractService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交预约车到订单
|
* 提交预约车到订单
|
||||||
*/
|
*/
|
||||||
|
|
@ -154,14 +164,18 @@ public class OrderController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "租赁协议(查看)")
|
@ApiOperation(value = "租赁协议(查看)")
|
||||||
@PostMapping("/leaseAgreement")
|
@GetMapping("/leaseAgreement")
|
||||||
public ResponseEntity<String> getleaseAgreement(@RequestParam("file") MultipartFile file,
|
public ResponseEntity<byte[]> getleaseAgreement(String orderId,
|
||||||
@RequestParam("orderId") String orderId,
|
Map<String, String> replacements) throws IOException {
|
||||||
@RequestParam Map<String, String> replacements) {
|
|
||||||
// 根据orderId获取订单信息
|
|
||||||
OrderInfoDto orderInfoDto = orderService.getAgreementByOrderId(orderId);
|
OrderInfoDto orderInfoDto = orderService.getAgreementByOrderId(orderId);
|
||||||
try (XWPFDocument document = new XWPFDocument(file.getInputStream())) {
|
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);
|
||||||
|
|
||||||
|
XWPFDocument document = new XWPFDocument(inputStream);
|
||||||
//订单日期
|
//订单日期
|
||||||
replacements.put("${orderTime}", orderInfoDto.getOrderTime().toString());
|
replacements.put("${orderTime}", orderInfoDto.getOrderTime().toString());
|
||||||
//装备所属公司
|
//装备所属公司
|
||||||
|
|
@ -171,7 +185,6 @@ public class OrderController extends BaseController {
|
||||||
//订单金额
|
//订单金额
|
||||||
replacements.put("${cost}", orderInfoDto.getCost().toString());
|
replacements.put("${cost}", orderInfoDto.getCost().toString());
|
||||||
|
|
||||||
// 遍历文档中的段落,进行占位符替换
|
|
||||||
for (IBodyElement element : document.getBodyElements()) {
|
for (IBodyElement element : document.getBodyElements()) {
|
||||||
if (element instanceof XWPFParagraph) {
|
if (element instanceof XWPFParagraph) {
|
||||||
XWPFParagraph paragraph = (XWPFParagraph) element;
|
XWPFParagraph paragraph = (XWPFParagraph) element;
|
||||||
|
|
@ -187,18 +200,25 @@ public class OrderController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将修改后的文档写入字节数组输出流
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
document.write(outputStream);
|
||||||
document.write(byteArrayOutputStream);
|
byte[] wordBytes = outputStream.toByteArray();
|
||||||
|
|
||||||
// 将字节数组转换为字符串(仅用于演示,实际应提供文件下载)
|
// Convert Word to Image (simple example using BufferedImage)
|
||||||
String content = byteArrayOutputStream.toString("UTF-8");
|
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();
|
||||||
|
|
||||||
return ResponseEntity.ok(content);
|
ByteArrayOutputStream imageOutputStream = new ByteArrayOutputStream();
|
||||||
} catch (IOException e) {
|
ImageIO.write(image, "png", imageOutputStream);
|
||||||
e.printStackTrace();
|
byte[] imageBytes = imageOutputStream.toByteArray();
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing file");
|
|
||||||
}
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.IMAGE_PNG);
|
||||||
|
return ResponseEntity.ok().headers(headers).body(imageBytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue