FeiYunUtils.java 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338
  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) {
  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. //endregion
  475. //<B></B> :放大一倍
  476. //<BOLD></BOLD> :字体加粗
  477. //<C></C> :居中
  478. //<CB></CB> :居中放大
  479. // :右对齐
  480. //PrintModelResult result
  481. //字体样式只针对内容
  482. List<OrderGoods> orderGoodsList = tbOrder.getOrderGoodsList();
  483. StringBuilder stringBuilder = new StringBuilder();
  484. int max = Integer.parseInt(commonInfoService.findOne(420).getValue());
  485. for (int i = 0; i < max; i++) {
  486. //region 基本信息:平台名称 店铺名 订单号 送达时间 订单类型
  487. Optional<PrintModelResult> oBaseInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.Base.getValue()).findFirst();
  488. List<PrintModelTypeResult> baseTypes = oBaseInfo.get().getTypes();
  489. //region 平台名称
  490. String bplatformNameType_start = null;
  491. String bplatformNameType_end = null;
  492. //endregion
  493. //region 商铺名
  494. String bshopName_start = null;
  495. String bshopName_end = null;
  496. //endregion
  497. //region 订单类型
  498. String borderTypeExtra_start = null;
  499. String borderTypeExtra_end = null;
  500. //endregion
  501. //region 订单号
  502. String borderNumber_start = null;
  503. String borderNumber_end = null;
  504. //endregion
  505. StringBuilder baseStringBuilder = new StringBuilder();
  506. for (PrintModelTypeResult baseType : baseTypes) {
  507. StringBuilder start = new StringBuilder();
  508. StringBuilder end = new StringBuilder();
  509. if (baseType.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  510. start.append("<B>");
  511. end.append("</B>");
  512. }
  513. if (baseType.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  514. start.append("<BOLD>");
  515. end.append("</BOLD>");
  516. }
  517. int isCheck = 0;
  518. Optional<PrintModelDetailResult> oCheck = oBaseInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(baseType.getPrintField())).findFirst();
  519. if (oCheck != null && oCheck.isPresent()) {
  520. isCheck = oCheck.get().getIsCheck().intValue();
  521. }
  522. switch (baseType.getPrintField()) {
  523. case "platform_name":
  524. bplatformNameType_start = "<C>" + start.toString();
  525. bplatformNameType_end = end.toString() + "</C>";
  526. break;
  527. case "shop_name":
  528. bshopName_start = "<C>" + start.toString();
  529. bshopName_end = end.toString() + "</C>";
  530. break;
  531. case "order_type_extra":
  532. borderTypeExtra_start = start.toString();
  533. borderTypeExtra_end = end.toString();
  534. break;
  535. case "order_number":
  536. borderNumber_start = start.toString();
  537. borderNumber_end = end.toString();
  538. break;
  539. case "expect_delivery_time":
  540. 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>");
  541. break;
  542. case "user_nick_name":
  543. if (isCheck == 1) {
  544. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  545. }
  546. break;
  547. case "shop_phone":
  548. if (isCheck == 1) {
  549. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  550. }
  551. break;
  552. case "distribution_distance_start":
  553. if (isCheck == 1) {
  554. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  555. }
  556. break;
  557. case "detailed_address":
  558. if (isCheck == 1) {
  559. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  560. }
  561. break;
  562. case "remark":
  563. if (isCheck == 1) {
  564. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getRemark()).append(end.toString()).append("<BR>");
  565. }
  566. break;
  567. case "shop_receiving_time":
  568. if (isCheck == 1) {
  569. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  570. }
  571. break;
  572. case "shop_id":
  573. if (isCheck == 1) {
  574. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  575. }
  576. break;
  577. case "parent_user_id":
  578. if (isCheck == 1) {
  579. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  580. }
  581. break;
  582. case "pay_money":
  583. if (isCheck == 1) {
  584. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPayMoney()).append("元").append(end.toString()).append("<BR>");
  585. }
  586. break;
  587. case "auto_send_order":
  588. if (isCheck == 1) {
  589. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  590. }
  591. break;
  592. case "errand_money":
  593. if (isCheck == 1) {
  594. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getErrandMoney()).append("元").append(end.toString()).append("<BR>");
  595. }
  596. break;
  597. case "pack_money":
  598. if (isCheck == 1) {
  599. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPackMoney()).append("元").append(end.toString()).append("<BR>");
  600. }
  601. break;
  602. case "order_code":
  603. if (isCheck == 1) {
  604. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  605. }
  606. break;
  607. case "pay_type":
  608. if (isCheck == 1) {
  609. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  610. }
  611. break;
  612. case "pay_time":
  613. if (isCheck == 1) {
  614. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getPayTime()).append(end.toString()).append("<BR>");
  615. }
  616. break;
  617. case "create_time":
  618. if (isCheck == 1) {
  619. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  620. }
  621. break;
  622. case "address":
  623. if (isCheck == 1) {
  624. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  625. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  626. String addressDetail = jsonObject.getString("addressDetail");
  627. String city = jsonObject.getString("city");
  628. String district = jsonObject.getString("district");
  629. String province = jsonObject.getString("province");
  630. baseStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  631. }
  632. }
  633. break;
  634. case "phone":
  635. if (isCheck == 1) {
  636. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  637. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  638. String phone = jsonObject.getString("userPhone");
  639. baseStringBuilder.append(start.toString()).append(phone).append(end.toString()).append("<BR>");
  640. }
  641. }
  642. break;
  643. case "user_name":
  644. if (isCheck == 1) {
  645. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  646. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  647. String userName = jsonObject.getString("userName");
  648. baseStringBuilder.append(start.toString()).append(userName).append(end.toString()).append("<BR>");
  649. }
  650. }
  651. break;
  652. case "user_id"://显示isVip和vipExpirationTime
  653. if (isCheck == 1) {
  654. baseStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  655. baseStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  656. }
  657. break;
  658. case "coupon_id"://拿优惠券表中的优惠券名称
  659. if (isCheck == 1) {
  660. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  661. }
  662. break;
  663. case "activity_title"://通过订单ID去activity_part_record表中查到activity_id后再去activity表中获取活动标题
  664. if (isCheck == 1) {
  665. baseStringBuilder.append(start.toString()).append(baseType.getPrintName() + ":").append(activity == null ? "" : activity.getTitle()).append(end.toString()).append("<BR>");
  666. }
  667. break;
  668. default:
  669. break;
  670. }
  671. }
  672. if (bplatformNameType_start != null) {
  673. stringBuilder.append(bplatformNameType_start).append("#").append(tbOrder.getCountOrder()).append("-").append("墨轩云商").append(bplatformNameType_end);
  674. }
  675. if (bshopName_start != null) {
  676. stringBuilder.append(bshopName_start).append(tbOrder.getShopName()).append(bshopName_end);
  677. }
  678. if (borderTypeExtra_start != null) {
  679. stringBuilder.append(borderTypeExtra_start).append("类型:").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(borderTypeExtra_end).append("<BR>");
  680. }
  681. if (borderNumber_start != null) {
  682. stringBuilder.append(borderNumber_start).append("订单号:").append(tbOrder.getOrderNumber()).append(borderNumber_end).append("<BR>");
  683. }
  684. stringBuilder.append(baseStringBuilder.toString());
  685. //endregion
  686. stringBuilder.append("--------------------------------<BR>");
  687. //region 商品信息:商品名称 单价 数量 备注 金额
  688. //region 字号样式
  689. Optional<PrintModelResult> oGoodInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.Good.getValue()).findFirst();
  690. List<PrintModelTypeResult> goodTypes = oGoodInfo.get().getTypes();
  691. //region 商品名称
  692. String goods_name_start = null;
  693. String goods_name_end = null;
  694. //endregion
  695. //region 单价
  696. String goods_price_start = null;
  697. String goods_price_end = null;
  698. //endregion
  699. //region 数量
  700. String goods_num_start = null;
  701. String goods_num_end = null;
  702. //endregion
  703. //region 备注
  704. String remark_start = null;
  705. String remark_end = null;
  706. //endregion
  707. //region 金额
  708. String sum_money_start = null;
  709. String sum_money_end = null;
  710. //endregion
  711. StringBuilder goodStringBuilder = new StringBuilder();
  712. for (PrintModelTypeResult type : goodTypes) {
  713. StringBuilder start = new StringBuilder();
  714. StringBuilder end = new StringBuilder();
  715. if (type.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  716. start.append("<B>");
  717. end.append("</B>");
  718. }
  719. if (type.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  720. start.append("<BOLD>");
  721. end.append("</BOLD>");
  722. }
  723. int isCheck = 0;
  724. Optional<PrintModelDetailResult> oCheck = oGoodInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(type.getPrintField())).findFirst();
  725. if (oCheck != null && oCheck.isPresent()) {
  726. isCheck = oCheck.get().getIsCheck().intValue();
  727. }
  728. switch (type.getPrintField()) {
  729. case "goods_name":
  730. goods_name_start = start.toString();
  731. goods_name_end = end.toString();
  732. break;
  733. case "goods_price":
  734. goods_price_start = start.toString();
  735. goods_price_end = end.toString();
  736. break;
  737. case "goods_num":
  738. goods_num_start = start.toString();
  739. goods_num_end = end.toString();
  740. break;
  741. case "remark":
  742. remark_start = start.toString();
  743. remark_end = end.toString();
  744. break;
  745. case "sum_money":
  746. if (isCheck == 1) {
  747. sum_money_start = start.toString();
  748. sum_money_end = end.toString();
  749. }
  750. break;
  751. case "platform_name":
  752. if (isCheck == 1) {
  753. goodStringBuilder.append(start.toString()).append("#").append(tbOrder.getCountOrder()).append("-").append("墨轩云商").append(end.toString());
  754. }
  755. break;
  756. case "shop_name":
  757. if (isCheck == 1) {
  758. goodStringBuilder.append(start.toString()).append(tbOrder.getShopName()).append(end.toString());
  759. }
  760. break;
  761. case "order_type_extra":
  762. if (isCheck == 1) {
  763. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(end.toString()).append("<BR>");
  764. }
  765. break;
  766. case "order_number":
  767. if (isCheck == 1) {
  768. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderNumber()).append(end.toString()).append("<BR>");
  769. }
  770. break;
  771. case "user_nick_name":
  772. if (isCheck == 1) {
  773. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  774. }
  775. break;
  776. case "shop_phone":
  777. if (isCheck == 1) {
  778. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  779. }
  780. break;
  781. case "distribution_distance_start":
  782. if (isCheck == 1) {
  783. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  784. }
  785. break;
  786. case "detailed_address":
  787. if (isCheck == 1) {
  788. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  789. }
  790. break;
  791. case "shop_receiving_time":
  792. if (isCheck == 1) {
  793. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  794. }
  795. break;
  796. case "shop_id":
  797. if (isCheck == 1) {
  798. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  799. }
  800. break;
  801. case "parent_user_id":
  802. if (isCheck == 1) {
  803. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  804. }
  805. break;
  806. case "pay_money":
  807. if (isCheck == 1) {
  808. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayMoney()).append("元").append(end.toString()).append("<BR>");
  809. }
  810. break;
  811. case "auto_send_order":
  812. if (isCheck == 1) {
  813. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  814. }
  815. break;
  816. case "errand_money":
  817. if (isCheck == 1) {
  818. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getErrandMoney()).append("元").append(end.toString()).append("<BR>");
  819. }
  820. break;
  821. case "pack_money":
  822. if (isCheck == 1) {
  823. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPackMoney()).append("元").append(end.toString()).append("<BR>");
  824. }
  825. break;
  826. case "order_code":
  827. if (isCheck == 1) {
  828. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  829. }
  830. break;
  831. case "pay_type":
  832. if (isCheck == 1) {
  833. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  834. }
  835. break;
  836. case "pay_time":
  837. if (isCheck == 1) {
  838. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayTime()).append(end.toString()).append("<BR>");
  839. }
  840. break;
  841. case "create_time":
  842. if (isCheck == 1) {
  843. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  844. }
  845. break;
  846. case "address":
  847. if (isCheck == 1) {
  848. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  849. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  850. String addressDetail = jsonObject.getString("addressDetail");
  851. String city = jsonObject.getString("city");
  852. String district = jsonObject.getString("district");
  853. String province = jsonObject.getString("province");
  854. goodStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  855. }
  856. }
  857. break;
  858. case "phone":
  859. if (isCheck == 1) {
  860. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  861. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  862. String phone = jsonObject.getString("userPhone");
  863. goodStringBuilder.append(start.toString()).append(phone).append(end.toString()).append("<BR>");
  864. }
  865. }
  866. break;
  867. case "user_name":
  868. if (isCheck == 1) {
  869. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  870. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  871. String userName = jsonObject.getString("userName");
  872. goodStringBuilder.append(start.toString()).append(userName).append(end.toString()).append("<BR>");
  873. }
  874. }
  875. break;
  876. case "user_id"://显示isVip和vipExpirationTime
  877. if (isCheck == 1) {
  878. goodStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  879. goodStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  880. }
  881. break;
  882. case "coupon_id"://拿优惠券表中的优惠券名称
  883. if (isCheck == 1) {
  884. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  885. }
  886. break;
  887. case "expect_delivery_time":
  888. if (isCheck == 1) {
  889. 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>");
  890. }
  891. break;
  892. case "activity_title"://通过订单ID去activity_part_record表中查到activity_id后再去activity表中获取活动标题
  893. if (isCheck == 1) {
  894. goodStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(activity == null ? "" : activity.getTitle()).append(end.toString()).append("<BR>");
  895. }
  896. break;
  897. default:
  898. break;
  899. }
  900. }
  901. //endregion
  902. if (goods_name_start != null) {
  903. stringBuilder.append(goods_name_start).append("名称").append(goods_name_end).append("    ");
  904. }
  905. if (goods_price_start != null) {
  906. stringBuilder.append(goods_price_start).append("单价").append(goods_price_end).append("  ");
  907. }
  908. if (goods_num_start != null) {
  909. stringBuilder.append(goods_num_start).append("数量").append(goods_num_end).append("  ");
  910. }
  911. if (sum_money_start != null) {
  912. stringBuilder.append(sum_money_start).append("金额").append(sum_money_end);
  913. }
  914. stringBuilder.append("<BR>");
  915. stringBuilder.append("--------------------------------<BR>");
  916. BigDecimal packMoney = BigDecimal.ZERO;
  917. BigDecimal goodsMoney = BigDecimal.ZERO;
  918. for (OrderGoods orderGoods : orderGoodsList) {
  919. BigDecimal sumMoney = orderGoods.getGoodsPrice().multiply(BigDecimal.valueOf(orderGoods.getGoodsNum()));
  920. BigDecimal sumPack = orderGoods.getGoodsPack().multiply(BigDecimal.valueOf(orderGoods.getGoodsNum()));
  921. packMoney = packMoney.add(sumPack);
  922. goodsMoney = goodsMoney.add(sumMoney);
  923. String name;
  924. if (StringUtils.isNotEmpty(orderGoods.getSkuMessage())) {
  925. name = orderGoods.getGoodsName() + "(" + orderGoods.getSkuMessage() + ")";
  926. } else {
  927. name = orderGoods.getGoodsName();
  928. }
  929. stringBuilder.append(goods_name_start).append(name).append(goods_name_end);
  930. stringBuilder.append("    ");
  931. stringBuilder.append(goods_price_start).append(orderGoods.getGoodsPrice()).append(goods_price_end);
  932. if (orderGoods.getGoodsPrice().doubleValue() < 10) {
  933. stringBuilder.append("  ");
  934. } else if (orderGoods.getGoodsPrice().doubleValue() < 100) {
  935. stringBuilder.append("  ");
  936. } else {
  937. stringBuilder.append("  ");
  938. }
  939. stringBuilder.append(goods_num_start).append("x" + orderGoods.getGoodsNum()).append(goods_num_end);
  940. stringBuilder.append("  ");
  941. if (sum_money_start != null) {
  942. stringBuilder.append(sum_money_start).append(sumMoney).append(sum_money_end);
  943. }
  944. stringBuilder.append("<BR>");
  945. //stringBuilder.append("<BR>");
  946. }
  947. stringBuilder.append("--------------------------------<BR>");
  948. String remark = tbOrder.getRemark();
  949. if (StringUtils.isEmpty(remark)) {
  950. remark = "";
  951. }
  952. stringBuilder.append(remark_start).append("备注:").append(remark).append(remark_end).append("<BR>");
  953. stringBuilder.append(goodStringBuilder.toString());
  954. //endregion
  955. stringBuilder.append("--------------------------------<BR>");
  956. //region 支付信息:打包费 商品费 优惠券 跑腿费 优惠活动 合计
  957. //region 字号样式
  958. Optional<PrintModelResult> oPayInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.Pay.getValue()).findFirst();
  959. List<PrintModelTypeResult> payTypes = oPayInfo.get().getTypes();
  960. //region 打包费
  961. String pack_money_start = null;
  962. String pack_money_end = null;
  963. //endregion
  964. //region 商品费
  965. String goods_money_start = null;
  966. String goods_money_end = null;
  967. //endregion
  968. //region 优惠券
  969. String coupon_money_start = null;
  970. String coupon_money_end = null;
  971. //endregion
  972. //region 跑腿费
  973. String errand_money_start = null;
  974. String errand_money_end = null;
  975. //endregion
  976. //region 优惠活动
  977. String activity_title_start = null;
  978. String activity_title_end = null;
  979. //endregion
  980. //region 合计
  981. String pay_money_start = null;
  982. String pay_money_end = null;
  983. //endregion
  984. StringBuilder payStringBuilder = new StringBuilder();
  985. for (PrintModelTypeResult type : payTypes) {
  986. StringBuilder start = new StringBuilder();
  987. StringBuilder end = new StringBuilder();
  988. if (type.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  989. start.append("<B>");
  990. end.append("</B>");
  991. }
  992. if (type.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  993. start.append("<BOLD>");
  994. end.append("</BOLD>");
  995. }
  996. int isCheck = 0;
  997. Optional<PrintModelDetailResult> oCheck = oPayInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(type.getPrintField())).findFirst();
  998. if (oCheck != null && oCheck.isPresent()) {
  999. isCheck = oCheck.get().getIsCheck().intValue();
  1000. }
  1001. switch (type.getPrintField()) {
  1002. case "pack_money":
  1003. pack_money_start = start.toString();
  1004. pack_money_end = end.toString();
  1005. break;
  1006. case "goods_money":
  1007. goods_money_start = start.toString();
  1008. goods_money_end = end.toString();
  1009. break;
  1010. case "coupon_money":
  1011. coupon_money_start = start.toString();
  1012. coupon_money_end = end.toString();
  1013. break;
  1014. case "errand_money":
  1015. errand_money_start = start.toString();
  1016. errand_money_end = end.toString();
  1017. break;
  1018. case "activity_title":
  1019. activity_title_start = start.toString();
  1020. activity_title_end = end.toString();
  1021. break;
  1022. case "pay_money":
  1023. pay_money_start = start.toString();
  1024. pay_money_end = end.toString();
  1025. break;
  1026. case "platform_name":
  1027. if (isCheck == 1) {
  1028. payStringBuilder.append(start.toString()).append("#").append(tbOrder.getCountOrder()).append("-").append("墨轩云商").append(end.toString());
  1029. }
  1030. break;
  1031. case "shop_name":
  1032. if (isCheck == 1) {
  1033. payStringBuilder.append(start.toString()).append(tbOrder.getShopName()).append(end.toString());
  1034. }
  1035. break;
  1036. case "order_type_extra":
  1037. if (isCheck == 1) {
  1038. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(end.toString()).append("<BR>");
  1039. }
  1040. break;
  1041. case "order_number":
  1042. if (isCheck == 1) {
  1043. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderNumber()).append(end.toString()).append("<BR>");
  1044. }
  1045. break;
  1046. case "user_nick_name":
  1047. if (isCheck == 1) {
  1048. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  1049. }
  1050. break;
  1051. case "shop_phone":
  1052. if (isCheck == 1) {
  1053. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  1054. }
  1055. break;
  1056. case "distribution_distance_start":
  1057. if (isCheck == 1) {
  1058. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  1059. }
  1060. break;
  1061. case "detailed_address":
  1062. if (isCheck == 1) {
  1063. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  1064. }
  1065. break;
  1066. case "remark":
  1067. if (isCheck == 1) {
  1068. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getRemark()).append(end.toString()).append("<BR>");
  1069. }
  1070. break;
  1071. case "shop_receiving_time":
  1072. if (isCheck == 1) {
  1073. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  1074. }
  1075. break;
  1076. case "shop_id":
  1077. if (isCheck == 1) {
  1078. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  1079. }
  1080. break;
  1081. case "parent_user_id":
  1082. if (isCheck == 1) {
  1083. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  1084. }
  1085. break;
  1086. case "auto_send_order":
  1087. if (isCheck == 1) {
  1088. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  1089. }
  1090. break;
  1091. case "order_code":
  1092. if (isCheck == 1) {
  1093. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  1094. }
  1095. break;
  1096. case "pay_type":
  1097. if (isCheck == 1) {
  1098. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  1099. }
  1100. break;
  1101. case "pay_time":
  1102. if (isCheck == 1) {
  1103. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayTime()).append(end.toString()).append("<BR>");
  1104. }
  1105. break;
  1106. case "create_time":
  1107. if (isCheck == 1) {
  1108. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  1109. }
  1110. break;
  1111. case "address":
  1112. if (isCheck == 1) {
  1113. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1114. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1115. String addressDetail = jsonObject.getString("addressDetail");
  1116. String city = jsonObject.getString("city");
  1117. String district = jsonObject.getString("district");
  1118. String province = jsonObject.getString("province");
  1119. payStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  1120. }
  1121. }
  1122. break;
  1123. case "phone":
  1124. if (isCheck == 1) {
  1125. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1126. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1127. String phone = jsonObject.getString("userPhone");
  1128. payStringBuilder.append(start.toString()).append(phone).append(end.toString()).append("<BR>");
  1129. }
  1130. }
  1131. break;
  1132. case "user_name":
  1133. if (isCheck == 1) {
  1134. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1135. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1136. String userName = jsonObject.getString("userName");
  1137. payStringBuilder.append(start.toString()).append(userName).append(end.toString()).append("<BR>");
  1138. }
  1139. }
  1140. break;
  1141. case "user_id"://显示isVip和vipExpirationTime
  1142. if (isCheck == 1) {
  1143. payStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  1144. payStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  1145. }
  1146. break;
  1147. case "coupon_id"://拿优惠券表中的优惠券名称
  1148. if (isCheck == 1) {
  1149. payStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  1150. }
  1151. break;
  1152. case "expect_delivery_time":
  1153. if (isCheck == 1) {
  1154. 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>");
  1155. }
  1156. break;
  1157. default:
  1158. break;
  1159. }
  1160. }
  1161. //endregion
  1162. stringBuilder.append(pack_money_start).append("打包费:").append(packMoney).append("元").append(pack_money_end + "<BR>");
  1163. stringBuilder.append(goods_money_start).append("商品费:").append(goodsMoney).append("元").append(goods_money_end + "<BR>");
  1164. if (tbOrder.getCouponMoney() != null) {
  1165. stringBuilder.append(coupon_money_start).append("优惠券:").append("-" + tbOrder.getCouponMoney()).append("元").append(coupon_money_end + "<BR>");
  1166. } else {
  1167. stringBuilder.append(coupon_money_start).append("优惠券:").append("-0").append("元").append(coupon_money_end + "<BR>");
  1168. }
  1169. BigDecimal errandMoney = tbOrder.getErrandMoney();
  1170. if (errandMoney == null) {
  1171. errandMoney = BigDecimal.ZERO;
  1172. }
  1173. BigDecimal errandMoneyT = errandMoney.setScale(2, BigDecimal.ROUND_HALF_UP);
  1174. stringBuilder.append(errand_money_start).append("跑腿费:").append(errandMoneyT).append("元").append(errand_money_end + "<BR>");
  1175. //从这个表里拿优惠活动 activity_part_record 活动参与记录表
  1176. stringBuilder.append(activity_title_start).append("优惠活动:").append(activity == null ? "" : activity.getTitle()).append(activity_title_end + "<BR>");
  1177. BigDecimal patMoney = tbOrder.getPayMoney().setScale(2, BigDecimal.ROUND_HALF_UP);
  1178. stringBuilder.append(pay_money_start).append("合计:").append(patMoney).append("元").append(pay_money_end + "<BR>");
  1179. stringBuilder.append(payStringBuilder.toString());
  1180. //endregion
  1181. stringBuilder.append("--------------------------------<BR>");
  1182. //region 用户信息:姓名 电话号 地址 订餐时间 商家联系电话
  1183. //region 字号样式
  1184. Optional<PrintModelResult> oUserInfo = resultData.stream().filter(e -> e.getId().intValue() == ePrintStatu.User.getValue()).findFirst();
  1185. List<PrintModelTypeResult> userTypes = oUserInfo.get().getTypes();
  1186. //region 姓名
  1187. String user_name_start = null;
  1188. String user_name_end = null;
  1189. //endregion
  1190. //region 电话号
  1191. String phone_start = null;
  1192. String phone_end = null;
  1193. //endregion
  1194. //region 地址
  1195. String address_detail_start = null;
  1196. String address_detail_end = null;
  1197. //endregion
  1198. //region 订餐时间
  1199. String pay_time_start = null;
  1200. String pay_time_end = null;
  1201. //endregion
  1202. StringBuilder userStringBuilder = new StringBuilder();
  1203. for (PrintModelTypeResult type : userTypes) {
  1204. StringBuilder start = new StringBuilder();
  1205. StringBuilder end = new StringBuilder();
  1206. if (type.getWordSize().intValue() == eWordSize.Amplify.getValue()) {
  1207. start.append("<B>");
  1208. end.append("</B>");
  1209. }
  1210. if (type.getIsBlod().intValue() == eWordSize.Normal.getValue()) {//这里normal表示加粗
  1211. start.append("<BOLD>");
  1212. end.append("</BOLD>");
  1213. }
  1214. int isCheck = 0;
  1215. Optional<PrintModelDetailResult> oCheck = oUserInfo.get().getDetails().stream().filter(e -> e.getPrintField().equals(type.getPrintField())).findFirst();
  1216. if (oCheck != null && oCheck.isPresent()) {
  1217. isCheck = oCheck.get().getIsCheck().intValue();
  1218. }
  1219. switch (type.getPrintField()) {
  1220. case "user_name":
  1221. user_name_start = start.toString();
  1222. user_name_end = end.toString();
  1223. break;
  1224. case "phone":
  1225. phone_start = start.toString();
  1226. phone_end = end.toString();
  1227. break;
  1228. case "address_detail":
  1229. address_detail_start = start.toString();
  1230. address_detail_end = end.toString();
  1231. break;
  1232. case "pay_time":
  1233. pay_time_start = start.toString();
  1234. pay_time_end = end.toString();
  1235. break;
  1236. case "platform_name":
  1237. if (isCheck == 1) {
  1238. userStringBuilder.append(start.toString()).append("#").append(tbOrder.getCountOrder()).append("-").append("墨轩云商").append(end.toString());
  1239. }
  1240. break;
  1241. case "shop_name":
  1242. if (isCheck == 1) {
  1243. userStringBuilder.append(start.toString()).append(tbOrder.getShopName()).append(end.toString());
  1244. }
  1245. break;
  1246. case "order_type_extra":
  1247. if (isCheck == 1) {
  1248. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append(end.toString()).append("<BR>");
  1249. }
  1250. break;
  1251. case "order_number":
  1252. if (isCheck == 1) {
  1253. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderNumber()).append(end.toString()).append("<BR>");
  1254. }
  1255. break;
  1256. case "user_nick_name":
  1257. if (isCheck == 1) {
  1258. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getUserNickName() == null ? (user == null ? "" : user.getNickName()) : tbOrder.getUserNickName()).append(end.toString()).append("<BR>");
  1259. }
  1260. break;
  1261. case "shop_phone":
  1262. if (isCheck == 1) {
  1263. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopPhone() == null ? (shopData == null ? "" : shopData.getPhone()) : tbOrder.getShopPhone()).append(end.toString()).append("<BR>");
  1264. }
  1265. break;
  1266. case "distribution_distance_start":
  1267. if (isCheck == 1) {
  1268. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDistributionDistance() == null ? (shopData == null ? "" : String.valueOf(shopData.getDistributionDistance())) : tbOrder.getDistributionDistance()).append(end.toString()).append("<BR>");
  1269. }
  1270. break;
  1271. case "detailed_address":
  1272. if (isCheck == 1) {
  1273. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getDetailedAddress() == null ? (tbOrder == null ? "" : shopData.getDetailedAddress()) : tbOrder.getDetailedAddress()).append(end.toString()).append("<BR>");
  1274. }
  1275. break;
  1276. case "remark":
  1277. if (isCheck == 1) {
  1278. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getRemark()).append(end.toString()).append("<BR>");
  1279. }
  1280. break;
  1281. case "shop_receiving_time":
  1282. if (isCheck == 1) {
  1283. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getShopReceivingTime()).append(end.toString()).append("<BR>");
  1284. }
  1285. break;
  1286. case "shop_id":
  1287. if (isCheck == 1) {
  1288. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(shopData != null ? shopData.getBusinessHours() + "-" + shopData.getLockHours() : "").append(end.toString()).append("<BR>");
  1289. }
  1290. break;
  1291. case "parent_user_id":
  1292. if (isCheck == 1) {
  1293. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(parentUser == null ? "" : parentUser.getNickName()).append(end.toString()).append("<BR>");
  1294. }
  1295. break;
  1296. case "pay_money":
  1297. if (isCheck == 1) {
  1298. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayMoney()).append("元").append(end.toString()).append("<BR>");
  1299. }
  1300. break;
  1301. case "auto_send_order":
  1302. if (isCheck == 1) {
  1303. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getAutoSendOrder().intValue() == 0 ? "开启" : "关闭").append(end.toString()).append("<BR>");
  1304. }
  1305. break;
  1306. case "errand_money":
  1307. if (isCheck == 1) {
  1308. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getErrandMoney()).append("元").append(end.toString()).append("<BR>");
  1309. }
  1310. break;
  1311. case "pack_money":
  1312. if (isCheck == 1) {
  1313. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPackMoney()).append("元").append(end.toString()).append("<BR>");
  1314. }
  1315. break;
  1316. case "order_code":
  1317. if (isCheck == 1) {
  1318. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getOrderCode()).append(end.toString()).append("<BR>");
  1319. }
  1320. break;
  1321. case "pay_type":
  1322. if (isCheck == 1) {
  1323. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getPayType().intValue() == 1 ? "微信支付" : (tbOrder.getPayType().intValue() == 2 ? "余额支付" : "支付宝支付")).append(end.toString()).append("<BR>");
  1324. }
  1325. break;
  1326. case "create_time":
  1327. if (isCheck == 1) {
  1328. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbOrder.getCreateTime()).append(end.toString()).append("<BR>");
  1329. }
  1330. break;
  1331. case "address":
  1332. if (isCheck == 1) {
  1333. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1334. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1335. String addressDetail = jsonObject.getString("addressDetail");
  1336. String city = jsonObject.getString("city");
  1337. String district = jsonObject.getString("district");
  1338. String province = jsonObject.getString("province");
  1339. userStringBuilder.append(start.toString()).append(province).append(city).append(district).append(addressDetail).append(end.toString()).append("<BR>");
  1340. }
  1341. }
  1342. break;
  1343. case "user_id"://显示isVip和vipExpirationTime
  1344. if (isCheck == 1) {
  1345. userStringBuilder.append(start.toString()).append("是否会员:").append(user == null ? "" : (user.getIsVip().intValue() == 1 ? "是" : "否")).append(end.toString()).append("<BR>");
  1346. userStringBuilder.append(start.toString()).append("会员有效期:").append(user == null ? "" : user.getVipExpirationTime()).append(end.toString()).append("<BR>");
  1347. }
  1348. break;
  1349. case "coupon_id"://拿优惠券表中的优惠券名称
  1350. if (isCheck == 1) {
  1351. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(tbCoupon == null ? "" : tbCoupon.getCouponName()).append(end.toString()).append("<BR>");
  1352. }
  1353. break;
  1354. case "expect_delivery_time":
  1355. if (isCheck == 1) {
  1356. 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>");
  1357. }
  1358. break;
  1359. case "activity_title"://通过订单ID去activity_part_record表中查到activity_id后再去activity表中获取活动标题
  1360. if (isCheck == 1) {
  1361. userStringBuilder.append(start.toString()).append(type.getPrintName() + ":").append(activity == null ? "" : activity.getTitle()).append(end.toString()).append("<BR>");
  1362. }
  1363. break;
  1364. default:
  1365. break;
  1366. }
  1367. }
  1368. //endregion
  1369. if (StringUtils.isNotEmpty(tbOrder.getAddress())) {
  1370. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1371. String addressDetail = jsonObject.getString("addressDetail");
  1372. String city = jsonObject.getString("city");
  1373. String district = jsonObject.getString("district");
  1374. String province = jsonObject.getString("province");
  1375. String userName = jsonObject.getString("userName");
  1376. String phone = jsonObject.getString("userPhone");
  1377. stringBuilder.append(user_name_start).append(userName).append(user_name_end).append("<BR>");
  1378. stringBuilder.append(phone_start).append(phone).append(phone_end).append("<BR>");
  1379. stringBuilder.append(address_detail_start).append(province).append(city).append(district).append(addressDetail).append(address_detail_end).append("<BR>");
  1380. } else {
  1381. stringBuilder.append(phone_start).append(tbOrder.getPhone()).append(phone_end).append("<BR>");
  1382. }
  1383. stringBuilder.append(pay_time_start).append("订餐时间:").append(tbOrder.getPayTime()).append(pay_time_end).append("<BR>");
  1384. stringBuilder.append(userStringBuilder);
  1385. stringBuilder.append("<BR>");
  1386. //String returnNo = getDigitBarCode();
  1387. //sb.append("<BC128_C>"+returnNo+"</BC128_C>");
  1388. stringBuilder.append("<CB><QR>").append(tbOrder.getOrderId()).append("</QR></CB><BR>");
  1389. stringBuilder.append("<CB>收单码:").append(tbOrder.getOrderId()).append("</CB>");
  1390. stringBuilder.append("<BR>").append("<BR>").append("<BR>");
  1391. stringBuilder.append("<CUT>");
  1392. //endregion
  1393. }
  1394. String content = stringBuilder.toString();
  1395. log.info("打印内容:" + content);
  1396. //通过POST请求,发送打印信息到服务器
  1397. RequestConfig requestConfig = RequestConfig.custom()
  1398. .setSocketTimeout(30000)//读取超时
  1399. .setConnectTimeout(30000)//连接超时
  1400. .build();
  1401. CloseableHttpClient httpClient = HttpClients.custom()
  1402. .setDefaultRequestConfig(requestConfig)
  1403. .build();
  1404. String URL = commonInfoService.findOne(325).getValue();
  1405. String USER = commonInfoService.findOne(326).getValue();
  1406. String UKEY = commonInfoService.findOne(327).getValue();
  1407. HttpPost post = new HttpPost(URL);
  1408. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1409. nvps.add(new BasicNameValuePair("user", USER));
  1410. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1411. nvps.add(new BasicNameValuePair("stime", STIME));
  1412. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1413. nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
  1414. nvps.add(new BasicNameValuePair("sn", sn));
  1415. nvps.add(new BasicNameValuePair("content", content));
  1416. nvps.add(new BasicNameValuePair("times", "1"));//打印联数
  1417. CloseableHttpResponse response = null;
  1418. String result = null;
  1419. try {
  1420. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1421. response = httpClient.execute(post);
  1422. int statecode = response.getStatusLine().getStatusCode();
  1423. if (statecode == 200) {
  1424. HttpEntity httpentity = response.getEntity();
  1425. if (httpentity != null) {
  1426. //服务器返回的JSON字符串,建议要当做日志记录起来
  1427. result = EntityUtils.toString(httpentity);
  1428. }
  1429. }
  1430. } catch (Exception e) {
  1431. e.printStackTrace();
  1432. } finally {
  1433. try {
  1434. if (response != null) {
  1435. response.close();
  1436. }
  1437. } catch (IOException e) {
  1438. e.printStackTrace();
  1439. }
  1440. try {
  1441. post.abort();
  1442. } catch (Exception e) {
  1443. e.printStackTrace();
  1444. }
  1445. try {
  1446. httpClient.close();
  1447. } catch (IOException e) {
  1448. e.printStackTrace();
  1449. }
  1450. }
  1451. log.error("打印返回值:" + result);
  1452. return result;
  1453. } catch (Exception e) {
  1454. e.printStackTrace();
  1455. log.error("打印异常:" + e.getMessage(), e);
  1456. }
  1457. return null;
  1458. }
  1459. /**
  1460. * 小票机打印订单接口
  1461. *
  1462. * @param sn 打印机编号
  1463. * @param classify 分类 1加油成功出票模版 2提货券推送模版 3加油订单结算模版 4商品消费结算
  1464. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  1465. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1466. */
  1467. public static String returnPrint(String sn, Integer classify, TbOrder tbOrder) {
  1468. try {
  1469. //标签说明:
  1470. //单标签:
  1471. //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
  1472. //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
  1473. //成对标签:
  1474. //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
  1475. //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,""为右对齐
  1476. //拼凑订单内容时可参考如下格式
  1477. //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
  1478. //region 以前的代码
  1479. /*content = "<CB>测试打印</CB><BR>";
  1480. content += "名称      单价 数量 金额<BR>";
  1481. content += "--------------------------------<BR>";
  1482. content += "饭       1.0 1 1.0<BR>";
  1483. content += "炒饭      10.0 10 10.0<BR>";
  1484. content += "蛋炒饭     10.0 10 100.0<BR>";
  1485. content += "鸡蛋炒饭    100.0 1 100.0<BR>";
  1486. content += "番茄蛋炒饭   1000.0 1 100.0<BR>";
  1487. content += "西红柿蛋炒饭  1000.0 1 100.0<BR>";
  1488. content += "西红柿鸡蛋炒饭 100.0 10 100.0<BR>";
  1489. content += "备注:加辣<BR>";
  1490. content += "--------------------------------<BR>";
  1491. content += "合计:xx.0元<BR>";
  1492. content += "送货地点:广州市南沙区xx路xx号<BR>";
  1493. content += "联系电话:13888888888888<BR>";
  1494. content += "订餐时间:2016-08-08 08:08:08<BR>";
  1495. content += "<QR>http://www.dzist.com</QR>";*/
  1496. //endregion
  1497. StringBuilder sb = new StringBuilder();
  1498. log.info("utils方法打印开始");
  1499. //region 以前的代码
  1500. sb.append("<AUDIO-REFUND>");
  1501. sb.append("#").append(tbOrder.getCountOrder()).append("-").append("墨轩云商<BR>");
  1502. sb.append("<CB>用户已取消,请勿继续配送</CB><BR>");
  1503. sb.append(tbOrder.getShopName()+"<BR>");
  1504. sb.append("订单号:").append(tbOrder.getOrderNumber()).append("<BR>");
  1505. sb.append("类型:").append(eOrderTypeExtra.stringOf(tbOrder.getOrderTypeExtra())).append("<BR>");
  1506. // String returnNo = getDigitBarCode(tbOrder.getOrderNumber());
  1507. // //sb.append("<BC128_C>"+returnNo+"</BC128_C>");
  1508. // sb.append("<CB>").append(returnNo).append("</CB>");
  1509. String content = sb.toString();
  1510. log.info("打印内容:" + content);
  1511. //通过POST请求,发送打印信息到服务器
  1512. RequestConfig requestConfig = RequestConfig.custom()
  1513. .setSocketTimeout(30000)//读取超时
  1514. .setConnectTimeout(30000)//连接超时
  1515. .build();
  1516. CloseableHttpClient httpClient = HttpClients.custom()
  1517. .setDefaultRequestConfig(requestConfig)
  1518. .build();
  1519. String URL = commonInfoService.findOne(325).getValue();
  1520. String USER = commonInfoService.findOne(326).getValue();
  1521. String UKEY = commonInfoService.findOne(327).getValue();
  1522. HttpPost post = new HttpPost(URL);
  1523. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1524. nvps.add(new BasicNameValuePair("user", USER));
  1525. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1526. nvps.add(new BasicNameValuePair("stime", STIME));
  1527. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1528. nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
  1529. nvps.add(new BasicNameValuePair("sn", sn));
  1530. nvps.add(new BasicNameValuePair("content", content));
  1531. nvps.add(new BasicNameValuePair("times", "1"));//打印联数
  1532. CloseableHttpResponse response = null;
  1533. String result = null;
  1534. try {
  1535. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1536. response = httpClient.execute(post);
  1537. int statecode = response.getStatusLine().getStatusCode();
  1538. if (statecode == 200) {
  1539. HttpEntity httpentity = response.getEntity();
  1540. if (httpentity != null) {
  1541. //服务器返回的JSON字符串,建议要当做日志记录起来
  1542. result = EntityUtils.toString(httpentity);
  1543. }
  1544. }
  1545. } catch (Exception e) {
  1546. e.printStackTrace();
  1547. } finally {
  1548. try {
  1549. if (response != null) {
  1550. response.close();
  1551. }
  1552. } catch (IOException e) {
  1553. e.printStackTrace();
  1554. }
  1555. try {
  1556. post.abort();
  1557. } catch (Exception e) {
  1558. e.printStackTrace();
  1559. }
  1560. try {
  1561. httpClient.close();
  1562. } catch (IOException e) {
  1563. e.printStackTrace();
  1564. }
  1565. }
  1566. log.error("打印返回值:" + result);
  1567. return result;
  1568. } catch (Exception e) {
  1569. e.printStackTrace();
  1570. log.error("打印异常:" + e.getMessage(), e);
  1571. }
  1572. return null;
  1573. }
  1574. /**
  1575. * 小票机打印订单接口
  1576. *
  1577. * @param sn 打印机编号
  1578. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  1579. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1580. */
  1581. public static String testPrint(String sn) {
  1582. try {
  1583. //标签说明:
  1584. //单标签:
  1585. //"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
  1586. //"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
  1587. //成对标签:
  1588. //"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
  1589. //<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,""为右对齐
  1590. //拼凑订单内容时可参考如下格式
  1591. //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
  1592. log.info("utils方法打印开始");
  1593. //region 以前的代码
  1594. String content = "<AUDIO-REFUND>";
  1595. content += "<CB>测试打印</CB><BR>";
  1596. content += "名称      单价 数量 金额<BR>";
  1597. content += "--------------------------------<BR>";
  1598. content += "<B>饭       1.0 1 1.0</B><BR>";
  1599. content += "<BOLD>炒饭      10.0 10 10.0</BOLD><BR>";
  1600. content += "<B><BOLD>蛋炒饭     10.0 10 100.0</B></BOLD><BR>";
  1601. content += "<B><BOLD>蛋炒饭     10.0 10 100.0</BOLD></B><BR>";
  1602. content += "鸡蛋炒饭    100.0 1 100.0<BR>";
  1603. content += "番茄蛋炒饭   1000.0 1 100.0<BR>";
  1604. content += "西红柿蛋炒饭  1000.0 1 100.0<BR>";
  1605. content += "西红柿鸡蛋炒饭 100.0 10 100.0<BR>";
  1606. content += "备注:加辣<BR>";
  1607. content += "--------------------------------<BR>";
  1608. content += "合计:xx.0元<BR>";
  1609. content += "送货地点:广州市南沙区xx路xx号<BR>";
  1610. content += "联系电话:13888888888888<BR>";
  1611. content += "订餐时间:2016-08-08 08:08:08<BR>";
  1612. content += "<QR>http://www.dzist.com</QR>";
  1613. //endregion
  1614. log.info("utils方法打印开始1");
  1615. StringBuilder stringBuilder = new StringBuilder();
  1616. log.info("utils方法打印开始2");
  1617. //region 以前的代码
  1618. /*stringBuilder.append("<BR>").append("<BR>").append("<BR>");
  1619. stringBuilder.append("<CB>").append(tbOrder.getShopName()).append("</CB><BR>");
  1620. if(tbOrder.getOrderType()==1){
  1621. stringBuilder.append("<BOLD>类型:").append("到店取餐</BOLD><BR>");
  1622. stringBuilder.append("<BOLD>取餐号:").append(tbOrder.getOrderCode()).append("</BOLD><BR>");
  1623. }else{
  1624. stringBuilder.append("<BOLD>类型:").append("外卖配送</BOLD><BR>");
  1625. }
  1626. stringBuilder.append("<BOLD>订单号:").append(tbOrder.getOrderNumber()).append("</BOLD><BR>");
  1627. stringBuilder.append("--------------------------------<BR>");
  1628. stringBuilder.append("名称    单价  数量  金额 <BR>");
  1629. stringBuilder.append("--------------------------------<BR>");
  1630. stringBuilder.append("<BR>");
  1631. for(OrderGoods orderGoods:orderGoodsList){
  1632. BigDecimal sumMoney = orderGoods.getGoodsPrice().multiply(BigDecimal.valueOf(orderGoods.getGoodsNum()));
  1633. String name;
  1634. if(StringUtils.isNotEmpty(orderGoods.getSkuMessage())){
  1635. name=orderGoods.getGoodsName()+"("+orderGoods.getSkuMessage()+")";
  1636. }else{
  1637. name=orderGoods.getGoodsName();
  1638. }
  1639. stringBuilder.append(name).append("<BR>");
  1640. stringBuilder.append("      ");
  1641. stringBuilder.append(orderGoods.getGoodsPrice());
  1642. if(orderGoods.getGoodsPrice().doubleValue()<10){
  1643. stringBuilder.append("  ");
  1644. }else if(orderGoods.getGoodsPrice().doubleValue()<100){
  1645. stringBuilder.append("  ");
  1646. }else{
  1647. stringBuilder.append("  ");
  1648. }
  1649. stringBuilder.append(orderGoods.getGoodsNum());
  1650. stringBuilder.append("  ");
  1651. stringBuilder.append(sumMoney).append("<BR>");
  1652. stringBuilder.append("<BR>");
  1653. }
  1654. stringBuilder.append("--------------------------------<BR>");
  1655. stringBuilder.append("<BOLD>备注:").append(remark).append("</BOLD><BR>");
  1656. stringBuilder.append("--------------------------------<BR>");
  1657. stringBuilder.append("打包费:").append(packMoney).append("元<BR>");
  1658. stringBuilder.append("商品费:").append(goodsMoney).append("元<BR>");
  1659. if(tbOrder.getCouponMoney()!=null){
  1660. stringBuilder.append("优惠券:-").append(tbOrder.getCouponMoney()).append("元<BR>");
  1661. }
  1662. stringBuilder.append("跑腿费:").append(errandMoney).append("元<BR>");
  1663. stringBuilder.append("合计:").append(tbOrder.getPayMoney()).append("元<BR>");
  1664. stringBuilder.append("--------------------------------<BR>");
  1665. if(StringUtils.isNotEmpty(tbOrder.getAddress())){
  1666. JSONObject jsonObject = JSONObject.parseObject(tbOrder.getAddress());
  1667. String addressDetail = jsonObject.getString("addressDetail");
  1668. String city = jsonObject.getString("city");
  1669. String district = jsonObject.getString("district");
  1670. String province = jsonObject.getString("province");
  1671. String userName = jsonObject.getString("userName");
  1672. String phone = jsonObject.getString("userPhone");
  1673. stringBuilder.append("姓名:").append(userName).append("<BR>");
  1674. stringBuilder.append("联系电话:").append(phone).append("<BR>");
  1675. stringBuilder.append("送货地点:").append(province).append(city).append(district).append(addressDetail).append("<BR>");
  1676. }else{
  1677. stringBuilder.append("联系电话:").append(tbOrder.getPhone()).append("<BR>");
  1678. }
  1679. stringBuilder.append("订餐时间:").append(tbOrder.getPayTime()).append("<BR>");*/
  1680. //endregion
  1681. log.info("utils方法打印开始3");
  1682. //通过POST请求,发送打印信息到服务器
  1683. RequestConfig requestConfig = RequestConfig.custom()
  1684. .setSocketTimeout(30000)//读取超时
  1685. .setConnectTimeout(30000)//连接超时
  1686. .build();
  1687. log.info("utils方法打印开始4");
  1688. CloseableHttpClient httpClient = HttpClients.custom()
  1689. .setDefaultRequestConfig(requestConfig)
  1690. .build();
  1691. log.info("utils方法打印开始5");
  1692. String URL = commonInfoService.findOne(325).getValue();
  1693. log.info("utils方法打印开始6");
  1694. String USER = commonInfoService.findOne(326).getValue();
  1695. log.info("utils方法打印开始7");
  1696. String UKEY = commonInfoService.findOne(327).getValue();
  1697. log.info("utils方法打印开始8");
  1698. HttpPost post = new HttpPost(URL);
  1699. log.info("utils方法打印开始9");
  1700. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1701. log.info("utils方法打印开始10");
  1702. nvps.add(new BasicNameValuePair("user", USER));
  1703. log.info("utils方法打印开始11");
  1704. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1705. log.info("utils方法打印开始12");
  1706. nvps.add(new BasicNameValuePair("stime", STIME));
  1707. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1708. nvps.add(new BasicNameValuePair("apiname", "Open_printMsg"));//固定值,不需要修改
  1709. nvps.add(new BasicNameValuePair("sn", sn));
  1710. nvps.add(new BasicNameValuePair("content", content));
  1711. nvps.add(new BasicNameValuePair("times", "1"));//打印联数
  1712. log.info("utils方法打印开始13");
  1713. CloseableHttpResponse response = null;
  1714. String result = null;
  1715. log.info("utils方法打印开始14");
  1716. try {
  1717. log.info("utils方法打印开始15");
  1718. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1719. log.info("utils方法打印开始16");
  1720. response = httpClient.execute(post);
  1721. log.info("utils方法打印开始17");
  1722. int statecode = response.getStatusLine().getStatusCode();
  1723. log.info("utils方法打印开始18");
  1724. if (statecode == 200) {
  1725. log.info("utils方法打印开始19");
  1726. HttpEntity httpentity = response.getEntity();
  1727. log.info("utils方法打印开始20");
  1728. if (httpentity != null) {
  1729. log.info("utils方法打印开始21");
  1730. //服务器返回的JSON字符串,建议要当做日志记录起来
  1731. result = EntityUtils.toString(httpentity);
  1732. log.info("utils方法打印开始22");
  1733. }
  1734. log.info("utils方法打印开始23");
  1735. }
  1736. } catch (Exception e) {
  1737. log.info("utils方法打印开始24" + e.getMessage());
  1738. e.printStackTrace();
  1739. } finally {
  1740. try {
  1741. if (response != null) {
  1742. response.close();
  1743. }
  1744. } catch (IOException e) {
  1745. log.info("utils方法打印开始25" + e.getMessage());
  1746. e.printStackTrace();
  1747. }
  1748. try {
  1749. post.abort();
  1750. } catch (Exception e) {
  1751. log.info("utils方法打印开始26" + e.getMessage());
  1752. e.printStackTrace();
  1753. }
  1754. try {
  1755. httpClient.close();
  1756. } catch (IOException e) {
  1757. log.info("utils方法打印开始27" + e.getMessage());
  1758. e.printStackTrace();
  1759. }
  1760. }
  1761. log.info("打印返回值:" + result);
  1762. return result;
  1763. } catch (Exception e) {
  1764. e.printStackTrace();
  1765. log.error("打印异常:" + e.getMessage(), e);
  1766. }
  1767. return null;
  1768. }
  1769. /**
  1770. * 标签机专用打印订单接口
  1771. *
  1772. * @param sn 打印机编号
  1773. * @return 成功:{"msg":"ok","ret":0,"data":"xxxxxxx_xxxxxxxx_xxxxxxxx","serverExecutedTime":5}
  1774. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1775. */
  1776. private static String printLabelMsg(String sn) {
  1777. String content;
  1778. content = "<DIRECTION>1</DIRECTION>";//设定打印时出纸和打印字体的方向,n 0 或 1,每次设备重启后都会初始化为 0 值设置,1:正向出纸,0:反向出纸,
  1779. 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宽度标签纸打印例子,打开注释调用标签打印接口打印
  1780. //通过POST请求,发送打印信息到服务器
  1781. RequestConfig requestConfig = RequestConfig.custom()
  1782. .setSocketTimeout(30000)//读取超时
  1783. .setConnectTimeout(30000)//连接超时
  1784. .build();
  1785. CloseableHttpClient httpClient = HttpClients.custom()
  1786. .setDefaultRequestConfig(requestConfig)
  1787. .build();
  1788. String URL = commonInfoService.findOne(325).getValue();
  1789. String USER = commonInfoService.findOne(326).getValue();
  1790. String UKEY = commonInfoService.findOne(327).getValue();
  1791. HttpPost post = new HttpPost(URL);
  1792. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1793. nvps.add(new BasicNameValuePair("user", USER));
  1794. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1795. nvps.add(new BasicNameValuePair("stime", STIME));
  1796. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1797. nvps.add(new BasicNameValuePair("apiname", "Open_printLabelMsg"));//固定值,不需要修改
  1798. nvps.add(new BasicNameValuePair("sn", sn));
  1799. nvps.add(new BasicNameValuePair("content", content));
  1800. nvps.add(new BasicNameValuePair("times", "1"));//打印联数
  1801. CloseableHttpResponse response = null;
  1802. String result = null;
  1803. try {
  1804. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1805. response = httpClient.execute(post);
  1806. int statecode = response.getStatusLine().getStatusCode();
  1807. if (statecode == 200) {
  1808. HttpEntity httpentity = response.getEntity();
  1809. if (httpentity != null) {
  1810. //服务器返回的JSON字符串,建议要当做日志记录起来
  1811. result = EntityUtils.toString(httpentity);
  1812. }
  1813. }
  1814. } catch (Exception e) {
  1815. e.printStackTrace();
  1816. } finally {
  1817. try {
  1818. if (response != null) {
  1819. response.close();
  1820. }
  1821. } catch (IOException e) {
  1822. e.printStackTrace();
  1823. }
  1824. try {
  1825. post.abort();
  1826. } catch (Exception e) {
  1827. e.printStackTrace();
  1828. }
  1829. try {
  1830. httpClient.close();
  1831. } catch (IOException e) {
  1832. e.printStackTrace();
  1833. }
  1834. }
  1835. return result;
  1836. }
  1837. /**
  1838. * 查询某订单是否打印成功
  1839. *
  1840. * @param orderid 订单id
  1841. * @return 成功:{"msg":"ok","ret":0,"data":true,"serverExecutedTime":2}//data:true为已打印,false为未打印
  1842. * 失败:{"msg":"错误描述","ret":非0, "data":null,"serverExecutedTime":7}
  1843. */
  1844. private static String queryOrderState(String orderid) {
  1845. //通过POST请求,发送打印信息到服务器
  1846. RequestConfig requestConfig = RequestConfig.custom()
  1847. .setSocketTimeout(30000)//读取超时
  1848. .setConnectTimeout(30000)//连接超时
  1849. .build();
  1850. CloseableHttpClient httpClient = HttpClients.custom()
  1851. .setDefaultRequestConfig(requestConfig)
  1852. .build();
  1853. String URL = commonInfoService.findOne(325).getValue();
  1854. String USER = commonInfoService.findOne(326).getValue();
  1855. String UKEY = commonInfoService.findOne(327).getValue();
  1856. HttpPost post = new HttpPost(URL);
  1857. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1858. nvps.add(new BasicNameValuePair("user", USER));
  1859. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1860. nvps.add(new BasicNameValuePair("stime", STIME));
  1861. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1862. nvps.add(new BasicNameValuePair("apiname", "Open_queryOrderState"));//固定值,不需要修改
  1863. nvps.add(new BasicNameValuePair("orderid", orderid));
  1864. CloseableHttpResponse response = null;
  1865. String result = null;
  1866. try {
  1867. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1868. response = httpClient.execute(post);
  1869. int statecode = response.getStatusLine().getStatusCode();
  1870. if (statecode == 200) {
  1871. HttpEntity httpentity = response.getEntity();
  1872. if (httpentity != null) {
  1873. //服务器返回
  1874. result = EntityUtils.toString(httpentity);
  1875. }
  1876. }
  1877. } catch (Exception e) {
  1878. e.printStackTrace();
  1879. } finally {
  1880. try {
  1881. if (response != null) {
  1882. response.close();
  1883. }
  1884. } catch (IOException e) {
  1885. e.printStackTrace();
  1886. }
  1887. try {
  1888. post.abort();
  1889. } catch (Exception e) {
  1890. e.printStackTrace();
  1891. }
  1892. try {
  1893. httpClient.close();
  1894. } catch (IOException e) {
  1895. e.printStackTrace();
  1896. }
  1897. }
  1898. return result;
  1899. }
  1900. /**
  1901. * 查询指定打印机某天的订单详情
  1902. *
  1903. * @param sn 打印机编号
  1904. * @param strdate 时间 "yyyy-MM-dd"
  1905. * @return 成功:{"msg":"ok","ret":0,"data":{"print":6,"waiting":1},"serverExecutedTime":9}//print已打印,waiting为打印
  1906. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1907. */
  1908. private static String queryOrderInfoByDate(String sn, String strdate) {
  1909. //通过POST请求,发送打印信息到服务器
  1910. RequestConfig requestConfig = RequestConfig.custom()
  1911. .setSocketTimeout(30000)//读取超时
  1912. .setConnectTimeout(30000)//连接超时
  1913. .build();
  1914. CloseableHttpClient httpClient = HttpClients.custom()
  1915. .setDefaultRequestConfig(requestConfig)
  1916. .build();
  1917. String URL = commonInfoService.findOne(325).getValue();
  1918. String USER = commonInfoService.findOne(326).getValue();
  1919. String UKEY = commonInfoService.findOne(327).getValue();
  1920. HttpPost post = new HttpPost(URL);
  1921. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1922. nvps.add(new BasicNameValuePair("user", USER));
  1923. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1924. nvps.add(new BasicNameValuePair("stime", STIME));
  1925. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1926. nvps.add(new BasicNameValuePair("apiname", "Open_queryOrderInfoByDate"));//固定值,不需要修改
  1927. nvps.add(new BasicNameValuePair("sn", sn));
  1928. nvps.add(new BasicNameValuePair("date", strdate));//yyyy-MM-dd格式
  1929. CloseableHttpResponse response = null;
  1930. String result = null;
  1931. try {
  1932. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1933. response = httpClient.execute(post);
  1934. int statecode = response.getStatusLine().getStatusCode();
  1935. if (statecode == 200) {
  1936. HttpEntity httpentity = response.getEntity();
  1937. if (httpentity != null) {
  1938. //服务器返回
  1939. result = EntityUtils.toString(httpentity);
  1940. }
  1941. }
  1942. } catch (Exception e) {
  1943. e.printStackTrace();
  1944. } finally {
  1945. try {
  1946. if (response != null) {
  1947. response.close();
  1948. }
  1949. } catch (IOException e) {
  1950. e.printStackTrace();
  1951. }
  1952. try {
  1953. post.abort();
  1954. } catch (Exception e) {
  1955. e.printStackTrace();
  1956. }
  1957. try {
  1958. httpClient.close();
  1959. } catch (IOException e) {
  1960. e.printStackTrace();
  1961. }
  1962. }
  1963. return result;
  1964. }
  1965. /**
  1966. * 查询打印机的状态
  1967. *
  1968. * @param sn 打印机编号
  1969. * @return 成功:{"msg":"ok","ret":0,"data":"状态","serverExecutedTime":4}
  1970. * 失败:{"msg":"错误描述","ret":非0,"data":"null","serverExecutedTime":5}
  1971. */
  1972. private static String queryPrinterStatus(String sn) {
  1973. //通过POST请求,发送打印信息到服务器
  1974. RequestConfig requestConfig = RequestConfig.custom()
  1975. .setSocketTimeout(30000)//读取超时
  1976. .setConnectTimeout(30000)//连接超时
  1977. .build();
  1978. CloseableHttpClient httpClient = HttpClients.custom()
  1979. .setDefaultRequestConfig(requestConfig)
  1980. .build();
  1981. String URL = commonInfoService.findOne(325).getValue();
  1982. String USER = commonInfoService.findOne(326).getValue();
  1983. String UKEY = commonInfoService.findOne(327).getValue();
  1984. HttpPost post = new HttpPost(URL);
  1985. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  1986. nvps.add(new BasicNameValuePair("user", USER));
  1987. String STIME = String.valueOf(System.currentTimeMillis() / 1000);
  1988. nvps.add(new BasicNameValuePair("stime", STIME));
  1989. nvps.add(new BasicNameValuePair("sig", signature(USER, UKEY, STIME)));
  1990. nvps.add(new BasicNameValuePair("apiname", "Open_queryPrinterStatus"));//固定值,不需要修改
  1991. nvps.add(new BasicNameValuePair("sn", sn));
  1992. CloseableHttpResponse response = null;
  1993. String result = null;
  1994. try {
  1995. post.setEntity(new UrlEncodedFormEntity(nvps, "utf-8"));
  1996. response = httpClient.execute(post);
  1997. int statecode = response.getStatusLine().getStatusCode();
  1998. if (statecode == 200) {
  1999. HttpEntity httpentity = response.getEntity();
  2000. if (httpentity != null) {
  2001. //服务器返回
  2002. result = EntityUtils.toString(httpentity);
  2003. }
  2004. }
  2005. } catch (Exception e) {
  2006. e.printStackTrace();
  2007. } finally {
  2008. try {
  2009. if (response != null) {
  2010. response.close();
  2011. }
  2012. } catch (IOException e) {
  2013. e.printStackTrace();
  2014. }
  2015. try {
  2016. post.abort();
  2017. } catch (Exception e) {
  2018. e.printStackTrace();
  2019. }
  2020. try {
  2021. httpClient.close();
  2022. } catch (IOException e) {
  2023. e.printStackTrace();
  2024. }
  2025. }
  2026. return result;
  2027. }
  2028. //生成签名字符串
  2029. private static String signature(String USER, String UKEY, String STIME) {
  2030. String s = DigestUtils.sha1Hex(USER + UKEY + STIME);
  2031. return s;
  2032. }
  2033. /**
  2034. * 飞鹅技术支持-2020-03-25
  2035. * #########################################################################################################
  2036. * 一,纯数字条件下:
  2037. * 58mm打印机最大支持28位纯数字,80mm打印机最大支持46位纯数字,超出无效
  2038. *
  2039. * 26-28位数字条形码,在数字中不可以出现2个及以上连续的0存在
  2040. * 23-25位数字条形码,在数字中不可以出现3个及以上连续的0存在
  2041. * 21-22位数字条形码,在数字中不可以出现4个及以上连续的0存在
  2042. * 19-20位数字条形码,在数字中不可以出现6个及以上连续的0存在
  2043. * 17-18位数字条形码,在数字中不可以出现8个及以上连续的0存在
  2044. * 15-16位数字条形码,在数字中不可以出现10个及以上连续的0存在
  2045. * 少于或等于14位数字的条形码,0的数量没有影响
  2046. * #########################################################################################################
  2047. * 二,非纯数字混合条件下:
  2048. * 58mm打印机最大支持14位字符,80mm打印机最大支持23位字符,超出无效
  2049. *
  2050. * 支持数字,大小写字母,特殊字符例如: !@#$%^&*()-=+_
  2051. * #########################################################################################################
  2052. * 把条形码函数返回值,调用飞鹅云打印接口发给打印机打印
  2053. */
  2054. private static String getDigitBarCode(String input) {
  2055. String chr = "";
  2056. String laststr = "";
  2057. byte[] codeB = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39 }; // 匹配字符集B
  2058. byte[] codeC = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  2059. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
  2060. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31,
  2061. 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42,
  2062. 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53,
  2063. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63 }; // 匹配字符集C
  2064. int length = input.length();
  2065. byte[] b = new byte[100];
  2066. b[0] = 0x1b;
  2067. b[1] = 0x64;
  2068. b[2] = 0x02;
  2069. b[3] = 0x1d;
  2070. b[4] = 0x48;
  2071. b[5] = 0x32; // 0x32打印条形码下的数字, 0x30不打印条形码下的数字
  2072. b[6] = 0x1d;
  2073. b[7] = 0x68;
  2074. b[8] = 0x50; // 7F是最大的高度
  2075. b[9] = 0x1d;
  2076. b[10] = 0x77;
  2077. b[11] = 0x02; // 2-6 条码宽度
  2078. b[12] = 0x1d;
  2079. b[13] = 0x6b;
  2080. b[14] = 0x49; // code128
  2081. b[15] = (byte) (length + 2); // 得出条形码长度
  2082. b[16] = 0x7b;
  2083. b[17] = 0x42;
  2084. boolean result=input.matches("[0-9]+");//判断是否为纯数字
  2085. if (length > 14 && result == true) {
  2086. b[17] = 0x43;
  2087. int j = 0;
  2088. int key = 18;
  2089. int ss = length / 2;// 初始化数组长度
  2090. String temp = "";
  2091. int iindex = 0;
  2092. for (int i = 0; i < ss; i++) {
  2093. temp = input.substring(j, j + 2);
  2094. iindex = Integer.valueOf(temp);
  2095. j = j + 2;
  2096. if (iindex == 0) {
  2097. chr = "";
  2098. if(b[key + i - 1] == '0' && b[key + i - 2] == '0') {
  2099. b[key + i] = codeB[0];
  2100. b[key + i+1] = codeB[0];
  2101. key+=1;
  2102. }else {
  2103. if(b[key + i-1] == 'C' && b[key + i-2] == '{' ){//判断前面的为字符集C时转换字符集B
  2104. b[key + i - 2] = 0x7b;
  2105. b[key + i - 1] = 0x42;
  2106. b[key + i] = codeB[0];
  2107. b[key + i + 1] = codeB[0];
  2108. key += 1;
  2109. }else{
  2110. b[key + i] = 0x7b;
  2111. b[key + i + 1] = 0x42;
  2112. b[key + i + 2] = codeB[0];
  2113. b[key + i + 3] = codeB[0];
  2114. key += 3;
  2115. }
  2116. }
  2117. } else {
  2118. // 判断前面的为字符集B,此时要转换字符集C
  2119. if (b[key + i - 1] == '0' && b[key + i - 2] == '0' && chr != "chr") {
  2120. b[key + i] = 0x7b;
  2121. b[key + i + 1] = 0x43;
  2122. b[key + i + 2] = codeC[iindex];
  2123. key += 2;
  2124. }else {
  2125. chr = "";
  2126. b[key + i] = codeC[iindex];
  2127. if(iindex == 48) chr = "chr";//判断chr(48)等于0的情况
  2128. }
  2129. }
  2130. }
  2131. int lastKey = getLastIndex(b);
  2132. if (length % 2 > 0) {
  2133. int lastnum = Integer.valueOf(input.substring(input.length() - 1)); // 取得字符串的最后一个数字
  2134. if(b[lastKey] == '0' && b[lastKey-1] == '0'){//判断前面的为字符集B,此时不需要转换字符集
  2135. b[lastKey + 1] = codeB[lastnum];
  2136. }else{
  2137. b[lastKey + 1] = 0x7b;
  2138. b[lastKey + 2] = 0x42;
  2139. b[lastKey + 3] = codeB[lastnum];
  2140. }
  2141. }
  2142. // 得出条形码长度
  2143. int blength = getLastIndex(b);
  2144. int len = (blength - 15);
  2145. b[15] = (byte) (len);
  2146. String str = "";
  2147. str = new String(b);
  2148. laststr = str;
  2149. String Last_two = input.substring(input.length()-2,input.length());
  2150. int Last_two_int = 0;
  2151. Last_two_int = Integer.valueOf(Last_two);
  2152. if(Last_two_int > 32) {
  2153. laststr = laststr.trim().substring(1);
  2154. }
  2155. } else { // 1-14位数字的条形码进来这个区间
  2156. b[15] = (byte) (length+2);
  2157. laststr = new String(b);
  2158. laststr = laststr.substring(0, 18);
  2159. laststr += input;
  2160. }
  2161. return laststr;
  2162. }
  2163. // 获取数组中最后一个不是0x0的元素的下标
  2164. private static int getLastIndex(byte[] b) {
  2165. if (b == null || b.length == 0) {
  2166. return 0;
  2167. }
  2168. int blength = 0;
  2169. for (int i = b.length - 1; i >= 0; i--) {
  2170. if (b[i] != 0x0) {
  2171. blength = i;
  2172. break;
  2173. }
  2174. }
  2175. return blength;
  2176. }
  2177. public static void main(String[] args) {
  2178. String result = getDigitBarCode("!@#$%^&*()-=+_");
  2179. }
  2180. }