Browse Source

no message

FengChaoYu 2 weeks ago
parent
commit
9b1c388b76

+ 0 - 10
pom.xml

@@ -81,11 +81,6 @@
         <!--</dependency>-->
         <!--mybatis-->
         <dependency>
-            <groupId>org.mybatis.spring.boot</groupId>
-            <artifactId>mybatis-spring-boot-starter</artifactId>
-            <version>2.1.0</version>
-        </dependency>
-        <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
             <version>3.4.2</version>
@@ -101,11 +96,6 @@
             <version>1.18.8</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.mybatis.spring.boot</groupId>
-            <artifactId>mybatis-spring-boot-autoconfigure</artifactId>
-            <version>2.1.0</version>
-        </dependency>
 
 
         <dependency>

+ 31 - 3
src/main/java/com/gree/mall/miniapp/config/MyBatisPlusConfig.java

@@ -1,10 +1,14 @@
 package com.gree.mall.miniapp.config;
 
+import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.core.injector.ISqlInjector;
 import com.baomidou.mybatisplus.core.parser.ISqlParser;
-import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
 import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
+import com.gree.mall.miniapp.constant.Constant;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Bean;
@@ -65,8 +69,32 @@ public class MyBatisPlusConfig {
      *
      * @return com.baomidou.mybatisplus.core.injector.ISqlInjector
      */
+//    @Bean
+//    public ISqlInjector sqlInjector() {
+//        return new LogicSqlInjector();
+//    }
+    @Bean
+    public PaginationInnerInterceptor paginationInnerInterceptor() {
+        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
+        paginationInnerInterceptor.setMaxLimit(Long.valueOf(Constant.PAGE_SIZE));
+        paginationInnerInterceptor.setDbType(DbType.MYSQL);
+        return paginationInnerInterceptor;
+    }
+
+    /**
+     * 添加分页插件
+     */
     @Bean
-    public ISqlInjector sqlInjector() {
-        return new LogicSqlInjector();
+    public MybatisPlusInterceptor mybatisPlusInterceptor() {
+        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
+        interceptor.addInnerInterceptor(paginationInnerInterceptor());
+        // 添加非法SQL拦截器
+//        interceptor.addInnerInterceptor(new IllegalSQLInnerInterceptor());
+        // 阻止全表更新删除
+        interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
+        // 自定义权限拦截器
+//        interceptor.addInnerInterceptor(new DataScopeInnerInterceptor());
+        // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType
+        return interceptor;
     }
 }

+ 2 - 0
src/main/java/com/gree/mall/miniapp/constant/Constant.java

@@ -9,6 +9,8 @@ public class Constant {
     //广州格力售后服务(对接工单系统的企业微信)
     public static final String GD_COMPANY_WECHAT_ID = "1";
 
+    public final static Integer PAGE_SIZE = 100000;
+
     public class Ali{
         //        public final static String ACCESS_KEY_ID = "LTAI4G3XTLh8G8DiTpXHpWgt";
 //        public final static String ACCESS_KEY_SECERT = "LYe8uf7Lg9WxJ1xejk45qnPFqxXLzN";

+ 0 - 52
src/main/java/com/gree/mall/miniapp/controller/tag/TagController.java

@@ -1,52 +0,0 @@
-package com.gree.mall.miniapp.controller.tag;
-
-import com.gree.mall.miniapp.bean.tag.WxCustomerTagBean;
-import com.gree.mall.miniapp.exception.RemoteServiceException;
-import com.gree.mall.miniapp.helper.ResponseHelper;
-import com.gree.mall.miniapp.logic.tag.TagLogic;
-import com.gree.mall.miniapp.plus.entity.Tag;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import javax.servlet.http.HttpServletRequest;
-
-@Slf4j
-@RestController
-@Api(value = "标签", tags ={"标签"} )
-@RequestMapping(value = "/tag", produces = "application/json; charset=utf-8")
-public class TagController {
-
-    @Autowired
-    private TagLogic tagLogic;
-
-
-    @GetMapping("/wx/customer")
-    @ApiOperation(value = "微信客户列表")
-    public ResponseHelper wxCustomerList(HttpServletRequest request) throws RemoteServiceException {
-        return ResponseHelper.success(tagLogic.wxCustomerList(request));
-    }
-
-
-
-    @GetMapping("/wx/tag/list")
-    @ApiOperation(value = "根据外部联系人unionId获取标签列表")
-    public ResponseHelper wxTagList(HttpServletRequest request, @ApiParam(required = true, value = "用户id") @RequestParam(required = true) String unionId) throws RemoteServiceException {
-        return ResponseHelper.success(tagLogic.tagList(request,unionId));
-    }
-
-
-    @PostMapping("/custom/edit")
-    @ApiOperation("打标签")
-    public ResponseHelper tagEdit(
-            HttpServletRequest request,
-            @ApiParam(value = "标签数据", required = true) @RequestBody WxCustomerTagBean wxCustomerTagBean) throws RemoteServiceException {
-        tagLogic.edit(request,wxCustomerTagBean);
-        return ResponseHelper.success();
-    }
-
-
-}

+ 2 - 3
src/main/java/com/gree/mall/miniapp/controller/user/UserController.java

@@ -76,16 +76,15 @@ public class UserController {
     @ApiOperation(value = "微信授权")
     public ResponseHelper<UserWxBean> auth(
             @ApiParam(required = false,value="业务员用户id") @RequestParam(required = false) String serviceId,
-            @ApiParam(required = true, value = "code") @RequestParam(required = true) String code,
+            @ApiParam(required = true, value = "code") @RequestParam String code,
             @ApiParam(required = false, value = "授权类型true=企业微信 false= 微信,不传默认为微信") @RequestParam(required = false) Boolean work,
+            @ApiParam(required = false, value = "商家编号") @RequestParam String websitId,
             HttpServletRequest request
     ) throws RemoteServiceException, WxErrorException, InterruptedException {
         UserWxBean userWxBean = null;
         log.info("微信授权 code:{} serviceId:{} work:{}", code, serviceId, work);
         if(work == null || !work) {
             userWxBean = userLogic.addUser(code,serviceId,request);
-        }else{
-            userWxBean = userLogic.addWorkUser(code,serviceId,request);
         }
         userLogic.addVisit(request, userWxBean.getUserId());
         log.info(userWxBean.toString());

+ 10 - 8
src/main/java/com/gree/mall/miniapp/logic/common/CommonLogic.java

@@ -82,18 +82,20 @@ public class CommonLogic {
         if(StringUtils.isEmpty(appid)){
             throw new RemoteServiceException("非法请求,缺少必须的参数");
         }
-        AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.lambdaQuery()
-                .eq(AdminCompanyWechat::getSubAppId, appid).one();
-        if(adminCompanyWechat == null){
-            throw new RemoteServiceException("非法请求,请联系管理员配置必要的参数:"+appid);
-        }
+//        AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.lambdaQuery()
+//                .eq(AdminCompanyWechat::getSubAppId, appid)
+//
+//                .one();
+//        if(adminCompanyWechat == null){
+//            throw new RemoteServiceException("非法请求,请联系管理员配置必要的参数:"+appid);
+//        }
 
         User user = userService.getById(userId);
 
         CurrentCompanyWechat currentCompanyWechat = new CurrentCompanyWechat();
-        BeanUtils.copyProperties(adminCompanyWechat,currentCompanyWechat);
-        currentCompanyWechat.setCurrentCompanyWechatId(adminCompanyWechat.getCompanyWechatId());
-        currentCompanyWechat.setCurrentCompanyName(adminCompanyWechat.getCompanyName());
+//        BeanUtils.copyProperties(adminCompanyWechat,currentCompanyWechat);
+        currentCompanyWechat.setCurrentCompanyWechatId("0");
+        currentCompanyWechat.setCurrentCompanyName("平台");
         currentCompanyWechat.setUserId(CommonUtils.getUserId(request));
         currentCompanyWechat.setUser(user);
         return currentCompanyWechat;

+ 0 - 3
src/main/java/com/gree/mall/miniapp/logic/common/WechatLogic.java

@@ -83,9 +83,6 @@ public class WechatLogic {
         return WxConfiguration.wxMaService.get(companyWechatId);
     }
 
-    public WxCpService getWxCpService(Integer agentId){
-        return WxConfiguration.cpServices.get(agentId);
-    }
 
     public Map<String, Object> authToken(String code, AdminCompanyWechat adminCompanyWechat) throws RemoteServiceException {
         String url = "https://api.weixin.qq.com/sns/jscode2session";

+ 0 - 142
src/main/java/com/gree/mall/miniapp/logic/common/WorkWechatLogic.java

@@ -1,142 +0,0 @@
-package com.gree.mall.miniapp.logic.common;
-
-import com.gree.mall.miniapp.config.wx.WxConfiguration;
-import com.gree.mall.miniapp.plus.entity.AdminCompanyWechat;
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.api.WxCpService;
-import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
-import me.chanjar.weixin.cp.bean.WxCpUser;
-import me.chanjar.weixin.cp.bean.external.WxCpUserExternalTagGroupList;
-import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
-import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-
-/**
- *  企业微信api
- *  2021-09-17
- *  lijh
- */
-@Component
-@Slf4j
-public class WorkWechatLogic {
-
-    /**
-     * 小程序应用
-     */
-    public WxCpService miniApp(AdminCompanyWechat adminCompanyWechat){
-        WxCpService cpService = WxConfiguration.cpServices.get("");
-        return cpService;
-    }
-
-    /**
-     * 标签应用
-     */
-    public WxCpService miniTagApp(AdminCompanyWechat adminCompanyWechat){
-        WxCpService cpService = WxConfiguration.cpServices.get("");
-        return cpService;
-    }
-
-
-    /**
-     * 验证登录身份
-     * @param code
-     * @return
-     * @throws WxErrorException
-     */
-    public WxCpMaJsCode2SessionResult jsCode2Session(String code,AdminCompanyWechat adminCompanyWechat) {
-        try {
-            WxCpMaJsCode2SessionResult wxCpMaJsCode2SessionResult = this.miniApp(adminCompanyWechat).jsCode2Session(code);
-            return wxCpMaJsCode2SessionResult;
-        } catch (WxErrorException e) {
-            log.error("企业微信调用api失败" + e.getMessage());
-        }
-        return null;
-    }
-
-    /**
-     * 获取企业微信成员
-     * @param userId
-     * @return
-     * @throws WxErrorException
-     */
-    public WxCpUser getUser(String userId,AdminCompanyWechat adminCompanyWechat){
-        try {
-            WxCpUser wxCpUser = this.miniApp(adminCompanyWechat).getUserService().getById(userId);
-            return wxCpUser;
-        }catch(Exception e){
-            log.error("获取企业微信成员失败"+e.getMessage());
-            return null;
-        }
-    }
-
-
-    /**
-     * 获取企业标签
-     * @return
-     * @throws WxErrorException
-     */
-    public  List<WxCpUserExternalTagGroupList.TagGroup> getTag(AdminCompanyWechat adminCompanyWechat) {
-        WxCpUserExternalTagGroupList corpTagList = null;
-        try {
-            corpTagList = this.miniApp(adminCompanyWechat).getExternalContactService().getCorpTagList(null);
-        } catch (WxErrorException e) {
-            log.error("企业微信调用api失败"+e.getMessage());
-        }
-        List<WxCpUserExternalTagGroupList.TagGroup> tagGroupList = corpTagList.getTagGroupList();
-        return tagGroupList;
-    }
-
-    /**
-     * 获取客户列表用户id
-     * @param workUserId
-     * @return
-     * @throws WxErrorException
-     */
-    public List<String> getExternalUserIdByWorkUserId(String workUserId,AdminCompanyWechat adminCompanyWechat){
-        List<String> strings = null;
-        try {
-            strings = this.miniApp(adminCompanyWechat).getExternalContactService().listExternalContacts(workUserId);
-        } catch (WxErrorException e) {
-            log.error("企业微信调用api失败"+e.getMessage());
-        }
-        return strings;
-    }
-
-    /**
-     * 获取客户详情
-     */
-    public WxCpExternalContactInfo getCustomerDetail(String externalUserId,AdminCompanyWechat adminCompanyWechat) {
-        WxCpExternalContactInfo contactDetail = null;
-        try {
-            contactDetail = this.miniApp(adminCompanyWechat).getExternalContactService().getContactDetail(externalUserId);
-        } catch (WxErrorException e) {
-            e.printStackTrace();
-        }
-        return contactDetail;
-    }
-
-    /**
-     * 批量获取客户详情
-     * @param workUserIds 成员ids
-     * @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
-     * @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取最大值
-     */
-    public WxCpExternalContactBatchInfo getCustomerByExternalUserId(String workUserIds,String cursor,Integer limit,AdminCompanyWechat adminCompanyWechat) {
-        WxCpExternalContactBatchInfo contactDetailBatch = null;
-        try {
-            contactDetailBatch = this.miniApp(adminCompanyWechat).getExternalContactService()
-                    .getContactDetailBatch(workUserIds, cursor, limit);
-        } catch (WxErrorException e) {
-            log.error("企业微信调用api失败"+e.getMessage());
-        }
-        return contactDetailBatch;
-    }
-
-
-
-
-
-}

+ 4 - 3
src/main/java/com/gree/mall/miniapp/logic/member/UserCouponLogic.java

@@ -24,9 +24,10 @@ public class UserCouponLogic {
      * @return
      */
     public IPage<UserCoupon> page(String couponName, String couponType, Integer pageNum, Integer pageSize) {
-        LambdaQueryChainWrapper<UserCoupon> wrapper = userCouponService.lambdaQuery()
+        final Page<UserCoupon> page = userCouponService.lambdaQuery()
                 .like(StringUtils.isNotBlank(couponName), UserCoupon::getCouponName, couponName)
-                .eq(StringUtils.isNotBlank(couponName), UserCoupon::getCouponType, couponType);
-        return userCouponService.page(new Page<>(pageNum, pageSize), wrapper);
+                .eq(StringUtils.isNotBlank(couponName), UserCoupon::getCouponType, couponType)
+                .page(new Page<>(pageNum, pageSize));
+        return page;
     }
 }

+ 1 - 1
src/main/java/com/gree/mall/miniapp/logic/notice/NoticeLogic.java

@@ -50,7 +50,7 @@ public class NoticeLogic {
 //    private String wxMpAppid;
 //    @Value("${wx.mp.secret}")
 //    private String wxMpSecret;
-    @Value("${wechat.subAppId}")
+    @Value("${wechat.sub.appid}")
     private String subAppId;
     @Autowired
     RedisUtil redisUtil;

+ 6 - 4
src/main/java/com/gree/mall/miniapp/logic/order/OrderLogic.java

@@ -1,6 +1,7 @@
 package com.gree.mall.miniapp.logic.order;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.excel.util.CollectionUtils;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -738,15 +739,16 @@ public class OrderLogic {
         //todo 该方法订单量大时,需要使用其他方案进行优化
         String timeByMin = DateUtils.getTimeByMin(new Date(), -35);
         //1次至多处理50单
-        List<OrderInfo> list = orderInfoService.lambdaQuery()
+        final List<OrderInfo> list = orderInfoService.lambdaQuery()
                 .select(OrderInfo::getOrderId, OrderInfo::getUserCouponId, OrderInfo::getExchangeCode)
                 .le(OrderInfo::getCreateTime, timeByMin)
                 .eq(OrderInfo::getOrderStatus, OrderStatusEnum.NOPAY.toString())
-                .page(new Page<>(1, 50, false))
-                .getRecords();
-        if (CollectionUtils.isEmpty(list)) {
+                .last("limit 50")
+                .list();
+        if (CollectionUtil.isEmpty(list)) {
             return;
         }
+
         List<String> orderIds = list.stream().map(OrderInfo::getOrderId).collect(Collectors.toList());
         this.cancel(orderIds);
     }

+ 0 - 211
src/main/java/com/gree/mall/miniapp/logic/tag/TagLogic.java

@@ -1,211 +0,0 @@
-package com.gree.mall.miniapp.logic.tag;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.google.gson.JsonObject;
-import com.gree.mall.miniapp.bean.tag.*;
-import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
-import com.gree.mall.miniapp.commonmapper.WxCustomerMapper;
-import com.gree.mall.miniapp.exception.RemoteServiceException;
-import com.gree.mall.miniapp.logic.common.CommonLogic;
-import com.gree.mall.miniapp.logic.common.WorkWechatLogic;
-import com.gree.mall.miniapp.plus.entity.*;
-import com.gree.mall.miniapp.plus.service.*;
-import com.gree.mall.miniapp.utils.CommonUtils;
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.bean.WxCpBaseResp;
-import me.chanjar.weixin.cp.bean.external.contact.ExternalContact;
-import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
-import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.servlet.http.HttpServletRequest;
-import java.util.*;
-import java.util.stream.Collectors;
-
-@Slf4j
-@Service
-public class TagLogic {
-    @Autowired
-    private UserTagService userTagService;
-    @Autowired
-    private UserService userService;
-    @Autowired
-    private WxCustomerMapper wxCustomerMapper;
-    @Autowired
-    private ExternalUserService externalUserService;
-    @Autowired
-    private TagService tagService;
-    @Autowired
-    private TagGroupService tagGroupService;
-    @Autowired
-    private CustomUserTagService customUserTagService;
-    @Autowired
-    private WorkWechatLogic workWechatLogic;
-    @Autowired
-    CommonLogic commonLogic;
-
-    @Transactional()
-    public void edit(HttpServletRequest request, WxCustomerTagBean wxCustomerTagBean) throws RemoteServiceException {
-
-        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
-
-        User user = userService.lambdaQuery()
-                .eq(User::getUserId, currentCompanyWechat.getUserId())
-                .eq(User::getStatus,true)
-                .one();
-        if (user == null || StringUtils.isEmpty(user.getWorkUserId())) {
-            throw new RemoteServiceException("用户不存在");
-        }
-
-        if (wxCustomerTagBean != null) {
-            //添加自定义标签
-            if (wxCustomerTagBean.getSaveTags() != null && wxCustomerTagBean.getSaveTags().size() > 0) {
-                customUserTagService.lambdaUpdate()
-                        .eq(CustomUserTag::getUnionId, wxCustomerTagBean.getUnionId())
-                        .eq(CustomUserTag::getUserid, user.getWorkUserId())
-                        .remove();
-                List<CustomUserTag> customUserTagList = new ArrayList<>();
-                wxCustomerTagBean.getSaveTags().forEach(s -> {
-                    CustomUserTag customUserTag = new CustomUserTag();
-                    customUserTag.setTagName(s);
-                    customUserTag.setUnionId(wxCustomerTagBean.getUnionId());
-                    customUserTag.setUserid(user.getWorkUserId());
-                    customUserTag.setCreateTime(new Date());
-                    customUserTagList.add(customUserTag);
-                });
-                customUserTagService.saveBatch(customUserTagList);
-            }
-
-            List<String> addWxTag = new ArrayList<>();
-            List<String> delWxTag = new ArrayList<>();
-            if (wxCustomerTagBean.getAddTags() != null) {
-                addWxTag = wxCustomerTagBean.getAddTags().stream().map(SimpleTagBean::getTagId).collect(Collectors.toList());
-            }
-            if (wxCustomerTagBean.getDelTags() != null) {
-                delWxTag = wxCustomerTagBean.getDelTags();
-            }
-
-            if (addWxTag.size() < 1 && delWxTag.size() < 1) {
-                return;
-            }
-            String externalUserId = null;
-            List<String> externalList =  workWechatLogic.getExternalUserIdByWorkUserId(user.getWorkUserId(),currentCompanyWechat);
-            if (externalList != null && externalList.size() > 0) {
-                externalUserId = getContactDetail(externalList, wxCustomerTagBean.getUnionId(),currentCompanyWechat);
-            }
-            if (externalUserId == null) {
-                throw new RemoteServiceException("请先用企业微信添加客户微信为好友,再添加客户标签");
-            }
-
-            try {
-                WxCpBaseResp wxCpBaseResp = workWechatLogic.miniTagApp(currentCompanyWechat)
-                        .getExternalContactService().markTag(user.getWorkUserId(), externalUserId, addWxTag.toArray(new String[0]), delWxTag.toArray(new String[0]));
-                if (wxCpBaseResp.success()) {
-                    if (delWxTag.size() > 0) {
-                        userTagService.lambdaUpdate()
-                                .eq(UserTag::getUnionId, wxCustomerTagBean.getUnionId())
-                                .in(UserTag::getTagId, delWxTag)
-                                .remove();
-                    }
-                    if (addWxTag.size() > 0) {
-                        for (SimpleTagBean simpleTagBean : wxCustomerTagBean.getAddTags()) {
-                            this.saveUserTag(wxCustomerTagBean.getUnionId(), user.getWorkUserId(), simpleTagBean.getTagId(), simpleTagBean.getTagName());
-                        }
-                    }
-
-                }
-            } catch (WxErrorException e) {
-                throw new RemoteServiceException("微信标签同步失败");
-            }
-
-
-        }
-
-    }
-
-    private String getContactDetail(List<String> externalList, String unionId,AdminCompanyWechat adminCompanyWechat) {
-
-        for (String externalUserId : externalList) {
-            WxCpExternalContactInfo wxCpExternalContactInfoInfo = workWechatLogic.getCustomerDetail(externalUserId, adminCompanyWechat);
-            if (wxCpExternalContactInfoInfo == null) {
-                continue;
-            }
-            if (!unionId.equals(wxCpExternalContactInfoInfo.getExternalContact().getUnionId())) {
-                continue;
-            }
-            ExternalUser externalUser = new ExternalUser();
-            BeanUtils.copyProperties(wxCpExternalContactInfoInfo.getExternalContact(), externalUser, "externalProfile");
-            externalUser.setExternalProfile(JSONObject.toJSONString(wxCpExternalContactInfoInfo.getExternalContact().getExternalProfile()));
-            externalUser.setCreateTime(new Date());
-            externalUser.setAddType(true);
-
-            externalUserService.saveOrUpdate(externalUser);
-            return externalUserId;
-        }
-        return null;
-    }
-
-
-    public List<UserWxCustomerBean> wxCustomerList(HttpServletRequest request) {
-        String userId = CommonUtils.getUserId(request);
-        User user = userService.lambdaQuery()
-                .eq(User::getUserId, userId)
-                .eq(User::getStatus,true)
-                .one();
-        if (user == null || StringUtils.isEmpty(user.getWorkUserId())) {
-            return null;
-        }
-        return wxCustomerMapper.queryCustomerByUser(userId, user.getWorkUserId());
-    }
-
-    public TagBean tagList(HttpServletRequest request, String unionId) {
-        String userId = CommonUtils.getUserId(request);
-        User user = userService.lambdaQuery()
-                .eq(User::getUserId, userId)
-                .eq(User::getStatus,true)
-                .one();
-        if (user == null || StringUtils.isEmpty(user.getWorkUserId())) {
-            return null;
-        }
-
-        TagBean tagBean = new TagBean();
-        tagBean.setTagGroupBeanList(wxCustomerMapper.queryTagList(unionId));
-        tagBean.setTagNameList(wxCustomerMapper.queryCustomTagList(unionId, user.getWorkUserId()));
-        return tagBean;
-    }
-
-
-    public Tag addTag(String tagGroupId, String tagName) {
-        TagGroup tagGroup = tagGroupService.getById(tagGroupId);
-        Tag tag = new Tag();
-        tag.setGroupId(tagGroupId);
-        tag.setGroupName(tagGroup.getTagGroupName());
-        tag.setName(tagName);
-        tag.setCreateTime(new Date());
-        tagService.save(tag);
-        return tag;
-    }
-
-    public void delTag(String tagId) {
-        tagService.removeById(tagId);
-    }
-
-    private void saveUserTag(String unionId, String workUserId, String tagId, String tagName) {
-        UserTag userTag = new UserTag();
-        userTag.setUserTagId(null);
-        userTag.setUnionId(unionId);
-        userTag.setUserid(workUserId);
-        userTag.setTagId(tagId);
-        userTag.setTagName(tagName);
-        userTag.setCreateTime(new Date());
-        userTagService.save(userTag);
-    }
-
-
-}

+ 1 - 144
src/main/java/com/gree/mall/miniapp/logic/user/UserLogic.java

@@ -3,11 +3,9 @@ package com.gree.mall.miniapp.logic.user;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
 import cn.hutool.core.util.IdUtil;
-import com.alibaba.excel.util.CollectionUtils;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.github.binarywang.wxpay.service.WxPayService;
 import com.gree.mall.miniapp.bean.user.*;
 import com.gree.mall.miniapp.commonmapper.*;
 import com.gree.mall.miniapp.constant.Constant;
@@ -18,7 +16,6 @@ import com.gree.mall.miniapp.exception.RemoteServiceException;
 import com.gree.mall.miniapp.helper.ResponseHelper;
 import com.gree.mall.miniapp.logic.common.CommonLogic;
 import com.gree.mall.miniapp.logic.common.WechatLogic;
-import com.gree.mall.miniapp.logic.common.WorkWechatLogic;
 import com.gree.mall.miniapp.logic.coupon.CouponLogic;
 import com.gree.mall.miniapp.logic.order.ShoppingCartLogic;
 import com.gree.mall.miniapp.plus.entity.*;
@@ -26,23 +23,17 @@ import com.gree.mall.miniapp.plus.service.*;
 import com.gree.mall.miniapp.utils.*;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
-import me.chanjar.weixin.cp.api.WxCpService;
 import me.chanjar.weixin.cp.bean.Gender;
 import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
 import me.chanjar.weixin.cp.bean.WxCpUser;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.xmlbeans.UserType;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.integration.redis.util.RedisLockRegistry;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -68,8 +59,6 @@ public class UserLogic {
     @Autowired
     CouponLogic couponLogic;
     @Autowired
-    WorkWechatLogic workWechatLogic;
-    @Autowired
     RedisLockRegistry redisLockRegistry;
     @Autowired
     UserService userService;
@@ -208,139 +197,6 @@ public class UserLogic {
     }
 
     /**
-     * 企业微信里授权的场景
-     *
-     * @param code
-     * @param serviceId
-     * @return
-     * @throws WxErrorException
-     * @throws RemoteServiceException
-     * @throws InterruptedException
-     */
-    @Transactional
-    public UserWxBean addWorkUser(String code, String serviceId,HttpServletRequest request) throws RemoteServiceException, InterruptedException {
-        CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat(request);
-        //企业微信里拉取微信授权
-        if (StringUtils.isNotEmpty(serviceId)) {
-            User user = userService.getById(serviceId);
-            Map<String, Object> returnMap = wechatLogic.authToken(code,currentCompanyWechat);
-            String openId = (String) returnMap.get("openid");
-            String sessionKey = (String) returnMap.get("session_key");
-            //删掉可能存在的openid数据
-            userService.lambdaUpdate()
-                    .eq(User::getOpenId, openId)
-                    .eq(User::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
-                    .remove();
-            //微信授权,二次绑定微信openid
-            user.setOpenId(openId);
-            user.setSessionKey(sessionKey);
-            user.updateById();
-            return this.supplyUser(user);
-        }
-
-        //企业微信进入
-        WxCpMaJsCode2SessionResult wxCpMaJsCode2SessionResult = workWechatLogic.jsCode2Session(code,currentCompanyWechat);
-
-        String workUserId = wxCpMaJsCode2SessionResult.getUserId();
-        String sessionKey = wxCpMaJsCode2SessionResult.getSessionKey();
-
-        String key = Constant.RedisPrefix.LOCK_AUTH + ":" + workUserId;
-        Lock obtain = redisLockRegistry.obtain(key);
-        if (!obtain.tryLock(2, TimeUnit.SECONDS)) {
-            log.error("请勿重复授权");
-            return null;
-        }
-        try {
-
-            User user = userService.lambdaQuery()
-                    .eq(User::getWorkUserId, workUserId)
-                    .eq(User::getStatus,true)
-                    .eq(User::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
-                    .one();
-            if (user != null) {
-                user.setWorkSessionKey(sessionKey);
-                user.setLastLoginTime(new Date());
-                user.updateById();
-                return this.supplyUser(user);
-            }
-            //获取企业微信个人信息
-            WxCpUser wxCpUser = workWechatLogic.getUser(workUserId,currentCompanyWechat);
-            if (wxCpUser == null) {
-                List<EnterpriseWechatWorker> list = enterpriseWechatWorkerService.lambdaQuery()
-                        .eq(EnterpriseWechatWorker::getWechatUserId, workUserId)
-                        .eq(EnterpriseWechatWorker::getCorpId,"").list();
-                if (list.size() > 0) {
-                    EnterpriseWechatWorker enterpriseWechatWorker = list.get(0);
-                    wxCpUser = new WxCpUser();
-                    wxCpUser.setMobile(enterpriseWechatWorker.getMobile());
-                    wxCpUser.setGender(Gender.UNDEFINED);
-                    wxCpUser.setAvatar(enterpriseWechatWorker.getQrCode());
-                    wxCpUser.setName(enterpriseWechatWorker.getName());
-                    wxCpUser.setStatus(1);
-                    wxCpUser.setQrCode(enterpriseWechatWorker.getQrCode());
-                }
-            }
-            if (wxCpUser == null) {
-                log.error("企业微信授权失败,workUserId:{}", workUserId);
-                throw new RemoteServiceException("授权失败,请联系相关人员");
-            }
-
-            //查询是否能根据手机号查询到微信用户
-            if(StringUtils.isNotEmpty(wxCpUser.getMobile())){
-                user = this.getUserByMobile(wxCpUser.getMobile(),currentCompanyWechat.getCompanyWechatId());
-            }
-            Integer count = userService.lambdaQuery()
-                    .eq(User::getWorkUserId, workUserId)
-                    .eq(User::getType, UserTypeEnum.SERVICE.toString())
-                    .eq(User::getCompanyWechatId,currentCompanyWechat.getCompanyWechatId())
-                    .count();
-            if (user == null) {
-                user = new User();
-                user.setMobile(wxCpUser.getMobile());
-                user.setNickName(wxCpUser.getName());
-                if(wxCpUser.getGender() != null) {
-                    user.setSex(wxCpUser.getGender().getGenderName());
-                }
-                user.setAvatar(wxCpUser.getAvatar());
-                user.setStatus(wxCpUser.getStatus() == 1);
-
-                if (count < 1) {
-                    user.setWorkName(wxCpUser.getName());
-                    user.setWorkPhone(wxCpUser.getMobile());
-                    user.setWorkUserId(workUserId);
-                    user.setType(UserTypeEnum.SERVICE.toString());
-                    user.setPosition(wxCpUser.getPosition());
-                    user.setWorkQrcode(wxCpUser.getQrCode());
-                    user.setWorkSessionKey(sessionKey);
-                }
-                user.setLastLoginTime(new Date());
-                user.setCreateTime(new Date());
-                user.setCompanyWechatId(currentCompanyWechat.getCompanyWechatId());
-                user.setCompanyName(currentCompanyWechat.getCompanyName());
-                user.insert();
-            } else {
-                if (!user.getStatus()) {
-                    throw new RemoteServiceException("用户已被冻结");
-                }
-                if (count < 1) {
-                    user.setWorkUserId(workUserId);
-                    user.setWorkName(wxCpUser.getName());
-                    user.setWorkPhone(wxCpUser.getMobile());
-                    user.setWorkQrcode(wxCpUser.getQrCode());
-                    user.setType(UserTypeEnum.SERVICE.toString());
-                    user.setWorkSessionKey(sessionKey);
-                }
-                user.setLastLoginTime(new Date());
-                user.updateById();
-            }
-            return this.supplyUser(user);
-        } finally {
-            obtain.unlock();
-        }
-    }
-
-
-    /**
      * 返回小程序用户登录需要的信息
      *
      * @param user
@@ -700,6 +556,7 @@ public class UserLogic {
             userVisit.setVisitTime(new Date());
             userVisit.setCompanyWechatId(currentCompanyWechat.getCurrentCompanyWechatId());
             userVisit.setCompanyName(currentCompanyWechat.getCurrentCompanyName());
+            userVisit.setWebsitId("");
             userVisit.insert();
         } catch (Exception e) {
             log.error("新增用户访问记录失败", e);

+ 1 - 1
src/main/java/com/gree/mall/miniapp/utils/HttpUtils.java

@@ -1,8 +1,8 @@
 package com.gree.mall.miniapp.utils;
 
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.gree.mall.miniapp.exception.RemoteServiceException;
 import okhttp3.*;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;