Jelajahi Sumber

fix: 优化迭代

xdd 3 hari lalu
induk
melakukan
1754c313e8

+ 2 - 2
deploy.sh

@@ -53,10 +53,10 @@ deploy_jar() {
 deploy_jar "$LOCAL_FS_ADMIN_JAR" "fs-admin"
 
 # 部署 fs-company
-deploy_jar "$LOCAL_FS_COMPANY_JAR" "fs-company"
+#deploy_jar "$LOCAL_FS_COMPANY_JAR" "fs-company"
 
 # 部署 fs-user-app
-deploy_jar "$LOCAL_FS_USER_APP_JAR" "fs-user-app"
+#deploy_jar "$LOCAL_FS_USER_APP_JAR" "fs-user-app"
 
 echo "Deployment completed."
 

+ 9 - 0
fs-admin/src/test/java/com/fs/company/controller/CompanyControllerTest.java

@@ -9,6 +9,7 @@ import com.fs.erp.service.IErpOrderService;
 import com.fs.erp.service.impl.ErpOrderServiceImpl;
 import com.fs.pay.pay.util.PayUtil;
 import com.fs.store.domain.FsStoreOrder;
+import com.fs.store.param.FsStoreOrderExpressEditParam;
 import com.fs.store.service.IFsStoreOrderService;
 import com.fs.wx.dto.*;
 import com.fs.wx.service.OrderQueryService;
@@ -50,6 +51,14 @@ public class CompanyControllerTest {
     @Autowired
     private IFsStoreOrderService fsStoreOrderService;
 
+
+    @Test
+    public void diver(){
+        FsStoreOrderExpressEditParam param = new FsStoreOrderExpressEditParam();
+        param.setOrderId(1340561L);
+        fsStoreOrderService.syncExpress(param);
+    }
+
     @Test
     public void test4() throws ParseException {
         FsStoreOrder order=fsStoreOrderService.selectFsStoreOrderByOrderCode("1935899736686985216");

File diff ditekan karena terlalu besar
+ 141 - 861
fs-admin/src/test/java/com/fs/store/controller/FsStorePaymentControllerTest.java


+ 5 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsStorePaymentMapper.java

@@ -9,6 +9,7 @@ import com.fs.store.param.FsStorePaymentParam;
 import com.fs.store.param.FsStoreStatisticsParam;
 import com.fs.store.vo.FsStorePaymentStatisticsVO;
 import com.fs.store.vo.FsStorePaymentVO;
+import org.apache.ibatis.annotations.MapKey;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
@@ -388,4 +389,8 @@ public interface FsStorePaymentMapper
     List<FsStorePayment> queryNormalData();
 
     List<FsStorePayment> queryByBankTrxId(@Param("list") List<String> bankTrxIds);
+
+    @MapKey("orderId")
+    @Select("select order_id,bank_transaction_id from fs_store_payment where bank_transaction_id is not null")
+    Map<Long,FsStorePayment> selectAllPayments();
 }

+ 9 - 0
fs-service-system/src/main/java/com/fs/store/mapper/FsUserMapper.java

@@ -190,4 +190,13 @@ public interface FsUserMapper
             "tui_money DESC "+
             "</script>"})
     List<FsUserShareVO> selectFsUserShareList(@Param("userId") String userId,@Param("type")Integer type);
+
+    @Select("select user_id from fs_user where ma_open_id=#{openid}")
+    FsUser selectFsUserByMaOpenIdNew(String openid);
+
+    @Select("select user_id from fs_user where union_id=#{unionId}")
+    FsUser selectFsUserByUnionIdNew(String unionId);
+
+
+    FsUser selectFsUserByMaOpenIdOrUnionId(@Param("openId") String openId,@Param("unionId") String unionId);
 }

+ 11 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsUserService.java

@@ -2,15 +2,19 @@ package com.fs.store.service;
 
 import java.util.List;
 
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import com.fs.common.core.domain.R;
 import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStoreOrderItem;
 import com.fs.store.domain.FsUser;
 
+import com.fs.store.param.LoginMpWxParam;
 import com.fs.store.vo.FsUserListVO;
 import com.fs.store.vo.FsUserVO;
 import com.fs.store.vo.FsCompanyUserListQueryVO;
 import com.fs.store.vo.FsUserShareVO;
 import com.fs.store.vo.FsUserTuiVO;
+import org.springframework.scheduling.annotation.Async;
 
 /**
  * 用户Service接口
@@ -104,13 +108,20 @@ public interface IFsUserService
     void addMoney(FsStoreOrder order);
 
     FsUser selectFsUserByMaOpenId(String openid);
+    FsUser selectFsUserByMaOpenIdNew(String openid);
 
     FsUser selectFsUserByMpOpenId(String openid);
 
     FsUser selectFsUserByUnionId(String unionId);
+    FsUser selectFsUserByUnionIdNew(String unionId);
 
 
     FsUser selectFsUserByUserCode(String userCode);
 
     List<FsUserShareVO> selectFsUserShareList(String userId,Integer type);
+
+    R loginByMiniApp(LoginMpWxParam param);
+
+    @Async
+    void updateUserLastIp(FsUser user, String ip, WxMaJscode2SessionResult session);
 }

+ 11 - 1
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -2591,9 +2591,19 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
         return fsStoreOrderMapper.selectFsStoreOrderStatisticsList(param);
     }
 
+
+
     @Override
     public List<FsStoreOrderExportVO> selectFsStoreOrderListVOByExport(FsStoreOrderParam param) {
-        return fsStoreOrderMapper.selectFsStoreOrderListVOByExport(param);
+        List<FsStoreOrderExportVO> fsStoreOrderExportVOS = fsStoreOrderMapper.selectFsStoreOrderListVOByExport(param);
+        Map<Long, FsStorePayment> paymentMap = fsStorePaymentMapper.selectAllPayments();
+        for (FsStoreOrderExportVO item : fsStoreOrderExportVOS) {
+            FsStorePayment fsStorePayment = paymentMap.get(item.getId());
+            if(ObjectUtil.isNotNull(fsStorePayment)){
+                item.setBankTrxId(fsStorePayment.getBankTransactionId());
+            }
+        }
+        return fsStoreOrderExportVOS;
     }
 
     @Override

+ 113 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsUserServiceImpl.java

@@ -1,10 +1,19 @@
 package com.fs.store.service.impl;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
 
+import cn.binarywang.wx.miniapp.api.WxMaService;
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
+import com.fs.common.core.domain.R;
 import com.fs.common.utils.DateUtils;
+import com.fs.common.utils.IpUtil;
 import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStoreOrderItem;
 import com.fs.store.domain.FsUserBill;
@@ -13,21 +22,33 @@ import com.fs.store.enums.BillDetailEnum;
 import com.fs.store.mapper.FsStoreOrderMapper;
 import com.fs.store.mapper.FsStoreProductAttrValueMapper;
 import com.fs.store.mapper.FsUserTuiMoneyRankMapper;
+import com.fs.store.param.LoginMpWxParam;
 import com.fs.store.service.IFsUserBillService;
+import com.fs.store.utils.JwtUtils;
 import com.fs.store.vo.FsUserListVO;
 import com.fs.store.vo.FsUserVO;
 import com.fs.store.vo.FsCompanyUserListQueryVO;
 import com.fs.store.vo.FsUserShareVO;
 import com.fs.store.vo.FsUserTuiVO;
+import com.fs.wx.miniapp.config.WxMaConfiguration;
+import com.fs.wx.miniapp.config.WxMaProperties;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.api.WxMpService;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.aop.framework.AopContext;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import com.fs.store.mapper.FsUserMapper;
 import com.fs.store.domain.FsUser;
 import com.fs.store.service.IFsUserService;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.PostConstruct;
+
 import static com.fs.store.enums.BillDetailEnum.CATEGORY_1;
 import static com.fs.store.enums.BillDetailEnum.CATEGORY_3;
 
@@ -38,6 +59,7 @@ import static com.fs.store.enums.BillDetailEnum.CATEGORY_3;
  * @date 2022-03-15
  */
 @Service
+@EnableAspectJAutoProxy(exposeProxy = true, proxyTargetClass = true)
 public class FsUserServiceImpl implements IFsUserService
 {
     @Autowired
@@ -51,7 +73,20 @@ public class FsUserServiceImpl implements IFsUserService
     @Autowired
     private FsStoreOrderMapper storeOrderMapper;
 
+    @Autowired
+    private WxMaProperties maProperties;
+
+    @Autowired
+    private WxMpService wxMpService;
+
+    @Autowired
+    private JwtUtils jwtUtils;
+
+
+
     Logger logger =  LoggerFactory.getLogger(FsUserServiceImpl.class);
+
+
     /**
      * 查询用户
      *
@@ -312,6 +347,11 @@ public class FsUserServiceImpl implements IFsUserService
         return fsUserMapper.selectFsUserByMaOpenId(openid);
     }
 
+    @Override
+    public FsUser selectFsUserByMaOpenIdNew(String openid) {
+        return fsUserMapper.selectFsUserByMaOpenIdNew(openid);
+    }
+
     @Override
     public FsUser selectFsUserByMpOpenId(String openid) {
         return fsUserMapper.selectFsUserByMpOpenId(openid);
@@ -322,6 +362,11 @@ public class FsUserServiceImpl implements IFsUserService
         return fsUserMapper.selectFsUserByUnionId(unionId);
     }
 
+    @Override
+    public FsUser selectFsUserByUnionIdNew(String unionId) {
+        return fsUserMapper.selectFsUserByUnionIdNew(unionId);
+    }
+
     @Override
     public FsUser selectFsUserByUserCode(String userCode) {
         return fsUserMapper.selectFsUserByUserCode(userCode);
@@ -337,5 +382,73 @@ public class FsUserServiceImpl implements IFsUserService
         return fsUserTuiMoneyRankMapper.selectFsUserShareList(type);
     }
 
+    @Override
+    public R loginByMiniApp(LoginMpWxParam param) {
+        if (StringUtils.isBlank(param.getCode())) {
+            return R.error("code不存在");
+        }
+        try {
+            WxMaService wxService = WxMaConfiguration.getMaService(maProperties.getConfigs().get(0).getAppid());
+
+            WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
+            FsUser user=fsUserMapper.selectFsUserByMaOpenIdOrUnionId(session.getOpenid(),session.getUnionid());
+
+            String ip = IpUtil.getRequestIp();
+            if(ObjectUtil.isNull(user)) {
+                // 保存用户信息
+                user = saveUser(param, wxService, session, ip);
+            } else {
+                // 异步更新用户IP信息
+                FsUser finalUser = user;
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        updateUserLastIp(finalUser, ip, session);
+                    } catch (Exception e) {
+                        logger.error("更新用户IP异常", e);
+                    }
+                });
+            }
+            String token = jwtUtils.generateToken(user.getUserId());
+            return R.ok("登录成功").put("token",token).put("user", user);
+        } catch (WxErrorException e) {
+            return R.error("授权失败,"+e.getMessage());
+        }
+    }
+
+    private FsUser saveUser(LoginMpWxParam param, WxMaService wxService, WxMaJscode2SessionResult session, String ip) {
+        FsUser user;
+        // 解密
+        WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(session.getSessionKey(), param.getEncryptedData(), param.getIv());
+        //写入
+        user=new FsUser();
+        user.setPhone(phoneNoInfo.getPhoneNumber());
+        user.setNickname("微信用户");
+        user.setStatus(1);
+        user.setMaOpenId(session.getOpenid());
+        user.setLastIp(ip);
+        user.setIsWeixinAuth(0);
+        user.setCreateTime(new Date());
+        if(StringUtils.isNotEmpty(session.getUnionid())){
+            user.setUnionId(session.getUnionid());
+        }
+        this.insertFsUser(user);
+        return user;
+    }
+
+    @Override
+    public void updateUserLastIp(FsUser user, String ip, WxMaJscode2SessionResult session) {
+        FsUser userMap=new FsUser();
+        userMap.setUserId(user.getUserId());
+        userMap.setUpdateTime(new DateTime());
+        userMap.setLastIp(ip);
+        if(StringUtils.isNotEmpty(session.getUnionid())){
+            userMap.setUnionId(session.getUnionid());
+        }
+        if(StringUtils.isNotBlank(session.getOpenid())) {
+            userMap.setMaOpenId(session.getOpenid());
+        }
+        this.updateFsUser(userMap);
+    }
+
 
 }

+ 89 - 0
fs-service-system/src/main/java/com/fs/store/utils/JwtUtils.java

@@ -0,0 +1,89 @@
+package com.fs.store.utils;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Primary;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+/**
+ * jwt工具类
+
+ */
+@ConfigurationProperties(prefix = "fs.jwt")
+@Component("jwtUtilsService")
+@Primary
+public class JwtUtils {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+
+    private String secret;
+    private long expire;
+    private String header;
+
+    /**
+     * 生成jwt token
+     */
+    public String generateToken(long userId) {
+        Date nowDate = new Date();
+        //过期时间
+        Date expireDate = new Date(nowDate.getTime() + expire * 1000);
+
+        return Jwts.builder()
+                .setHeaderParam("typ", "JWT")
+                .setSubject(userId+"")
+                .setIssuedAt(nowDate)
+                .setExpiration(expireDate)
+                .signWith(SignatureAlgorithm.HS512, secret)
+                .compact();
+    }
+
+    public Claims getClaimByToken(String token) {
+        try {
+            return Jwts.parser()
+                    .setSigningKey(secret)
+                    .parseClaimsJws(token)
+                    .getBody();
+        }catch (Exception e){
+            logger.debug("validate is token error ", e);
+            return null;
+        }
+    }
+
+    /**
+     * token是否过期
+     * @return  true:过期
+     */
+    public boolean isTokenExpired(Date expiration) {
+        return expiration.before(new Date());
+    }
+
+    public String getSecret() {
+        return secret;
+    }
+
+    public void setSecret(String secret) {
+        this.secret = secret;
+    }
+
+    public long getExpire() {
+        return expire;
+    }
+
+    public void setExpire(long expire) {
+        this.expire = expire;
+    }
+
+    public String getHeader() {
+        return header;
+    }
+
+    public void setHeader(String header) {
+        this.header = header;
+    }
+}

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/vo/FsStoreOrderExportVO.java

@@ -130,6 +130,9 @@ public class FsStoreOrderExportVO implements Serializable
     @Excel(name = "订单状态", dictType = "store_order_status")
     private String status;
 
+    @Excel(name = "交易单号")
+    private String bankTrxId;
+
 //    /** 0 未退款 1 申请中 2 已退款 */
 ////    @Excel(name = "0 未退款 1 申请中 2 已退款")
 //    private Integer refundStatus;
@@ -262,4 +265,6 @@ public class FsStoreOrderExportVO implements Serializable
 
     @Excel(name = "归属档期")
     private String scheduleName;
+
+
 }

+ 21 - 0
fs-service-system/src/main/resources/mapper/store/FsUserMapper.xml

@@ -87,6 +87,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectFsUserVo"/>
         where user_id = #{userId}
     </select>
+    <select id="selectFsUserByMaOpenIdOrUnionId" resultType="com.fs.store.domain.FsUser">
+        SELECT user_id
+        FROM fs_user
+        <where>
+            <choose>
+                <when test="openId != null and openId != '' and unionId != null and unionId != ''">
+                    (ma_open_id = #{openId} OR union_id = #{unionId})
+                </when>
+                <when test="openId != null and openId != ''">
+                    ma_open_id = #{openId}
+                </when>
+                <when test="unionId != null and unionId != ''">
+                    union_id = #{unionId}
+                </when>
+                <otherwise>
+                    1 = 0
+                </otherwise>
+            </choose>
+        </where>
+        LIMIT 1
+    </select>
 
     <insert id="insertFsUser" parameterType="FsUser" useGeneratedKeys="true" keyProperty="userId">
         insert into fs_user

+ 2 - 52
fs-user-app/src/main/java/com/fs/app/controller/WxUserController.java

@@ -123,59 +123,9 @@ public class WxUserController extends AppBaseController{
 
     @ApiOperation("小程序登录")
     @PostMapping("/loginByMiniApp")
-    @Synchronized
     public R loginByMiniApp( @RequestBody LoginMpWxParam param) {
-        if (StringUtils.isBlank(param.getCode())) {
-            return R.error("code不存在");
-        }
-        final WxMaService wxService = WxMaConfiguration.getMaService(maProperties.getConfigs().get(0).getAppid());
-        try {
-            WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(param.getCode());
-            // 解密
-            FsUser user=userService.selectFsUserByMaOpenId(session.getOpenid());
-            String ip = IpUtil.getRequestIp();
-            if(user==null){
-                user=userService.selectFsUserByUnionId(session.getUnionid());
-                if(user!=null){
-                    FsUser userMap=new FsUser();
-                    userMap.setUserId(user.getUserId());
-                    userMap.setUpdateTime(new DateTime());
-                    user.setMaOpenId(session.getOpenid());
-                    userMap.setLastIp(ip);
-                    userService.updateFsUser(userMap);
-                }
-                else{
-                    //写入
-                    user=new FsUser();
-                    user.setUsername("");
-                    user.setPhone("");
-                    user.setNickname("微信用户");
-                    user.setStatus(1);
-                    user.setMaOpenId(session.getOpenid());
-                    user.setLastIp(ip);
-                    user.setIsWeixinAuth(0);
-                    user.setCreateTime(new Date());
-                    if(StringUtils.isNotEmpty(session.getUnionid())){
-                        user.setUnionId(session.getUnionid());
-                    }
-                    userService.insertFsUser(user);
-                }
-            }
-            else{
-                FsUser userMap=new FsUser();
-                userMap.setUserId(user.getUserId());
-                userMap.setUpdateTime(new DateTime());
-                userMap.setLastIp(ip);
-                if(StringUtils.isNotEmpty(session.getUnionid())){
-                    userMap.setUnionId(session.getUnionid());
-                }
-                userService.updateFsUser(userMap);
-            }
-            String token = jwtUtils.generateToken(user.getUserId());
-            return R.ok("登录成功").put("token",token).put("user", user);
-        } catch (WxErrorException e) {
-            return R.error("授权失败,"+e.getMessage());
-        }
+        logger.info("小程序登录 {}",param);
+        return userService.loginByMiniApp(param);
     }
     @ApiOperation("公众号登录")
     @PostMapping("/loginByMp")

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini