PrintInfoController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. package com.sqx.modules.printInfo.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.fasterxml.jackson.core.JsonProcessingException;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.sqx.common.utils.Result;
  6. import com.sqx.modules.address.entity.Address;
  7. import com.sqx.modules.goods.entity.GoodsShop;
  8. import com.sqx.modules.goods.service.GoodsShopService;
  9. import com.sqx.modules.order.entity.TbOrder;
  10. import com.sqx.modules.order.service.AppOrderService;
  11. import com.sqx.modules.order.service.impl.AppAppOrderServiceImpl;
  12. import com.sqx.modules.printInfo.entity.*;
  13. import com.sqx.modules.printInfo.service.PrintInfoService;
  14. import com.sqx.modules.printInfo.service.PrintInfoShopService;
  15. import com.sqx.modules.utils.fieYun.FeiYunUtils;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiModelProperty;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.apache.commons.lang.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.web.bind.annotation.*;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.stream.Collectors;
  25. /**
  26. * <p>
  27. * 活动管理
  28. * </p>
  29. *
  30. * @author 吴畅
  31. * @since 2022-11-04
  32. */
  33. @RestController
  34. @Api(value = "管理端-打印模板信息", tags = {"管理端-打印模板信息"})
  35. @RequestMapping("/admin/printInfo/")
  36. public class PrintInfoController {
  37. @Autowired
  38. private PrintInfoService printInfoService;
  39. @Autowired
  40. private PrintInfoShopService printInfoShopService;
  41. @Autowired
  42. private AppAppOrderServiceImpl appAppOrderService;
  43. @Autowired
  44. private GoodsShopService goodsShopService;
  45. @GetMapping("testPrintModel")
  46. @ApiOperation("获取打印信息列表")
  47. public Result testPrintModel(Long orderId) {
  48. // 查询订单信息
  49. TbOrder tbOrder = appAppOrderService.selectOrderByIds(orderId);
  50. Long shopId = tbOrder.getShopId();
  51. // 查询店铺信息
  52. GoodsShop goodsShop = goodsShopService.selectGoodDatas(shopId);
  53. // 查询当天店铺所有已支付的订单号,按支付时间排序
  54. tbOrder.setCountOrder(3);
  55. if (StringUtils.isNotEmpty(goodsShop.getSnCode())) {
  56. FeiYunUtils.print(goodsShop.getSnCode(), null, tbOrder);
  57. } else {
  58. return Result.error("当前商家未绑定打印机!");
  59. }
  60. return Result.success();
  61. }
  62. @GetMapping("getPrintInfoList")
  63. @ApiOperation("获取打印信息列表")
  64. public Result getPrintInfoList(Integer page, Integer limit) {
  65. return printInfoService.selectPrintInfoList(page, limit);
  66. }
  67. @GetMapping("getPrintInfo")
  68. @ApiOperation("获取打印信息")
  69. public Result getPrintInfoInfo(Integer id) {
  70. return printInfoService.selectPrintInfoById(id);
  71. }
  72. @PostMapping("insertPrintInfo")
  73. @ApiOperation("新增打印信息")
  74. public Result insertPrintInfo(@RequestBody PrintInfo printInfo) {
  75. return printInfoService.insertPrintInfo(printInfo);
  76. }
  77. @GetMapping("updatePrintInfo")
  78. @ApiOperation("更新打印信息")
  79. private Result updatePrintInfo(@RequestBody PrintInfo printInfo) {
  80. return printInfoService.updatePrintInfo(printInfo);
  81. }
  82. @GetMapping("getPrintDropList")
  83. @ApiOperation("获取打印信息类型下拉列表")
  84. public Result getPrintDropList() {
  85. int length = ePrintStatu.values().length;
  86. List<PrintDropVo> result = new ArrayList<>();
  87. for (int i = 1; i < length + 1; i++) {
  88. PrintDropVo data = new PrintDropVo();
  89. data.setId(i);
  90. data.setName(ePrintStatu.stringOf(i));
  91. result.add(data);
  92. }
  93. return Result.success().put("data", result);
  94. }
  95. /**
  96. * 根据店铺ID获取对应店铺的打印模板信息
  97. *
  98. * @param shopId
  99. * @return
  100. */
  101. @GetMapping("getPrintModelData")
  102. @ApiOperation("获取打印模板信息")
  103. public Result getPrintModelData(Integer shopId) throws JsonProcessingException {
  104. if (shopId == null) {
  105. return Result.error("商铺ID不能为空");
  106. }
  107. PrintResultModelVo resultData = new PrintResultModelVo();
  108. resultData.setShopId(shopId);
  109. List<PrintModelResult> result = new ArrayList<>();
  110. List<PrintInfo> infos = printInfoService.printInfos();
  111. List<Integer> typeIds = infos.stream().map(PrintInfo::getTypeId).distinct().collect(Collectors.toList());
  112. PrintInfoShop pis = printInfoShopService.selectPrintInfoShopById(shopId);
  113. if (pis == null) {
  114. for (Integer typeId : typeIds) {
  115. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == typeId.intValue()).collect(Collectors.toList());
  116. PrintModelResult data = new PrintModelResult();
  117. List<PrintModelDetailResult> details = new ArrayList<>();
  118. List<PrintModelTypeResult> types = new ArrayList<>();
  119. for (PrintInfo nowInfo : nowInfos) {
  120. PrintModelDetailResult detailData = new PrintModelDetailResult();
  121. detailData.setId(nowInfo.getId());
  122. detailData.setPrintField(nowInfo.getPrintField());
  123. detailData.setPrintName(nowInfo.getPrintName());
  124. detailData.setIsCheck(0);
  125. details.add(detailData);
  126. PrintModelTypeResult typeData = new PrintModelTypeResult();
  127. typeData.setId(nowInfo.getId());
  128. typeData.setIsBlod(0);
  129. typeData.setWordSize(0);
  130. typeData.setPrintField(nowInfo.getPrintField());
  131. typeData.setPrintName(nowInfo.getPrintName());
  132. types.add(typeData);
  133. }
  134. if (nowInfos != null && nowInfos.size() > 0) {
  135. data.setId(typeId);
  136. data.setName(nowInfos.get(0).getTypeName());
  137. }
  138. data.setDetails(details);
  139. data.setTypes(types);
  140. result.add(data);
  141. }
  142. } else {
  143. //要修改获取逻辑
  144. resultData.setId(pis.getId());
  145. if (pis.getBaseInfo().isEmpty()) {
  146. PrintModelResult data = new PrintModelResult();
  147. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Base.getValue()).collect(Collectors.toList());
  148. List<PrintModelDetailResult> details = new ArrayList<>();
  149. List<PrintModelTypeResult> types = new ArrayList<>();
  150. for (PrintInfo nowInfo : nowInfos) {
  151. PrintModelDetailResult detailData = new PrintModelDetailResult();
  152. detailData.setId(nowInfo.getId());
  153. detailData.setPrintField(nowInfo.getPrintField());
  154. detailData.setPrintName(nowInfo.getPrintName());
  155. detailData.setIsCheck(0);
  156. details.add(detailData);
  157. PrintModelTypeResult typeData = new PrintModelTypeResult();
  158. typeData.setId(nowInfo.getId());
  159. typeData.setIsBlod(0);
  160. typeData.setWordSize(0);
  161. typeData.setPrintField(nowInfo.getPrintField());
  162. typeData.setPrintName(nowInfo.getPrintName());
  163. types.add(typeData);
  164. }
  165. data.setId(ePrintStatu.Base.getValue());
  166. data.setName(nowInfos.get(0).getTypeName());
  167. data.setDetails(details);
  168. data.setTypes(types);
  169. result.add(data);
  170. } else {
  171. ObjectMapper objectMapper = new ObjectMapper();
  172. PrintModelResult data = objectMapper.readValue(pis.getBaseInfo(), PrintModelResult.class);
  173. result.add(data);
  174. }
  175. if (pis.getGoodInfo().isEmpty()) {
  176. PrintModelResult data = new PrintModelResult();
  177. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Good.getValue()).collect(Collectors.toList());
  178. List<PrintModelDetailResult> details = new ArrayList<>();
  179. List<PrintModelTypeResult> types = new ArrayList<>();
  180. for (PrintInfo nowInfo : nowInfos) {
  181. PrintModelDetailResult detailData = new PrintModelDetailResult();
  182. detailData.setId(nowInfo.getId());
  183. detailData.setPrintField(nowInfo.getPrintField());
  184. detailData.setPrintName(nowInfo.getPrintName());
  185. detailData.setIsCheck(0);
  186. details.add(detailData);
  187. PrintModelTypeResult typeData = new PrintModelTypeResult();
  188. typeData.setId(nowInfo.getId());
  189. typeData.setIsBlod(0);
  190. typeData.setWordSize(0);
  191. typeData.setPrintField(nowInfo.getPrintField());
  192. typeData.setPrintName(nowInfo.getPrintName());
  193. types.add(typeData);
  194. }
  195. data.setId(ePrintStatu.Good.getValue());
  196. data.setName(nowInfos.get(0).getTypeName());
  197. data.setDetails(details);
  198. data.setTypes(types);
  199. result.add(data);
  200. } else {
  201. ObjectMapper objectMapper = new ObjectMapper();
  202. PrintModelResult data = objectMapper.readValue(pis.getGoodInfo(), PrintModelResult.class);
  203. result.add(data);
  204. }
  205. if (pis.getPayInfo().isEmpty()) {
  206. PrintModelResult data = new PrintModelResult();
  207. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Pay.getValue()).collect(Collectors.toList());
  208. List<PrintModelDetailResult> details = new ArrayList<>();
  209. List<PrintModelTypeResult> types = new ArrayList<>();
  210. for (PrintInfo nowInfo : nowInfos) {
  211. PrintModelDetailResult detailData = new PrintModelDetailResult();
  212. detailData.setId(nowInfo.getId());
  213. detailData.setPrintField(nowInfo.getPrintField());
  214. detailData.setPrintName(nowInfo.getPrintName());
  215. detailData.setIsCheck(0);
  216. details.add(detailData);
  217. PrintModelTypeResult typeData = new PrintModelTypeResult();
  218. typeData.setId(nowInfo.getId());
  219. typeData.setIsBlod(0);
  220. typeData.setWordSize(0);
  221. typeData.setPrintField(nowInfo.getPrintField());
  222. typeData.setPrintName(nowInfo.getPrintName());
  223. types.add(typeData);
  224. }
  225. data.setId(ePrintStatu.Pay.getValue());
  226. data.setName(nowInfos.get(0).getTypeName());
  227. data.setDetails(details);
  228. data.setTypes(types);
  229. result.add(data);
  230. } else {
  231. ObjectMapper objectMapper = new ObjectMapper();
  232. PrintModelResult data = objectMapper.readValue(pis.getPayInfo(), PrintModelResult.class);
  233. result.add(data);
  234. }
  235. if (pis.getUserInfo().isEmpty()) {
  236. PrintModelResult data = new PrintModelResult();
  237. List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.User.getValue()).collect(Collectors.toList());
  238. List<PrintModelDetailResult> details = new ArrayList<>();
  239. List<PrintModelTypeResult> types = new ArrayList<>();
  240. for (PrintInfo nowInfo : nowInfos) {
  241. PrintModelDetailResult detailData = new PrintModelDetailResult();
  242. detailData.setId(nowInfo.getId());
  243. detailData.setPrintField(nowInfo.getPrintField());
  244. detailData.setPrintName(nowInfo.getPrintName());
  245. detailData.setIsCheck(0);
  246. details.add(detailData);
  247. PrintModelTypeResult typeData = new PrintModelTypeResult();
  248. typeData.setId(nowInfo.getId());
  249. typeData.setIsBlod(0);
  250. typeData.setWordSize(0);
  251. typeData.setPrintField(nowInfo.getPrintField());
  252. typeData.setPrintName(nowInfo.getPrintName());
  253. types.add(typeData);
  254. }
  255. data.setId(ePrintStatu.User.getValue());
  256. data.setName(nowInfos.get(0).getTypeName());
  257. data.setDetails(details);
  258. data.setTypes(types);
  259. result.add(data);
  260. } else {
  261. ObjectMapper objectMapper = new ObjectMapper();
  262. PrintModelResult data = objectMapper.readValue(pis.getUserInfo(), PrintModelResult.class);
  263. result.add(data);
  264. }
  265. }
  266. resultData.setModelDatas(result);
  267. return Result.success().put("data", resultData);
  268. }
  269. /**
  270. * 根据店铺ID获取对应店铺的打印模板信息
  271. *
  272. * @param printResult 模板信息数据
  273. * @return
  274. */
  275. @PostMapping("insertPrintModelData")
  276. @ApiOperation("新增打印模板信息")
  277. public Result insertPrintModelData(@RequestBody PrintResultModelVo printResult) {
  278. PrintInfoShop pis = new PrintInfoShop();
  279. pis.setShopId(printResult.getShopId());
  280. if (printResult != null && printResult.getModelDatas() != null && printResult.getModelDatas().size() > 0) {
  281. for (PrintModelResult pmr : printResult.getModelDatas()) {
  282. switch (pmr.getId().intValue()) {
  283. case 1://基本信息:1
  284. pis.setBaseInfo(JSON.toJSONString(pmr));
  285. break;
  286. case 2:// 商品信息:2
  287. pis.setGoodInfo(JSON.toJSONString(pmr));
  288. break;
  289. case 3:// 支付信息:3
  290. pis.setPayInfo(JSON.toJSONString(pmr));
  291. break;
  292. case 4:// 用户信息:4
  293. pis.setUserInfo(JSON.toJSONString(pmr));
  294. break;
  295. default:
  296. break;
  297. }
  298. }
  299. }
  300. return printInfoShopService.insertPrintInfoShop(pis);
  301. }
  302. /**
  303. * 根据店铺ID获取对应店铺的打印模板信息
  304. *
  305. * @param printResult 模板信息数据
  306. * @return
  307. */
  308. @PostMapping("updatePrintModelData")
  309. @ApiOperation("更新打印模板信息")
  310. public Result updatePrintModelData(@RequestBody PrintResultModelVo printResult) {
  311. PrintInfoShop pis = new PrintInfoShop();
  312. pis.setId(printResult.getId());
  313. pis.setShopId(printResult.getShopId());
  314. if (printResult != null && printResult.getModelDatas() != null && printResult.getModelDatas().size() > 0) {
  315. for (PrintModelResult pmr : printResult.getModelDatas()) {
  316. switch (pmr.getId().intValue()) {
  317. case 1://基本信息:1
  318. pis.setBaseInfo(JSON.toJSONString(pmr));
  319. break;
  320. case 2:// 商品信息:2
  321. pis.setGoodInfo(JSON.toJSONString(pmr));
  322. break;
  323. case 3:// 支付信息:3
  324. pis.setPayInfo(JSON.toJSONString(pmr));
  325. break;
  326. case 4:// 用户信息:4
  327. pis.setUserInfo(JSON.toJSONString(pmr));
  328. break;
  329. default:
  330. break;
  331. }
  332. }
  333. }
  334. return printInfoShopService.updatePrintInfoShop(pis);
  335. }
  336. /**
  337. * 测试打印功能
  338. */
  339. @GetMapping("testPrintInfo")
  340. @ApiOperation("测试打印功能")
  341. public Result testPrintInfo(String sn) {
  342. FeiYunUtils.testPrint(sn);
  343. return Result.success();
  344. }
  345. }