付款单模板,榜单导入 支持多种类型数据

product
chuang 2 years ago
parent 2ecd9e8553
commit 4b5b00d6e5

@ -84,6 +84,7 @@ public class WebFilterConfig implements WebMvcConfigurer {
list.add("/favicon.ico");
list.add("/api/info/exportPdf/**");
list.add("/api/info/getPaymentDocPdf/**");
return list;
}

@ -53,7 +53,7 @@ public class MobilePortController {
* @throws Exception
*/
@GetMapping(value = "/getPaymentDocPdf/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public void getPaymentDocPdf(HttpServletResponse response,@PathVariable("id") String id) {
public void getPaymentDocPdf(HttpServletResponse response,@PathVariable("id") String id) throws IOException {
String idd="410787543580384837";
paymentdocService.getPaymentDocPdf(idd);
}

@ -7,6 +7,7 @@ import jnpf.paymentdoc.entity.PaymentdocItem1Entity;
import jnpf.paymentdoc.entity.PaymentdocItem2Entity;
import jnpf.paymentdoc.model.paymentdoc.PaymentdocPagination;
import java.io.IOException;
import java.util.List;
/**
*
@ -39,5 +40,5 @@ public interface PaymentdocService extends IService<PaymentdocEntity> {
//列表子表数据方法
void getPaymentDocPdf(String id);
void getPaymentDocPdf(String id) throws IOException;
}

@ -6,9 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.config.ConfigValueUtil;
import jnpf.mobilePort.utils.ExportPdf;
import jnpf.mobilePort.utils.MultipartFileDto;
import jnpf.paymentdoc.entity.PaymentdocEntity;
import jnpf.paymentdoc.entity.PaymentdocItem0Entity;
import jnpf.paymentdoc.entity.PaymentdocItem1Entity;
@ -26,15 +24,17 @@ import jnpf.supplier.service.SupplierService;
import jnpf.util.ServletUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import lombok.Cleanup;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -362,46 +362,49 @@ public class PaymentdocServiceImpl extends ServiceImpl<PaymentdocMapper, Payment
return paymentdocItem2Service.list(queryWrapper);
}
@Resource
private ConfigValueUtil configValueUtil;
@Override
public void getPaymentDocPdf(String id) {
public void getPaymentDocPdf(String id) throws IOException {
List<PaymentdocItem2Entity> item2Entities = this.GetPaymentdocItem2List(id);
List<Map<String, Object>> paymentDocNodeInfo = paymentdocMapper.getPaymentDocNodeInfo(id);
String templateFilePath = configValueUtil.getTemplateFilePath() ;
// String templateFilePath = configValueUtil.getTemplateFilePath() +"paymentDocPdf//";
HashMap<String, Object> map = new HashMap<>();
map.put("reportList",paymentDocNodeInfo);
byte[] bytes = null;
ByteArrayOutputStream out = null;
ByteArrayOutputStream out = null;
ExportPdf exportPdf = new ExportPdf();
// word模板
try {
out = exportPdf.createPdf(map, "paymentDoc.ftl", "/templates/export");
bytes = out.toByteArray();
out.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
bytes = out.toByteArray();
String fileName = "2023年3月30日.pdf";
// fileName = URLEncoder.encode(fileName, "utf-8");
// 存在本地文件中
String fileName = "城市矿产请示.pdf";
MultipartFile file = null;
HttpServletResponse response = ServletUtil.getResponse();
response.reset();
String excelTitle = fileName;
String filen = null;
try {
@Cleanup InputStream inputStream = new ByteArrayInputStream(bytes);
file = new MultipartFileDto(ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);
// FileUtil.upFile(file, templateFilePath+"/wc/", fileName);
File f = new File(templateFilePath, fileName);
//将上传的文件存储到指定位置
file.transferTo(f);
filen = URLEncoder.encode(excelTitle, "UTF-8").replaceAll("\\+", "%20");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
// 设置response的Header
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + filen );
response.setContentType("application/x-download;charset=utf-8");
BufferedOutputStream toClient = null;
try {
toClient = new BufferedOutputStream(response.getOutputStream());
toClient.write(out.toByteArray());
toClient.flush();
toClient.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
log.warn("pdf文件生成成功");
}

@ -1459,7 +1459,12 @@ public class PurchaseorderitemServiceImpl extends ServiceImpl<PurchaseorderitemM
if (model.getPoundDate() != null && !model.getPoundDate().isEmpty() && !model.getPoundDate().equals("null")) {
// model.setCreatorTime(DateUtil.cstFormat(model.getCreatorTime()));
Date date = new SimpleDateFormat("yyyy.MM.dd").parse(model.getPoundDate());
Date date = null;
if (model.getPoundDate().contains(".")){
date = new SimpleDateFormat("yyyy.MM.dd").parse(model.getPoundDate());
}else if (model.getPoundDate().contains("-")){
date = new SimpleDateFormat("yyyy-MM-dd").parse(model.getPoundDate());
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
model.setPoundDate(formatter.format(date));
// 单位

Loading…
Cancel
Save