Browse Source

no message

FengChaoYu 6 months ago
parent
commit
0bb875c49c

+ 57 - 50
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/common/CommonLogic.java

@@ -67,7 +67,7 @@ public class CommonLogic {
     //高德的webkey
     private final String mapWebKey = "428a7111e02ea8367a3b34804eaa025b";
 
-    public CurrentCompanyWechat getCurrentCompanyWechat(){
+    public CurrentCompanyWechat getCurrentCompanyWechat() {
         HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
         return getCurrentCompanyWechat(request);
     }
@@ -75,7 +75,7 @@ public class CommonLogic {
     /**
      * 获取当前用户
      */
-    public CurrentCompanyWechat getCurrentCompanyWechat(HttpServletRequest request){
+    public CurrentCompanyWechat getCurrentCompanyWechat(HttpServletRequest request) {
 
         String appid = CommonUtils.getAPPID(request);
         String userId = CommonUtils.getUserId(request);
@@ -88,11 +88,11 @@ public class CommonLogic {
             token = request.getParameter("x-token");
         }
 
-        if(StringUtils.isBlank(device) && StringUtils.isBlank(appid)){
+        if (StringUtils.isBlank(device) && StringUtils.isBlank(appid)) {
             throw new RemoteServiceException("非法请求,缺少必须的参数");
         }
         AdminCompanyWechat adminCompanyWechat;
-        User user;
+        User user = null;
         if (StringUtils.isBlank(device)) {
             adminCompanyWechat = adminCompanyWechatService.lambdaQuery()
                     .eq(AdminCompanyWechat::getSubAppId, appid)
@@ -108,19 +108,23 @@ public class CommonLogic {
             adminCompanyWechat = adminCompanyWechatService.lambdaQuery()
                     .last("limit 1")
                     .one();
-            Object result = redisUtil.get(Constant.RedisPrefix.TOKEN_APP_USER + token);
-            if (Objects.isNull(result)) {
-                throw new RemoteServiceException("非法请求,登录信息不存在");
+            if (StringUtils.isNotBlank(token)) {
+                Object result = redisUtil.get(Constant.RedisPrefix.TOKEN_APP_USER + token);
+                if (Objects.isNull(result)) {
+                    throw new RemoteServiceException("非法请求,登录信息不存在");
+                }
+                user = (User) result;
             }
-            user = (User) result;
         }
 
         CurrentCompanyWechat currentCompanyWechat = new CurrentCompanyWechat();
-        BeanUtils.copyProperties(adminCompanyWechat,currentCompanyWechat);
-        currentCompanyWechat.setCurrentCompanyWechatId(adminCompanyWechat.getCompanyWechatId());
-        currentCompanyWechat.setCurrentCompanyName(adminCompanyWechat.getCompanyName());
-        currentCompanyWechat.setUserId(CommonUtils.getUserId(request));
-        currentCompanyWechat.setUser(user);
+        BeanUtils.copyProperties(adminCompanyWechat, currentCompanyWechat);
+        if (Objects.nonNull(user)) {
+            currentCompanyWechat.setCurrentCompanyWechatId(adminCompanyWechat.getCompanyWechatId());
+            currentCompanyWechat.setCurrentCompanyName(adminCompanyWechat.getCompanyName());
+            currentCompanyWechat.setUserId(CommonUtils.getUserId(request));
+            currentCompanyWechat.setUser(user);
+        }
         return currentCompanyWechat;
 
     }
@@ -128,7 +132,7 @@ public class CommonLogic {
     /**
      * 获取当前企业
      */
-    public AdminCompanyWechat getAdminCompanyWechat(String companyWechatId){
+    public AdminCompanyWechat getAdminCompanyWechat(String companyWechatId) {
         AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getById(companyWechatId);
         return adminCompanyWechat;
     }
@@ -136,7 +140,7 @@ public class CommonLogic {
     /**
      * 微信scene
      */
-    public String getSceneValue(String wxSceneId){
+    public String getSceneValue(String wxSceneId) {
         WxScene wxScene = this.getScene(wxSceneId);
         return wxScene == null ? "" : wxScene.getParam();
     }
@@ -144,12 +148,12 @@ public class CommonLogic {
     /**
      * 微信scene
      */
-    public WxScene getScene(String wxSceneId){
+    public WxScene getScene(String wxSceneId) {
         WxScene wxScene = wxSceneService.getById(wxSceneId);
-        if(!wxScene.getStatus()){
+        if (!wxScene.getStatus()) {
             throw new RemoteServiceException("链接无效");
         }
-        if(wxScene.getEndTime().getTime() < new Date().getTime()){
+        if (wxScene.getEndTime().getTime() < new Date().getTime()) {
             throw new RemoteServiceException("链接已过期");
         }
         return wxScene;
@@ -158,7 +162,7 @@ public class CommonLogic {
     /**
      * 获取来源
      */
-    public  String getSource(){
+    public String getSource() {
         HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
         String token = request.getHeader("source");
         return token;
@@ -167,7 +171,7 @@ public class CommonLogic {
     /**
      * 获取来源
      */
-    public  String getMiniOpenId(){
+    public String getMiniOpenId() {
         HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
         String token = request.getHeader("miniOpenId");
         return token;
@@ -177,7 +181,7 @@ public class CommonLogic {
     /**
      * 微信scene详情
      */
-    public List<WxSceneDetail> getSceneDetail(String wxSceneId){
+    public List<WxSceneDetail> getSceneDetail(String wxSceneId) {
         List<WxSceneDetail> list = wxSceneDetailService.lambdaQuery().eq(WxSceneDetail::getWxSceneId, wxSceneId).list();
         return list;
     }
@@ -185,29 +189,29 @@ public class CommonLogic {
     /**
      * 附件归属绑定
      */
-    public void bindFile(String objId,String objType,List<String> fileIds){
-        if(fileIds.size() == 0){
+    public void bindFile(String objId, String objType, List<String> fileIds) {
+        if (fileIds.size() == 0) {
             return;
         }
         //先删除后绑定
         commonFileService.lambdaUpdate()
-                .eq(CommonFile::getObjId,objId)
-                .eq(CommonFile::getObjType,objType)
-                .notIn(CommonFile::getId,fileIds).remove();
+                .eq(CommonFile::getObjId, objId)
+                .eq(CommonFile::getObjType, objType)
+                .notIn(CommonFile::getId, fileIds).remove();
 
         commonFileService.lambdaUpdate()
-                .set(CommonFile::getObjId,objId)
-                .set(CommonFile::getObjType,objType)
-                .in(CommonFile::getId,fileIds).update();
+                .set(CommonFile::getObjId, objId)
+                .set(CommonFile::getObjType, objType)
+                .in(CommonFile::getId, fileIds).update();
     }
 
     /**
      * 查询附件列表
      */
-    public List<CommonFile> queryFileByObjId(String objId,String objType){
+    public List<CommonFile> queryFileByObjId(String objId, String objType) {
         return commonFileService.lambdaQuery()
-                .eq(CommonFile::getObjId,objId)
-                .eq(CommonFile::getObjType,objType)
+                .eq(CommonFile::getObjId, objId)
+                .eq(CommonFile::getObjType, objType)
                 .orderByAsc(CommonFile::getCreateTime)
                 .list();
     }
@@ -215,11 +219,11 @@ public class CommonLogic {
     /**
      * 查询街道列表
      */
-    public List<Map> street(String province,String city,String area){
+    public List<Map> street(String province, String city, String area) {
         List<Map> street = getStreet(province, area);
-        if(street.size() == 0){
+        if (street.size() == 0) {
             Map map = new HashMap();
-            map.put("name",area);
+            map.put("name", area);
             street.add(map);
         }
         return street;
@@ -239,23 +243,23 @@ public class CommonLogic {
     /**
      * 获取高德行政地址
      */
-    public List<Map> getStreet(String province,String area){
+    public List<Map> getStreet(String province, String area) {
         try {
             String s = HttpUtil.get("https://restapi.amap.com/v3/config/district?keywords=" + province + "&subdistrict=1&key=" + mapWebKey);
             JSONObject jsonObject = JSONObject.parseObject(s);
-            String status = (String)jsonObject.get("status");
-            if(status.equals("1")){
+            String status = (String) jsonObject.get("status");
+            if (status.equals("1")) {
                 List<Object> districts = (List<Object>) jsonObject.get("districts");
-                String adcode = (String)((Map<String,Object>)districts.get(0)).get("adcode");
+                String adcode = (String) ((Map<String, Object>) districts.get(0)).get("adcode");
 
-                String street = HttpUtil.get("https://restapi.amap.com/v3/config/district?keywords=" + area + "&subdistrict=1&key=" + mapWebKey+"&adcode="+adcode);
+                String street = HttpUtil.get("https://restapi.amap.com/v3/config/district?keywords=" + area + "&subdistrict=1&key=" + mapWebKey + "&adcode=" + adcode);
                 Object districts1 = JSONObject.parseObject(street).get("districts");
                 List<Map> maps = JSONArray.parseArray(JSONObject.toJSONString(districts1), Map.class);
 
                 List<Map> districts2 = JSONArray.parseArray(JSONObject.toJSONString(maps.get(0).get("districts")), Map.class);
                 return districts2;
             }
-        }catch(Exception e){
+        } catch (Exception e) {
             return new ArrayList<>();
         }
         return new ArrayList<>();
@@ -263,11 +267,12 @@ public class CommonLogic {
 
     /**
      * 上传附件
+     *
      * @param file
      * @return
      * @throws IOException
      */
-    public CommonFile uploadFile( MultipartFile file) throws IOException, RemoteServiceException {
+    public CommonFile uploadFile(MultipartFile file) throws IOException, RemoteServiceException {
 
         if (file == null || file.isEmpty()) {
             return null;
@@ -289,7 +294,7 @@ public class CommonLogic {
         }
 
         try {
-            String filePath = ossUtil.getFilePath()+"/"+currentTime + UUID.randomUUID().toString() + "." + uploadFileSuffix;
+            String filePath = ossUtil.getFilePath() + "/" + currentTime + UUID.randomUUID().toString() + "." + uploadFileSuffix;
             if (!ossUtil.uploadFile(filePath, file.getBytes())) {
                 throw new RemoteServiceException("文件同步oss失败");
             }
@@ -313,12 +318,13 @@ public class CommonLogic {
 
     /**
      * 生成订单号
-     * @param start 前缀
+     *
+     * @param start     前缀
      * @param orderType 订单类型
-     * @param length 一般13 位
+     * @param length    一般13 位
      * @return
      */
-    public  String generateNo(String start, String orderType, int length) {
+    public String generateNo(String start, String orderType, int length) {
         String dayFmt = DateUtil.format(new Date(), "yyMMdd");
         String tNumKey = Constant.RedisPrefix.ORDER_NUM + orderType + dayFmt;
         StringBuffer number = new StringBuffer();
@@ -332,19 +338,20 @@ public class CommonLogic {
         return number.toString();
     }
 
-    public List<Region> getRegion(String parentId){
+    public List<Region> getRegion(String parentId) {
         List<Region> list = regionService.lambdaQuery()
-                .eq(StringUtils.isBlank(parentId),Region::getPid,"0")
+                .eq(StringUtils.isBlank(parentId), Region::getPid, "0")
                 .eq(StringUtils.isNotBlank(parentId), Region::getPid, parentId).list();
         return list;
     }
 
     /**
      * 生成辅材编号
+     *
      * @param companyId 商户编号
-     * @param start 前缀
+     * @param start     前缀
      * @param orderType 订单类型
-     * @param length 一般13 位
+     * @param length    一般13 位
      * @return
      */
     public String generateMaterialNo(String companyId, String start, String orderType, int length) {