收款码缩短
diff --git a/src/main/java/com/supwisdom/dlpay/api/controller/PhoneScanQRcodeController.java b/src/main/java/com/supwisdom/dlpay/api/controller/PhoneScanQRcodeController.java
index a231514..ae52ab7 100644
--- a/src/main/java/com/supwisdom/dlpay/api/controller/PhoneScanQRcodeController.java
+++ b/src/main/java/com/supwisdom/dlpay/api/controller/PhoneScanQRcodeController.java
@@ -1,224 +1,216 @@
-package com.supwisdom.dlpay.api.controller;
-
-import com.google.gson.Gson;
-import com.supwisdom.dlpay.api.bean.DoorQrcodeResponse;
-import com.supwisdom.dlpay.api.bean.JsonResult;
-import com.supwisdom.dlpay.api.service.PhoneScanQRcodeService;
-import com.supwisdom.dlpay.exception.WebCheckException;
-import com.supwisdom.dlpay.framework.core.JwtConfig;
-import com.supwisdom.dlpay.framework.core.JwtTokenUtil;
-import com.supwisdom.dlpay.framework.domain.TShopSettlement;
-import com.supwisdom.dlpay.framework.redistable.ShopQRCodeRedis;
-import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.util.MoneyUtil;
-import com.supwisdom.dlpay.framework.util.StringUtil;
-import com.supwisdom.dlpay.restaurant.bean.ShopQRcodeData;
-import com.supwisdom.dlpay.restaurant.domain.TDeviceGroup;
-import com.supwisdom.dlpay.restaurant.domain.TTransDtl;
-import com.supwisdom.dlpay.restaurant.service.DeviceGroupService;
-import com.supwisdom.dlpay.restaurant.util.AesUtil;
-import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
-import com.supwisdom.multitenant.TenantContextHolder;
-import com.supwisdom.multitenant.TenantDetails;
-import com.supwisdom.multitenant.config.TenantSessionProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.List;
-import java.util.Map;
-
-@Controller
-@RequestMapping("/api/qrscan")
-public class PhoneScanQRcodeController {
- @Autowired
- private JwtConfig jwtConfig;
- @Autowired
- private PhoneScanQRcodeService phoneScanQRcodeService;
- @Autowired
- private DeviceGroupService groupService;
- @Autowired
- private SystemUtilService systemUtilService;
- @Autowired
- private TenantSessionProperties tenantSessionProperties;
-
-
- private static final Gson _gson = new Gson();
- private static final Logger logger = LoggerFactory.getLogger(PhoneScanQRcodeController.class);
-
- /**
- * 扫码下单页面
- */
- @RequestMapping("/order")
- public String order(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
- String q = request.getParameter("q");
- String token = request.getHeader(jwtConfig.getHeader());
-
- logger.info("url=[/api/qrscan/order], q=[" + q + "], jwt=["+token+"]");
- ShopQRcodeData data = null;
- try {
- if (!StringUtil.isEmpty(q)) {
- String qStr = AesUtil.decryptHex(q, RestaurantConstant.SHOP_QRCODE_AESKEY);
- if (!StringUtil.isEmpty(qStr)) data = _gson.fromJson(qStr, ShopQRcodeData.class);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (null == data || null == data.getDevGroupId() || StringUtil.isEmpty(data.getTenantId())) {
- model.put("errmsg", "商户收款码错误!");
- return "h5/qrscan/error";
- }
-
- String jwtSecret = null;
- TDeviceGroup deviceGroup = null;
- List<TShopSettlement> shops = null;
- TenantDetails tenantDetails = null;
- try {
- tenantDetails = TenantContextHolder.getContext().getTenant(); //租户信息
- if (null == tenantDetails || !data.getTenantId().equals(tenantDetails.getId())) {
- model.put("errmsg", "租户ID错误!");
- return "h5/qrscan/error";
- }
- deviceGroup = groupService.getByGroupId(data.getDevGroupId());
- shops = groupService.getByDevGroupId(deviceGroup.getDevgroupid());
- jwtSecret = systemUtilService.getBusinessValue(RestaurantConstant.SHOP_QRCODE_JWTKEY);
- } catch (Exception e) {
- e.printStackTrace();
- model.put("errmsg", "租户ID错误!");
- return "h5/qrscan/error";
- }
-
- if (null == deviceGroup) {
- model.put("errmsg", "商户已注销!");
- return "h5/qrscan/error";
- }
- if (StringUtil.isEmpty(shops) || shops.size() > 1) {
- model.put("errmsg", "收费商户获取失败!");
- return "h5/qrscan/error";
- }
- if (StringUtil.isEmpty(jwtSecret)) {
- model.put("errmsg", "系统用户密钥未配置!");
- return "h5/qrscan/error";
- }
-
- //获取用户uid
- String uid = "";
- try {
- if (!StringUtil.isEmpty(token) && token.startsWith(jwtConfig.getTokenHeader())) {
- final String jwt = token.substring(jwtConfig.getTokenHeader().length());
- final Map<String, Object> claims = new JwtTokenUtil(jwtConfig, jwtSecret).verifyToken(jwt);
- uid = claims.get("uid") == null ? null : claims.get("uid").toString();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- if (StringUtil.isEmpty(uid)) {
- model.put("errmsg", "用户未登录!");
- return "h5/qrscan/error";
-// uid="2c9cab9475d4f1b10175d4f6b7360000"; //测试
- }
-
- //获取用户市民卡信息
- DoorQrcodeResponse queryResp = phoneScanQRcodeService.queryDlCardInfo(uid);
- if (null == queryResp || queryResp.getRetcode() != 0) {
- logger.error("请求核心平台获取市民卡信息失败!" + queryResp == null ? "" : queryResp.getRetmsg());
- model.put("errmsg", "获取用户信息失败!");
- return "h5/qrscan/error";
- }
-
- try {
- ShopQRCodeRedis qrCodeRedis = new ShopQRCodeRedis();
- qrCodeRedis.setUid(uid);
- qrCodeRedis.setUserid(queryResp.getUserid());
- qrCodeRedis.setCardno(queryResp.getCitycardno());
- qrCodeRedis.setBankcardno(queryResp.getBankcardno());
- qrCodeRedis.setDevgroupid(deviceGroup.getDevgroupid());
- qrCodeRedis.setShopaccno(shops.get(0).getShopid());
- qrCodeRedis.setTenantId(data.getTenantId());
- qrCodeRedis = phoneScanQRcodeService.saveShopQRCodeRedis(qrCodeRedis);
- if (StringUtil.isEmpty(qrCodeRedis.getId())) {
- model.put("errmsg", "获取用户信息错误!");
- return "h5/qrscan/error";
- }
-
- request.getSession().setAttribute(tenantSessionProperties.getName(), tenantDetails); //租户ID
-
- model.put("devShop", shops.get(0));
- model.put("devGroup", deviceGroup);
- model.put("uid", qrCodeRedis.getId());
- return "h5/qrscan/order";
- } catch (Exception e) {
- e.printStackTrace();
- model.put("errmsg", "业务处理异常!" + (StringUtil.isEmpty(e.getMessage()) ? e.getClass().getName() : e.getMessage()));
- return "h5/qrscan/error";
- }
- }
-
- /**
- * 支付
- * */
- @PostMapping("/pay")
- @ResponseBody
- public JsonResult pay(@RequestParam("uid") String uid,
- @RequestParam("amount") Double amount,
- @RequestParam("remark") String remark) {
- ShopQRCodeRedis data = phoneScanQRcodeService.getShopQRCodeRedisById(uid);
- if (null == data) return JsonResult.error("等待支付时间过长,请重新扫码!");
- if (null == amount || amount <= 0) return JsonResult.error("支付金额必须大于零!");
-
- TenantDetails tenantDetails = TenantContextHolder.getContext().getTenant(); //租户信息
- if (null == tenantDetails || !data.getTenantId().equals(tenantDetails.getId())) {
- return JsonResult.error("租户ID错误!");
- }
-
- try {
- TTransDtl transDtl = phoneScanQRcodeService.doCreateNewTransdtl(data, amount, remark);
- if(null==transDtl || StringUtil.isEmpty(transDtl.getBillno())){
- return JsonResult.error("订单初始化失败!");
- }
-
- int ret = phoneScanQRcodeService.doShopQRCodePay(transDtl.getBillno());
- if (ret >= 0) {
- return JsonResult.ok("success").put("billno", transDtl.getBillno());
- } else {
- TTransDtl temp = phoneScanQRcodeService.getByBillno(transDtl.getBillno());
- return JsonResult.error("支付失败!" + (temp == null ? "" : temp.getAttr1())).put("billno", transDtl.getBillno());
- }
- } catch (WebCheckException wce) {
- logger.error(wce.getMessage());
- return JsonResult.error(wce.getMessage());
- } catch (Exception e) {
- return JsonResult.error(e.getMessage() == null ? "业务处理失败!" : e.getMessage());
- }
- }
-
- /**
- * 展示结果
- */
- @RequestMapping("/result")
- public String result(@RequestParam("billno") String billno, ModelMap map) {
- TTransDtl transDtl = phoneScanQRcodeService.getByBillno(billno);
- if (null == transDtl) {
- map.put("errmsg", "流水初始化失败!");
- return "h5/qrscan/error";
- }
- TDeviceGroup deviceGroup = groupService.getByGroupId(transDtl.getDevgroupid());
- map.put("billno", transDtl.getBillno());
- map.put("amount", MoneyUtil.formatYuanToString(transDtl.getAmount()));
- map.put("managefee", MoneyUtil.formatYuanToString(transDtl.getManagefee()));
- map.put("remark", transDtl.getRemark());
- map.put("shopname", deviceGroup == null ? "" : deviceGroup.getGroupname());
- map.put("dtlstatus", transDtl.getStatus());
- return "h5/qrscan/result";
- }
-
-}
+package com.supwisdom.dlpay.api.controller;
+
+import com.google.gson.Gson;
+import com.supwisdom.dlpay.api.bean.DoorQrcodeResponse;
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.api.service.PhoneScanQRcodeService;
+import com.supwisdom.dlpay.exception.WebCheckException;
+import com.supwisdom.dlpay.framework.core.JwtConfig;
+import com.supwisdom.dlpay.framework.core.JwtTokenUtil;
+import com.supwisdom.dlpay.framework.domain.TShopSettlement;
+import com.supwisdom.dlpay.framework.redistable.ShopQRCodeRedis;
+import com.supwisdom.dlpay.framework.service.SystemUtilService;
+import com.supwisdom.dlpay.framework.util.MoneyUtil;
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.restaurant.domain.TDeviceGroup;
+import com.supwisdom.dlpay.restaurant.domain.TShopQRcode;
+import com.supwisdom.dlpay.restaurant.domain.TTransDtl;
+import com.supwisdom.dlpay.restaurant.service.DeviceGroupService;
+import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
+import com.supwisdom.multitenant.TenantContextHolder;
+import com.supwisdom.multitenant.TenantDetails;
+import com.supwisdom.multitenant.config.TenantSessionProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.Map;
+
+@Controller
+@RequestMapping("/api/qrscan")
+public class PhoneScanQRcodeController {
+ @Autowired
+ private JwtConfig jwtConfig;
+ @Autowired
+ private PhoneScanQRcodeService phoneScanQRcodeService;
+ @Autowired
+ private DeviceGroupService groupService;
+ @Autowired
+ private SystemUtilService systemUtilService;
+ @Autowired
+ private TenantSessionProperties tenantSessionProperties;
+
+
+ private static final Gson _gson = new Gson();
+ private static final Logger logger = LoggerFactory.getLogger(PhoneScanQRcodeController.class);
+
+ /**
+ * 扫码下单页面
+ */
+ @RequestMapping("/order")
+ public String order(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
+ String q = request.getParameter("q");
+ String token = request.getHeader(jwtConfig.getHeader());
+
+ logger.info("url=[/api/qrscan/order], q=[" + q + "], jwt=["+token+"]");
+ TShopQRcode data = groupService.getShopQRcodeById(q);
+
+ if (null == data || null == data.getDevgroupid() || StringUtil.isEmpty(data.getTenantid())) {
+ model.put("errmsg", "商户收款码错误!");
+ return "h5/qrscan/error";
+ }
+
+ String jwtSecret = null;
+ TDeviceGroup deviceGroup = null;
+ List<TShopSettlement> shops = null;
+ TenantDetails tenantDetails = null;
+ try {
+ tenantDetails = TenantContextHolder.getContext().getTenant(); //租户信息
+ if (null == tenantDetails || !data.getTenantid().equals(tenantDetails.getId())) {
+ model.put("errmsg", "租户ID错误!");
+ return "h5/qrscan/error";
+ }
+ deviceGroup = groupService.getByGroupId(data.getDevgroupid());
+ shops = groupService.getByDevGroupId(deviceGroup.getDevgroupid());
+ jwtSecret = systemUtilService.getBusinessValue(RestaurantConstant.SHOP_QRCODE_JWTKEY);
+ } catch (Exception e) {
+ e.printStackTrace();
+ model.put("errmsg", "租户ID错误!");
+ return "h5/qrscan/error";
+ }
+
+ if (null == deviceGroup) {
+ model.put("errmsg", "商户已注销!");
+ return "h5/qrscan/error";
+ }
+ if (StringUtil.isEmpty(shops) || shops.size() > 1) {
+ model.put("errmsg", "收费商户获取失败!");
+ return "h5/qrscan/error";
+ }
+ if (StringUtil.isEmpty(jwtSecret)) {
+ model.put("errmsg", "系统用户密钥未配置!");
+ return "h5/qrscan/error";
+ }
+
+ //获取用户uid
+ String uid = "";
+ try {
+ if (!StringUtil.isEmpty(token) && token.startsWith(jwtConfig.getTokenHeader())) {
+ final String jwt = token.substring(jwtConfig.getTokenHeader().length());
+ final Map<String, Object> claims = new JwtTokenUtil(jwtConfig, jwtSecret).verifyToken(jwt);
+ uid = claims.get("uid") == null ? null : claims.get("uid").toString();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ if (StringUtil.isEmpty(uid)) {
+ model.put("errmsg", "用户未登录!");
+ return "h5/qrscan/error";
+// uid="2c9cab9475d4f1b10175d4f6b7360000"; //测试
+ }
+
+ //获取用户市民卡信息
+ DoorQrcodeResponse queryResp = phoneScanQRcodeService.queryDlCardInfo(uid);
+ if (null == queryResp || queryResp.getRetcode() != 0) {
+ logger.error("请求核心平台获取市民卡信息失败!" + queryResp == null ? "" : queryResp.getRetmsg());
+ model.put("errmsg", "获取用户信息失败!");
+ return "h5/qrscan/error";
+ }
+
+ try {
+ ShopQRCodeRedis qrCodeRedis = new ShopQRCodeRedis();
+ qrCodeRedis.setUid(uid);
+ qrCodeRedis.setUserid(queryResp.getUserid());
+ qrCodeRedis.setCardno(queryResp.getCitycardno());
+ qrCodeRedis.setBankcardno(queryResp.getBankcardno());
+ qrCodeRedis.setDevgroupid(deviceGroup.getDevgroupid());
+ qrCodeRedis.setShopaccno(shops.get(0).getShopid());
+ qrCodeRedis.setTenantId(data.getTenantid());
+ qrCodeRedis = phoneScanQRcodeService.saveShopQRCodeRedis(qrCodeRedis);
+ if (StringUtil.isEmpty(qrCodeRedis.getId())) {
+ model.put("errmsg", "获取用户信息错误!");
+ return "h5/qrscan/error";
+ }
+
+ request.getSession().setAttribute(tenantSessionProperties.getName(), tenantDetails); //租户ID
+
+ model.put("devShop", shops.get(0));
+ model.put("devGroup", deviceGroup);
+ model.put("uid", qrCodeRedis.getId());
+ return "h5/qrscan/order";
+ } catch (Exception e) {
+ e.printStackTrace();
+ model.put("errmsg", "业务处理异常!" + (StringUtil.isEmpty(e.getMessage()) ? e.getClass().getName() : e.getMessage()));
+ return "h5/qrscan/error";
+ }
+ }
+
+ /**
+ * 支付
+ * */
+ @PostMapping("/pay")
+ @ResponseBody
+ public JsonResult pay(@RequestParam("uid") String uid,
+ @RequestParam("amount") Double amount,
+ @RequestParam("remark") String remark) {
+ ShopQRCodeRedis data = phoneScanQRcodeService.getShopQRCodeRedisById(uid);
+ if (null == data) return JsonResult.error("等待支付时间过长,请重新扫码!");
+ if (null == amount || amount <= 0) return JsonResult.error("支付金额必须大于零!");
+
+ TenantDetails tenantDetails = TenantContextHolder.getContext().getTenant(); //租户信息
+ if (null == tenantDetails || !data.getTenantId().equals(tenantDetails.getId())) {
+ return JsonResult.error("租户ID错误!");
+ }
+
+ try {
+ TTransDtl transDtl = phoneScanQRcodeService.doCreateNewTransdtl(data, amount, remark);
+ if(null==transDtl || StringUtil.isEmpty(transDtl.getBillno())){
+ return JsonResult.error("订单初始化失败!");
+ }
+
+ int ret = phoneScanQRcodeService.doShopQRCodePay(transDtl.getBillno());
+ if (ret >= 0) {
+ return JsonResult.ok("success").put("billno", transDtl.getBillno());
+ } else {
+ TTransDtl temp = phoneScanQRcodeService.getByBillno(transDtl.getBillno());
+ return JsonResult.error("支付失败!" + (temp == null ? "" : temp.getAttr1())).put("billno", transDtl.getBillno());
+ }
+ } catch (WebCheckException wce) {
+ logger.error(wce.getMessage());
+ return JsonResult.error(wce.getMessage());
+ } catch (Exception e) {
+ return JsonResult.error(e.getMessage() == null ? "业务处理失败!" : e.getMessage());
+ }
+ }
+
+ /**
+ * 展示结果
+ */
+ @RequestMapping("/result")
+ public String result(@RequestParam("billno") String billno, ModelMap map) {
+ TTransDtl transDtl = phoneScanQRcodeService.getByBillno(billno);
+ if (null == transDtl) {
+ map.put("errmsg", "流水初始化失败!");
+ return "h5/qrscan/error";
+ }
+ TDeviceGroup deviceGroup = groupService.getByGroupId(transDtl.getDevgroupid());
+ map.put("billno", transDtl.getBillno());
+ map.put("amount", MoneyUtil.formatYuanToString(transDtl.getAmount()));
+ map.put("managefee", MoneyUtil.formatYuanToString(transDtl.getManagefee()));
+ map.put("remark", transDtl.getRemark());
+ map.put("shopname", deviceGroup == null ? "" : deviceGroup.getGroupname());
+ map.put("dtlstatus", transDtl.getStatus());
+ return "h5/qrscan/result";
+ }
+
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/dao/ShopQRcodeDao.java b/src/main/java/com/supwisdom/dlpay/restaurant/dao/ShopQRcodeDao.java
new file mode 100644
index 0000000..d61a55b
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/dao/ShopQRcodeDao.java
@@ -0,0 +1,10 @@
+package com.supwisdom.dlpay.restaurant.dao;
+
+import com.supwisdom.dlpay.restaurant.domain.TShopQRcode;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ShopQRcodeDao extends JpaRepository<TShopQRcode, String> {
+ TShopQRcode getById(String id);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/domain/TShopQRcode.java b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TShopQRcode.java
new file mode 100644
index 0000000..f9a18f4
--- /dev/null
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/domain/TShopQRcode.java
@@ -0,0 +1,55 @@
+package com.supwisdom.dlpay.restaurant.domain;
+
+
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "TB_SHOP_QRCODE")
+public class TShopQRcode {
+
+ private String id;
+ private Integer devgroupid;
+ private String tenantid;
+ private String createtime;
+
+ @Id
+ @GenericGenerator(name = "idGenerator", strategy = "uuid")
+ @GeneratedValue(generator = "idGenerator")
+ @Column(name = "ID", nullable = false, length = 32)
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Column(name = "DEVGROUPID", nullable = false, length = 8)
+ public Integer getDevgroupid() {
+ return devgroupid;
+ }
+
+ public void setDevgroupid(Integer devgroupid) {
+ this.devgroupid = devgroupid;
+ }
+
+ @Column(name = "TENANTID", length = 60)
+ public String getTenantid() {
+ return tenantid;
+ }
+
+ public void setTenantid(String tenantid) {
+ this.tenantid = tenantid;
+ }
+
+ @Column(name = "CREATETIME", length = 14)
+ public String getCreatetime() {
+ return createtime;
+ }
+
+ public void setCreatetime(String createtime) {
+ this.createtime = createtime;
+ }
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/DeviceGroupService.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/DeviceGroupService.java
index d13c606..951ef96 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/service/DeviceGroupService.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/DeviceGroupService.java
@@ -1,38 +1,40 @@
-package com.supwisdom.dlpay.restaurant.service;
-
-import com.supwisdom.dlpay.api.bean.JsonResult;
-import com.supwisdom.dlpay.api.bean.QRcodeConfig;
-import com.supwisdom.dlpay.framework.domain.TShopSettlement;
-import com.supwisdom.dlpay.restaurant.domain.TDeviceGroup;
-import com.supwisdom.dlpay.framework.util.PageResult;
-import com.supwisdom.dlpay.system.bean.ZTreeNode;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-public interface DeviceGroupService {
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
- PageResult<ZTreeNode> getDeviceGroupTree( );
-
- List<TDeviceGroup> findAll();
-
- List<TDeviceGroup> findByGrouptype(String grouptype);
-
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- JsonResult saveGroup(TDeviceGroup device);
-
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- JsonResult delete(Integer id);
-
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
- TDeviceGroup getByGroupId(Integer groupId);
-
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
- List<TShopSettlement> getByDevGroupId(int groupId);
-
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
- QRcodeConfig getQRcodeConfigByDevGroup(int groupId) throws Exception;
-
-
-}
+package com.supwisdom.dlpay.restaurant.service;
+
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.api.bean.QRcodeConfig;
+import com.supwisdom.dlpay.framework.domain.TShopSettlement;
+import com.supwisdom.dlpay.restaurant.domain.TDeviceGroup;
+import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.restaurant.domain.TShopQRcode;
+import com.supwisdom.dlpay.system.bean.ZTreeNode;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+public interface DeviceGroupService {
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
+ PageResult<ZTreeNode> getDeviceGroupTree( );
+
+ List<TDeviceGroup> findAll();
+
+ List<TDeviceGroup> findByGrouptype(String grouptype);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ JsonResult saveGroup(TDeviceGroup device);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ JsonResult delete(Integer id);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
+ TDeviceGroup getByGroupId(Integer groupId);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
+ List<TShopSettlement> getByDevGroupId(int groupId);
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
+ QRcodeConfig getQRcodeConfigByDevGroup(int groupId) throws Exception;
+
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class,readOnly = true)
+ TShopQRcode getShopQRcodeById(String id);
+}
diff --git a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/DeviceGroupServiceImpl.java b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/DeviceGroupServiceImpl.java
index 16cae8e..3fa2480 100644
--- a/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/DeviceGroupServiceImpl.java
+++ b/src/main/java/com/supwisdom/dlpay/restaurant/service/impl/DeviceGroupServiceImpl.java
@@ -1,160 +1,168 @@
-package com.supwisdom.dlpay.restaurant.service.impl;
-
-import com.google.gson.Gson;
-import com.supwisdom.dlpay.api.bean.JsonResult;
-import com.supwisdom.dlpay.api.bean.QRcodeConfig;
-import com.supwisdom.dlpay.exception.WebCheckException;
-import com.supwisdom.dlpay.framework.dao.ShopSettlementDao;
-import com.supwisdom.dlpay.framework.domain.TShopSettlement;
-import com.supwisdom.dlpay.framework.service.SystemUtilService;
-import com.supwisdom.dlpay.framework.util.StringUtil;
-import com.supwisdom.dlpay.restaurant.bean.ShopQRcodeData;
-import com.supwisdom.dlpay.restaurant.dao.DeviceDao;
-import com.supwisdom.dlpay.restaurant.dao.DeviceGroupDao;
-import com.supwisdom.dlpay.restaurant.domain.TDeviceGroup;
-import com.supwisdom.dlpay.restaurant.service.DeviceGroupService;
-import com.supwisdom.dlpay.framework.security.OperUtil;
-import com.supwisdom.dlpay.framework.util.PageResult;
-import com.supwisdom.dlpay.restaurant.util.AesUtil;
-import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
-import com.supwisdom.dlpay.system.bean.ZTreeNode;
-import com.supwisdom.dlpay.tenant.TenantConstant;
-import com.supwisdom.multitenant.TenantContextHolder;
-import org.apache.commons.lang3.StringUtils;
-import org.hibernate.query.internal.NativeQueryImpl;
-import org.hibernate.transform.Transformers;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.Query;
-import java.util.ArrayList;
-import java.util.List;
-
-@Service
-public class DeviceGroupServiceImpl implements DeviceGroupService {
- @Autowired
- private DeviceGroupDao groupDao;
- @Autowired
- private DeviceDao deviceDao;
- @Autowired
- private ShopSettlementDao shopSettlementDao;
-
- @Autowired
- private SystemUtilService systemUtilService;
-
- @PersistenceContext
- private EntityManager entityManager;
-
- @Override
- public PageResult<ZTreeNode> getDeviceGroupTree() {
- List<TDeviceGroup> groups=groupDao.findAll();
- List<ZTreeNode> zlist=new ArrayList<>();
- for(TDeviceGroup g:groups){
- ZTreeNode z=new ZTreeNode();
- z.setId(g.getDevgroupid().toString());
- z.setName(g.getGroupname());
- z.setGrouptype(g.getGrouptype());
- if(g.getPid()==null){
- z.setpId("0");
- }else{
- z.setpId(g.getPid().toString());
- }
-
- z.setChecked(false);
- z.setOpen(true);
- zlist.add(z);
- }
- PageResult<ZTreeNode> p=new PageResult<>(zlist);
- p.setCode(0);
- return p;
- }
-
- @Override
- public List<TDeviceGroup> findAll(){
- return groupDao.findAll();
- }
-
- @Override
- public List<TDeviceGroup> findByGrouptype(String grouptype) {
- return groupDao.findByGrouptype(grouptype);
- }
-
- @Override
- public JsonResult saveGroup(TDeviceGroup device){
- device.setOperid(OperUtil.getCurrentOperid());
- if(device.getPid()==null){
- device.setPid(0);
- }
- groupDao.save(device);
- return JsonResult.ok("成功");
- }
-
- @Override
- public JsonResult delete(Integer id) {
- if(deviceDao.countByDevgroupid(id)>0){
- return JsonResult.error("不能删除有正常设备的设备组");
- }
- if(groupDao.countByPid(id)>0){
- return JsonResult.error("不能删除含有子节点的设备组");
- }
- if(groupDao.deleteByDevgroupid(id)<=0){
- return JsonResult.error("删除失败");
- }
- return JsonResult.ok("删除成功");
- }
-
- @Override
- public TDeviceGroup getByGroupId(Integer groupId) {
- return null == groupId ? null : groupDao.getByDevgroupid(groupId);
- }
-
- private List<String> getShopByDevgroupId(int groupId) {
- Query chirdGroupQuery = entityManager.createNativeQuery(" WITH RECURSIVE r AS ( " +
- " SELECT * FROM tb_devicegroup WHERE devgroupid = :gid " +
- " union ALL " +
- " SELECT a.* FROM tb_devicegroup a, r WHERE a.pid = r.devgroupid ) " +
- " SELECT devgroupid FROM r ORDER BY devgroupid ");
- chirdGroupQuery.setParameter("gid", groupId);
- List<Integer> chirdGroupids = chirdGroupQuery.getResultList(); //递归查询所有的子节点
-
- StringBuffer sb = new StringBuffer("select distinct t.shopid from tb_device t where t.devgroupid in (" + StringUtils.join(chirdGroupids.toArray(), ",") + ")");
- Query query = entityManager.createNativeQuery(sb.toString());
-// query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.aliasToBean(String.class));
- return (List<String>) query.getResultList();
- }
-
- @Override
- public List<TShopSettlement> getByDevGroupId(int groupId) {
- List<String> shopids = getShopByDevgroupId(groupId);
- if (!StringUtil.isEmpty(shopids)) {
- return shopSettlementDao.findByShopidIn(shopids);
- }
- return null;
- }
-
- @Override
- public QRcodeConfig getQRcodeConfigByDevGroup(int groupId) throws Exception {
- String h5Url = systemUtilService.getBusinessValue(RestaurantConstant.SHOP_QRCODE_ORDERURL);
- if (StringUtil.isEmpty(h5Url)) {
- throw new WebCheckException("商户收款码跳转地址未配置!");
- }
-
- String tenantId = TenantConstant.DEFAULT_TENANTID;
- if (null != TenantContextHolder.getContext().getTenant() && !StringUtil.isEmpty(TenantContextHolder.getContext().getTenant().getId())) {
- tenantId = TenantContextHolder.getContext().getTenant().getId();
- }
-
- ShopQRcodeData data = new ShopQRcodeData();
- data.setTenantId(tenantId);
- data.setDevGroupId(groupId);
- data.setTimestamp(systemUtilService.getSysdatetime().getHostdatetime());
- String q = AesUtil.encryptHex(new Gson().toJson(data), RestaurantConstant.SHOP_QRCODE_AESKEY);
- if (StringUtil.isEmpty(q)) {
- throw new WebCheckException("商户收款码生成失败!");
- }
- String url = h5Url + "?" + RestaurantConstant.SHOP_QRCODE_TENANTID + "=" + tenantId + "&q=" + q;
- return new QRcodeConfig(url);
- }
-}
+package com.supwisdom.dlpay.restaurant.service.impl;
+
+import com.supwisdom.dlpay.api.bean.JsonResult;
+import com.supwisdom.dlpay.api.bean.QRcodeConfig;
+import com.supwisdom.dlpay.exception.WebCheckException;
+import com.supwisdom.dlpay.framework.dao.ShopSettlementDao;
+import com.supwisdom.dlpay.framework.domain.TShopSettlement;
+import com.supwisdom.dlpay.framework.service.SystemUtilService;
+import com.supwisdom.dlpay.framework.util.StringUtil;
+import com.supwisdom.dlpay.restaurant.dao.DeviceDao;
+import com.supwisdom.dlpay.restaurant.dao.DeviceGroupDao;
+import com.supwisdom.dlpay.restaurant.dao.ShopQRcodeDao;
+import com.supwisdom.dlpay.restaurant.domain.TDeviceGroup;
+import com.supwisdom.dlpay.restaurant.domain.TShopQRcode;
+import com.supwisdom.dlpay.restaurant.service.DeviceGroupService;
+import com.supwisdom.dlpay.framework.security.OperUtil;
+import com.supwisdom.dlpay.framework.util.PageResult;
+import com.supwisdom.dlpay.restaurant.util.RestaurantConstant;
+import com.supwisdom.dlpay.system.bean.ZTreeNode;
+import com.supwisdom.dlpay.tenant.TenantConstant;
+import com.supwisdom.multitenant.TenantContextHolder;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class DeviceGroupServiceImpl implements DeviceGroupService {
+ @Autowired
+ private DeviceGroupDao groupDao;
+ @Autowired
+ private DeviceDao deviceDao;
+ @Autowired
+ private ShopSettlementDao shopSettlementDao;
+ @Autowired
+ private ShopQRcodeDao shopQRcodeDao;
+
+ @Autowired
+ private SystemUtilService systemUtilService;
+
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Override
+ public PageResult<ZTreeNode> getDeviceGroupTree() {
+ List<TDeviceGroup> groups=groupDao.findAll();
+ List<ZTreeNode> zlist=new ArrayList<>();
+ for(TDeviceGroup g:groups){
+ ZTreeNode z=new ZTreeNode();
+ z.setId(g.getDevgroupid().toString());
+ z.setName(g.getGroupname());
+ z.setGrouptype(g.getGrouptype());
+ if(g.getPid()==null){
+ z.setpId("0");
+ }else{
+ z.setpId(g.getPid().toString());
+ }
+
+ z.setChecked(false);
+ z.setOpen(true);
+ zlist.add(z);
+ }
+ PageResult<ZTreeNode> p=new PageResult<>(zlist);
+ p.setCode(0);
+ return p;
+ }
+
+ @Override
+ public List<TDeviceGroup> findAll(){
+ return groupDao.findAll();
+ }
+
+ @Override
+ public List<TDeviceGroup> findByGrouptype(String grouptype) {
+ return groupDao.findByGrouptype(grouptype);
+ }
+
+ @Override
+ public JsonResult saveGroup(TDeviceGroup device){
+ device.setOperid(OperUtil.getCurrentOperid());
+ if(device.getPid()==null){
+ device.setPid(0);
+ }
+ groupDao.save(device);
+ return JsonResult.ok("成功");
+ }
+
+ @Override
+ public JsonResult delete(Integer id) {
+ if(deviceDao.countByDevgroupid(id)>0){
+ return JsonResult.error("不能删除有正常设备的设备组");
+ }
+ if(groupDao.countByPid(id)>0){
+ return JsonResult.error("不能删除含有子节点的设备组");
+ }
+ if(groupDao.deleteByDevgroupid(id)<=0){
+ return JsonResult.error("删除失败");
+ }
+ return JsonResult.ok("删除成功");
+ }
+
+ @Override
+ public TDeviceGroup getByGroupId(Integer groupId) {
+ return null == groupId ? null : groupDao.getByDevgroupid(groupId);
+ }
+
+ private List<String> getShopByDevgroupId(int groupId) {
+ Query chirdGroupQuery = entityManager.createNativeQuery(" WITH RECURSIVE r AS ( " +
+ " SELECT * FROM tb_devicegroup WHERE devgroupid = :gid " +
+ " union ALL " +
+ " SELECT a.* FROM tb_devicegroup a, r WHERE a.pid = r.devgroupid ) " +
+ " SELECT devgroupid FROM r ORDER BY devgroupid ");
+ chirdGroupQuery.setParameter("gid", groupId);
+ List<Integer> chirdGroupids = chirdGroupQuery.getResultList(); //递归查询所有的子节点
+
+ StringBuffer sb = new StringBuffer("select distinct t.shopid from tb_device t where t.devgroupid in (" + StringUtils.join(chirdGroupids.toArray(), ",") + ")");
+ Query query = entityManager.createNativeQuery(sb.toString());
+// query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.aliasToBean(String.class));
+ return (List<String>) query.getResultList();
+ }
+
+ @Override
+ public List<TShopSettlement> getByDevGroupId(int groupId) {
+ List<String> shopids = getShopByDevgroupId(groupId);
+ if (!StringUtil.isEmpty(shopids)) {
+ return shopSettlementDao.findByShopidIn(shopids);
+ }
+ return null;
+ }
+
+ @Override
+ public QRcodeConfig getQRcodeConfigByDevGroup(int groupId) throws Exception {
+ String h5Url = systemUtilService.getBusinessValue(RestaurantConstant.SHOP_QRCODE_ORDERURL);
+ if (StringUtil.isEmpty(h5Url)) {
+ throw new WebCheckException("商户收款码跳转地址未配置!");
+ }
+
+ String tenantId = TenantConstant.DEFAULT_TENANTID;
+ if (null != TenantContextHolder.getContext().getTenant() && !StringUtil.isEmpty(TenantContextHolder.getContext().getTenant().getId())) {
+ tenantId = TenantContextHolder.getContext().getTenant().getId();
+ }
+
+ TShopQRcode qRcode = new TShopQRcode();
+ qRcode.setTenantid(tenantId);
+ qRcode.setDevgroupid(groupId);
+ qRcode.setCreatetime(systemUtilService.getSysdatetime().getHostdatetime());
+ qRcode = shopQRcodeDao.save(qRcode);
+ if (qRcode == null || StringUtil.isEmpty(qRcode.getId())) {
+ throw new WebCheckException("商户收款码生成失败!");
+ }
+
+ String url = h5Url + "?" + RestaurantConstant.SHOP_QRCODE_TENANTID + "=" + tenantId + "&q=" + qRcode.getId();
+ return new QRcodeConfig(url);
+ }
+
+ @Override
+ public TShopQRcode getShopQRcodeById(String id) {
+ if (!StringUtil.isEmpty(id)) {
+ return shopQRcodeDao.getById(id.trim());
+ }
+ return null;
+ }
+}