FeiYunUtils.java 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222
  1. package com.sqx.modules.utils.fieYun;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.sqx.modules.activity.service.ActivityService;
  5. import com.sqx.modules.activity.vo.ActivityOrderVO;
  6. import com.sqx.modules.activity.vo.ActivityVO;
  7. import com.sqx.modules.app.entity.UserEntity;
  8. import com.sqx.modules.app.service.UserService;
  9. import com.sqx.modules.common.service.CommonInfoService;
  10. import com.sqx.modules.coupon.entity.TbCoupon;
  11. import com.sqx.modules.coupon.entity.TbCouponUser;
  12. import com.sqx.modules.coupon.service.TbCouponService;
  13. import com.sqx.modules.goods.entity.GoodsShop;
  14. import com.sqx.modules.goods.service.GoodsShopService;
  15. import com.sqx.modules.order.entity.OrderGoods;
  16. import com.sqx.modules.order.entity.TbOrder;
  17. import com.sqx.modules.printInfo.entity.*;
  18. import com.sqx.modules.printInfo.service.PrintInfoService;
  19. import com.sqx.modules.printInfo.service.PrintInfoShopService;
  20. import com.sqx.modules.utils.fieYun.model.OrderForm;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.apache.commons.codec.digest.DigestUtils;
  23. import org.apache.commons.lang.StringUtils;
  24. import org.apache.http.HttpEntity;
  25. import org.apache.http.NameValuePair;
  26. import org.apache.http.client.config.RequestConfig;
  27. import org.apache.http.client.entity.UrlEncodedFormEntity;
  28. import org.apache.http.client.methods.CloseableHttpResponse;
  29. import org.apache.http.client.methods.HttpPost;
  30. import org.apache.http.impl.client.CloseableHttpClient;
  31. import org.apache.http.impl.client.HttpClients;
  32. import org.apache.http.message.BasicNameValuePair;
  33. import org.apache.http.util.EntityUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.stereotype.Component;
  36. import java.io.IOException;
  37. import java.math.BigDecimal;
  38. import java.text.SimpleDateFormat;
  39. import java.util.ArrayList;
  40. import java.util.List;
  41. import java.util.Optional;
  42. import java.util.stream.Collectors;
  43. @Component
  44. @Slf4j
  45. public class FeiYunUtils {
  46. private static ActivityService activityService;
  47. private static UserService userService;
  48. private static TbCouponService tbCouponService;
  49. private static GoodsShopService goodsShopService;
  50. private static CommonInfoService commonInfoService;
  51. private static PrintInfoShopService printInfoShopService;
  52. private static PrintInfoService printInfoService;
  53. @Autowired
  54. public void setActivityService(ActivityService activityService) {
  55. FeiYunUtils.activityService = activityService;
  56. }
  57. @Autowired
  58. public void setUserService(UserService userService) {
  59. FeiYunUtils.userService = userService;
  60. }
  61. @Autowired
  62. public void setTbCouponService(TbCouponService tbCouponService) {
  63. FeiYunUtils.tbCouponService = tbCouponService;
  64. }
  65. @Autowired
  66. public void setGoodsShopService(GoodsShopService goodsShopService) {
  67. FeiYunUtils.goodsShopService = goodsShopService;
  68. }
  69. @Autowired
  70. public void setCommonInfoService(CommonInfoService commonInfoService) {
  71. FeiYunUtils.commonInfoService = commonInfoService;
  72. }
  73. @Autowired
  74. public void setPrintInfoShopService(PrintInfoShopService printInfoShopService) {
  75. FeiYunUtils.printInfoShopService = printInfoShopService;
  76. }
  77. @Autowired
  78. public void setPrintInfoService(PrintInfoService printInfoService) {
  79. FeiYunUtils.printInfoService = printInfoService;
  80. }
  81. /**
  82. * 添加打印机接口
  83. *
  84. * @param snlist 提示:打印机编号(必填) # 打印机识别码(必填) # 备注名称(选填) # 流量卡号码(选填),多台打印机请换行(\n)添加新打印机信息,每次最多100行(台)。
  85. * @return 正确例子:{"msg":"ok","ret":0,"data":{"ok":["sn#key#remark#carnum","316500011#abcdefgh#快餐前台"],"no":["316500012#abcdefgh#快餐前台#13688889999 (错误:识别码不正确)"]},"serverExecutedTime":3}
  86. * 错误:{"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
  87. */
  88. public static String addprinter(String snlist) {
  89. String URL = commonInfoService.findOne(325).getValue();
  90. String USER = commonInfoService.findOne(326).getValue();
  91. String UKEY = commonInfoService.findOne(327).getValue();
  92. //通过POST请求,发送打印信息到服务器
  93. RequestConfig requestConfig = RequestConfig.custom()
  94. .setSocketTimeout(30000)//读取超时
  95. .setConnectTimeout(30000)//连接超时
  96. .build();
  97. CloseableHttpClient httpClient = HttpClients.custom()
  98. .setDefaultRequestConfig(requestConfig)
  99. .build();
  100. HttpPost post = new HttpPost(URL);
  101. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  102. nvps.add(new BasicNameValuePair("user", USER));
  103. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  104. nvps.add(new BasicNameValuePair("stime", STIME));
  105. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  106. nvps.add(new BasicNameValuePair("apiname", "Open_printerAddlist"));//固定值,不需要修改
  107. nvps.add(new BasicNameValuePair("printerContent", snlist));
  108. CloseableHttpResponse response = null;
  109. String result = null;
  110. try {
  111. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  112. response = httpClient.execute(post);
  113. int statecode = response.getStatusLine().getStatusCode();
  114. if (statecode == 200) {
  115. HttpEntity httpentity = response.getEntity();
  116. if (httpentity != null) {
  117. result = EntityUtils.toString(httpentity);
  118. }
  119. }
  120. } catch (Exception e) {
  121. e.printStackTrace();
  122. } finally {
  123. try {
  124. if (response != null) {
  125. response.close();
  126. }
  127. } catch (IOException e) {
  128. e.printStackTrace();
  129. }
  130. try {
  131. post.abort();
  132. } catch (Exception e) {
  133. e.printStackTrace();
  134. }
  135. try {
  136. httpClient.close();
  137. } catch (IOException e) {
  138. e.printStackTrace();
  139. }
  140. }
  141. return result;
  142. }
  143. /**
  144. * 修改打印机接口
  145. *
  146. * @param snlist 提示:打印机编号(必填) # 打印机识别码(必填) # 备注名称(选填) # 流量卡号码(选填),多台打印机请换行(\n)添加新打印机信息,每次最多100行(台)。
  147. * @return 正确例子:{"msg":"ok","ret":0,"data":{"ok":["sn#key#remark#carnum","316500011#abcdefgh#快餐前台"],"no":["316500012#abcdefgh#快餐前台#13688889999 (错误:识别码不正确)"]},"serverExecutedTime":3}
  148. * 错误:{"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
  149. */
  150. public static String updatePrinter(String snlist, String name) {
  151. String URL = commonInfoService.findOne(325).getValue();
  152. String USER = commonInfoService.findOne(326).getValue();
  153. String UKEY = commonInfoService.findOne(327).getValue();
  154. //通过POST请求,发送打印信息到服务器
  155. RequestConfig requestConfig = RequestConfig.custom()
  156. .setSocketTimeout(30000)//读取超时
  157. .setConnectTimeout(30000)//连接超时
  158. .build();
  159. CloseableHttpClient httpClient = HttpClients.custom()
  160. .setDefaultRequestConfig(requestConfig)
  161. .build();
  162. HttpPost post = new HttpPost(URL);
  163. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  164. nvps.add(new BasicNameValuePair("user", USER));
  165. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  166. nvps.add(new BasicNameValuePair("stime", STIME));
  167. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  168. nvps.add(new BasicNameValuePair("apiname", "Open_printerEdit"));//固定值,不需要修改
  169. nvps.add(new BasicNameValuePair("sn", snlist));
  170. nvps.add(new BasicNameValuePair("name", name));
  171. CloseableHttpResponse response = null;
  172. String result = null;
  173. try {
  174. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  175. response = httpClient.execute(post);
  176. int statecode = response.getStatusLine().getStatusCode();
  177. if (statecode == 200) {
  178. HttpEntity httpentity = response.getEntity();
  179. if (httpentity != null) {
  180. result = EntityUtils.toString(httpentity);
  181. }
  182. }
  183. } catch (Exception e) {
  184. e.printStackTrace();
  185. } finally {
  186. try {
  187. if (response != null) {
  188. response.close();
  189. }
  190. } catch (IOException e) {
  191. e.printStackTrace();
  192. }
  193. try {
  194. post.abort();
  195. } catch (Exception e) {
  196. e.printStackTrace();
  197. }
  198. try {
  199. httpClient.close();
  200. } catch (IOException e) {
  201. e.printStackTrace();
  202. }
  203. }
  204. return result;
  205. }
  206. /**
  207. * 删除打印机接口
  208. *
  209. * @param snlist 提示:打印机编号(必填) # 打印机识别码(必填) # 备注名称(选填) # 流量卡号码(选填),多台打印机请换行(\n)添加新打印机信息,每次最多100行(台)。
  210. * @return 正确例子:{"msg":"ok","ret":0,"data":{"ok":["sn#key#remark#carnum","316500011#abcdefgh#快餐前台"],"no":["316500012#abcdefgh#快餐前台#13688889999 (错误:识别码不正确)"]},"serverExecutedTime":3}
  211. * 错误:{"msg":"参数错误 : 该帐号未注册.","ret":-2,"data":null,"serverExecutedTime":37}
  212. */
  213. public static String deletePrinter(String snlist) {
  214. try {
  215. String URL = commonInfoService.findOne(325).getValue();
  216. String USER = commonInfoService.findOne(326).getValue();
  217. String UKEY = commonInfoService.findOne(327).getValue();
  218. //通过POST请求,发送打印信息到服务器
  219. RequestConfig requestConfig = RequestConfig.custom()
  220. .setSocketTimeout(30000)//读取超时
  221. .setConnectTimeout(30000)//连接超时
  222. .build();
  223. CloseableHttpClient httpClient = HttpClients.custom()
  224. .setDefaultRequestConfig(requestConfig)
  225. .build();
  226. HttpPost post = new HttpPost(URL);
  227. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  228. nvps.add(new BasicNameValuePair("user", USER));
  229. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  230. nvps.add(new BasicNameValuePair("stime", STIME));
  231. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  232. nvps.add(new BasicNameValuePair("apiname", "Open_printerDelList"));//固定值,不需要修改
  233. nvps.add(new BasicNameValuePair("snlist", snlist));
  234. CloseableHttpResponse response = null;
  235. String result = null;
  236. try {
  237. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  238. response = httpClient.execute(post);
  239. int statecode = response.getStatusLine().getStatusCode();
  240. if (statecode == 200) {
  241. HttpEntity httpentity = response.getEntity();
  242. if (httpentity != null) {
  243. result = EntityUtils.toString(httpentity);
  244. }
  245. }
  246. } catch (Exception e) {
  247. e.printStackTrace();
  248. } finally {
  249. try {
  250. if (response != null) {
  251. response.close();
  252. }
  253. } catch (IOException e) {
  254. e.printStackTrace();
  255. }
  256. try {
  257. post.abort();
  258. } catch (Exception e) {
  259. e.printStackTrace();
  260. }
  261. try {
  262. httpClient.close();
  263. } catch (IOException e) {
  264. e.printStackTrace();
  265. }
  266. }
  267. return result;
  268. } catch (Exception e) {
  269. e.printStackTrace();
  270. log.error("删除打印机异常:" + e.getMessage(), e);
  271. }
  272. return null;
  273. }
  274. /**
  275. * 小票机打印订单接口
  276. *
  277. * @param sn 打印机编号
  278. * @param classify 分类 1加油成功出票模版 2提货券推送模版 3加油订单结算模版 4商品消费结算
  279. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  280. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  281. */
  282. public static String print(String sn, Integer classify, TbOrder tbOrder, Integer isAppend) {
  283. try {
  284. //标签说明:
  285. //单标签:
  286. //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
  287. //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
  288. //成对标签:
  289. //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
  290. //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,""为右对齐
  291. //拼凑订单内容时可参考如下格式
  292. //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
  293. //region 以前的代码
  294. /*content = "<CB>测试打印</CB><BR>";
  295. content += "名称      单价 数量 金额<BR>";
  296. content += "--------------------------------<BR>";
  297. content += "饭       1.0 1 1.0<BR>";
  298. content += "炒饭      10.0 10 10.0<BR>";
  299. content += "蛋炒饭     10.0 10 100.0<BR>";
  300. content += "鸡蛋炒饭    100.0 1 100.0<BR>";
  301. content += "番茄蛋炒饭   1000.0 1 100.0<BR>";
  302. content += "西红柿蛋炒饭  1000.0 1 100.0<BR>";
  303. content += "西红柿鸡蛋炒饭 100.0 10 100.0<BR>";
  304. content += "备注:加辣<BR>";
  305. content += "--------------------------------<BR>";
  306. content += "合计:xx.0元<BR>";
  307. content += "送货地点:广州市南沙区xx路xx号<BR>";
  308. content += "联系电话:13888888888888<BR>";
  309. content += "订餐时间:2016-08-08 08:08:08<BR>";
  310. content += "<QR>http://www.dzist.com</QR>";*/
  311. //endregion
  312. //region 获取配置的打印模板信息 没设置的就正常不加粗
  313. GoodsShop shopData = goodsShopService.selectGoodDatas(tbOrder.getShopId());
  314. UserEntity parentUser = userService.selectUserById(tbOrder.getParentUserId());
  315. TbCoupon tbCoupon = tbCouponService.selectCoupon(tbOrder.getCouponId());
  316. ActivityOrderVO activity = tbOrder.getOrderId() == null ? null : activityService.selectByOrder(tbOrder.getOrderId());
  317. UserEntity user = userService.selectUserById(tbOrder.getUserId());//用户
  318. List<PrintModelResult> resultData = new ArrayList<>();
  319. List<PrintInfo> infos = printInfoService.printInfos();
  320. List<Integer> typeIds = infos.stream().map(PrintInfo::getTypeId).distinct().collect(Collectors.toList());
  321. PrintInfoShop pis = printInfoShopService.selectPrintInfoShopById(tbOrder.getShopId().intValue());
  322. if (pis == null) {
  323. for (Integer typeId : typeIds) {
  324. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == typeId.intValue()).collect(Collectors.toList());
  325. PrintModelResult data = new PrintModelResult();
  326. List<PrintModelDetailResult> details = new ArrayList<>();
  327. List<PrintModelTypeResult> types = new ArrayList<>();
  328. for (PrintInfo nowInfo : nowInfos) {
  329. PrintModelDetailResult detailData = new PrintModelDetailResult();
  330. detailData.setId(nowInfo.getId());
  331. detailData.setPrintField(nowInfo.getPrintField());
  332. detailData.setPrintName(nowInfo.getPrintName());
  333. detailData.setIsCheck(0);
  334. details.add(detailData);
  335. PrintModelTypeResult typeData = new PrintModelTypeResult();
  336. typeData.setId(nowInfo.getId());
  337. typeData.setIsBlod(0);
  338. typeData.setWordSize(0);
  339. typeData.setPrintField(nowInfo.getPrintField());
  340. typeData.setPrintName(nowInfo.getPrintName());
  341. types.add(typeData);
  342. }
  343. if (nowInfos != null && nowInfos.size() > 0) {
  344. data.setId(typeId);
  345. data.setName(nowInfos.get(0).getTypeName());
  346. }
  347. data.setDetails(details);
  348. data.setTypes(types);
  349. resultData.add(data);
  350. }
  351. } else {
  352. //要修改获取逻辑
  353. if (pis.getBaseInfo().isEmpty()) {
  354. PrintModelResult data = new PrintModelResult();
  355. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Base.getValue()).collect(Collectors.toList());
  356. List<PrintModelDetailResult> details = new ArrayList<>();
  357. List<PrintModelTypeResult> types = new ArrayList<>();
  358. for (PrintInfo nowInfo : nowInfos) {
  359. PrintModelDetailResult detailData = new PrintModelDetailResult();
  360. detailData.setId(nowInfo.getId());
  361. detailData.setPrintField(nowInfo.getPrintField());
  362. detailData.setPrintName(nowInfo.getPrintName());
  363. detailData.setIsCheck(0);
  364. details.add(detailData);
  365. PrintModelTypeResult typeData = new PrintModelTypeResult();
  366. typeData.setId(nowInfo.getId());
  367. typeData.setIsBlod(0);
  368. typeData.setWordSize(0);
  369. typeData.setPrintField(nowInfo.getPrintField());
  370. typeData.setPrintName(nowInfo.getPrintName());
  371. types.add(typeData);
  372. }
  373. data.setId(ePrintStatu.Base.getValue());
  374. data.setName(nowInfos.get(0).getTypeName());
  375. data.setDetails(details);
  376. data.setTypes(types);
  377. resultData.add(data);
  378. } else {
  379. ObjectMapper objectMapper = new ObjectMapper();
  380. PrintModelResult data = objectMapper.readValue(pis.getBaseInfo(), PrintModelResult.class);
  381. resultData.add(data);
  382. }
  383. if (pis.getGoodInfo().isEmpty()) {
  384. PrintModelResult data = new PrintModelResult();
  385. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Good.getValue()).collect(Collectors.toList());
  386. List<PrintModelDetailResult> details = new ArrayList<>();
  387. List<PrintModelTypeResult> types = new ArrayList<>();
  388. for (PrintInfo nowInfo : nowInfos) {
  389. PrintModelDetailResult detailData = new PrintModelDetailResult();
  390. detailData.setId(nowInfo.getId());
  391. detailData.setPrintField(nowInfo.getPrintField());
  392. detailData.setPrintName(nowInfo.getPrintName());
  393. detailData.setIsCheck(0);
  394. details.add(detailData);
  395. PrintModelTypeResult typeData = new PrintModelTypeResult();
  396. typeData.setId(nowInfo.getId());
  397. typeData.setIsBlod(0);
  398. typeData.setWordSize(0);
  399. typeData.setPrintField(nowInfo.getPrintField());
  400. typeData.setPrintName(nowInfo.getPrintName());
  401. types.add(typeData);
  402. }
  403. data.setId(ePrintStatu.Good.getValue());
  404. data.setName(nowInfos.get(0).getTypeName());
  405. data.setDetails(details);
  406. data.setTypes(types);
  407. resultData.add(data);
  408. } else {
  409. ObjectMapper objectMapper = new ObjectMapper();
  410. PrintModelResult data = objectMapper.readValue(pis.getGoodInfo(), PrintModelResult.class);
  411. resultData.add(data);
  412. }
  413. if (pis.getPayInfo().isEmpty()) {
  414. PrintModelResult data = new PrintModelResult();
  415. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Pay.getValue()).collect(Collectors.toList());
  416. List<PrintModelDetailResult> details = new ArrayList<>();
  417. List<PrintModelTypeResult> types = new ArrayList<>();
  418. for (PrintInfo nowInfo : nowInfos) {
  419. PrintModelDetailResult detailData = new PrintModelDetailResult();
  420. detailData.setId(nowInfo.getId());
  421. detailData.setPrintField(nowInfo.getPrintField());
  422. detailData.setPrintName(nowInfo.getPrintName());
  423. detailData.setIsCheck(0);
  424. details.add(detailData);
  425. PrintModelTypeResult typeData = new PrintModelTypeResult();
  426. typeData.setId(nowInfo.getId());
  427. typeData.setIsBlod(0);
  428. typeData.setWordSize(0);
  429. typeData.setPrintField(nowInfo.getPrintField());
  430. typeData.setPrintName(nowInfo.getPrintName());
  431. types.add(typeData);
  432. }
  433. data.setId(ePrintStatu.Pay.getValue());
  434. data.setName(nowInfos.get(0).getTypeName());
  435. data.setDetails(details);
  436. data.setTypes(types);
  437. resultData.add(data);
  438. } else {
  439. ObjectMapper objectMapper = new ObjectMapper();
  440. PrintModelResult data = objectMapper.readValue(pis.getPayInfo(), PrintModelResult.class);
  441. resultData.add(data);
  442. }
  443. if (pis.getUserInfo().isEmpty()) {
  444. PrintModelResult data = new PrintModelResult();
  445. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.User.getValue()).collect(Collectors.toList());
  446. List<PrintModelDetailResult> details = new ArrayList<>();
  447. List<PrintModelTypeResult> types = new ArrayList<>();
  448. for (PrintInfo nowInfo : nowInfos) {
  449. PrintModelDetailResult detailData = new PrintModelDetailResult();
  450. detailData.setId(nowInfo.getId());
  451. detailData.setPrintField(nowInfo.getPrintField());
  452. detailData.setPrintName(nowInfo.getPrintName());
  453. detailData.setIsCheck(0);
  454. details.add(detailData);
  455. PrintModelTypeResult typeData = new PrintModelTypeResult();
  456. typeData.setId(nowInfo.getId());
  457. typeData.setIsBlod(0);
  458. typeData.setWordSize(0);
  459. typeData.setPrintField(nowInfo.getPrintField());
  460. typeData.setPrintName(nowInfo.getPrintName());
  461. types.add(typeData);
  462. }
  463. data.setId(ePrintStatu.User.getValue());
  464. data.setName(nowInfos.get(0).getTypeName());
  465. data.setDetails(details);
  466. data.setTypes(types);
  467. resultData.add(data);
  468. } else {
  469. ObjectMapper objectMapper = new ObjectMapper();
  470. PrintModelResult data = objectMapper.readValue(pis.getUserInfo(), PrintModelResult.class);
  471. resultData.add(data);
  472. }
  473. }
  474. List<OrderGoods> orderGoodsList = tbOrder.getOrderGoodsList();
  475. StringBuilder stringBuilder = new StringBuilder();
  476. int max = Integer.parseInt(commonInfoService.findOne(420).getValue());
  477. for (int i = 0; i < max; i++) {
  478. //region 基本信息:平台名称 店铺名 订单号 送达时间 订单类型
  479. Optional<PrintModelResult> oBaseInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.Base.getValue()).findFirst();
  480. List<PrintModelTypeResult> baseTypes = oBaseInfo.get().getTypes();
  481. //region 平台名称
  482. String bplatformNameType_start = null;
  483. String bplatformNameType_end = null;
  484. //endregion
  485. //region 商铺名
  486. String bshopName_start = null;
  487. String bshopName_end = null;
  488. //endregion
  489. //region 订单类型
  490. String borderTypeExtra_start = null;
  491. String borderTypeExtra_end = null;
  492. //endregion
  493. //region 订单号
  494. String borderNumber_start = null;
  495. String borderNumber_end = null;
  496. //endregion
  497. StringBuilder baseStringBuilder = new StringBuilder();
  498. for (PrintModelTypeResult baseType : baseTypes) {
  499. StringBuilder start = new StringBuilder();
  500. StringBuilder end = new StringBuilder();
  501. if (baseType.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  502. start.append("<B>");
  503. end.append("</B>");
  504. }
  505. if (baseType.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  506. start.append("<BOLD>");
  507. end.append("</BOLD>");
  508. }
  509. int isCheck = 0;
  510. Optional<PrintModelDetailResult> oCheck = oBaseInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(baseType.getPrintField())).findFirst();
  511. if (oCheck != null && oCheck.isPresent()) {
  512. isCheck = oCheck.get().getIsCheck().intValue();
  513. }
  514. switch (baseType.getPrintField()) {
  515. case "platform_name":
  516. bplatformNameType_start = "<C>" + start.toString();
  517. bplatformNameType_end = end.toString() + "</C>";
  518. break;
  519. case "shop_name":
  520. bshopName_start = "<C>" + start.toString();
  521. bshopName_end = end.toString() + "</C>";
  522. break;
  523. case "order_type_extra":
  524. borderTypeExtra_start = start.toString();
  525. borderTypeExtra_end = end.toString();
  526. break;
  527. case "order_number":
  528. borderNumber_start = start.toString();
  529. borderNumber_end = end.toString();
  530. break;
  531. case "expect_delivery_time":
  532. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getExpectDeliveryTime() == null ? "即时送达" : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tbOrder.getExpectDeliveryTime())).append(end.toString()).append("<BR>");
  533. break;
  534. case "user_nick_name":
  535. if (isCheck == 1) {
  536. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  537. }
  538. break;
  539. case "shop_phone":
  540. if (isCheck == 1) {
  541. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  542. }
  543. break;
  544. case "distribution_distance_start":
  545. if (isCheck == 1) {
  546. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  547. }
  548. break;
  549. case "detailed_address":
  550. if (isCheck == 1) {
  551. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  552. }
  553. break;
  554. case "remark":
  555. if (isCheck == 1) {
  556. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getRemark()).append(end.toString()).append("<BR>");
  557. }
  558. break;
  559. case "shop_receiving_time":
  560. if (isCheck == 1) {
  561. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  562. }
  563. break;
  564. case "shop_id":
  565. if (isCheck == 1) {
  566. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  567. }
  568. break;
  569. case "parent_user_id":
  570. if (isCheck == 1) {
  571. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  572. }
  573. break;
  574. case "pay_money":
  575. if (isCheck == 1) {
  576. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPayMoney()).append("元").append(end.toString()).append("<BR>");
  577. }
  578. break;
  579. case "auto_send_order":
  580. if (isCheck == 1) {
  581. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  582. }
  583. break;
  584. case "errand_money":
  585. if (isCheck == 1) {
  586. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getErrandMoney()).append("元").append(end.toString()).append("<BR>");
  587. }
  588. break;
  589. case "pack_money":
  590. if (isCheck == 1) {
  591. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPackMoney()).append("元").append(end.toString()).append("<BR>");
  592. }
  593. break;
  594. case "order_code":
  595. if (isCheck == 1) {
  596. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  597. }
  598. break;
  599. case "pay_type":
  600. if (isCheck == 1) {
  601. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  602. }
  603. break;
  604. case "pay_time":
  605. if (isCheck == 1) {
  606. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPayTime()).append(end.toString()).append("<BR>");
  607. }
  608. break;
  609. case "create_time":
  610. if (isCheck == 1) {
  611. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  612. }
  613. break;
  614. case "address":
  615. if (isCheck == 1) {
  616. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  617. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  618. String addressDetail = jsonObject.getString("addressDetail");
  619. String city = jsonObject.getString("city");
  620. String district = jsonObject.getString("district");
  621. String province = jsonObject.getString("province");
  622. baseStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  623. }
  624. }
  625. break;
  626. case "phone":
  627. if (isCheck == 1) {
  628. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  629. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  630. String phone = jsonObject.getString("userPhone");
  631. baseStringBuilder.append(start.toString()).append(phone).append(end.toString()).append("<BR>");
  632. }
  633. }
  634. break;
  635. case "user_name":
  636. if (isCheck == 1) {
  637. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  638. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  639. String userName = jsonObject.getString("userName");
  640. baseStringBuilder.append(start.toString()).append(userName).append(end.toString()).append("<BR>");
  641. }
  642. }
  643. break;
  644. case "user_id"://显示isVip和vipExpirationTime
  645. if (isCheck == 1) {
  646. baseStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  647. baseStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  648. }
  649. break;
  650. case "coupon_id"://拿优惠券表中的优惠券名称
  651. if (isCheck == 1) {
  652. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  653. }
  654. break;
  655. case "activity_title"://通过订单ID去activity_part_record表中查到activity_id后再去activity表中获取活动标题
  656. if (isCheck == 1) {
  657. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(activity == null ? "" : activity.getTitle()).append(end.toString()).append("<BR>");
  658. }
  659. break;
  660. default:
  661. break;
  662. }
  663. }
  664. if (bplatformNameType_start != null) {
  665. stringBuilder.append(bplatformNameType_start).append("#").append(tbOrder.getOrderSequence()).append("-").append("墨轩云商").append(bplatformNameType_end);
  666. }
  667. if (bshopName_start != null) {
  668. stringBuilder.append(bshopName_start).append(tbOrder.getShopName()).append(bshopName_end);
  669. }
  670. if (borderTypeExtra_start != null) {
  671. stringBuilder.append(borderTypeExtra_start).append("类型:").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(borderTypeExtra_end).append("<BR>");
  672. }
  673. if (borderNumber_start != null) {
  674. stringBuilder.append(borderNumber_start).append("订单号:").append(tbOrder.getOrderNumber()).append(borderNumber_end).append("<BR>");
  675. }
  676. stringBuilder.append(baseStringBuilder.toString());
  677. //endregion
  678. stringBuilder.append("--------------------------------<BR>");
  679. //region 商品信息:商品名称 单价 数量 备注 金额
  680. //region 字号样式
  681. Optional<PrintModelResult> oGoodInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.Good.getValue()).findFirst();
  682. List<PrintModelTypeResult> goodTypes = oGoodInfo.get().getTypes();
  683. //region 商品名称
  684. String goods_name_start = null;
  685. String goods_name_end = null;
  686. //endregion
  687. //region 单价
  688. String goods_price_start = null;
  689. String goods_price_end = null;
  690. //endregion
  691. //region 数量
  692. String goods_num_start = null;
  693. String goods_num_end = null;
  694. //endregion
  695. //region 备注
  696. String remark_start = null;
  697. String remark_end = null;
  698. //endregion
  699. //region 金额
  700. String sum_money_start = null;
  701. String sum_money_end = null;
  702. //endregion
  703. StringBuilder goodStringBuilder = new StringBuilder();
  704. for (PrintModelTypeResult type : goodTypes) {
  705. StringBuilder start = new StringBuilder();
  706. StringBuilder end = new StringBuilder();
  707. if (type.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  708. start.append("<B>");
  709. end.append("</B>");
  710. }
  711. if (type.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  712. start.append("<BOLD>");
  713. end.append("</BOLD>");
  714. }
  715. int isCheck = 0;
  716. Optional<PrintModelDetailResult> oCheck = oGoodInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(type.getPrintField())).findFirst();
  717. if (oCheck != null && oCheck.isPresent()) {
  718. isCheck = oCheck.get().getIsCheck().intValue();
  719. }
  720. switch (type.getPrintField()) {
  721. case "goods_name":
  722. goods_name_start = start.toString();
  723. goods_name_end = end.toString();
  724. break;
  725. case "goods_price":
  726. goods_price_start = start.toString();
  727. goods_price_end = end.toString();
  728. break;
  729. case "goods_num":
  730. goods_num_start = start.toString();
  731. goods_num_end = end.toString();
  732. break;
  733. case "remark":
  734. remark_start = start.toString();
  735. remark_end = end.toString();
  736. break;
  737. case "sum_money":
  738. if (isCheck == 1) {
  739. sum_money_start = start.toString();
  740. sum_money_end = end.toString();
  741. }
  742. break;
  743. case "platform_name":
  744. if (isCheck == 1) {
  745. goodStringBuilder.append(start.toString()).append("#").append(tbOrder.getOrderSequence()).append("-").append("墨轩云商").append(end.toString());
  746. }
  747. break;
  748. case "shop_name":
  749. if (isCheck == 1) {
  750. goodStringBuilder.append(start.toString()).append(tbOrder.getShopName()).append(end.toString());
  751. }
  752. break;
  753. case "order_type_extra":
  754. if (isCheck == 1) {
  755. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(end.toString()).append("<BR>");
  756. }
  757. break;
  758. case "order_number":
  759. if (isCheck == 1) {
  760. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderNumber()).append(end.toString()).append("<BR>");
  761. }
  762. break;
  763. case "user_nick_name":
  764. if (isCheck == 1) {
  765. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  766. }
  767. break;
  768. case "shop_phone":
  769. if (isCheck == 1) {
  770. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  771. }
  772. break;
  773. case "distribution_distance_start":
  774. if (isCheck == 1) {
  775. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  776. }
  777. break;
  778. case "detailed_address":
  779. if (isCheck == 1) {
  780. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  781. }
  782. break;
  783. case "shop_receiving_time":
  784. if (isCheck == 1) {
  785. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  786. }
  787. break;
  788. case "shop_id":
  789. if (isCheck == 1) {
  790. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  791. }
  792. break;
  793. case "parent_user_id":
  794. if (isCheck == 1) {
  795. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  796. }
  797. break;
  798. case "pay_money":
  799. if (isCheck == 1) {
  800. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayMoney()).append("元").append(end.toString()).append("<BR>");
  801. }
  802. break;
  803. case "auto_send_order":
  804. if (isCheck == 1) {
  805. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  806. }
  807. break;
  808. case "errand_money":
  809. if (isCheck == 1) {
  810. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getErrandMoney()).append("元").append(end.toString()).append("<BR>");
  811. }
  812. break;
  813. case "pack_money":
  814. if (isCheck == 1) {
  815. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPackMoney()).append("元").append(end.toString()).append("<BR>");
  816. }
  817. break;
  818. case "order_code":
  819. if (isCheck == 1) {
  820. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  821. }
  822. break;
  823. case "pay_type":
  824. if (isCheck == 1) {
  825. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  826. }
  827. break;
  828. case "pay_time":
  829. if (isCheck == 1) {
  830. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayTime()).append(end.toString()).append("<BR>");
  831. }
  832. break;
  833. case "create_time":
  834. if (isCheck == 1) {
  835. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  836. }
  837. break;
  838. case "address":
  839. if (isCheck == 1) {
  840. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  841. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  842. String addressDetail = jsonObject.getString("addressDetail");
  843. String city = jsonObject.getString("city");
  844. String district = jsonObject.getString("district");
  845. String province = jsonObject.getString("province");
  846. goodStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  847. }
  848. }
  849. break;
  850. case "phone":
  851. if (isCheck == 1) {
  852. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  853. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  854. String phone = jsonObject.getString("userPhone");
  855. goodStringBuilder.append(start.toString()).append(phone).append(end.toString()).append("<BR>");
  856. }
  857. }
  858. break;
  859. case "user_name":
  860. if (isCheck == 1) {
  861. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  862. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  863. String userName = jsonObject.getString("userName");
  864. goodStringBuilder.append(start.toString()).append(userName).append(end.toString()).append("<BR>");
  865. }
  866. }
  867. break;
  868. case "user_id"://显示isVip和vipExpirationTime
  869. if (isCheck == 1) {
  870. goodStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  871. goodStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  872. }
  873. break;
  874. case "coupon_id"://拿优惠券表中的优惠券名称
  875. if (isCheck == 1) {
  876. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  877. }
  878. break;
  879. case "expect_delivery_time":
  880. if (isCheck == 1) {
  881. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getExpectDeliveryTime() == null ? "即时送达" : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tbOrder.getExpectDeliveryTime())).append(end.toString()).append("<BR>");
  882. }
  883. break;
  884. case "activity_title"://通过订单ID去activity_part_record表中查到activity_id后再去activity表中获取活动标题
  885. if (isCheck == 1) {
  886. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(activity == null ? "" : activity.getTitle()).append(end.toString()).append("<BR>");
  887. }
  888. break;
  889. default:
  890. break;
  891. }
  892. }
  893. //endregion
  894. if (goods_name_start != null) {
  895. stringBuilder.append(goods_name_start).append("名称").append(goods_name_end).append("    ");
  896. }
  897. if (goods_price_start != null) {
  898. stringBuilder.append(goods_price_start).append("单价").append(goods_price_end).append("  ");
  899. }
  900. if (goods_num_start != null) {
  901. stringBuilder.append(goods_num_start).append("数量").append(goods_num_end).append("  ");
  902. }
  903. if (sum_money_start != null) {
  904. stringBuilder.append(sum_money_start).append("金额").append(sum_money_end);
  905. }
  906. stringBuilder.append("<BR>");
  907. stringBuilder.append("--------------------------------<BR>");
  908. BigDecimal packMoney = BigDecimal.ZERO;
  909. BigDecimal goodsMoney = BigDecimal.ZERO;
  910. for (OrderGoods orderGoods : orderGoodsList) {
  911. BigDecimal sumMoney = orderGoods.getGoodsPrice().multiply(BigDecimal.valueOf(orderGoods.getGoodsNum()));
  912. BigDecimal sumPack = orderGoods.getGoodsPack().multiply(BigDecimal.valueOf(orderGoods.getGoodsNum()));
  913. packMoney = packMoney.add(sumPack);
  914. goodsMoney = goodsMoney.add(sumMoney);
  915. String name;
  916. if (StringUtils.isNotEmpty(orderGoods.getSkuMessage())) {
  917. name = orderGoods.getGoodsName() + "(" + orderGoods.getSkuMessage() + ")";
  918. } else {
  919. name = orderGoods.getGoodsName();
  920. }
  921. stringBuilder.append(goods_name_start).append(name).append(goods_name_end);
  922. stringBuilder.append("    ");
  923. stringBuilder.append(goods_price_start).append(orderGoods.getGoodsPrice()).append(goods_price_end);
  924. if (orderGoods.getGoodsPrice().doubleValue() < 10) {
  925. stringBuilder.append("  ");
  926. } else if (orderGoods.getGoodsPrice().doubleValue() < 100) {
  927. stringBuilder.append("  ");
  928. } else {
  929. stringBuilder.append("  ");
  930. }
  931. stringBuilder.append(goods_num_start).append("x" + orderGoods.getGoodsNum()).append(goods_num_end);
  932. stringBuilder.append("  ");
  933. if (sum_money_start != null) {
  934. stringBuilder.append(sum_money_start).append(sumMoney).append(sum_money_end);
  935. }
  936. stringBuilder.append("<BR>");
  937. //stringBuilder.append("<BR>");
  938. }
  939. stringBuilder.append("--------------------------------<BR>");
  940. String remark = tbOrder.getRemark();
  941. if (StringUtils.isEmpty(remark)) {
  942. remark = "";
  943. }
  944. stringBuilder.append(remark_start).append("备注:").append(remark).append(remark_end).append("<BR>");
  945. stringBuilder.append(goodStringBuilder.toString());
  946. //endregion
  947. stringBuilder.append("--------------------------------<BR>");
  948. //region 支付信息:打包费 商品费 优惠券 跑腿费 优惠活动 合计
  949. //region 字号样式
  950. Optional<PrintModelResult> oPayInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.Pay.getValue()).findFirst();
  951. List<PrintModelTypeResult> payTypes = oPayInfo.get().getTypes();
  952. //region 打包费
  953. String pack_money_start = null;
  954. String pack_money_end = null;
  955. //endregion
  956. //region 商品费
  957. String goods_money_start = null;
  958. String goods_money_end = null;
  959. //endregion
  960. //region 优惠券
  961. String coupon_money_start = null;
  962. String coupon_money_end = null;
  963. //endregion
  964. //region 跑腿费
  965. String errand_money_start = null;
  966. String errand_money_end = null;
  967. //endregion
  968. //region 优惠活动
  969. String activity_title_start = null;
  970. String activity_title_end = null;
  971. //endregion
  972. //region 合计
  973. String pay_money_start = null;
  974. String pay_money_end = null;
  975. //endregion
  976. StringBuilder payStringBuilder = new StringBuilder();
  977. for (PrintModelTypeResult type : payTypes) {
  978. StringBuilder start = new StringBuilder();
  979. StringBuilder end = new StringBuilder();
  980. if (type.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  981. start.append("<B>");
  982. end.append("</B>");
  983. }
  984. if (type.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  985. start.append("<BOLD>");
  986. end.append("</BOLD>");
  987. }
  988. int isCheck = 0;
  989. Optional<PrintModelDetailResult> oCheck = oPayInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(type.getPrintField())).findFirst();
  990. if (oCheck != null && oCheck.isPresent()) {
  991. isCheck = oCheck.get().getIsCheck().intValue();
  992. }
  993. switch (type.getPrintField()) {
  994. case "pack_money":
  995. pack_money_start = start.toString();
  996. pack_money_end = end.toString();
  997. break;
  998. case "goods_money":
  999. goods_money_start = start.toString();
  1000. goods_money_end = end.toString();
  1001. break;
  1002. case "coupon_money":
  1003. coupon_money_start = start.toString();
  1004. coupon_money_end = end.toString();
  1005. break;
  1006. case "errand_money":
  1007. errand_money_start = start.toString();
  1008. errand_money_end = end.toString();
  1009. break;
  1010. case "activity_title":
  1011. activity_title_start = start.toString();
  1012. activity_title_end = end.toString();
  1013. break;
  1014. case "pay_money":
  1015. pay_money_start = start.toString();
  1016. pay_money_end = end.toString();
  1017. break;
  1018. case "platform_name":
  1019. if (isCheck == 1) {
  1020. payStringBuilder.append(start.toString()).append("#").append(tbOrder.getOrderSequence()).append("-").append("墨轩云商").append(end.toString());
  1021. }
  1022. break;
  1023. case "shop_name":
  1024. if (isCheck == 1) {
  1025. payStringBuilder.append(start.toString()).append(tbOrder.getShopName()).append(end.toString());
  1026. }
  1027. break;
  1028. case "order_type_extra":
  1029. if (isCheck == 1) {
  1030. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(end.toString()).append("<BR>");
  1031. }
  1032. break;
  1033. case "order_number":
  1034. if (isCheck == 1) {
  1035. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderNumber()).append(end.toString()).append("<BR>");
  1036. }
  1037. break;
  1038. case "user_nick_name":
  1039. if (isCheck == 1) {
  1040. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  1041. }
  1042. break;
  1043. case "shop_phone":
  1044. if (isCheck == 1) {
  1045. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  1046. }
  1047. break;
  1048. case "distribution_distance_start":
  1049. if (isCheck == 1) {
  1050. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  1051. }
  1052. break;
  1053. case "detailed_address":
  1054. if (isCheck == 1) {
  1055. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  1056. }
  1057. break;
  1058. case "remark":
  1059. if (isCheck == 1) {
  1060. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getRemark()).append(end.toString()).append("<BR>");
  1061. }
  1062. break;
  1063. case "shop_receiving_time":
  1064. if (isCheck == 1) {
  1065. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  1066. }
  1067. break;
  1068. case "shop_id":
  1069. if (isCheck == 1) {
  1070. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  1071. }
  1072. break;
  1073. case "parent_user_id":
  1074. if (isCheck == 1) {
  1075. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  1076. }
  1077. break;
  1078. case "auto_send_order":
  1079. if (isCheck == 1) {
  1080. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  1081. }
  1082. break;
  1083. case "order_code":
  1084. if (isCheck == 1) {
  1085. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  1086. }
  1087. break;
  1088. case "pay_type":
  1089. if (isCheck == 1) {
  1090. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  1091. }
  1092. break;
  1093. case "pay_time":
  1094. if (isCheck == 1) {
  1095. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayTime()).append(end.toString()).append("<BR>");
  1096. }
  1097. break;
  1098. case "create_time":
  1099. if (isCheck == 1) {
  1100. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  1101. }
  1102. break;
  1103. case "address":
  1104. if (isCheck == 1) {
  1105. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1106. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1107. String addressDetail = jsonObject.getString("addressDetail");
  1108. String city = jsonObject.getString("city");
  1109. String district = jsonObject.getString("district");
  1110. String province = jsonObject.getString("province");
  1111. payStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  1112. }
  1113. }
  1114. break;
  1115. case "phone":
  1116. if (isCheck == 1) {
  1117. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1118. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1119. String phone = jsonObject.getString("userPhone");
  1120. payStringBuilder.append(start.toString()).append(phone).append(end.toString()).append("<BR>");
  1121. }
  1122. }
  1123. break;
  1124. case "user_name":
  1125. if (isCheck == 1) {
  1126. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1127. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1128. String userName = jsonObject.getString("userName");
  1129. payStringBuilder.append(start.toString()).append(userName).append(end.toString()).append("<BR>");
  1130. }
  1131. }
  1132. break;
  1133. case "user_id"://显示isVip和vipExpirationTime
  1134. if (isCheck == 1) {
  1135. payStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  1136. payStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  1137. }
  1138. break;
  1139. case "coupon_id"://拿优惠券表中的优惠券名称
  1140. if (isCheck == 1) {
  1141. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  1142. }
  1143. break;
  1144. case "expect_delivery_time":
  1145. if (isCheck == 1) {
  1146. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getExpectDeliveryTime() == null ? "即时送达" : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tbOrder.getExpectDeliveryTime())).append(end.toString()).append("<BR>");
  1147. }
  1148. break;
  1149. default:
  1150. break;
  1151. }
  1152. }
  1153. //endregion
  1154. stringBuilder.append(pack_money_start).append("打包费:").append(packMoney).append("元").append(pack_money_end + "<BR>");
  1155. stringBuilder.append(goods_money_start).append("商品费:").append(goodsMoney).append("元").append(goods_money_end + "<BR>");
  1156. if (tbOrder.getCouponMoney() != null) {
  1157. stringBuilder.append(coupon_money_start).append("优惠券:").append("-" + tbOrder.getCouponMoney()).append("元").append(coupon_money_end + "<BR>");
  1158. } else {
  1159. stringBuilder.append(coupon_money_start).append("优惠券:").append("-0").append("元").append(coupon_money_end + "<BR>");
  1160. }
  1161. BigDecimal errandMoney = tbOrder.getErrandMoney();
  1162. if (errandMoney == null) {
  1163. errandMoney = BigDecimal.ZERO;
  1164. }
  1165. BigDecimal errandMoneyT = errandMoney.setScale(2, BigDecimal.ROUND_HALF_UP);
  1166. stringBuilder.append(errand_money_start).append("跑腿费:").append(errandMoneyT).append("元").append(errand_money_end + "<BR>");
  1167. //从这个表里拿优惠活动 activity_part_record 活动参与记录表
  1168. stringBuilder.append(activity_title_start).append("优惠活动:").append(activity == null ? "" : activity.getTitle()).append(activity_title_end + "<BR>");
  1169. BigDecimal patMoney = tbOrder.getPayMoney().setScale(2, BigDecimal.ROUND_HALF_UP);
  1170. stringBuilder.append(pay_money_start).append("合计:").append(patMoney).append("元").append(pay_money_end + "<BR>");
  1171. stringBuilder.append(payStringBuilder.toString());
  1172. //endregion
  1173. stringBuilder.append("--------------------------------<BR>");
  1174. //region 用户信息:姓名 电话号 地址 订餐时间 商家联系电话
  1175. //region 字号样式
  1176. Optional<PrintModelResult> oUserInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.User.getValue()).findFirst();
  1177. List<PrintModelTypeResult> userTypes = oUserInfo.get().getTypes();
  1178. //region 姓名
  1179. String user_name_start = null;
  1180. String user_name_end = null;
  1181. //endregion
  1182. //region 电话号
  1183. String phone_start = null;
  1184. String phone_end = null;
  1185. //endregion
  1186. //region 地址
  1187. String address_detail_start = null;
  1188. String address_detail_end = null;
  1189. //endregion
  1190. //region 订餐时间
  1191. String pay_time_start = null;
  1192. String pay_time_end = null;
  1193. //endregion
  1194. StringBuilder userStringBuilder = new StringBuilder();
  1195. for (PrintModelTypeResult type : userTypes) {
  1196. StringBuilder start = new StringBuilder();
  1197. StringBuilder end = new StringBuilder();
  1198. if (type.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  1199. start.append("<B>");
  1200. end.append("</B>");
  1201. }
  1202. if (type.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  1203. start.append("<BOLD>");
  1204. end.append("</BOLD>");
  1205. }
  1206. int isCheck = 0;
  1207. Optional<PrintModelDetailResult> oCheck = oUserInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(type.getPrintField())).findFirst();
  1208. if (oCheck != null && oCheck.isPresent()) {
  1209. isCheck = oCheck.get().getIsCheck().intValue();
  1210. }
  1211. switch (type.getPrintField()) {
  1212. case "user_name":
  1213. user_name_start = start.toString();
  1214. user_name_end = end.toString();
  1215. break;
  1216. case "phone":
  1217. phone_start = start.toString();
  1218. phone_end = end.toString();
  1219. break;
  1220. case "address_detail":
  1221. address_detail_start = start.toString();
  1222. address_detail_end = end.toString();
  1223. break;
  1224. case "pay_time":
  1225. pay_time_start = start.toString();
  1226. pay_time_end = end.toString();
  1227. break;
  1228. case "platform_name":
  1229. if (isCheck == 1) {
  1230. userStringBuilder.append(start.toString()).append("#").append(tbOrder.getOrderSequence()).append("-").append("墨轩云商").append(end.toString());
  1231. }
  1232. break;
  1233. case "shop_name":
  1234. if (isCheck == 1) {
  1235. userStringBuilder.append(start.toString()).append(tbOrder.getShopName()).append(end.toString());
  1236. }
  1237. break;
  1238. case "order_type_extra":
  1239. if (isCheck == 1) {
  1240. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(end.toString()).append("<BR>");
  1241. }
  1242. break;
  1243. case "order_number":
  1244. if (isCheck == 1) {
  1245. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderNumber()).append(end.toString()).append("<BR>");
  1246. }
  1247. break;
  1248. case "user_nick_name":
  1249. if (isCheck == 1) {
  1250. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  1251. }
  1252. break;
  1253. case "shop_phone":
  1254. if (isCheck == 1) {
  1255. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  1256. }
  1257. break;
  1258. case "distribution_distance_start":
  1259. if (isCheck == 1) {
  1260. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  1261. }
  1262. break;
  1263. case "detailed_address":
  1264. if (isCheck == 1) {
  1265. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  1266. }
  1267. break;
  1268. case "remark":
  1269. if (isCheck == 1) {
  1270. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getRemark()).append(end.toString()).append("<BR>");
  1271. }
  1272. break;
  1273. case "shop_receiving_time":
  1274. if (isCheck == 1) {
  1275. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  1276. }
  1277. break;
  1278. case "shop_id":
  1279. if (isCheck == 1) {
  1280. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  1281. }
  1282. break;
  1283. case "parent_user_id":
  1284. if (isCheck == 1) {
  1285. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  1286. }
  1287. break;
  1288. case "pay_money":
  1289. if (isCheck == 1) {
  1290. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayMoney()).append("元").append(end.toString()).append("<BR>");
  1291. }
  1292. break;
  1293. case "auto_send_order":
  1294. if (isCheck == 1) {
  1295. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  1296. }
  1297. break;
  1298. case "errand_money":
  1299. if (isCheck == 1) {
  1300. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getErrandMoney()).append("元").append(end.toString()).append("<BR>");
  1301. }
  1302. break;
  1303. case "pack_money":
  1304. if (isCheck == 1) {
  1305. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPackMoney()).append("元").append(end.toString()).append("<BR>");
  1306. }
  1307. break;
  1308. case "order_code":
  1309. if (isCheck == 1) {
  1310. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  1311. }
  1312. break;
  1313. case "pay_type":
  1314. if (isCheck == 1) {
  1315. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  1316. }
  1317. break;
  1318. case "create_time":
  1319. if (isCheck == 1) {
  1320. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  1321. }
  1322. break;
  1323. case "address":
  1324. if (isCheck == 1) {
  1325. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1326. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1327. String addressDetail = jsonObject.getString("addressDetail");
  1328. String city = jsonObject.getString("city");
  1329. String district = jsonObject.getString("district");
  1330. String province = jsonObject.getString("province");
  1331. userStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  1332. }
  1333. }
  1334. break;
  1335. case "user_id"://显示isVip和vipExpirationTime
  1336. if (isCheck == 1) {
  1337. userStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  1338. userStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  1339. }
  1340. break;
  1341. case "coupon_id"://拿优惠券表中的优惠券名称
  1342. if (isCheck == 1) {
  1343. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  1344. }
  1345. break;
  1346. case "expect_delivery_time":
  1347. if (isCheck == 1) {
  1348. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getExpectDeliveryTime() == null ? "即时送达" : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tbOrder.getExpectDeliveryTime())).append(end.toString()).append("<BR>");
  1349. }
  1350. break;
  1351. case "activity_title"://通过订单ID去activity_part_record表中查到activity_id后再去activity表中获取活动标题
  1352. if (isCheck == 1) {
  1353. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(activity == null ? "" : activity.getTitle()).append(end.toString()).append("<BR>");
  1354. }
  1355. break;
  1356. default:
  1357. break;
  1358. }
  1359. }
  1360. //endregion
  1361. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1362. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1363. String addressDetail = jsonObject.getString("addressDetail");
  1364. String city = jsonObject.getString("city");
  1365. String district = jsonObject.getString("district");
  1366. String province = jsonObject.getString("province");
  1367. String userName = jsonObject.getString("userName");
  1368. String phone = jsonObject.getString("userPhone");
  1369. stringBuilder.append(user_name_start).append(userName).append(user_name_end).append("<BR>");
  1370. stringBuilder.append(phone_start).append(phone).append(phone_end).append("<BR>");
  1371. stringBuilder.append(address_detail_start).append(province).append(city).append(district).append(addressDetail).append(address_detail_end).append("<BR>");
  1372. } else {
  1373. stringBuilder.append(phone_start).append(tbOrder.getPhone()).append(phone_end).append("<BR>");
  1374. }
  1375. stringBuilder.append(pay_time_start).append("订餐时间:").append(tbOrder.getPayTime()).append(pay_time_end).append("<BR>");
  1376. stringBuilder.append(userStringBuilder);
  1377. stringBuilder.append("<BR>");
  1378. //String returnNo = getDigitBarCode();
  1379. //sb.append("<BC128_C>"+returnNo+"</BC128_C>");
  1380. stringBuilder.append("<CB><QR>").append(tbOrder.getOrderId()).append("</QR></CB>");
  1381. stringBuilder.append("<CB>收单码:").append(tbOrder.getOrderId()).append("</CB>");
  1382. stringBuilder.append("<BR>").append("<BR>").append("<BR>");
  1383. stringBuilder.append("<CUT>");
  1384. //endregion
  1385. }
  1386. String content = stringBuilder.toString();
  1387. doRequest(sn, content, tbOrder.getStatus(), isAppend);
  1388. } catch (Exception e) {
  1389. e.printStackTrace();
  1390. log.error("打印异常:" + e.getMessage(), e);
  1391. }
  1392. return null;
  1393. }
  1394. /**
  1395. * 小票机打印订单接口
  1396. *
  1397. * @param sn 打印机编号
  1398. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  1399. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1400. */
  1401. public static String returnPrint(String sn, TbOrder tbOrder) {
  1402. try {
  1403. StringBuilder sb = new StringBuilder();
  1404. sb.append("<AUDIO-REFUND>");
  1405. sb.append("<C>墨轩云商</C>");
  1406. sb.append("<CB>");
  1407. sb.append("#").append(tbOrder.getOrderSequence()).append("<BR>");
  1408. sb.append("用户已取消,请勿继续配送<BR>");
  1409. sb.append("<BR>");
  1410. sb.append("<CUT>");
  1411. doRequest(sn, sb.toString(),5,null);
  1412. } catch (Exception e) {
  1413. e.printStackTrace();
  1414. log.error("退款小票打印失败:{},{}" + e.getMessage(), e);
  1415. }
  1416. return null;
  1417. }
  1418. private static void doRequest(String sn, String content, Integer status, Integer isAppend) {
  1419. RequestConfig requestConfig = RequestConfig.custom()
  1420. .setSocketTimeout(30000)//读取超时
  1421. .setConnectTimeout(30000)//连接超时
  1422. .build();
  1423. try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build()) {
  1424. String url = commonInfoService.findOne(325).getValue();
  1425. String user = commonInfoService.findOne(326).getValue();
  1426. String uKey = commonInfoService.findOne(327).getValue();
  1427. HttpPost post = new HttpPost(url);
  1428. List<NameValuePair> nameValuePairs = new ArrayList<>();
  1429. String sTime = String.valueOf(System.currentTimeMillis() / 1000);
  1430. nameValuePairs.add(new BasicNameValuePair("user", user));
  1431. nameValuePairs.add(new BasicNameValuePair("stime", sTime));
  1432. nameValuePairs.add(new BasicNameValuePair("sig", signature(user, uKey, sTime)));
  1433. nameValuePairs.add(new BasicNameValuePair("apiname", "Open_printMsg"));
  1434. nameValuePairs.add(new BasicNameValuePair("sn", sn));
  1435. nameValuePairs.add(new BasicNameValuePair("content", content));
  1436. nameValuePairs.add(new BasicNameValuePair("times", "1"));
  1437. post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "utf-8"));
  1438. CloseableHttpResponse response = httpClient.execute(post);
  1439. int stateCode = response.getStatusLine().getStatusCode();
  1440. if (stateCode == 200) {
  1441. HttpEntity httpentity = response.getEntity();
  1442. String result = "";
  1443. if (httpentity != null) {
  1444. result = EntityUtils.toString(httpentity);
  1445. }
  1446. log.info("打印请求成功,打印机sn:{},打印内容:{},响应结果:{}", sn, content, result);
  1447. } else {
  1448. log.error("打印请求失败,响应码为:{}", stateCode);
  1449. }
  1450. } catch (Exception e) {
  1451. log.error("打印请求失败,失败原因:{}", e.getMessage());
  1452. }
  1453. }
  1454. /**
  1455. * 小票机打印订单接口
  1456. *
  1457. * @param sn 打印机编号
  1458. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  1459. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1460. */
  1461. public static String testPrint(String sn) {
  1462. try {
  1463. //标签说明:
  1464. //单标签:
  1465. //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
  1466. //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
  1467. //成对标签:
  1468. //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
  1469. //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,""为右对齐
  1470. //拼凑订单内容时可参考如下格式
  1471. //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
  1472. log.info("utils方法打印开始");
  1473. //region 以前的代码
  1474. String content = "<AUDIO-REFUND>";
  1475. content += "<CB>测试打印</CB><BR>";
  1476. content += "名称      单价 数量 金额<BR>";
  1477. content += "--------------------------------<BR>";
  1478. content += "<B>饭       1.0 1 1.0</B><BR>";
  1479. content += "<BOLD>炒饭      10.0 10 10.0</BOLD><BR>";
  1480. content += "<B><BOLD>蛋炒饭     10.0 10 100.0</B></BOLD><BR>";
  1481. content += "<B><BOLD>蛋炒饭     10.0 10 100.0</BOLD></B><BR>";
  1482. content += "鸡蛋炒饭    100.0 1 100.0<BR>";
  1483. content += "番茄蛋炒饭   1000.0 1 100.0<BR>";
  1484. content += "西红柿蛋炒饭  1000.0 1 100.0<BR>";
  1485. content += "西红柿鸡蛋炒饭 100.0 10 100.0<BR>";
  1486. content += "备注:加辣<BR>";
  1487. content += "--------------------------------<BR>";
  1488. content += "合计:xx.0元<BR>";
  1489. content += "送货地点:广州市南沙区xx路xx号<BR>";
  1490. content += "联系电话:13888888888888<BR>";
  1491. content += "订餐时间:2016-08-08 08:08:08<BR>";
  1492. content += "<QR>http://www.dzist.com</QR>";
  1493. //endregion
  1494. log.info("utils方法打印开始1");
  1495. StringBuilder stringBuilder = new StringBuilder();
  1496. log.info("utils方法打印开始2");
  1497. //region 以前的代码
  1498. /*stringBuilder.append("<BR>").append("<BR>").append("<BR>");
  1499. stringBuilder.append("<CB>").append(tbOrder.getShopName()).append("</CB><BR>");
  1500. if(tbOrder.getOrderType()==1){
  1501. stringBuilder.append("<BOLD>类型:").append("到店取餐</BOLD><BR>");
  1502. stringBuilder.append("<BOLD>取餐号:").append(tbOrder.getOrderCode()).append("</BOLD><BR>");
  1503. }else{
  1504. stringBuilder.append("<BOLD>类型:").append("外卖配送</BOLD><BR>");
  1505. }
  1506. stringBuilder.append("<BOLD>订单号:").append(tbOrder.getOrderNumber()).append("</BOLD><BR>");
  1507. stringBuilder.append("--------------------------------<BR>");
  1508. stringBuilder.append("名称    单价  数量  金额 <BR>");
  1509. stringBuilder.append("--------------------------------<BR>");
  1510. stringBuilder.append("<BR>");
  1511. for(OrderGoods orderGoods:orderGoodsList){
  1512. BigDecimal sumMoney = orderGoods.getGoodsPrice().multiply(BigDecimal.valueOf(orderGoods.getGoodsNum()));
  1513. String name;
  1514. if(StringUtils.isNotEmpty(orderGoods.getSkuMessage())){
  1515. name=orderGoods.getGoodsName()+"("+orderGoods.getSkuMessage()+")";
  1516. }else{
  1517. name=orderGoods.getGoodsName();
  1518. }
  1519. stringBuilder.append(name).append("<BR>");
  1520. stringBuilder.append("      ");
  1521. stringBuilder.append(orderGoods.getGoodsPrice());
  1522. if(orderGoods.getGoodsPrice().doubleValue()<10){
  1523. stringBuilder.append("  ");
  1524. }else if(orderGoods.getGoodsPrice().doubleValue()<100){
  1525. stringBuilder.append("  ");
  1526. }else{
  1527. stringBuilder.append("  ");
  1528. }
  1529. stringBuilder.append(orderGoods.getGoodsNum());
  1530. stringBuilder.append("  ");
  1531. stringBuilder.append(sumMoney).append("<BR>");
  1532. stringBuilder.append("<BR>");
  1533. }
  1534. stringBuilder.append("--------------------------------<BR>");
  1535. stringBuilder.append("<BOLD>备注:").append(remark).append("</BOLD><BR>");
  1536. stringBuilder.append("--------------------------------<BR>");
  1537. stringBuilder.append("打包费:").append(packMoney).append("元<BR>");
  1538. stringBuilder.append("商品费:").append(goodsMoney).append("元<BR>");
  1539. if(tbOrder.getCouponMoney()!=null){
  1540. stringBuilder.append("优惠券:-").append(tbOrder.getCouponMoney()).append("元<BR>");
  1541. }
  1542. stringBuilder.append("跑腿费:").append(errandMoney).append("元<BR>");
  1543. stringBuilder.append("合计:").append(tbOrder.getPayMoney()).append("元<BR>");
  1544. stringBuilder.append("--------------------------------<BR>");
  1545. if(StringUtils.isNotEmpty(tbOrder.getAddress())){
  1546. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1547. String addressDetail = jsonObject.getString("addressDetail");
  1548. String city = jsonObject.getString("city");
  1549. String district = jsonObject.getString("district");
  1550. String province = jsonObject.getString("province");
  1551. String userName = jsonObject.getString("userName");
  1552. String phone = jsonObject.getString("userPhone");
  1553. stringBuilder.append("姓名:").append(userName).append("<BR>");
  1554. stringBuilder.append("联系电话:").append(phone).append("<BR>");
  1555. stringBuilder.append("送货地点:").append(province).append(city).append(district).append(addressDetail).append("<BR>");
  1556. }else{
  1557. stringBuilder.append("联系电话:").append(tbOrder.getPhone()).append("<BR>");
  1558. }
  1559. stringBuilder.append("订餐时间:").append(tbOrder.getPayTime()).append("<BR>");*/
  1560. //endregion
  1561. log.info("utils方法打印开始3");
  1562. //通过POST请求,发送打印信息到服务器
  1563. RequestConfig requestConfig = RequestConfig.custom()
  1564. .setSocketTimeout(30000)//读取超时
  1565. .setConnectTimeout(30000)//连接超时
  1566. .build();
  1567. log.info("utils方法打印开始4");
  1568. CloseableHttpClient httpClient = HttpClients.custom()
  1569. .setDefaultRequestConfig(requestConfig)
  1570. .build();
  1571. log.info("utils方法打印开始5");
  1572. String URL = commonInfoService.findOne(325).getValue();
  1573. log.info("utils方法打印开始6");
  1574. String USER = commonInfoService.findOne(326).getValue();
  1575. log.info("utils方法打印开始7");
  1576. String UKEY = commonInfoService.findOne(327).getValue();
  1577. log.info("utils方法打印开始8");
  1578. HttpPost post = new HttpPost(URL);
  1579. log.info("utils方法打印开始9");
  1580. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1581. log.info("utils方法打印开始10");
  1582. nvps.add(new BasicNameValuePair("user", USER));
  1583. log.info("utils方法打印开始11");
  1584. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1585. log.info("utils方法打印开始12");
  1586. nvps.add(new BasicNameValuePair("stime", STIME));
  1587. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1588. nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
  1589. nvps.add(new BasicNameValuePair("sn", sn));
  1590. nvps.add(new BasicNameValuePair("content", content));
  1591. nvps.add(new BasicNameValuePair("times", "1"));//打印联数
  1592. log.info("utils方法打印开始13");
  1593. CloseableHttpResponse response = null;
  1594. String result = null;
  1595. log.info("utils方法打印开始14");
  1596. try {
  1597. log.info("utils方法打印开始15");
  1598. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1599. log.info("utils方法打印开始16");
  1600. response = httpClient.execute(post);
  1601. log.info("utils方法打印开始17");
  1602. int statecode = response.getStatusLine().getStatusCode();
  1603. log.info("utils方法打印开始18");
  1604. if (statecode == 200) {
  1605. log.info("utils方法打印开始19");
  1606. HttpEntity httpentity = response.getEntity();
  1607. log.info("utils方法打印开始20");
  1608. if (httpentity != null) {
  1609. log.info("utils方法打印开始21");
  1610. //服务器返回的JSON字符串,建议要当做日志记录起来
  1611. result = EntityUtils.toString(httpentity);
  1612. log.info("utils方法打印开始22");
  1613. }
  1614. log.info("utils方法打印开始23");
  1615. }
  1616. } catch (Exception e) {
  1617. log.info("utils方法打印开始24" + e.getMessage());
  1618. e.printStackTrace();
  1619. } finally {
  1620. try {
  1621. if (response != null) {
  1622. response.close();
  1623. }
  1624. } catch (IOException e) {
  1625. log.info("utils方法打印开始25" + e.getMessage());
  1626. e.printStackTrace();
  1627. }
  1628. try {
  1629. post.abort();
  1630. } catch (Exception e) {
  1631. log.info("utils方法打印开始26" + e.getMessage());
  1632. e.printStackTrace();
  1633. }
  1634. try {
  1635. httpClient.close();
  1636. } catch (IOException e) {
  1637. log.info("utils方法打印开始27" + e.getMessage());
  1638. e.printStackTrace();
  1639. }
  1640. }
  1641. log.info("打印返回值:" + result);
  1642. return result;
  1643. } catch (Exception e) {
  1644. e.printStackTrace();
  1645. log.error("打印异常:" + e.getMessage(), e);
  1646. }
  1647. return null;
  1648. }
  1649. /**
  1650. * 标签机专用打印订单接口
  1651. *
  1652. * @param sn 打印机编号
  1653. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  1654. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1655. */
  1656. private static String printLabelMsg(String sn) {
  1657. String content;
  1658. content = "<DIRECTION>1</DIRECTION>";//设定打印时出纸和打印字体的方向,n 0 或 1,每次设备重启后都会初始化为 0 值设置,1:正向出纸,0:反向出纸,
  1659. content += "<TEXT x='9' y='10' font='12' w='1' h='2' r='0'>#001 五号桌 1/3</TEXT><TEXT x='80' y='80' font='12' w='2' h='2' r='0'>可乐鸡翅</TEXT><TEXT x='9' y='180' font='12' w='1' h='1' r='0'>张三先生 13800138000</TEXT>";//40mm宽度标签纸打印例子,打开注释调用标签打印接口打印
  1660. //通过POST请求,发送打印信息到服务器
  1661. RequestConfig requestConfig = RequestConfig.custom()
  1662. .setSocketTimeout(30000)//读取超时
  1663. .setConnectTimeout(30000)//连接超时
  1664. .build();
  1665. CloseableHttpClient httpClient = HttpClients.custom()
  1666. .setDefaultRequestConfig(requestConfig)
  1667. .build();
  1668. String URL = commonInfoService.findOne(325).getValue();
  1669. String USER = commonInfoService.findOne(326).getValue();
  1670. String UKEY = commonInfoService.findOne(327).getValue();
  1671. HttpPost post = new HttpPost(URL);
  1672. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1673. nvps.add(new BasicNameValuePair("user", USER));
  1674. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1675. nvps.add(new BasicNameValuePair("stime", STIME));
  1676. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1677. nvps.add(new BasicNameValuePair("apiname", "Open_printLabelMsg"));//固定值,不需要修改
  1678. nvps.add(new BasicNameValuePair("sn", sn));
  1679. nvps.add(new BasicNameValuePair("content", content));
  1680. nvps.add(new BasicNameValuePair("times", "1"));//打印联数
  1681. CloseableHttpResponse response = null;
  1682. String result = null;
  1683. try {
  1684. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1685. response = httpClient.execute(post);
  1686. int statecode = response.getStatusLine().getStatusCode();
  1687. if (statecode == 200) {
  1688. HttpEntity httpentity = response.getEntity();
  1689. if (httpentity != null) {
  1690. //服务器返回的JSON字符串,建议要当做日志记录起来
  1691. result = EntityUtils.toString(httpentity);
  1692. }
  1693. }
  1694. } catch (Exception e) {
  1695. e.printStackTrace();
  1696. } finally {
  1697. try {
  1698. if (response != null) {
  1699. response.close();
  1700. }
  1701. } catch (IOException e) {
  1702. e.printStackTrace();
  1703. }
  1704. try {
  1705. post.abort();
  1706. } catch (Exception e) {
  1707. e.printStackTrace();
  1708. }
  1709. try {
  1710. httpClient.close();
  1711. } catch (IOException e) {
  1712. e.printStackTrace();
  1713. }
  1714. }
  1715. return result;
  1716. }
  1717. /**
  1718. * 查询某订单是否打印成功
  1719. *
  1720. * @param orderid 订单id
  1721. * @return 成功:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":2}//data:true为已打印,false为未打印
  1722. * 失败:{"msg":"错误描述","ret":非0, "data":null,"serverExecutedTime":7}
  1723. */
  1724. private static String queryOrderState(String orderid) {
  1725. //通过POST请求,发送打印信息到服务器
  1726. RequestConfig requestConfig = RequestConfig.custom()
  1727. .setSocketTimeout(30000)//读取超时
  1728. .setConnectTimeout(30000)//连接超时
  1729. .build();
  1730. CloseableHttpClient httpClient = HttpClients.custom()
  1731. .setDefaultRequestConfig(requestConfig)
  1732. .build();
  1733. String URL = commonInfoService.findOne(325).getValue();
  1734. String USER = commonInfoService.findOne(326).getValue();
  1735. String UKEY = commonInfoService.findOne(327).getValue();
  1736. HttpPost post = new HttpPost(URL);
  1737. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1738. nvps.add(new BasicNameValuePair("user", USER));
  1739. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1740. nvps.add(new BasicNameValuePair("stime", STIME));
  1741. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1742. nvps.add(new BasicNameValuePair("apiname", "Open_queryOrderState"));//固定值,不需要修改
  1743. nvps.add(new BasicNameValuePair("orderid", orderid));
  1744. CloseableHttpResponse response = null;
  1745. String result = null;
  1746. try {
  1747. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1748. response = httpClient.execute(post);
  1749. int statecode = response.getStatusLine().getStatusCode();
  1750. if (statecode == 200) {
  1751. HttpEntity httpentity = response.getEntity();
  1752. if (httpentity != null) {
  1753. //服务器返回
  1754. result = EntityUtils.toString(httpentity);
  1755. }
  1756. }
  1757. } catch (Exception e) {
  1758. e.printStackTrace();
  1759. } finally {
  1760. try {
  1761. if (response != null) {
  1762. response.close();
  1763. }
  1764. } catch (IOException e) {
  1765. e.printStackTrace();
  1766. }
  1767. try {
  1768. post.abort();
  1769. } catch (Exception e) {
  1770. e.printStackTrace();
  1771. }
  1772. try {
  1773. httpClient.close();
  1774. } catch (IOException e) {
  1775. e.printStackTrace();
  1776. }
  1777. }
  1778. return result;
  1779. }
  1780. /**
  1781. * 查询指定打印机某天的订单详情
  1782. *
  1783. * @param sn 打印机编号
  1784. * @param strdate 时间 "yyyy-MM-dd"
  1785. * @return 成功:{"msg":"ok","ret":0,"data":{"print":6,"waiting":1},"serverExecutedTime":9}//print已打印,waiting为打印
  1786. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1787. */
  1788. private static String queryOrderInfoByDate(String sn, String strdate) {
  1789. //通过POST请求,发送打印信息到服务器
  1790. RequestConfig requestConfig = RequestConfig.custom()
  1791. .setSocketTimeout(30000)//读取超时
  1792. .setConnectTimeout(30000)//连接超时
  1793. .build();
  1794. CloseableHttpClient httpClient = HttpClients.custom()
  1795. .setDefaultRequestConfig(requestConfig)
  1796. .build();
  1797. String URL = commonInfoService.findOne(325).getValue();
  1798. String USER = commonInfoService.findOne(326).getValue();
  1799. String UKEY = commonInfoService.findOne(327).getValue();
  1800. HttpPost post = new HttpPost(URL);
  1801. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1802. nvps.add(new BasicNameValuePair("user", USER));
  1803. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1804. nvps.add(new BasicNameValuePair("stime", STIME));
  1805. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1806. nvps.add(new BasicNameValuePair("apiname", "Open_queryOrderInfoByDate"));//固定值,不需要修改
  1807. nvps.add(new BasicNameValuePair("sn", sn));
  1808. nvps.add(new BasicNameValuePair("date", strdate));//yyyy-MM-dd格式
  1809. CloseableHttpResponse response = null;
  1810. String result = null;
  1811. try {
  1812. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1813. response = httpClient.execute(post);
  1814. int statecode = response.getStatusLine().getStatusCode();
  1815. if (statecode == 200) {
  1816. HttpEntity httpentity = response.getEntity();
  1817. if (httpentity != null) {
  1818. //服务器返回
  1819. result = EntityUtils.toString(httpentity);
  1820. }
  1821. }
  1822. } catch (Exception e) {
  1823. e.printStackTrace();
  1824. } finally {
  1825. try {
  1826. if (response != null) {
  1827. response.close();
  1828. }
  1829. } catch (IOException e) {
  1830. e.printStackTrace();
  1831. }
  1832. try {
  1833. post.abort();
  1834. } catch (Exception e) {
  1835. e.printStackTrace();
  1836. }
  1837. try {
  1838. httpClient.close();
  1839. } catch (IOException e) {
  1840. e.printStackTrace();
  1841. }
  1842. }
  1843. return result;
  1844. }
  1845. /**
  1846. * 查询打印机的状态
  1847. *
  1848. * @param sn 打印机编号
  1849. * @return 成功:{"msg":"ok","ret":0,"data":"状态","serverExecutedTime":4}
  1850. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1851. */
  1852. private static String queryPrinterStatus(String sn) {
  1853. //通过POST请求,发送打印信息到服务器
  1854. RequestConfig requestConfig = RequestConfig.custom()
  1855. .setSocketTimeout(30000)//读取超时
  1856. .setConnectTimeout(30000)//连接超时
  1857. .build();
  1858. CloseableHttpClient httpClient = HttpClients.custom()
  1859. .setDefaultRequestConfig(requestConfig)
  1860. .build();
  1861. String URL = commonInfoService.findOne(325).getValue();
  1862. String USER = commonInfoService.findOne(326).getValue();
  1863. String UKEY = commonInfoService.findOne(327).getValue();
  1864. HttpPost post = new HttpPost(URL);
  1865. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1866. nvps.add(new BasicNameValuePair("user", USER));
  1867. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1868. nvps.add(new BasicNameValuePair("stime", STIME));
  1869. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1870. nvps.add(new BasicNameValuePair("apiname", "Open_queryPrinterStatus"));//固定值,不需要修改
  1871. nvps.add(new BasicNameValuePair("sn", sn));
  1872. CloseableHttpResponse response = null;
  1873. String result = null;
  1874. try {
  1875. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1876. response = httpClient.execute(post);
  1877. int statecode = response.getStatusLine().getStatusCode();
  1878. if (statecode == 200) {
  1879. HttpEntity httpentity = response.getEntity();
  1880. if (httpentity != null) {
  1881. //服务器返回
  1882. result = EntityUtils.toString(httpentity);
  1883. }
  1884. }
  1885. } catch (Exception e) {
  1886. e.printStackTrace();
  1887. } finally {
  1888. try {
  1889. if (response != null) {
  1890. response.close();
  1891. }
  1892. } catch (IOException e) {
  1893. e.printStackTrace();
  1894. }
  1895. try {
  1896. post.abort();
  1897. } catch (Exception e) {
  1898. e.printStackTrace();
  1899. }
  1900. try {
  1901. httpClient.close();
  1902. } catch (IOException e) {
  1903. e.printStackTrace();
  1904. }
  1905. }
  1906. return result;
  1907. }
  1908. //生成签名字符串
  1909. private static String signature(String USER, String UKEY, String STIME) {
  1910. String s = DigestUtils.sha1Hex(USER + UKEY + STIME);
  1911. return s;
  1912. }
  1913. /**
  1914. * 飞鹅技术支持-2020-03-25
  1915. * #########################################################################################################
  1916. * 一,纯数字条件下:
  1917. * 58mm打印机最大支持28位纯数字,80mm打印机最大支持46位纯数字,超出无效
  1918. *
  1919. * 26-28位数字条形码,在数字中不可以出现2个及以上连续的0存在
  1920. * 23-25位数字条形码,在数字中不可以出现3个及以上连续的0存在
  1921. * 21-22位数字条形码,在数字中不可以出现4个及以上连续的0存在
  1922. * 19-20位数字条形码,在数字中不可以出现6个及以上连续的0存在
  1923. * 17-18位数字条形码,在数字中不可以出现8个及以上连续的0存在
  1924. * 15-16位数字条形码,在数字中不可以出现10个及以上连续的0存在
  1925. * 少于或等于14位数字的条形码,0的数量没有影响
  1926. * #########################################################################################################
  1927. * 二,非纯数字混合条件下:
  1928. * 58mm打印机最大支持14位字符,80mm打印机最大支持23位字符,超出无效
  1929. *
  1930. * 支持数字,大小写字母,特殊字符例如: !@#$%^&*()-=+_
  1931. * #########################################################################################################
  1932. * 把条形码函数返回值,调用飞鹅云打印接口发给打印机打印
  1933. */
  1934. private static String getDigitBarCode(String input) {
  1935. String chr = "";
  1936. String laststr = "";
  1937. byte[] codeB = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }; // 匹配字符集B
  1938. byte[] codeC = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  1939. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
  1940. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31,
  1941. 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42,
  1942. 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53,
  1943. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63 }; // 匹配字符集C
  1944. int length = input.length();
  1945. byte[] b = new byte[100];
  1946. b[0] = 0x1b;
  1947. b[1] = 0x64;
  1948. b[2] = 0x02;
  1949. b[3] = 0x1d;
  1950. b[4] = 0x48;
  1951. b[5] = 0x32; // 0x32打印条形码下的数字, 0x30不打印条形码下的数字
  1952. b[6] = 0x1d;
  1953. b[7] = 0x68;
  1954. b[8] = 0x50; // 7F是最大的高度
  1955. b[9] = 0x1d;
  1956. b[10] = 0x77;
  1957. b[11] = 0x02; // 2-6 条码宽度
  1958. b[12] = 0x1d;
  1959. b[13] = 0x6b;
  1960. b[14] = 0x49; // code128
  1961. b[15] = (byte) (length + 2); // 得出条形码长度
  1962. b[16] = 0x7b;
  1963. b[17] = 0x42;
  1964. boolean result=input.matches("[0-9]+");//判断是否为纯数字
  1965. if (length > 14 && result == true) {
  1966. b[17] = 0x43;
  1967. int j = 0;
  1968. int key = 18;
  1969. int ss = length / 2;// 初始化数组长度
  1970. String temp = "";
  1971. int iindex = 0;
  1972. for (int i = 0; i < ss; i++) {
  1973. temp = input.substring(j, j + 2);
  1974. iindex = Integer.valueOf(temp);
  1975. j = j + 2;
  1976. if (iindex == 0) {
  1977. chr = "";
  1978. if(b[key + i - 1] == '0' && b[key + i - 2] == '0') {
  1979. b[key + i] = codeB[0];
  1980. b[key + i+1] = codeB[0];
  1981. key+=1;
  1982. }else {
  1983. if(b[key + i-1] == 'C' && b[key + i-2] == '{' ){//判断前面的为字符集C时转换字符集B
  1984. b[key + i - 2] = 0x7b;
  1985. b[key + i - 1] = 0x42;
  1986. b[key + i] = codeB[0];
  1987. b[key + i + 1] = codeB[0];
  1988. key += 1;
  1989. }else{
  1990. b[key + i] = 0x7b;
  1991. b[key + i + 1] = 0x42;
  1992. b[key + i + 2] = codeB[0];
  1993. b[key + i + 3] = codeB[0];
  1994. key += 3;
  1995. }
  1996. }
  1997. } else {
  1998. // 判断前面的为字符集B,此时要转换字符集C
  1999. if (b[key + i - 1] == '0' && b[key + i - 2] == '0' && chr != "chr") {
  2000. b[key + i] = 0x7b;
  2001. b[key + i + 1] = 0x43;
  2002. b[key + i + 2] = codeC[iindex];
  2003. key += 2;
  2004. }else {
  2005. chr = "";
  2006. b[key + i] = codeC[iindex];
  2007. if(iindex == 48) chr = "chr";//判断chr(48)等于0的情况
  2008. }
  2009. }
  2010. }
  2011. int lastKey = getLastIndex(b);
  2012. if (length % 2 > 0) {
  2013. int lastnum = Integer.valueOf(input.substring(input.length() - 1)); // 取得字符串的最后一个数字
  2014. if(b[lastKey] == '0' && b[lastKey-1] == '0'){//判断前面的为字符集B,此时不需要转换字符集
  2015. b[lastKey + 1] = codeB[lastnum];
  2016. }else{
  2017. b[lastKey + 1] = 0x7b;
  2018. b[lastKey + 2] = 0x42;
  2019. b[lastKey + 3] = codeB[lastnum];
  2020. }
  2021. }
  2022. // 得出条形码长度
  2023. int blength = getLastIndex(b);
  2024. int len = (blength - 15);
  2025. b[15] = (byte) (len);
  2026. String str = "";
  2027. str = new String(b);
  2028. laststr = str;
  2029. String Last_two = input.substring(input.length()-2,input.length());
  2030. int Last_two_int = 0;
  2031. Last_two_int = Integer.valueOf(Last_two);
  2032. if(Last_two_int > 32) {
  2033. laststr = laststr.trim().substring(1);
  2034. }
  2035. } else { // 1-14位数字的条形码进来这个区间
  2036. b[15] = (byte) (length+2);
  2037. laststr = new String(b);
  2038. laststr = laststr.substring(0, 18);
  2039. laststr += input;
  2040. }
  2041. return laststr;
  2042. }
  2043. // 获取数组中最后一个不是0x0的元素的下标
  2044. private static int getLastIndex(byte[] b) {
  2045. if (b == null || b.length == 0) {
  2046. return 0;
  2047. }
  2048. int blength = 0;
  2049. for (int i = b.length - 1; i >= 0; i--) {
  2050. if (b[i] != 0x0) {
  2051. blength = i;
  2052. break;
  2053. }
  2054. }
  2055. return blength;
  2056. }
  2057. public static void main(String[] args) {
  2058. String result = getDigitBarCode("!@#$%^&*()-=+_");
  2059. }
  2060. }