| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 |
- package com.sqx.modules.printInfo.controller;
- import com.alibaba.fastjson.JSON;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.sqx.common.utils.Result;
- import com.sqx.modules.address.entity.Address;
- import com.sqx.modules.goods.entity.GoodsShop;
- import com.sqx.modules.goods.service.GoodsShopService;
- import com.sqx.modules.order.entity.TbOrder;
- import com.sqx.modules.order.service.AppOrderService;
- import com.sqx.modules.order.service.impl.AppAppOrderServiceImpl;
- import com.sqx.modules.printInfo.entity.*;
- import com.sqx.modules.printInfo.service.PrintInfoService;
- import com.sqx.modules.printInfo.service.PrintInfoShopService;
- import com.sqx.modules.utils.fieYun.FeiYunUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiModelProperty;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 活动管理
- * </p>
- *
- * @author 吴畅
- * @since 2022-11-04
- */
- @RestController
- @Api(value = "管理端-打印模板信息", tags = {"管理端-打印模板信息"})
- @RequestMapping("/admin/printInfo/")
- public class PrintInfoController {
- @Autowired
- private PrintInfoService printInfoService;
- @Autowired
- private PrintInfoShopService printInfoShopService;
- @Autowired
- private AppAppOrderServiceImpl appAppOrderService;
- @Autowired
- private GoodsShopService goodsShopService;
- @GetMapping("testPrintModel")
- @ApiOperation("获取打印信息列表")
- public Result testPrintModel(Long orderId) {
- // 查询订单信息
- TbOrder tbOrder = appAppOrderService.selectOrderByIds(orderId);
- Long shopId = tbOrder.getShopId();
- // 查询店铺信息
- GoodsShop goodsShop = goodsShopService.selectGoodDatas(shopId);
- // 查询当天店铺所有已支付的订单号,按支付时间排序
- tbOrder.setCountOrder(3);
- if (StringUtils.isNotEmpty(goodsShop.getSnCode())) {
- FeiYunUtils.print(goodsShop.getSnCode(), null, tbOrder);
- } else {
- return Result.error("当前商家未绑定打印机!");
- }
- return Result.success();
- }
- @GetMapping("getPrintInfoList")
- @ApiOperation("获取打印信息列表")
- public Result getPrintInfoList(Integer page, Integer limit) {
- return printInfoService.selectPrintInfoList(page, limit);
- }
- @GetMapping("getPrintInfo")
- @ApiOperation("获取打印信息")
- public Result getPrintInfoInfo(Integer id) {
- return printInfoService.selectPrintInfoById(id);
- }
- @PostMapping("insertPrintInfo")
- @ApiOperation("新增打印信息")
- public Result insertPrintInfo(@RequestBody PrintInfo printInfo) {
- return printInfoService.insertPrintInfo(printInfo);
- }
- @GetMapping("updatePrintInfo")
- @ApiOperation("更新打印信息")
- private Result updatePrintInfo(@RequestBody PrintInfo printInfo) {
- return printInfoService.updatePrintInfo(printInfo);
- }
- @GetMapping("getPrintDropList")
- @ApiOperation("获取打印信息类型下拉列表")
- public Result getPrintDropList() {
- int length = ePrintStatu.values().length;
- List<PrintDropVo> result = new ArrayList<>();
- for (int i = 1; i < length + 1; i++) {
- PrintDropVo data = new PrintDropVo();
- data.setId(i);
- data.setName(ePrintStatu.stringOf(i));
- result.add(data);
- }
- return Result.success().put("data", result);
- }
- /**
- * 根据店铺ID获取对应店铺的打印模板信息
- *
- * @param shopId
- * @return
- */
- @GetMapping("getPrintModelData")
- @ApiOperation("获取打印模板信息")
- public Result getPrintModelData(Integer shopId) throws JsonProcessingException {
- if (shopId == null) {
- return Result.error("商铺ID不能为空");
- }
- PrintResultModelVo resultData = new PrintResultModelVo();
- resultData.setShopId(shopId);
- List<PrintModelResult> result = new ArrayList<>();
- List<PrintInfo> infos = printInfoService.printInfos();
- List<Integer> typeIds = infos.stream().map(PrintInfo::getTypeId).distinct().collect(Collectors.toList());
- PrintInfoShop pis = printInfoShopService.selectPrintInfoShopById(shopId);
- if (pis == null) {
- for (Integer typeId : typeIds) {
- List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == typeId.intValue()).collect(Collectors.toList());
- PrintModelResult data = new PrintModelResult();
- List<PrintModelDetailResult> details = new ArrayList<>();
- List<PrintModelTypeResult> types = new ArrayList<>();
- for (PrintInfo nowInfo : nowInfos) {
- PrintModelDetailResult detailData = new PrintModelDetailResult();
- detailData.setId(nowInfo.getId());
- detailData.setPrintField(nowInfo.getPrintField());
- detailData.setPrintName(nowInfo.getPrintName());
- detailData.setIsCheck(0);
- details.add(detailData);
- PrintModelTypeResult typeData = new PrintModelTypeResult();
- typeData.setId(nowInfo.getId());
- typeData.setIsBlod(0);
- typeData.setWordSize(0);
- typeData.setPrintField(nowInfo.getPrintField());
- typeData.setPrintName(nowInfo.getPrintName());
- types.add(typeData);
- }
- if (nowInfos != null && nowInfos.size() > 0) {
- data.setId(typeId);
- data.setName(nowInfos.get(0).getTypeName());
- }
- data.setDetails(details);
- data.setTypes(types);
- result.add(data);
- }
- } else {
- //要修改获取逻辑
- resultData.setId(pis.getId());
- if (pis.getBaseInfo().isEmpty()) {
- PrintModelResult data = new PrintModelResult();
- List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Base.getValue()).collect(Collectors.toList());
- List<PrintModelDetailResult> details = new ArrayList<>();
- List<PrintModelTypeResult> types = new ArrayList<>();
- for (PrintInfo nowInfo : nowInfos) {
- PrintModelDetailResult detailData = new PrintModelDetailResult();
- detailData.setId(nowInfo.getId());
- detailData.setPrintField(nowInfo.getPrintField());
- detailData.setPrintName(nowInfo.getPrintName());
- detailData.setIsCheck(0);
- details.add(detailData);
- PrintModelTypeResult typeData = new PrintModelTypeResult();
- typeData.setId(nowInfo.getId());
- typeData.setIsBlod(0);
- typeData.setWordSize(0);
- typeData.setPrintField(nowInfo.getPrintField());
- typeData.setPrintName(nowInfo.getPrintName());
- types.add(typeData);
- }
- data.setId(ePrintStatu.Base.getValue());
- data.setName(nowInfos.get(0).getTypeName());
- data.setDetails(details);
- data.setTypes(types);
- result.add(data);
- } else {
- ObjectMapper objectMapper = new ObjectMapper();
- PrintModelResult data = objectMapper.readValue(pis.getBaseInfo(), PrintModelResult.class);
- result.add(data);
- }
- if (pis.getGoodInfo().isEmpty()) {
- PrintModelResult data = new PrintModelResult();
- List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Good.getValue()).collect(Collectors.toList());
- List<PrintModelDetailResult> details = new ArrayList<>();
- List<PrintModelTypeResult> types = new ArrayList<>();
- for (PrintInfo nowInfo : nowInfos) {
- PrintModelDetailResult detailData = new PrintModelDetailResult();
- detailData.setId(nowInfo.getId());
- detailData.setPrintField(nowInfo.getPrintField());
- detailData.setPrintName(nowInfo.getPrintName());
- detailData.setIsCheck(0);
- details.add(detailData);
- PrintModelTypeResult typeData = new PrintModelTypeResult();
- typeData.setId(nowInfo.getId());
- typeData.setIsBlod(0);
- typeData.setWordSize(0);
- typeData.setPrintField(nowInfo.getPrintField());
- typeData.setPrintName(nowInfo.getPrintName());
- types.add(typeData);
- }
- data.setId(ePrintStatu.Good.getValue());
- data.setName(nowInfos.get(0).getTypeName());
- data.setDetails(details);
- data.setTypes(types);
- result.add(data);
- } else {
- ObjectMapper objectMapper = new ObjectMapper();
- PrintModelResult data = objectMapper.readValue(pis.getGoodInfo(), PrintModelResult.class);
- result.add(data);
- }
- if (pis.getPayInfo().isEmpty()) {
- PrintModelResult data = new PrintModelResult();
- List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.Pay.getValue()).collect(Collectors.toList());
- List<PrintModelDetailResult> details = new ArrayList<>();
- List<PrintModelTypeResult> types = new ArrayList<>();
- for (PrintInfo nowInfo : nowInfos) {
- PrintModelDetailResult detailData = new PrintModelDetailResult();
- detailData.setId(nowInfo.getId());
- detailData.setPrintField(nowInfo.getPrintField());
- detailData.setPrintName(nowInfo.getPrintName());
- detailData.setIsCheck(0);
- details.add(detailData);
- PrintModelTypeResult typeData = new PrintModelTypeResult();
- typeData.setId(nowInfo.getId());
- typeData.setIsBlod(0);
- typeData.setWordSize(0);
- typeData.setPrintField(nowInfo.getPrintField());
- typeData.setPrintName(nowInfo.getPrintName());
- types.add(typeData);
- }
- data.setId(ePrintStatu.Pay.getValue());
- data.setName(nowInfos.get(0).getTypeName());
- data.setDetails(details);
- data.setTypes(types);
- result.add(data);
- } else {
- ObjectMapper objectMapper = new ObjectMapper();
- PrintModelResult data = objectMapper.readValue(pis.getPayInfo(), PrintModelResult.class);
- result.add(data);
- }
- if (pis.getUserInfo().isEmpty()) {
- PrintModelResult data = new PrintModelResult();
- List<PrintInfo> nowInfos = infos.stream().filter(e -> e.getTypeId().intValue() == ePrintStatu.User.getValue()).collect(Collectors.toList());
- List<PrintModelDetailResult> details = new ArrayList<>();
- List<PrintModelTypeResult> types = new ArrayList<>();
- for (PrintInfo nowInfo : nowInfos) {
- PrintModelDetailResult detailData = new PrintModelDetailResult();
- detailData.setId(nowInfo.getId());
- detailData.setPrintField(nowInfo.getPrintField());
- detailData.setPrintName(nowInfo.getPrintName());
- detailData.setIsCheck(0);
- details.add(detailData);
- PrintModelTypeResult typeData = new PrintModelTypeResult();
- typeData.setId(nowInfo.getId());
- typeData.setIsBlod(0);
- typeData.setWordSize(0);
- typeData.setPrintField(nowInfo.getPrintField());
- typeData.setPrintName(nowInfo.getPrintName());
- types.add(typeData);
- }
- data.setId(ePrintStatu.User.getValue());
- data.setName(nowInfos.get(0).getTypeName());
- data.setDetails(details);
- data.setTypes(types);
- result.add(data);
- } else {
- ObjectMapper objectMapper = new ObjectMapper();
- PrintModelResult data = objectMapper.readValue(pis.getUserInfo(), PrintModelResult.class);
- result.add(data);
- }
- }
- resultData.setModelDatas(result);
- return Result.success().put("data", resultData);
- }
- /**
- * 根据店铺ID获取对应店铺的打印模板信息
- *
- * @param printResult 模板信息数据
- * @return
- */
- @PostMapping("insertPrintModelData")
- @ApiOperation("新增打印模板信息")
- public Result insertPrintModelData(@RequestBody PrintResultModelVo printResult) {
- PrintInfoShop pis = new PrintInfoShop();
- pis.setShopId(printResult.getShopId());
- if (printResult != null && printResult.getModelDatas() != null && printResult.getModelDatas().size() > 0) {
- for (PrintModelResult pmr : printResult.getModelDatas()) {
- switch (pmr.getId().intValue()) {
- case 1://基本信息:1
- pis.setBaseInfo(JSON.toJSONString(pmr));
- break;
- case 2:// 商品信息:2
- pis.setGoodInfo(JSON.toJSONString(pmr));
- break;
- case 3:// 支付信息:3
- pis.setPayInfo(JSON.toJSONString(pmr));
- break;
- case 4:// 用户信息:4
- pis.setUserInfo(JSON.toJSONString(pmr));
- break;
- default:
- break;
- }
- }
- }
- return printInfoShopService.insertPrintInfoShop(pis);
- }
- /**
- * 根据店铺ID获取对应店铺的打印模板信息
- *
- * @param printResult 模板信息数据
- * @return
- */
- @PostMapping("updatePrintModelData")
- @ApiOperation("更新打印模板信息")
- public Result updatePrintModelData(@RequestBody PrintResultModelVo printResult) {
- PrintInfoShop pis = new PrintInfoShop();
- pis.setId(printResult.getId());
- pis.setShopId(printResult.getShopId());
- if (printResult != null && printResult.getModelDatas() != null && printResult.getModelDatas().size() > 0) {
- for (PrintModelResult pmr : printResult.getModelDatas()) {
- switch (pmr.getId().intValue()) {
- case 1://基本信息:1
- pis.setBaseInfo(JSON.toJSONString(pmr));
- break;
- case 2:// 商品信息:2
- pis.setGoodInfo(JSON.toJSONString(pmr));
- break;
- case 3:// 支付信息:3
- pis.setPayInfo(JSON.toJSONString(pmr));
- break;
- case 4:// 用户信息:4
- pis.setUserInfo(JSON.toJSONString(pmr));
- break;
- default:
- break;
- }
- }
- }
- return printInfoShopService.updatePrintInfoShop(pis);
- }
- /**
- * 测试打印功能
- */
- @GetMapping("testPrintInfo")
- @ApiOperation("测试打印功能")
- public Result testPrintInfo(String sn) {
- FeiYunUtils.testPrint(sn);
- return Result.success();
- }
- }
|