新建 文本文档

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

@Override

public String exportOrderTechList(HttpServletRequest request,


HttpServletResponse response, List<String> l1,Integer longType) throws MyException
{

List<File> files = new ArrayList<>();


String fileName="";
FileInputStream bis = null;
BufferedInputStream bs = null;
OutputStream os = null;
try {
for (String pkorder : l1) {

Integer pkcompany = GetCurUser.getCusBasicUser().getPkcompany();


/*P--获取技术交底_是否显示二维码,1=orderTechnical,2=orderTechnical_2(去除二
维码)*/
String modelname = getModelName(pkcompany);
//1.查询出主子表信息放入 word
MOrder mOrder = mOrderMapper.selectByPrimaryKey(pkorder);
List<MOrderDtl> mOrderDtlList =
mOrderDtlMapper.selectOrderDtlByPkOrder(pkorder);
List<MOrderAcessoriesTempPo> mOrderAcessoriesList =
morderdtlacessoriesMapper.selectAcessoriesOrderDtlByorder(pkorder);
Map<String, Object> map = new HashMap<>();
//填充主表
MBasicCustomer mBasicCustomer =
mBasicCustomerMapper.selectByPrimaryKey(mOrder.getPkcustomer());
String customer;
if (mBasicCustomer == null) {
customer = "无客户";
} else {
customer = mBasicCustomer.getCustomer();
}
/* 20201214 hmf 表头 customer 改为 comname 公司名称*/
String comname =
basicCompanyMapper.selectByPrimaryKey(pkcompany).getComname();
map.put("comname", comname);
map.put("customer", customer);
map.put("cusbillnobillno", mOrder.getCusbillno() + "/" +
mOrder.getBillno());
map.put("cusbillno", mOrder.getCusbillno());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
map.put("jiaohuodate", sdf.format(mOrder.getJiaohuodate()));
map.put("projectname", mOrder.getProjectname() + "/" +
mOrder.getXiangmuname());
String cuslinker = "";
if (mOrder.getCuslinker() != null && !"".equals(mOrder.getCuslinker()))
{
cuslinker = mOrder.getCuslinker() + "/";
}
String linktel = "";
if (mOrder.getLinktel() != null && !"".equals(mOrder.getLinktel())) {
linktel = mOrder.getLinktel();
}
map.put("cuslinker", cuslinker + linktel);
map.put("weight", new
DataConverUtil().roundByScale(mOrder.getWeight(),3));
map.put("createdate", sdf.format(mOrder.getCreatedate()));//下单时间
map.put("cusaddress", mOrder.getCusaddress());//交货地址
map.put("remark", mOrder.getRemark());//备注

map.put("approvecontent",mOrder.getApprovecontent()==null?"":mOrder.getApproveconte
nt());
/*hmf 20210416 添加审核时间,添加按照规格统计重量*/
if (null != mOrder.getApprovedate()) {
map.put("approvedate", sdf.format(mOrder.getApprovedate()));//审核时

} else {
map.put("approvedate", "");//审核时间
}
List<HashMap<String, Object>> listKey =
mOrderDtlMapper.selectOrderDtlSumCusliweightByPkOrder(pkorder);
for (int i = 0; i < listKey.size(); i++) {
HashMap<String, Object> hashMap = listKey.get(i);
if (hashMap.containsKey("diaweightbypkorder")) {
hashMap.put("diaweightbypkorder", new
DataConverUtil().roundByScale(((BigDecimal)
hashMap.get("diaweightbypkorder")).doubleValue(),3));
}
hashMap.put("no", i + 1);
}
map.put("listKey", listKey);//【导出技术交底】根据订单主键按照规格直径统计重量
//填充子表
/*p--导出技术交底【长度】使用方式(默认 2 方式计算后的长度):1=zlong(总长),
2=mlong(计算后的长度)*/
//Integer longValue = getMlongMode(pkcompany);
List<Map<String, Object>> list = new ArrayList<>();
List<Map<String,Object>> list1 = new ArrayList<>();
for (int i = 0; i < mOrderDtlList.size(); i++) {
MOrderDtl mOrderDtl = mOrderDtlList.get(i);
MBasicProduct mBasicProduct =
mBasicProductMapper.selectByPrimaryKey(mOrderDtl.getPkproduct());
if (mBasicProduct == null) {
int intindexno = mOrderDtlList.get(i).getDef20().intValue();
throw new MyException(EMError.DOWNLOAD_ERROR, "第" + intindexno
+ "号数据没有查到成品信息,无法导出");
}
MBasicDiameter mBasicDiameter =
mBasicDiameterMapper.selectByPrimaryKey(mOrderDtl.getCusdiameter());
MBasicSpec mBasicSpec =
mBasicSpecMapper.selectByPrimaryKey(mOrderDtl.getCusspec());
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("id", mOrderDtl.getDef20());
String cusno = "";
if (mOrderDtl.getCusno() == null) {
cusno = "无";
} else {
cusno = mOrderDtl.getCusno();
}
dataMap.put("cusno", cusno);
String cusspecdiameter = "";
String spec = "";
if (mBasicSpec != null) {
spec = mBasicSpec.getSpec();
cusspecdiameter = cusspecdiameter + spec;
}
String diameter = "";
if (mBasicDiameter != null) {
diameter =
CommonTool.doubleRemoveZeros(mBasicDiameter.getDiameter());
cusspecdiameter = cusspecdiameter + "-" + diameter;
}
dataMap.put("cusdiameter", diameter);
/*hmf 20210416 添加*/
dataMap.put("orderno", mOrderDtl.getDef20());//订单序号
dataMap.put("cusspecdiameter", cusspecdiameter);//规格-直接
dataMap.put("proname", "(" +
(mBasicProduct.getTuhao()==null?"":mBasicProduct.getTuhao()) + ")" +
mBasicProduct.getProname());
Integer mlong = mBasicProduct.getMlong();
if (longType.intValue() == 1) {
//结算技术交底,使用 zlong
mlong = mBasicProduct.getZlong();
}
dataMap.put("cuslong", CommonTool.numberFormat(mlong));
dataMap.put("neednum",
CommonTool.numberFormat(mOrderDtl.getNeednum()));
dataMap.put("cusliweight", new
DataConverUtil().roundByScale(mOrderDtl.getCusliweight(),3));
String goujianname = "";
if (mOrderDtl.getGoujianname() == null) {
goujianname = "/";
} else {
goujianname = mOrderDtl.getGoujianname() + "/";
;
}
if (mOrderDtl.getGoujianplace() != null) {
if (mOrderDtl.getGoujianplace().length() > 0) {
goujianname = goujianname + mOrderDtl.getGoujianplace();
}
}
dataMap.put("goujianname", goujianname);
//备注:判断产品备注和订单备注是否相同,不相同的话合并显示
String remark;
String productRemark = mBasicProduct.getRemark();
String orderDtlRemark = mOrderDtl.getRemark();
if (null == productRemark || "".equals(productRemark)) {
remark = orderDtlRemark;
} else {
remark = productRemark + "" + orderDtlRemark;
}
dataMap.put("remark", remark);
/*//查询图形表
MBasicChart mBasicChart =
mBasicChartMapper.selectByPrimaryKey(Integer.valueOf(mOrderDtl.getPkchart()));
//得到图片 base64
String imageBase = DrawCommon.paint1(mBasicChart.getChartpar());*/
//产品中获取图片 base64
String imgBase = new String(mBasicProduct.getDef1());
if (imgBase == null || imgBase.equals("")) {
imgBase =
mBasicProductService.getpicbase64(mBasicProduct.getDef9(),
mBasicProduct.getDef10(), mBasicProduct.getPkchart());
}
String[] split = imgBase.split(",");
if (split.length > 1) {
imgBase = split[1];
}
dataMap.put("imageBase", imgBase);
dataMap.put("imageIndex", i + 1);
/*根据产品主键获取二维码 base64*/
String qrCodeImageBase = getQRCode("CP", mOrderDtl.getPkproduct() +
"");
dataMap.put("QRCodeImageBase", qrCodeImageBase);

list.add(dataMap);
}
map.put("newList", list);
for(MOrderAcessoriesTempPo
mOrderAcessoriesTempPo :mOrderAcessoriesList){
Map<String, Object> dataMap = new HashMap<>();
String rawcode = mOrderAcessoriesTempPo.getRawcode()
==null?"":mOrderAcessoriesTempPo.getRawcode();
dataMap.put("rawcode",rawcode);
String rawname = mOrderAcessoriesTempPo.getRawname()
==null?"":mOrderAcessoriesTempPo.getRawname();
dataMap.put("rawname",rawname);
String spec = mOrderAcessoriesTempPo.getSpec()
==null?"":mOrderAcessoriesTempPo.getSpec();
dataMap.put("spec",spec);

dataMap.put("acessoriesnum",mOrderAcessoriesTempPo.getAcessoriesnum());
dataMap.put("acessoriesliweight", new
DataConverUtil().roundByScale(mOrderAcessoriesTempPo.getAcessoriesliweight(),3));;
String remark = mOrderAcessoriesTempPo.getRemark()
==null?"":mOrderAcessoriesTempPo.getRemark();
dataMap.put("remark",remark);
list1.add(dataMap);
}
map.put("newList1", list1);
//2.调用生成工具 orderTechnical2 orderTechnical
// fileName = customer + "-"+mOrder.getCusbillno()+"-"+
mOrder.getBillno()+ ".doc";

if (fileName.contains(customer)){

}else fileName += customer ;


File file = new ComPrintModel().createDoc2(request, response, map,
modelname, "doc");
// response.setHeader("Content-Disposition", "attachment;filename="
// .concat(String.valueOf(URLEncoder.encode(fileName, "UTF-
8"))));
files.add(file);
}
// 生成压缩文件
FileUtil fileUtil = new FileUtil();
//将文件打包到服务器指定路径
String jarpath = fileUtil.downLoadFiles(files);
//获取文件名
String realfilename = jarpath.substring(19, jarpath.length());
//获取文件名后缀
String ffHouZhui =
realfilename.substring(realfilename.lastIndexOf("."), realfilename.length());

//生成单个 新的文件名
fileName +=
GetCurUser.getCusBasicUser().getUsername().concat(DateUtil.getcurrDate()).concat(ff
HouZhui);
response.setHeader("Access-Control-Expose-Headers", "Content-
Disposition");
response.setCharacterEncoding("utf-8");
response.setHeader("content-type", "application/octet-stream");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename="
.concat(String.valueOf(URLEncoder.encode(fileName, "UTF-
8"))));
File file1 = new File(jarpath);
bis = new FileInputStream(file1);
bs = new BufferedInputStream(bis);
os = response.getOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = bs.read(buffer)) != -1) {
os.write(buffer, 0, len);
}

}catch (Exception e) {
throw new MyException(EMError.DOWNLOAD_ERROR, "文件导出下载异常");
} finally {
try {
if (bis != null) {
bis.close();
}
if (bs != null) {
bs.close();
}
if (os != null) {
os.flush();
os.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
}
// InputStream fin = new FileInputStream(file);
// ServletOutputStream out = null;
// response.setHeader("Access-Control-Expose-Headers", "Content-
Disposition");
// response.setCharacterEncoding("utf-8");
// response.setContentType("application/msword");
// // 设置浏览器以下载的方式处理该文件名
// String fileName = customer + "-"+mOrder.getCusbillno()+"-"+
mOrder.getBillno()+ ".doc";
// response.setHeader("Content-Disposition", "attachment;filename="
// .concat(String.valueOf(URLEncoder.encode(fileName, "UTF-
8"))));
// out = response.getOutputStream();
// byte[] buffer = new byte[512]; // 缓冲区
// int bytesToRead = -1;
// // 通过循环将读入的 Word 文件的内容输出到浏览器中
// while ((bytesToRead = fin.read(buffer)) != -1) {
// out.write(buffer, 0, bytesToRead);
// }
// out.close();

// } catch (IOException e) {
// e.printStackTrace();
// } catch (TemplateException e) {
// e.printStackTrace();
// } catch (Exception e) {
// e.printStackTrace();
// }

return "success";
}

You might also like