AppUserInfoController.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. package com.platform.yijia.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.google.gson.Gson;
  4. import com.platform.yijia.param.request.AppUserInfoRequest;
  5. import com.platform.yijia.pojo.AppUserInfo;
  6. import com.platform.yijia.pojo.CustomerElectronicCard;
  7. import com.platform.yijia.pojo.CustomerPoints;
  8. import com.platform.yijia.pojo.StationPayManage;
  9. import com.platform.yijia.service.*;
  10. import com.platform.yijia.utils.CodeMsg;
  11. import com.platform.yijia.utils.ResultData;
  12. import com.platform.yijia.utils.redis.RedisCacheUtil;
  13. import com.platform.yijia.utils.weixinapp.AesDecryptUtil;
  14. import com.platform.yijia.utils.weixinapp.WeiXinUserUtil;
  15. import org.apache.commons.codec.digest.DigestUtils;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Controller;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import org.springframework.web.bind.annotation.*;
  23. import javax.annotation.Resource;
  24. import java.math.BigDecimal;
  25. import java.security.MessageDigest;
  26. import java.security.NoSuchAlgorithmException;
  27. import java.util.Date;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.concurrent.TimeUnit;
  32. @Controller
  33. @RequestMapping("/demo")
  34. public class AppUserInfoController {
  35. private static Logger logger =(Logger) LoggerFactory.getLogger(AppUserInfoController.class);
  36. @Autowired
  37. private PayOrderService payOrderService;
  38. @Autowired
  39. private AppUserInfoService appUserInfoService;
  40. @Resource
  41. private StationService stationService;
  42. @Resource
  43. private CustomerPointsService customerPointsService;
  44. @Resource
  45. private RedisCacheUtil redisCacheUtil;
  46. @Resource
  47. private ElectronicMembershipCardService electronicMembershipCardService;
  48. // String appId = "wxe1135cd390b38a54"; //微信小程序appID
  49. // String appSecret = "0532c7d9ae876c4ad636df0b1e3b9ddb"; //微信小程序密钥
  50. /*
  51. * 微信小程序根据code获取用户openId和sessionKey
  52. * @param code
  53. * @param stationId
  54. * @return
  55. */
  56. @ResponseBody
  57. @RequestMapping(value = "/getSessionKeyAndOpenID")
  58. public Map<String, Object> getSessionKeyAndOpenID(@RequestParam("code") String code, @RequestParam("stationId") Integer stationId){
  59. logger.info("微信小程序获取用户openId和sessionKey入参code和stationId: "+code +"-----" +stationId);
  60. String appId = ""; //微信小程序appID
  61. String appSecret = ""; //微信小程序密钥
  62. if(stationId !=null){
  63. Map<String, String> map = stationService.getStationAppIdAndAppSecret(stationId);
  64. appId = map.get("appId"); //微信小程序appID
  65. appSecret = map.get("appSecret"); //微信小程序密钥
  66. logger.info("油站信息:"+map.toString());
  67. }
  68. //获取session_key 和 openid
  69. return WeiXinUserUtil.getUserSessionKeyAndOpenID(appId, appSecret, code);
  70. }
  71. /*
  72. * 解密 encryptedData
  73. * @param sessionKey
  74. * @param encryptedData
  75. * @param iv
  76. * @return
  77. */
  78. @ResponseBody
  79. @RequestMapping(value = "/decryptEncryptedData", method = RequestMethod.POST, consumes = "application/json")
  80. public String decryptEncryptedData(@RequestBody JSONObject jsonObject){
  81. logger.info("解密获取手机号前台传入参数:" +jsonObject.toString());
  82. return AesDecryptUtil.decryptEncryptedData(jsonObject.get("encryptedData").toString(), jsonObject.get("sessionKey").toString(), jsonObject.get("iv").toString(), "UTF-8").toString();
  83. }
  84. /*
  85. * JS-SDK使用权限签名算法
  86. * @param noncestr 随机字符串
  87. * @param timestamp 时间戳
  88. * @param url 页面访问路径
  89. * @param stationId 油站ID
  90. * @return
  91. */
  92. @RequestMapping(value = "/getSignature", method = RequestMethod.GET)
  93. @ResponseBody
  94. public String getSignature(@RequestParam String noncestr, String timestamp, String url, Integer stationId){
  95. Gson gson =new Gson();
  96. //返回结果集
  97. ResultData resultData = null;
  98. logger.info("JS-SDK使用权限签名算法前台传来参数: "+"油站ID:"+stationId+"; noncestr: " +noncestr+"; timestamp: " +timestamp + "; url: "+url);
  99. Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
  100. String gzhAppId ="";
  101. String gzhAppSecret ="";
  102. String accessToken ="";
  103. if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
  104. gzhAppId = m.get("gzhAppId");
  105. gzhAppSecret = m.get("gzhAppSecret");
  106. accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
  107. //当前用户登录的公众号redis缓存中的jsapi_ticket
  108. String appIdTicket =gzhAppId + "-ticket";
  109. String jsapiTicket ="";
  110. if(redisCacheUtil.hasKey(appIdTicket)){
  111. jsapiTicket = redisCacheUtil.getCacheObject(appIdTicket);
  112. }else {
  113. //获取jsapi_ticket
  114. net.sf.json.JSONObject gzhJsapiTicket = WeiXinUserUtil.getGzhJsapiTicket(accessToken);
  115. if(gzhJsapiTicket.containsKey("ticket")){
  116. redisCacheUtil.setCacheObject(appIdTicket, gzhJsapiTicket.get("ticket"));
  117. redisCacheUtil.expire(appIdTicket, 7200, TimeUnit.SECONDS);
  118. jsapiTicket = gzhJsapiTicket.get("ticket").toString();
  119. }
  120. }
  121. String string1 = "jsapi_ticket="+jsapiTicket + "&noncestr=" +noncestr +"&timestamp=" +timestamp +"&url=" +url;
  122. logger.info("签名参数拼接:"+ string1);
  123. //sha1加密
  124. String signature = DigestUtils.sha1Hex(string1);
  125. logger.info("JS-SDK签名参数sha1加密后:"+ signature);
  126. resultData = ResultData.success(signature);
  127. }
  128. return gson.toJson(resultData);
  129. }
  130. /*
  131. * 判断使用小程序支付的用户是否关注公众号
  132. * @param unionId
  133. * @param stationId
  134. * @return
  135. */
  136. @RequestMapping(value = "/whetherFollowGzh", method = RequestMethod.GET)
  137. @ResponseBody
  138. public String whetherFollowGzh(@RequestParam String unionId, Integer stationId){
  139. Gson gson =new Gson();
  140. //返回结果集
  141. ResultData resultData = null;
  142. if (unionId !=null){
  143. Map<String, String> param = new HashMap<>();
  144. param.put("unionId", unionId);
  145. param.put("userType", "1");
  146. param.put("stationId", stationId.toString());
  147. String openId = appUserInfoService.whetherFollowGzh(param);
  148. if(openId !=null){
  149. Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
  150. String gzhAppId ="";
  151. String gzhAppSecret ="";
  152. String accessToken ="";
  153. if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
  154. gzhAppId = m.get("gzhAppId");
  155. gzhAppSecret = m.get("gzhAppSecret");
  156. accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
  157. net.sf.json.JSONObject unionIdInfo = WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
  158. logger.info("用户公众号信息:" + unionIdInfo);
  159. if(unionIdInfo.containsKey("subscribe") && unionIdInfo.get("subscribe").equals(1)){
  160. resultData = ResultData.success(CodeMsg.SUCCESS);
  161. }else {
  162. resultData = ResultData.error(CodeMsg.NO_FollowGzh);
  163. }
  164. }else {
  165. resultData = ResultData.error(CodeMsg.SEARCH_APPID_FAIL);
  166. }
  167. }else {
  168. resultData = ResultData.error(CodeMsg.USERGZHINFO_EXSIST);
  169. }
  170. }
  171. return gson.toJson(resultData);
  172. }
  173. /*
  174. * 获取公众号授权后的信息
  175. * @param code
  176. * @param stationId
  177. * @return
  178. */
  179. @RequestMapping(value = "/getGzhAuthorizeInfo", method = RequestMethod.GET)
  180. @ResponseBody
  181. public String getGzhAuthorizeInfo(@RequestParam String code, Integer stationId){
  182. logger.info("获取公众号授权后的信息前端传递参数:code:"+ code );
  183. logger.info("获取公众号授权后的信息前端传递参数:stationId:" +stationId);
  184. Gson gson =new Gson();
  185. //返回结果集
  186. ResultData resultData = null;
  187. if(code != null && stationId !=null){
  188. String gzhAppId ="";
  189. String gzhAppSecret ="";
  190. Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
  191. if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
  192. gzhAppId = m.get("gzhAppId");
  193. gzhAppSecret = m.get("gzhAppSecret");
  194. net.sf.json.JSONObject gzhAuthorizeInfo = WeiXinUserUtil.getGzhAuthorizeInfo(gzhAppId, gzhAppSecret, code);
  195. logger.info("授权获取到信息:" + gzhAuthorizeInfo.toString());
  196. resultData = ResultData.success(gzhAuthorizeInfo);
  197. }else {
  198. resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
  199. }
  200. }else {
  201. resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
  202. }
  203. return gson.toJson(resultData);
  204. }
  205. /*
  206. * 测试用来
  207. * 获取公众号授权后的信息测试
  208. * @param code
  209. * @param stationId
  210. * @return
  211. */
  212. @RequestMapping(value = "/getGzhAuthorizeInfoNew", method = RequestMethod.GET)
  213. @ResponseBody
  214. public String getGzhAuthorizeInfoNew(@RequestParam String code, Integer stationId){
  215. logger.info("获取公众号授权后的信息前端传递参数:code:"+ code );
  216. logger.info("获取公众号授权后的信息前端传递参数:stationId:" +stationId);
  217. Gson gson =new Gson();
  218. //返回结果集
  219. ResultData resultData = null;
  220. if(code != null && stationId !=null){
  221. String gzhAppId ="";
  222. String gzhAppSecret ="";
  223. Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
  224. if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
  225. gzhAppId = m.get("gzhAppId");
  226. gzhAppSecret = m.get("gzhAppSecret");
  227. net.sf.json.JSONObject gzhAuthorizeInfo = WeiXinUserUtil.getGzhAuthorizeInfo(gzhAppId, gzhAppSecret, code);
  228. logger.info("授权获取到信息:" + gzhAuthorizeInfo.toString());
  229. if(gzhAuthorizeInfo.containsKey("openid")){
  230. String openId = gzhAuthorizeInfo.get("openid").toString();
  231. String accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
  232. net.sf.json.JSONObject unionIdInfo = null;
  233. unionIdInfo= WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
  234. if(unionIdInfo.containsKey("errcode")){
  235. //删除原来key
  236. redisCacheUtil.deleteObject(gzhAppId);
  237. String token = WeiXinUserUtil.getToken(gzhAppId, gzhAppSecret).getAccessToken();
  238. redisCacheUtil.setCacheObject(gzhAppId, token);
  239. redisCacheUtil.expire(gzhAppId, 7200, TimeUnit.SECONDS);
  240. unionIdInfo= WeiXinUserUtil.getUnionIdInfo(token, openId);
  241. }
  242. AppUserInfo appUserInfo = new AppUserInfo();
  243. if(unionIdInfo.containsKey("openid")){
  244. appUserInfo.setBlogOpenid(unionIdInfo.get("openid").toString());
  245. }
  246. if(unionIdInfo.containsKey("nickname")){
  247. appUserInfo.setBlogNickName(unionIdInfo.get("nickname").toString());
  248. }
  249. if(unionIdInfo.containsKey("sex")){
  250. appUserInfo.setSexFlag(unionIdInfo.get("sex").toString());
  251. }
  252. if(unionIdInfo.containsKey("headimgurl")){
  253. appUserInfo.setBlogProfilePhoto(unionIdInfo.get("headimgurl").toString());
  254. }
  255. if(unionIdInfo.containsKey("unionid")){
  256. appUserInfo.setUnionId(unionIdInfo.get("unionid").toString());
  257. }
  258. appUserInfo.setUserType("1");
  259. Map<String, Object> params = new HashMap<>();
  260. params.put("openId", openId); //注册用户openId
  261. params.put("userType", appUserInfo.getUserType()); //用户类型
  262. //判断该用户是否已存在
  263. int count = appUserInfoService.isExistAppUser(params);
  264. if(count > 0){
  265. appUserInfoService.updateAppUserInfo(appUserInfo);
  266. }else {
  267. appUserInfoService.AddAppUserInfo(appUserInfo);
  268. }
  269. resultData = ResultData.success(unionIdInfo);
  270. }
  271. }else {
  272. resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
  273. }
  274. }else {
  275. resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
  276. }
  277. return gson.toJson(resultData);
  278. }
  279. /*
  280. * 获取公众号信息
  281. * @param openId
  282. * @param stationId
  283. * @return
  284. */
  285. @RequestMapping(value = "/getGzhUserInfo", method = RequestMethod.GET)
  286. @ResponseBody
  287. public String getGzhUserInfo(@RequestParam String openId, Integer stationId){
  288. Gson gson =new Gson();
  289. //返回结果集
  290. ResultData resultData = null;
  291. if(openId !=null && stationId !=null){
  292. String gzhAppId ="";
  293. String gzhAppSecret ="";
  294. String accessToken ="";
  295. Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
  296. if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
  297. gzhAppId = m.get("gzhAppId");
  298. gzhAppSecret = m.get("gzhAppSecret");
  299. accessToken = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
  300. net.sf.json.JSONObject unionIdInfo = null;
  301. unionIdInfo= WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
  302. if(unionIdInfo.containsKey("errcode")){
  303. //删除原来key
  304. redisCacheUtil.deleteObject(gzhAppId);
  305. String token = WeiXinUserUtil.getToken(gzhAppId, gzhAppSecret).getAccessToken();
  306. redisCacheUtil.setCacheObject(gzhAppId, token);
  307. redisCacheUtil.expire(gzhAppId, 7200, TimeUnit.SECONDS);
  308. unionIdInfo= WeiXinUserUtil.getUnionIdInfo(token, openId);
  309. }
  310. resultData=ResultData.success(unionIdInfo);
  311. }
  312. }else {
  313. resultData=ResultData.error(CodeMsg.REQUEST_FAIL);
  314. }
  315. return gson.toJson(resultData);
  316. }
  317. /*
  318. * 从Redis缓存中获取 tokenCache
  319. * @param appId
  320. * @param appSecret
  321. * @return
  322. */
  323. public String getTokenByRedisCache(String appId, String appSecret){
  324. logger.info("appId参数: "+ appId+" ;appSecret参数: " +appSecret);
  325. if(!redisCacheUtil.hasKey(appId) || redisCacheUtil.getCacheObject(appId) ==null || redisCacheUtil.getCacheObject(appId).equals("")){
  326. String token = WeiXinUserUtil.getToken(appId, appSecret).getAccessToken();
  327. redisCacheUtil.setCacheObject(appId, token);
  328. redisCacheUtil.expire(appId, 7200, TimeUnit.SECONDS);
  329. logger.info("Redis缓存中token信息: " + token);
  330. return token;
  331. }else {
  332. return redisCacheUtil.getCacheObject(appId);
  333. }
  334. }
  335. /*
  336. * 添加用户信息
  337. * @param request
  338. * @return
  339. */
  340. @RequestMapping(value = "/addAppUserInfo", method = RequestMethod.POST)
  341. @ResponseBody
  342. @Transactional
  343. public String addAppUserInfo(@RequestBody AppUserInfoRequest request){
  344. Gson gson =new Gson();
  345. ResultData resultData=null;
  346. try{
  347. logger.info("前端传入参数:" +request.toString());
  348. AppUserInfo appUserInfo =new AppUserInfo();
  349. CustomerPoints customerPoints = new CustomerPoints();
  350. CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard(); //客户电子卡
  351. String openId = ""; //此参数用于查询该用户是否已注册过
  352. if(request.getUserType()!=null){
  353. //1-微信公众号
  354. if(request.getUserType().equals("1") &&StringUtils.isNotBlank(request.getOpenId())){
  355. appUserInfo.setUserType(request.getUserType());
  356. appUserInfo.setBlogToken(request.getBlogToken());
  357. openId = request.getOpenId();
  358. appUserInfo.setBlogOpenid(openId);
  359. customerPoints.setBlogOpenId(openId);
  360. customerElectronicCard.setBlogOpenid(openId);
  361. //2-微信小程序
  362. }else if(request.getUserType().equals("2") &&StringUtils.isNotBlank(request.getOpenId())){
  363. appUserInfo.setUserType(request.getUserType());
  364. appUserInfo.setMinaToken(request.getMinaToken());
  365. openId = request.getOpenId();
  366. appUserInfo.setMinaOpenid(openId);
  367. customerPoints.setMinaOpenId(openId);
  368. customerElectronicCard.setMinaOpenid(openId);
  369. }
  370. }
  371. if(StringUtils.isNotBlank(request.getBlogNickName())){
  372. appUserInfo.setBlogNickName(request.getBlogNickName());
  373. customerPoints.setCustomerName(request.getBlogNickName());
  374. customerElectronicCard.setCustomerName(request.getBlogNickName());
  375. }
  376. if(StringUtils.isNotBlank(request.getMobilePhone())){
  377. appUserInfo.setMobilePhone(request.getMobilePhone());
  378. customerPoints.setMobilePhone(request.getMobilePhone());
  379. customerElectronicCard.setMobilePhone(request.getMobilePhone());
  380. }
  381. if(StringUtils.isNotBlank(request.getBlogProfilePhoto())){
  382. appUserInfo.setBlogProfilePhoto(request.getBlogProfilePhoto());
  383. }
  384. if(StringUtils.isNotBlank(request.getUnionId())){
  385. appUserInfo.setUnionId(request.getUnionId());
  386. customerPoints.setUnionId(request.getUnionId());
  387. customerElectronicCard.setUnionId(request.getUnionId());
  388. }
  389. appUserInfo.setStationId(request.getStationId());
  390. appUserInfo.setRegisteDate(new Date());
  391. appUserInfo.setUpdateDate(new Date());
  392. customerPoints.setCreateTime(new Date());
  393. customerPoints.setUnionId(request.getUnionId());
  394. customerPoints.setPoints(0);
  395. customerPoints.setConsumptionPoints(0);
  396. customerPoints.setAccumulatePoints(0);
  397. customerPoints.setInvalidPoints(0);
  398. customerPoints.setStationId(request.getStationId());
  399. customerPoints.setStationName(request.getStationName());
  400. customerElectronicCard.setCreateTime(new Date());
  401. customerElectronicCard.setStationId(request.getStationId());
  402. customerElectronicCard.setStationName(request.getStationName());
  403. if(StringUtils.isNotBlank(request.getSexFlag())){
  404. appUserInfo.setSexFlag(request.getSexFlag());
  405. }
  406. logger.info("插入数据库用户信息参数:"+appUserInfo.toString());
  407. Map<String, Object> params = new HashMap<>();
  408. params.put("openId", openId); //注册用户openId
  409. params.put("userType", request.getUserType()); //用户类型
  410. //判断该用户是否已存在
  411. int count = appUserInfoService.isExistAppUser(params);
  412. if(count > 0){
  413. appUserInfoService.updateAppUserInfo(appUserInfo);
  414. }else {
  415. appUserInfoService.AddAppUserInfo(appUserInfo);
  416. }
  417. StationPayManage stationPayManage = new StationPayManage();
  418. stationPayManage.setStationId(request.getStationId());
  419. StationPayManage stationPayManageInfo = stationService.selectStationPayManage(stationPayManage); //换取油站配置信息
  420. //是否开起积分功能
  421. if(stationPayManageInfo !=null && stationPayManageInfo.getIntegralFlag().equals("1")){
  422. this.insertCustomerPointsInfo(customerPoints, request);
  423. }
  424. //是否开起电子卡功能
  425. if(stationPayManageInfo !=null && stationPayManageInfo.getCardEnabledFlag().equals("1")){
  426. this.insertCustomerElectronicCard(customerElectronicCard, request);
  427. }
  428. resultData = ResultData.success(CodeMsg.SUCCESS);
  429. }catch (Exception e){
  430. resultData = ResultData.error(CodeMsg.INSERT_FAIL);
  431. e.printStackTrace();
  432. }
  433. return gson.toJson(resultData);
  434. }
  435. //客户积分表信息操作
  436. public void insertCustomerPointsInfo(CustomerPoints customerPoints, AppUserInfoRequest request){
  437. boolean boo = customerPointsService.isExistCustomerPointsInfo(customerPoints);
  438. if(!boo){
  439. customerPointsService.insertCustomerPointsInfo(customerPoints);
  440. }else {
  441. //此处用于:如果客户积分信息存在可能会出现小程序ID或者公众号ID没有的情况
  442. CustomerPoints c = new CustomerPoints();
  443. c.setUnionId(customerPoints.getUnionId());
  444. if(request.getUserType().equals("1")){
  445. c.setBlogOpenId(customerPoints.getBlogOpenId());
  446. }else if(request.getUserType().equals("2")){
  447. c.setMinaOpenId(customerPoints.getMinaOpenId());
  448. }
  449. c.setStationId(request.getStationId());
  450. c.setStationName(request.getStationName());
  451. c.setMobilePhone(request.getMobilePhone());
  452. c.setStationId(request.getStationId());
  453. c.setCustomerName(request.getBlogNickName());
  454. c.setStationName(request.getStationName());
  455. customerPointsService.updateCustomerPointsInfo(c);
  456. }
  457. }
  458. //客户电子会员卡表操作
  459. public void insertCustomerElectronicCard(CustomerElectronicCard customerElectronicCard, AppUserInfoRequest request){
  460. List<CustomerElectronicCard> electronicCardList = electronicMembershipCardService.getElectronicCardList(customerElectronicCard);
  461. if(electronicCardList !=null && electronicCardList.size() ==2){
  462. electronicMembershipCardService.updateElectronicCardInfoByUnionId(customerElectronicCard);
  463. }else {
  464. //当前时间戳
  465. String currentTime = String.valueOf(System.currentTimeMillis());
  466. String customerNo = request.getStationId() + currentTime;
  467. customerElectronicCard.setStationName(request.getStationName());
  468. customerElectronicCard.setCustomerNo(customerNo);
  469. customerElectronicCard.setAmt(new BigDecimal(0));
  470. customerElectronicCard.setCardOilsType("1");
  471. electronicMembershipCardService.insetElectronicCard(customerElectronicCard);
  472. customerElectronicCard.setCardOilsType("2");
  473. String currentTime1 = String.valueOf(System.currentTimeMillis());
  474. String customerNo1 = request.getStationId() + currentTime1;
  475. customerElectronicCard.setCustomerNo(customerNo1);
  476. electronicMembershipCardService.insetElectronicCard(customerElectronicCard);
  477. }
  478. }
  479. }