@RequestMapping("exportHt")
public void exportHt(@RequestParam("fid") String fid, HttpServletResponse response) throws Exception {
if (StringUtils.isNotBlank(fid)) {
int fids = StringUtils.changeToInt(fid);
EsComOrder findByPrimaryKey = esComOrderService.findByPrimaryKey(fids);
List<EsComOrderDetails> listEsComOrderDetailsAjaxByOid = esComOrderDetailsService
.listEsComOrderDetailsAjaxByOid(fids);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("fid", StringUtils.changeToString(findByPrimaryKey.getFid()));
dataMap.put("fname", findByPrimaryKey.getOwnerName());
dataMap.put("date", DateFormatUtils.getSystemDateHMD());
dataMap.put("totalPrice", StringUtils.changeToString(findByPrimaryKey.getTotalAmount()));
dataMap.put("totalPriceK", MoneyUtils.change(Double.valueOf(findByPrimaryKey.getTotalAmount())));
dataMap.put("totalAmount", "1");
dataMap.put("customer", findByPrimaryKey.getCustomerName());
EsComOperator esComOperator = escomoperatorService.getOperatorByUserCode(findByPrimaryKey.getOwnerCode());
String signImage = ParamsUtils.pathForOSSOriginal(esComOperator.getSignImage());
String fprovince_code = esComOperator.getFprovince_code();
EsComDicProvinceUser esComDicProvinceUser = esComDicProvinceUserMapper.agentAKF(fprovince_code, "1");
String signImageOperator = null;
if (StringUtils.isNotBlank(esComDicProvinceUser)) {
String fuserCode = esComDicProvinceUser.getFuserCode();
EsComOperator operatorByUserCodes = esComOperatorMapper.getOperatorByUserCode(fuserCode);
signImageOperator = ParamsUtils.pathForOSSOriginal(operatorByUserCodes.getSignImage());
}
String newName = "";
// 图片
// String img = null;
// InputStream in;
// byte[] picdata = null;
//
// img = Base64.encodeBase64String(picdata);
// dataMap.put("image", img);
// 手签图片
if (StringUtils.isNotBlank(signImage)) {
String imgs = null;
InputStream ins;
StoreImage Blo = new StoreImage();
File url = Blo.insertBlobRemote(signImage);
byte[] picdatas = null;
try {
ins = new FileInputStream(url);
picdatas = new byte[ins.available()];
ins.read(picdatas);
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
imgs = Base64.encodeBase64String(picdatas);
dataMap.put("images", imgs);
}
// 客服手签图片
if (StringUtils.isNotBlank(signImageOperator)) {
String imgs = null;
InputStream ins;
StoreImage Blo = new StoreImage();
File url = Blo.insertBlobRemote(signImageOperator);
byte[] picdatas = null;
try {
ins = new FileInputStream(url);
picdatas = new byte[ins.available()];
ins.read(picdatas);
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
imgs = Base64.encodeBase64String(picdatas);
dataMap.put("image2", imgs);
}
String distributorCode = findByPrimaryKey.getDistributorCode();
if (StringUtils.isNotBlank(distributorCode)) {
EsComCustomer findCustomerByCodes = escomcustomerService.findCustomerByCodes(distributorCode);
dataMap.put("distributor", findCustomerByCodes.getFname());
dataMap.put("address", StringUtils.changeToString(findCustomerByCodes.getCompanyAddress()));
dataMap.put("phone", StringUtils.changeToString(findCustomerByCodes.getContactWay()));
dataMap.put("bank", StringUtils.changeToString(findCustomerByCodes.getOpenBank()));
dataMap.put("bankNo", StringUtils.changeToString(findCustomerByCodes.getOpenName()));
} else {
EsComCustomer findCustomerByCodes = escomcustomerService
.findCustomerByCodes(findByPrimaryKey.getCustomerCode());
dataMap.put("distributor", findCustomerByCodes.getFname());
dataMap.put("address", StringUtils.changeToString(findCustomerByCodes.getCompanyAddress()));
dataMap.put("phone", StringUtils.changeToString(findCustomerByCodes.getContactWay()));
dataMap.put("bank", StringUtils.changeToString(findCustomerByCodes.getOpenBank()));
dataMap.put("bankNo", StringUtils.changeToString(findCustomerByCodes.getOpenName()));
}
List<Map<String, Object>> sList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> sLists = new ArrayList<Map<String, Object>>();
String ftype = "1";
if (listEsComOrderDetailsAjaxByOid.size() > 5) {
// for (int i = 0; i < 5; i++) {
// Map<String, Object> dataMapsw = new HashMap<String, Object>();
// if (i == 0) {
// dataMapsw.put("name", "康复设备一批(详见清单)");
// } else {
// dataMapsw.put("name", "");
// }
// dataMapsw.put("model", "");
// dataMapsw.put("price", "");
// dataMapsw.put("amounts", StringUtils.changeToString(amounts));
// dataMapsw.put("totalPrice", StringUtils.changeToString(findByPrimaryKey.getTotalAmount()));
// dataMapsw.put("totalAmount", "");
// sList.add(dataMapsw);
// }
int amountInt = 0;
String amounts = amountInt + "";
for (int i = 0; i < listEsComOrderDetailsAjaxByOid.size(); i++) {
Map<String, Object> dataMapss = new HashMap<String, Object>();
dataMapss.put("name", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentName());
if ("翔宇能量波压力控制系统V1.0".equals(listEsComOrderDetailsAjaxByOid.get(i).getGoodsName())) {
newName += listEsComOrderDetailsAjaxByOid.get(i).getEquipmentName() + "、";
}
dataMapss.put("model", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentModel());
dataMapss.put("price",
StringUtils.changeToString(listEsComOrderDetailsAjaxByOid.get(i).getUnivalent()));
dataMapss.put("amount",
StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getAmount()));
dataMapss.put("totalPrice",
StringUtils.changeToString(listEsComOrderDetailsAjaxByOid.get(i).getTotalAmount()));
amountInt = Integer.parseInt(StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getAmount())) + amountInt;
sLists.add(dataMapss);
}
dataMap.put("name", "康复设备一批(详见清单)");
dataMap.put("model", "");
dataMap.put("price", "");
dataMap.put("amounts", StringUtils.changeToString(amountInt));
dataMap.put("totalPrice", StringUtils.changeToString(findByPrimaryKey.getTotalAmount()));
dataMap.put("totalAmount", "");
ftype = "2";
} else {
for (int i = 0; i < listEsComOrderDetailsAjaxByOid.size(); i++) {
Map<String, Object> dataMaps = new HashMap<String, Object>();
dataMaps.put("name", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentName());
if ("翔宇能量波压力控制系统V1.0".equals(listEsComOrderDetailsAjaxByOid.get(i).getGoodsName())) {
newName += listEsComOrderDetailsAjaxByOid.get(i).getEquipmentName() + "、";
}
// 本产品含"翔宇能量波压力控制系统V1.0"
dataMaps.put("model", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentModel());
dataMaps.put("price",
StringUtils.changeToString(listEsComOrderDetailsAjaxByOid.get(i).getUnivalent()));
dataMaps.put("amount",
StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getAmount()));
dataMaps.put("totalPrice",
StringUtils.changeToString(listEsComOrderDetailsAjaxByOid.get(i).getTotalAmount()));
sList.add(dataMaps);
}
for (int i = listEsComOrderDetailsAjaxByOid.size(); i < listEsComOrderDetailsAjaxByOid.size() + 1; i++) {
Map<String, Object> dataMaps = new HashMap<String, Object>();
if (i == listEsComOrderDetailsAjaxByOid.size()) {
dataMaps.put("name", "以下空白");
dataMaps.put("model", "");
dataMaps.put("price", "");
dataMaps.put("amount", "");
dataMaps.put("totalPrice", "");
}
// else {
// dataMaps.put("name", "");
// }
sList.add(dataMaps);
}
ftype = "1";
}
if (StringUtils.isNotBlank(newName)) {
newName = newName.substring(0, newName.length() - 1);
dataMap.put("newName", "说明:本合同中 " + newName + " 含“翔宇能量波压力控制系统V1.0”");
} else {
dataMap.put("newName", "");
}
dataMap.put("userList", sList);
dataMap.put("modelList", sLists);
configuration.setClassForTemplateLoading(this.getClass(), "/com/xiangyu/bigdata/xycom/util");
Template t = null;
try {
String fvalue;
if (StringUtils.isNotBlank(findByPrimaryKey.getPaymentCompanyCode())) {
fvalue = findByPrimaryKey.getPaymentCompanyCode();
} else {
List<EsComDicGlobal> globalByFgvalue5 = esComDicGlobalService.getEsComDicGlobalByFgvalue("PKORG");
fvalue = globalByFgvalue5.get(0).getFvalue();
}
//String fvalue = globalByFgvalue5.get(0).getFvalue();
if ("10101".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("zhengshionemNewPMS.ftl", "utf-8");
} else {
t = configuration.getTemplate("zhengshitwomNewPMS.ftl", "utf-8");
}
} else if ("1010102".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("ruihe.ftl", "utf-8");
} else {
t = configuration.getTemplate("ruihes.ftl", "utf-8");
}
} else if ("101010201".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("simate.ftl", "utf-8");
} else {
t = configuration.getTemplate("masites.ftl", "utf-8");
}
} else if ("1010105".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("jiayv.ftl", "utf-8");
} else {
t = configuration.getTemplate("jiayvs.ftl", "utf-8");
}
} else if ("1010106".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("beiruisi.ftl", "utf-8");
} else {
t = configuration.getTemplate("beiruisis.ftl", "utf-8");
}
} else if ("1010107".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("tuokai.ftl", "utf-8");
} else {
t = configuration.getTemplate("tuokais.ftl", "utf-8");
}
} else if ("1010108".equals(fvalue)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("maidier.ftl", "utf-8");
} else {
t = configuration.getTemplate("maidiers.ftl", "utf-8");
}
} else if ("1010109".equals(fvalue)) {
String fvalues;
if (StringUtils.isNotBlank(findByPrimaryKey.getPaymentCompanyCode())) {
fvalues = findByPrimaryKey.getPaymentCompanyCode();
if ("10101".equals(fvalues)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("ruibeita.ftl", "utf-8");
} else {
t = configuration.getTemplate("ruibeitas.ftl", "utf-8");
}
} else if ("1010109".equals(fvalues)) {
if ("1".equals(ftype)) {
t = configuration.getTemplate("ruibeita1.ftl", "utf-8");
} else {
t = configuration.getTemplate("ruibeita1s.ftl", "utf-8");
}
}
} else {
if ("1".equals(ftype)) {
t = configuration.getTemplate("ruibeita1.ftl", "utf-8");
} else {
t = configuration.getTemplate("ruibeita1s.ftl", "utf-8");
}
}
}
// if("10101".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("zhengshionemNewPMS.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("zhengshitwomNewPMS.ftl", "utf-8");
// }
// }else if("1010102".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("ruihe.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("ruihes.ftl", "utf-8");
// }
// }else if("101010201".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("simate.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("masites.ftl", "utf-8");
// }
// }else if("1010105".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("jiayv.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("jiayvs.ftl", "utf-8");
// }
// }else if("1010106".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("beiruisi.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("beiruisis.ftl", "utf-8");
// }
// }else if("1010108".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("maidier.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("maidiers.ftl", "utf-8");
// }
// }else if("1010109".equals(fvalue)) {
// if ("1".equals(ftype)) {
// t = configuration.getTemplate("ruibeita.ftl", "utf-8");
// } else {
// t = configuration.getTemplate("ruibeitas.ftl", "utf-8");
// }
// }
} catch (Exception e) {
e.printStackTrace();
}
response.resetBuffer();
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(findByPrimaryKey.getFid() + findByPrimaryKey.getTheme() + ".doc", "UTF-8"));
ServletOutputStream os = response.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "utf-8"));
try {
t.process(dataMap, bufferedWriter);
bufferedWriter.flush();
bufferedWriter.close();
os.close();
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequestMapping("exportHtToImage")
public void exportHtToImage(@RequestParam("fid") Integer fid, HttpServletResponse response) throws Exception {
EsComOrder findByPrimaryKey = esComOrderService.findByPrimaryKey(fid);
List<EsComOrderDetails> listEsComOrderDetailsAjaxByOid = esComOrderDetailsService
.listEsComOrderDetailsAjaxByOid(fid);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("fid", StringUtils.changeToString(findByPrimaryKey.getFid()));
dataMap.put("fname", findByPrimaryKey.getOwnerName());
dataMap.put("date", DateFormatUtils.getSystemDateHMD());
dataMap.put("totalPrice", StringUtils.removeXiaoShu(findByPrimaryKey.getTotalAmount()));
dataMap.put("totalPriceK", MoneyUtils.change(Double.valueOf(findByPrimaryKey.getTotalAmount())));
dataMap.put("totalAmount", "1");
dataMap.put("customer", findByPrimaryKey.getCustomerName());
// 图片
String img = null;
InputStream in;
byte[] picdata = null;
try {
in = new FileInputStream("D:/logo.jpg");
picdata = new byte[in.available()];
in.read(picdata);
in.close();
} catch (Exception e) {
e.printStackTrace();
}
img = Base64.encodeBase64String(picdata);
dataMap.put("image", img);
String distributorCode = findByPrimaryKey.getDistributorCode();
if (StringUtils.isNotBlank(distributorCode)) {
EsComCustomer findCustomerByCodes = escomcustomerService.findCustomerByCodes(distributorCode);
dataMap.put("distributor", findCustomerByCodes.getFname());
dataMap.put("address", StringUtils.changeToString(findCustomerByCodes.getCompanyAddress()));
dataMap.put("phone", StringUtils.changeToString(findCustomerByCodes.getContactWay()));
dataMap.put("bank", StringUtils.changeToString(findCustomerByCodes.getOpenBank()));
dataMap.put("bankNo", StringUtils.changeToString(findCustomerByCodes.getOpenName()));
} else {
EsComCustomer findCustomerByCodes = escomcustomerService
.findCustomerByCodes(findByPrimaryKey.getCustomerCode());
dataMap.put("distributor", findCustomerByCodes.getFname());
dataMap.put("address", StringUtils.changeToString(findCustomerByCodes.getCompanyAddress()));
dataMap.put("phone", StringUtils.changeToString(findCustomerByCodes.getContactWay()));
dataMap.put("bank", StringUtils.changeToString(findCustomerByCodes.getOpenBank()));
dataMap.put("bankNo", StringUtils.changeToString(findCustomerByCodes.getOpenName()));
}
List<Map<String, Object>> sList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> sLists = new ArrayList<Map<String, Object>>();
String ftype = "1";
if (listEsComOrderDetailsAjaxByOid.size() > 5) {
for (int i = 0; i < 5; i++) {
Map<String, Object> dataMapsw = new HashMap<String, Object>();
if (i == 0) {
dataMapsw.put("name", "康复设备一批(详见清单)");
} else {
dataMapsw.put("name", "");
}
dataMapsw.put("model", "");
dataMapsw.put("price", "");
dataMapsw.put("amount", "");
dataMapsw.put("totalPrice", "");
sList.add(dataMapsw);
}
for (int i = 0; i < listEsComOrderDetailsAjaxByOid.size(); i++) {
Map<String, Object> dataMapss = new HashMap<String, Object>();
dataMapss.put("name", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentName());
dataMapss.put("model", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentModel());
dataMapss.put("price", StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getUnivalent()));
dataMapss.put("amount", StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getAmount()));
dataMapss.put("totalPrice",
StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getTotalAmount()));
sLists.add(dataMapss);
}
ftype = "2";
} else {
for (int i = 0; i < listEsComOrderDetailsAjaxByOid.size(); i++) {
Map<String, Object> dataMaps = new HashMap<String, Object>();
dataMaps.put("name", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentName());
dataMaps.put("model", listEsComOrderDetailsAjaxByOid.get(i).getEquipmentModel());
dataMaps.put("price", StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getUnivalent()));
dataMaps.put("amount", StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getAmount()));
dataMaps.put("totalPrice",
StringUtils.removeXiaoShu(listEsComOrderDetailsAjaxByOid.get(i).getTotalAmount()));
sList.add(dataMaps);
}
for (int i = listEsComOrderDetailsAjaxByOid.size(); i < 5; i++) {
Map<String, Object> dataMaps = new HashMap<String, Object>();
if (i == listEsComOrderDetailsAjaxByOid.size()) {
dataMaps.put("name", "以下空白");
} else {
dataMaps.put("name", "");
}
dataMaps.put("model", "");
dataMaps.put("price", "");
dataMaps.put("amount", "");
dataMaps.put("totalPrice", "");
sList.add(dataMaps);
}
ftype = "1";
}
dataMap.put("userList", sList);
dataMap.put("modelList", sLists);
configuration.setClassForTemplateLoading(this.getClass(), "/com/xiangyu/bigdata/xycom/util");
Template t = null;
try {
if ("1".equals(ftype)) {
t = configuration.getTemplate("zhengshionew.ftl", "utf-8");
} else {
t = configuration.getTemplate("zhengshitwoe.ftl", "utf-8");
}
} catch (IOException e) {
e.printStackTrace();
}
response.resetBuffer();
response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment;filename="
+ URLEncoder.encode(findByPrimaryKey.getFid() + findByPrimaryKey.getTheme() + ".doc", "UTF-8"));
ServletOutputStream os = response.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os, "utf-8"));
try {
t.process(dataMap, bufferedWriter);
bufferedWriter.flush();
bufferedWriter.close();
os.close();
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}