Browse Source

批量处理消息

yq 3 years ago
parent
commit
be88e78443

+ 12 - 2
src/main/java/com/usky/dxtop/controller/web/ChargeController.java

@@ -4,13 +4,18 @@ package com.usky.dxtop.controller.web;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.dxtop.common.core.domain.AjaxResult;
+import com.usky.dxtop.common.exception.CustomException;
 import com.usky.dxtop.model.Charge;
+import com.usky.dxtop.model.Staff;
 import com.usky.dxtop.service.ChargeService;
+import com.usky.dxtop.service.StaffService;
 import com.usky.dxtop.service.vo.ChargeRequest;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Optional;
+
 /**
  * 充值模块
  * @author yq
@@ -24,6 +29,8 @@ public class ChargeController {
     @Autowired
     private ChargeService chargeService;
 
+    @Autowired
+    private StaffService staffService;
 
     /**
      * 分页
@@ -56,9 +63,12 @@ public class ChargeController {
      * @return
      */
     @PutMapping
-    public AjaxResult updateList(){
+    public AjaxResult updateList(@RequestParam String userId){
+        Staff staff = staffService.one(userId, null, null);
+        Optional.ofNullable(staff).orElseThrow(() -> new CustomException("用户信息不存在"));
         LambdaUpdateWrapper<Charge> updateWrapper = Wrappers.lambdaUpdate();
-        updateWrapper.set(Charge::getMessageFlag,true);
+        updateWrapper.set(Charge::getMessageFlag,true)
+                .eq(Charge::getCard,staff.getCardId());
         return AjaxResult.success(chargeService.update(updateWrapper));
     }
 }

+ 12 - 2
src/main/java/com/usky/dxtop/controller/web/DishController.java

@@ -4,13 +4,18 @@ package com.usky.dxtop.controller.web;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.dxtop.common.core.domain.AjaxResult;
+import com.usky.dxtop.common.exception.CustomException;
 import com.usky.dxtop.model.Dish;
+import com.usky.dxtop.model.Staff;
 import com.usky.dxtop.service.DishService;
+import com.usky.dxtop.service.StaffService;
 import com.usky.dxtop.service.vo.DishRequest;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Optional;
+
 /**
  * 消费模块
  * @author yq
@@ -25,6 +30,8 @@ public class DishController {
     @Autowired
     private DishService dishService;
 
+    @Autowired
+    private StaffService staffService;
 
     /**
      * 分页
@@ -62,9 +69,12 @@ public class DishController {
      * @return
      */
     @PutMapping
-    public AjaxResult update() {
+    public AjaxResult update(@RequestParam String userId) {
+        Staff staff = staffService.one(userId, null, null);
+        Optional.ofNullable(staff).orElseThrow(() -> new CustomException("用户信息不存在"));
         LambdaUpdateWrapper<Dish> updateWrapper = Wrappers.lambdaUpdate();
-        updateWrapper.set(Dish::getMessageFlag,true);
+        updateWrapper.set(Dish::getMessageFlag,true)
+                .eq(Dish::getCard,staff.getCardId());
         return AjaxResult.success(dishService.update(updateWrapper));
     }
 

+ 22 - 15
src/main/java/com/usky/dxtop/controller/web/WxController.java

@@ -1,5 +1,6 @@
 package com.usky.dxtop.controller.web;
 
+import com.usky.dxtop.common.core.domain.AjaxResult;
 import com.usky.dxtop.service.api.TopApiConfiger;
 import com.usky.dxtop.service.api.WxApi;
 import lombok.extern.slf4j.Slf4j;
@@ -8,8 +9,6 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.TreeMap;
-
 /**
  * @author yq
  * @date 2021/9/22 10:04
@@ -24,12 +23,8 @@ public class WxController {
     @Autowired
     private WxApi wxApi;
     @GetMapping("/wxLogin")
-    public String wxLogin(@RequestParam String jsCode,@RequestParam Integer type){
-        if (1 == type){
-            return wxApi.wxLogin(topApiConfiger.getWxAppId(),topApiConfiger.getWxAppSecret(),jsCode);
-        }else {
-            return wxApi.wxLogin(WxApi.APP_ID,WxApi.SECRET,jsCode);
-        }
+    public String wxLogin(@RequestParam String jsCode){
+        return wxApi.wxLogin(topApiConfiger.getWxAppId(),topApiConfiger.getWxAppSecret(),jsCode);
     }
 
     /**
@@ -38,8 +33,8 @@ public class WxController {
      * @return
      */
     @GetMapping("/wxAccToken")
-    public TreeMap<String, String> getAccToken(@RequestParam String url){
-        return wxApi.getPayParam(topApiConfiger.getWxAppId(),topApiConfiger.getWxAppSecret(),url);
+    public AjaxResult getAccToken(@RequestParam String url){
+        return AjaxResult.success(wxApi.getPayParam(topApiConfiger.getWxAppId(), topApiConfiger.getWxAppSecret(), url));
     }
 
     /**
@@ -47,12 +42,14 @@ public class WxController {
      * @return
      */
     @GetMapping("/accentToken")
-    public String getToken(@RequestParam Integer type){
+    public AjaxResult getToken(@RequestParam Integer type){
+        String token;
         if (1 == type){
-            return wxApi.getToken(topApiConfiger.getWxAppId(),topApiConfiger.getWxAppSecret());
+            token =  wxApi.getToken(topApiConfiger.getWxAppId(),topApiConfiger.getWxAppSecret());
         }else {
-            return wxApi.getToken(WxApi.APP_ID,WxApi.SECRET);
+            token =  wxApi.getToken(WxApi.APP_ID,WxApi.SECRET);
         }
+        return AjaxResult.success(token);
     }
 
     /**
@@ -64,10 +61,20 @@ public class WxController {
      * @return
      */
     @GetMapping("/offSendMessage")
-    public String offSendMessageT(@RequestParam String openId,
+    public AjaxResult offSendMessageT(@RequestParam String openId,
                                   @RequestParam Object data,
                                   @RequestParam String templateId,
                                   @RequestParam(required = false) String detailUrl){
-        return wxApi.sendMessageApi(openId,data,wxApi.getToken(WxApi.APP_ID,WxApi.SECRET),templateId,detailUrl);
+        return AjaxResult.success(wxApi.sendMessageApi(openId, data, wxApi.getToken(WxApi.APP_ID, WxApi.SECRET), templateId, detailUrl));
+    }
+
+    /**
+     * 公众号获取openid
+     * @param code
+     * @return
+     */
+    @GetMapping("/offOpenId")
+    public AjaxResult getOpenId(@RequestParam String code){
+        return AjaxResult.success(wxApi.getOpenId(WxApi.APP_ID, WxApi.SECRET, code));
     }
 }

+ 2 - 1
src/main/java/com/usky/dxtop/framework/config/SecurityConfig.java

@@ -100,7 +100,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                 .antMatchers("/login", "/register", "/captchaImage","/top/notify","/dxtop/order/topScanPayApi","/loginApi",
                         "/dxtop/charge/page","/dxtop/dish/page","/wxLogin","/wxAccToken","/dxtop/order/callUnifiedPay",
-                        "/dxtop/staff/one","/dxtop/staff/cardBalance","/dxtop/charge/cordPage","/dxtop/charge","/dxtop/dish","/dxtop/staff","offSendMessage"
+                        "/dxtop/staff/one","/dxtop/staff/cardBalance","/dxtop/charge/cordPage","/dxtop/charge","/dxtop/dish",
+                        "/dxtop/staff","/offSendMessage","/offOpenId"
                         ).permitAll()
                 .antMatchers(
                         HttpMethod.GET,

+ 27 - 0
src/main/java/com/usky/dxtop/service/api/WxApi.java

@@ -69,6 +69,9 @@ public class WxApi {
     private static final String WX_TICKET_KEY = "wxTicketKey";
 
 
+    private static final String GET_OPEN_ID_URL ="https://api.weixin.qq.com/sns/oauth2/access_token";
+
+
     /**
      * 小程序登录
      * @param appId
@@ -103,6 +106,9 @@ public class WxApi {
         map.put("url",detailUrl);
         String result = HttpUtils.sendPost(url, JSONObject.toJSONString(map), null);
         JSONObject jsonObject = JSONObject.parseObject(result);
+        if (!"0".equals(jsonObject.get("errcode").toString())){
+            throw new CustomException(String.format("发送异常:code:%s,message:%s",jsonObject.get("errcode"),jsonObject.get("errmsg")));
+        }
         return jsonObject.toJSONString();
 
     }
@@ -182,6 +188,27 @@ public class WxApi {
         return treeMap;
     }
 
+    /**
+     * 获取公众号openid
+     * @param appId
+     * @param secret
+     * @param code
+     * @return
+     */
+    public String getOpenId(String appId,String secret,String code){
+        TreeMap<String, String> treeMap = new TreeMap<>();
+        treeMap.put("appid",appId);
+        treeMap.put("secret",secret);
+        treeMap.put("code",code);
+        treeMap.put("grant_type","authorization_code");
+        String s = HttpUtils.sendGet(GET_OPEN_ID_URL, joinParam(treeMap), null);
+        JSONObject obj= JSON.parseObject(s);
+        if (null != obj.get("errcode")){
+            throw new CustomException(String.format("发送异常:code:%s,message:%s",obj.get("errcode"),obj.get("errmsg")));
+        }
+        return obj.get("openid").toString();
+    }
+
 
 
     public static String joinParam(TreeMap<String, String> params){