Prechádzať zdrojové kódy

优化开方存储条件优化、退款编码还原、优化雪花ID全局唯一

yjwang 1 mesiac pred
rodič
commit
762d6ee299

+ 1 - 1
fs-qw-task/src/main/java/com/fs/FsQwTaskApplication.java

@@ -13,7 +13,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
 @EnableTransactionManagement
 @EnableAsync
-@EnableScheduling
+//@EnableScheduling
 public class FsQwTaskApplication
 {
     public static void main(String[] args){

+ 13 - 4
fs-qw-task/src/main/java/com/fs/app/controller/CommonController.java

@@ -47,11 +47,9 @@ import com.fs.system.service.ISysConfigService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -420,4 +418,15 @@ public class CommonController {
         return  userWxService.generateUserWXInfo();
     }
 
+
+    @GetMapping("/wxQueryApiInfo/{appId}")
+    public R wxQueryApiInfo(@PathVariable String appId){
+        return userWxService.wxQueryApiInfo(appId);
+    }
+
+    @GetMapping("/wxQueryApiInfo")
+    public R getWxQueryLinkInfo(@Param("appId") String appId,@Param("link") String link){
+        return userWxService.getWxQueryLinkInfo(appId,link);
+    }
+
 }

+ 25 - 0
fs-service/src/main/java/com/fs/factory/SnowflakeFactory.java

@@ -0,0 +1,25 @@
+package com.fs.factory;
+
+import com.fs.utils.TwelveDigitSnowflake;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SnowflakeFactory {
+    @Value("${snowflake.machine-id:0}")
+    private long machineId;
+
+    private static TwelveDigitSnowflake snowflake;
+
+    // 初始化单例
+    public TwelveDigitSnowflake getSnowflake() {
+        if (snowflake == null) {
+            synchronized (SnowflakeFactory.class) {
+                if (snowflake == null) {
+                    snowflake = new TwelveDigitSnowflake(machineId);
+                }
+            }
+        }
+        return snowflake;
+    }
+}

+ 4 - 0
fs-service/src/main/java/com/fs/his/service/IFsUserWxService.java

@@ -15,4 +15,8 @@ public interface IFsUserWxService extends IService<FsUserWx> {
     FsUserWx selectByAppIdAndUserId(String appId, Long userId,Integer type);
 
     R generateUserWXInfo();
+
+    R wxQueryApiInfo(String appId);
+
+    R getWxQueryLinkInfo(String appId,String link);
 }

+ 71 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsUserWxServiceImpl.java

@@ -1,18 +1,26 @@
 package com.fs.his.service.impl;
 
+import cn.binarywang.wx.miniapp.api.WxMaService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.core.domain.R;
+import com.fs.core.config.WxMaConfiguration;
 import com.fs.his.domain.FsUserWx;
 import com.fs.his.dto.FsUserWxGenerateDTO;
 import com.fs.his.mapper.FsUserWxMapper;
 import com.fs.his.service.IFsUserWxService;
 import com.fs.qw.mapper.QwExternalContactMapper;
-import lombok.Data;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.HttpEntity;
+import org.apache.http.util.EntityUtils;
 
 import java.util.ArrayList;
 import java.util.Date;
@@ -76,4 +84,66 @@ public class FsUserWxServiceImpl extends ServiceImpl<FsUserWxMapper, FsUserWx> i
         }
         return R.ok("操作成功!处理-》"+ ((generateInfos.isEmpty() || generateInfos == null)?"0":generateInfos.size()) +"条数据");
     }
+
+    @Override
+    public R wxQueryApiInfo(String appId) {
+       try {
+           //获取微信token
+           final WxMaService wxService = WxMaConfiguration.getMaService(appId);
+           String token = wxService.getAccessToken();
+           log.info("小程序TOKEN值-------->刷新前TOKEN:{}", token);
+           CloseableHttpClient client = HttpClients.createDefault();
+           HttpPost httpPost2 = new HttpPost("https://api.weixin.qq.com/cgi-bin/openapi/quota/get?access_token=" + token);
+           JSONObject bodyObj2 = new JSONObject();
+           bodyObj2.put("cgi_path", "/wxa/generate_urllink");
+
+           log.info("微信小程序请求参数打印:{}", bodyObj2.toJSONString());
+           StringEntity entity2 = new StringEntity(bodyObj2.toJSONString(),"UTF-8");
+           httpPost2.setEntity(entity2);
+           httpPost2.setHeader("Content-type", "application/json");
+           httpPost2.setHeader("cache-control","max-age=0");
+           HttpEntity response2 = client.execute(httpPost2).getEntity();
+           String responseString2 = EntityUtils.toString(response2);
+           log.info("微信小程序接口响应数据:{}", responseString2);
+           JSONObject jsonObject2 = JSONObject.parseObject(responseString2);
+           return R.ok().put("data",jsonObject2);
+       }catch (Exception e) {
+        e.printStackTrace();
+       }
+        return null;
+    }
+
+    @Override
+    public R getWxQueryLinkInfo(String appId, String link) {
+        try {
+            //获取微信token
+            final WxMaService wxService = WxMaConfiguration.getMaService(appId);
+            String token = wxService.getAccessToken();
+            log.info("小程序TOKEN值-------->刷新前TOKEN:{}", token);
+            CloseableHttpClient client = HttpClients.createDefault();
+            HttpPost httpPost2 = new HttpPost("https://api.weixin.qq.com/wxa/query_urllink?access_token=" + token);
+            JSONObject bodyObj2 = new JSONObject();
+            bodyObj2.put("url_link", link);
+            bodyObj2.put("query_type", 1);
+
+            log.info("微信小程序请求参数打印:{}", bodyObj2.toJSONString());
+            StringEntity entity2 = new StringEntity(bodyObj2.toJSONString(),"UTF-8");
+            httpPost2.setEntity(entity2);
+            httpPost2.setHeader("Content-type", "application/json");
+            httpPost2.setHeader("cache-control","max-age=0");
+            HttpEntity response2 = client.execute(httpPost2).getEntity();
+            String responseString2 = EntityUtils.toString(response2);
+            log.info("微信小程序接口响应数据:{}", responseString2);
+            JSONObject jsonObject2 = JSONObject.parseObject(responseString2);
+            if("40001".equals(jsonObject2.getString("errcode"))){
+                wxService.getAccessToken(true);
+                return getWxQueryLinkInfo(appId, link);
+            }
+
+            return R.ok().put("data",jsonObject2);
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
 }

+ 2 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreAfterSalesScrmServiceImpl.java

@@ -59,7 +59,6 @@ import com.fs.tzBankPay.TzBankService.TzBankService;
 import com.fs.tzBankPay.doman.RefundParam;
 import com.fs.tzBankPay.doman.RefundResult;
 import com.fs.tzBankPay.doman.TzBankResult;
-import com.fs.utils.TwelveDigitSnowflake;
 import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
 import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
@@ -852,7 +851,8 @@ public class FsStoreAfterSalesScrmServiceImpl implements IFsStoreAfterSalesScrmS
                         request.setHuifuId(huifuId);
                         request.setOrdAmt(df.format(refundAmount));
                         request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
-                        request.setReqSeqId("refund-"+new TwelveDigitSnowflake(1).nextId());
+                        request.setReqSeqId("refund-"+payment.getPayCode());
+//                        request.setReqSeqId("refund-"+new TwelveDigitSnowflake(1).nextId());//回退初始单号
                         Map<String, Object> extendInfoMap = new HashMap<>();
                         extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
                         request.setExtendInfo(extendInfoMap);

+ 2 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -116,7 +116,6 @@ import com.fs.system.domain.SysConfig;
 import com.fs.system.service.ISysConfigService;
 import com.fs.wx.miniapp.config.WxMaProperties;
 import com.fs.ybPay.domain.OrderResult;
-import com.fs.utils.TwelveDigitSnowflake;
 import com.fs.ybPay.domain.RefundResult;
 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
 import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
@@ -2455,7 +2454,8 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
                         request.setHuifuId(huifuId);
                         request.setOrdAmt(payment.getPayMoney().toString());
                         request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
-                        request.setReqSeqId("refund-" + new TwelveDigitSnowflake(1).nextId());
+                        request.setReqSeqId("refund-"+payment.getPayCode());
+//                        request.setReqSeqId("refund-" + new TwelveDigitSnowflake(1).nextId());//回退初始状态
                         Map<String, Object> extendInfoMap = new HashMap<>();
                         extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
                         request.setExtendInfo(extendInfoMap);

+ 11 - 1
fs-service/src/main/java/com/fs/hospital580/vo/CacheOpenInformationVo.java

@@ -22,7 +22,7 @@ public class CacheOpenInformationVo implements Serializable {
     private List<DiseaseQueryRes> diseaseQueryResList;
 
     //答题
-    private List<HealthQuizVo> healthQuizVoList;
+    private List<HealthQuizVo> beforeAiDataList;
 
     //用户ID
     private Long userId;
@@ -32,4 +32,14 @@ public class CacheOpenInformationVo implements Serializable {
 
     //订单KEY
     private String dataKey;
+
+    private Integer isLactation;
+
+    private Integer isPregnantWoman;
+
+    private String patientId;
+
+    private Integer relationship;
+
+    private Integer souceFrom;
 }

+ 3 - 0
fs-service/src/main/resources/application-config-druid-yjb.yml

@@ -118,3 +118,6 @@ hospital580:
   secretKey: F5oXOThiYOLkZK4zBsp8R4ecs7c25umw
   storeId: 188804
   callbackUrl: https://storeuserapp.bjyjbao.com/hospital580/sync/medicine
+#雪花ID编码
+snowflake:
+  machine-id: 0

+ 10 - 10
fs-user-app/src/main/java/com/fs/app/controller/Hospital580Controller.java

@@ -1,12 +1,13 @@
 package com.fs.app.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.fs.app.annotation.Login;
 import com.fs.app.facade.Hospital580FacadeService;
 import com.fs.common.core.domain.PageResponse;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.Result;
-import com.fs.common.core.page.PageRequest;
 import com.fs.common.utils.StringUtils;
+import com.fs.factory.SnowflakeFactory;
 import com.fs.hospital580.vo.CacheOpenInformationVo;
 import com.fs.hospital580.vo.req.DiseaseReq;
 import com.fs.hospital580.vo.req.PrescriptionListReq;
@@ -32,6 +33,9 @@ import java.util.concurrent.TimeUnit;
 public class Hospital580Controller extends AppBaseController {
     private static final String CACHE_KEY_PREFIX = "cacheSquareInformation";
 
+    @Autowired
+    private SnowflakeFactory snowflakeFactory;
+
     @Autowired
     private Hospital580FacadeService hospital580FacadeService;
 
@@ -70,15 +74,11 @@ public class Hospital580Controller extends AppBaseController {
     @Login
     @PostMapping("/cacheSquareInformation")
     public R cacheOpenInformation(@RequestBody CacheOpenInformationVo vo){
-        if(StringUtils.isNull(vo.getDataKey())){
-            return R.error("操作失败,关键信息不能为空!");
-        }
-        int randomNum = (int)(Math.random() * 10);//随机
-        TwelveDigitSnowflake snowflake = new TwelveDigitSnowflake(randomNum);
+        TwelveDigitSnowflake snowflake = snowflakeFactory.getSnowflake();
         String key = String.valueOf(snowflake.nextId());
         //缓存开放信息-6小时
-        String redisKey = buildCacheKey(key,"square",vo.getCompanyUserId());
-        redisCache.setCacheObject(redisKey , vo , 6, TimeUnit.HOURS);
+        String redisKey = buildCacheKey(key,"square",vo.getUserId());
+        redisCache.setCacheObject(redisKey , JSON.toJSONString(vo), 6, TimeUnit.HOURS);
         return R.ok().put("dataKey",key);
     }
 
@@ -87,9 +87,9 @@ public class Hospital580Controller extends AppBaseController {
     @PostMapping("/selectSquareInformation")
     public R selectOpenInformation(@RequestBody CacheOpenInformationVo vo) {
         log.debug("获取缓存开放信息: orderKey={}, companyUserId={}",
-                vo.getDataKey(), vo.getCompanyUserId());
+                vo.getDataKey(), vo.getUserId());
 
-        String redisKey = buildCacheKey(vo.getDataKey(),"square", vo.getCompanyUserId());
+        String redisKey = buildCacheKey(vo.getDataKey(),"square", vo.getUserId());
         CacheOpenInformationVo informationVo = redisCache.getCacheObject(redisKey);
         if (informationVo == null) {
             log.warn("缓存未找到: key={}", redisKey);

+ 5 - 5
fs-user-app/src/main/java/com/fs/app/controller/UserAddressController.java

@@ -8,7 +8,7 @@ import com.fs.app.param.FsUserAddressAddEditParam;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.StringUtils;
-import com.fs.his.domain.FsCity;
+import com.fs.factory.SnowflakeFactory;
 import com.fs.his.domain.FsUserAddress;
 import com.fs.his.enums.FsUserIntegralLogTypeEnum;
 import com.fs.his.param.FsUserAddIntegralTemplateParam;
@@ -17,7 +17,6 @@ import com.fs.his.service.IFsExpressService;
 import com.fs.his.service.IFsUserAddressService;
 import com.fs.his.service.IFsUserIntegralLogsService;
 import com.fs.utils.TwelveDigitSnowflake;
-import com.google.common.collect.Lists;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -30,7 +29,6 @@ import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import static com.fs.his.utils.PhoneUtil.decryptPhone;
-import static com.fs.his.utils.PhoneUtil.encryptPhone;
 
 
 @Api("地址接口")
@@ -50,6 +48,9 @@ public class UserAddressController extends  AppBaseController {
     @Autowired
     private IFsUserIntegralLogsService fsUserIntegralLogsService;
 
+    @Autowired
+    private SnowflakeFactory snowflakeFactory;
+
 
 
 
@@ -171,8 +172,7 @@ public class UserAddressController extends  AppBaseController {
         if(userAddress == null){
            return R.error("操作失败,用户地址不存在!");
         }
-        int randomNum = (int)(Math.random() * 10);//随机
-        TwelveDigitSnowflake snowflake = new TwelveDigitSnowflake(randomNum);
+        TwelveDigitSnowflake snowflake = snowflakeFactory.getSnowflake();
         String key = String.valueOf(snowflake.nextId());
         //缓存地址信息-6小时
         String redisKey = buildCacheKey(key ,"address", address.getCompanyUserId());