Browse Source

pos桌台生成小程序二维码

gqx 2 years ago
parent
commit
82e2773fd7

+ 3 - 6
jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/service/impl/UserInfoServiceImpl.java

@@ -4,10 +4,8 @@ import cn.binarywang.wx.miniapp.api.WxMaUserService;
 import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
-import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.util.StrUtil;
-import com.alibaba.druid.support.json.JSONUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -22,14 +20,13 @@ import org.jeecg.modules.mall.entity.MallUserInfo;
 import org.jeecg.modules.wxuser.dto.LoginDto;
 import org.jeecg.modules.wxuser.dto.WxOpenDataDto;
 import org.jeecg.modules.wxuser.entity.ThirdSession;
-import org.jeecg.modules.wxuser.entity.WxAppConfig;
+import org.jeecg.modules.mall.entity.WxAppConfig;
 import org.jeecg.modules.wxuser.entity.WxUser;
 import org.jeecg.modules.wxuser.mapper.UserInfoMapper;
 import org.jeecg.modules.wxuser.service.IUserInfoService;
-import org.jeecg.modules.wxuser.service.IWxAppConfigService;
+import org.jeecg.modules.mall.service.IWxAppConfigService;
 import org.jeecg.modules.wxuser.service.IWxUserService;
-import org.jeecg.modules.wxuser.weixin.config.ma.WxMaInRedisConfigStorage;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.jeecg.modules.mall.ma.WxMaInRedisConfigStorage;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 

+ 12 - 0
jeecg-module-system/jeecg-system-biz/pom.xml

@@ -53,6 +53,18 @@
 			<artifactId>pinyin4j</artifactId>
 			<version>2.5.0</version>
 		</dependency>
+        <dependency>
+            <groupId>com.github.binarywang</groupId>
+            <artifactId>weixin-java-miniapp</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+        </dependency>
+		<dependency>
+			<groupId>org.springframework</groupId>
+			<artifactId>spring-test</artifactId>
+		</dependency>
 	</dependencies>
 
 </project>

+ 1 - 1
jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/entity/WxAppConfig.java

@@ -1,4 +1,4 @@
-package org.jeecg.modules.wxuser.entity;
+package org.jeecg.modules.mall.entity;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;

+ 1 - 1
jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/weixin/config/ma/WxMaInRedisConfigStorage.java

@@ -1,5 +1,5 @@
 
-package org.jeecg.modules.wxuser.weixin.config.ma;
+package org.jeecg.modules.mall.ma;
 
 import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
 import org.springframework.data.redis.core.RedisTemplate;

+ 2 - 5
jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/mapper/WxAppConfigMapper.java

@@ -1,10 +1,7 @@
-package org.jeecg.modules.wxuser.mapper;
+package org.jeecg.modules.mall.mapper;
 
-import java.util.List;
-
-import org.apache.ibatis.annotations.Param;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.jeecg.modules.wxuser.entity.WxAppConfig;
+import org.jeecg.modules.mall.entity.WxAppConfig;
 
 /**
  * @Description: wx_app_config

jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/mapper/xml/WxAppConfigMapper.xml → jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/mall/mapper/xml/WxAppConfigMapper.xml


+ 2 - 2
jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/service/IWxAppConfigService.java

@@ -1,7 +1,7 @@
-package org.jeecg.modules.wxuser.service;
+package org.jeecg.modules.mall.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
-import org.jeecg.modules.wxuser.entity.WxAppConfig;
+import org.jeecg.modules.mall.entity.WxAppConfig;
 
 /**
  * @Description: wx_app_config

+ 4 - 4
jeecg-mall-api/src/main/java/org/jeecg/modules/wxuser/service/impl/WxAppConfigServiceImpl.java

@@ -1,8 +1,8 @@
-package org.jeecg.modules.wxuser.service.impl;
+package org.jeecg.modules.mall.service.impl;
 
-import org.jeecg.modules.wxuser.entity.WxAppConfig;
-import org.jeecg.modules.wxuser.mapper.WxAppConfigMapper;
-import org.jeecg.modules.wxuser.service.IWxAppConfigService;
+import org.jeecg.modules.mall.entity.WxAppConfig;
+import org.jeecg.modules.mall.mapper.WxAppConfigMapper;
+import org.jeecg.modules.mall.service.IWxAppConfigService;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

+ 46 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/controller/PosSellClearGoodsController.java

@@ -89,6 +89,52 @@ public class PosSellClearGoodsController extends JeecgController<PosSellClearGoo
 	  * @return
 	  */
 	 @ApiOperation(value="pos_sell_clear_goods-分页列表查询", notes="pos_sell_clear_goods-分页列表查询")
+	 @GetMapping(value = "/list2")
+	 public Result<IPage<CesGoods>> queryPageList2(CesGoods cesGoods,
+												  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+												  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+												  @RequestParam(name="goodTypes[]",required = false) List<String> goodTypes,
+												  HttpServletRequest req) {
+		 LambdaQueryWrapper<CesGoods> queryWrapper = QueryGenerator.initQueryWrapper(cesGoods, req.getParameterMap()).lambda();
+		 queryWrapper.eq(CesGoods::getInvalid, false);
+		 queryWrapper.eq(CesGoods::getIsTemp, false);
+		 if (ObjectUtils.isNotEmpty(goodTypes)) {
+			 List<CesStockType> list = cesStockTypeService.list(Wrappers.<CesStockType>lambdaQuery()
+					 .eq(CesStockType::getHotelId, cesGoods.getHotelId())
+					 .eq(CesStockType::getInvalid, false));
+			 queryWrapper.and(j -> {
+				 for (int k = 0; k < goodTypes.size(); k++) {
+					 String id = goodTypes.get(k);
+					 List<CesStockType> stockTypeList = list.stream().filter(t -> t.getParentId().equals(id)).collect(Collectors.toList());
+					 if (ObjectUtils.isNotEmpty(stockTypeList)) {
+						 for (int z = 0; z < stockTypeList.size(); z++) {
+							 j = j.or().eq(CesGoods::getGoodType, stockTypeList.get(z).getId());
+						 }
+					 }
+					 j = j.or().eq(CesGoods::getGoodType, id);
+				 }
+			 });
+		 }
+		 Page<CesGoods> page = new Page<CesGoods>(pageNo, pageSize);
+		 IPage<CesGoods> pageList = cesGoodsService.page(page, queryWrapper);
+		 pageList.getRecords().forEach(item -> {
+			 LambdaQueryWrapper<PosSellClearGoods> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+			 lambdaQueryWrapper.eq(PosSellClearGoods::getGoodsId, item.getId());
+			 Long count = posSellClearGoodsService.count(lambdaQueryWrapper);
+			 item.setIsSellClear(count > 0);
+		 });
+		 return Result.OK(pageList);
+	 }
+
+	 /**
+	  * 商品沽清列表
+	  * @param cesGoods
+	  * @param pageNo
+	  * @param pageSize
+	  * @param req
+	  * @return
+	  */
+	 @ApiOperation(value="pos_sell_clear_goods-分页列表查询", notes="pos_sell_clear_goods-分页列表查询")
 	 @GetMapping(value = "/list")
 	 public Result<IPage<CesGoods>> queryPageList(CesGoods cesGoods,
 														   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,

+ 54 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/controller/PosTableController.java

@@ -1,26 +1,38 @@
 package org.jeecg.modules.pos.controller;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.commons.lang3.ObjectUtils;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.util.JwtUtil;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.CommonUtils;
+import org.jeecg.common.util.TenantContextHolder;
 import org.jeecg.common.util.TokenUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.business.entity.BusHotel;
 import org.jeecg.modules.business.service.IBusHotelService;
+import org.jeecg.modules.mall.entity.MallUserInfo;
+import org.jeecg.modules.mall.entity.WxAppConfig;
+import org.jeecg.modules.mall.ma.WxMaInRedisConfigStorage;
+import org.jeecg.modules.mall.service.IWxAppConfigService;
 import org.jeecg.modules.pos.entity.*;
 import org.jeecg.modules.pos.service.*;
 
@@ -36,6 +48,9 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -67,6 +82,11 @@ public class PosTableController extends JeecgController<PosTable, IPosTableServi
 	 private IPosTableTypeService posTableTypeService;
 	 @Autowired
 	 private IPosOrderGoodsService posOrderGoodsService;
+	 @Resource
+	 private IWxAppConfigService wxAppConfigService;
+	 @Resource
+	 private RedisTemplate redisTemplate;
+
 	/**
 	 * 分页列表查询
 	 *
@@ -155,10 +175,40 @@ public class PosTableController extends JeecgController<PosTable, IPosTableServi
 				throw new JeecgBootException("当前登录人租户信息错误");
 			}
 		}
+
+		LambdaQueryWrapper<WxAppConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+		lambdaQueryWrapper.eq(WxAppConfig::getTenantId, posTable.getTenantId());
+		WxAppConfig wxApp = wxAppConfigService.getOne(lambdaQueryWrapper);
+		if (wxApp == null) {
+			throw new JeecgBootException("没有找到此appid");
+		}
+		//获取小程序二维码
+		try {
+			WxMaInRedisConfigStorage configStorage = new WxMaInRedisConfigStorage(redisTemplate);
+			configStorage.setAppid(wxApp.getAppId());
+			configStorage.setSecret(wxApp.getAppSecret());
+			WxMaService wxMaService = new WxMaServiceImpl();
+			wxMaService.setWxMaConfig(configStorage);
+
+			File file = wxMaService.getQrcodeService().createQrcode("page/dc/index?id=", 430);
+			try {
+				MultipartFile cMultiFile = new MockMultipartFile("file", file.getName(), null, new FileInputStream(file));
+				String path = CommonUtils.upload(cMultiFile, "temp", CommonConstant.UPLOAD_TYPE_OSS);
+				posTable.setQrCode(path);
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+
+		} catch (WxErrorException e) {
+			e.printStackTrace();
+
+			throw new JeecgBootException("获取小程序二维码失败:" + e.getMessage());
+		}
 		posTableService.save(posTable);
 		return Result.OK("添加成功!");
 	}
 
+
 	 /**
 	  *  桌台用餐下单
 	  *

+ 4 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/pos/entity/PosTable.java

@@ -79,6 +79,10 @@ public class PosTable implements Serializable {
     @Excel(name = "就餐人数", width = 15)
     @ApiModelProperty(value = "就餐人数")
     private java.lang.Integer userNum;
+    /**二维码*/
+    @Excel(name = "二维码", width = 15)
+    @ApiModelProperty(value = "二维码")
+    private java.lang.String qrCode;
 
 	@TableField(exist = false)
 	private  String typeName;