Commit ee131705 by 徐高华

链接

parent 01aacb41
......@@ -6,8 +6,12 @@ import com.gic.haoban.manage.api.enums.KeyDataEnum;
public interface KeyDataApiService {
public ServiceResponse<KeyDataDTO> saveData(String data, KeyDataEnum dataEnum);
public ServiceResponse<String> saveMobileData(Long linkId, String mobile);
public ServiceResponse<KeyDataDTO> saveHmData(String unionid, Long linkId, Long hmId);
public ServiceResponse<String> getDataByKey(String key, KeyDataEnum dataEnum);
public ServiceResponse<String> getMobile(Long linkId, String key);
}
......@@ -36,4 +36,14 @@ public interface HmLinkApiService {
public ServiceResponse<Page<HmLinkDTO>> listPage(HmLinkSearchQDTO qdto, BasePageInfo basePageInfo);
public ServiceResponse<HmLinkDTO> save(HmLinkDTO dto);
/**
*
* @Title: getLinkHm
* @Description: 小程序获取展示活码
* @author xugh
* @return
* @throws
*/
public ServiceResponse<HmLinkDTO> getLinkHmFromWxa(String enterpriseId, String wxaLinkId);
}
package com.gic.haoban.manage.service.service.impl;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.ToolUtil;
import com.gic.commons.util.UniqueIdUtils;
......@@ -17,13 +20,18 @@ import com.gic.haoban.manage.service.service.KeyDataService;
@Service("keyDataService")
public class KeyDataServiceImpl implements KeyDataService {
public static String[] PADDING = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
"Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z" };
@Autowired
private TabKeyDataMapper tabKeyDataMapper;
@Override
public KeyDataDTO saveData(String data, KeyDataEnum dataEnum) {
KeyDataDTO dto = new KeyDataDTO();
dto.setDataKey(ToolUtil.randomUUID());
dto.setDataKey(generateKey(dataEnum, data));
dto.setCreateTime(new Date());
dto.setId(UniqueIdUtils.uniqueLong());
dto.setData(data);
......@@ -42,4 +50,35 @@ public class KeyDataServiceImpl implements KeyDataService {
return null;
}
public static String generateKey(KeyDataEnum dataEnum, String data) {
if (dataEnum.equals(KeyDataEnum.MOBILE)) {
StringBuilder sb = new StringBuilder();
String uuid = ToolUtil.randomUUID();
int length = 6;
int interval = (int) (uuid.length() / length);
String str;
for (int i = 0; i < length; i++) {
if (i == length - 1) {
str = uuid.substring(length * interval);
} else {
str = uuid.substring(i * interval, i * interval + interval);
}
int x = Integer.parseInt(str, 16);
sb.append(PADDING[x % 62]);
}
sb.append(PADDING[(int) (Math.random() * 62)]);
return JSON.parseObject(data).getString("ljid") + "_" + sb.toString();
}
return UniqueIdUtils.uniqueLongHex();
}
public static void main(String[] args) {
Set<String> set = new HashSet<>();
for (int i = 0; i < 1000000; i++) {
String s = generateKey(KeyDataEnum.MOBILE, "xxx");
set.add(s);
}
System.out.println(set.size());
}
}
......@@ -3,6 +3,8 @@ package com.gic.haoban.manage.service.service.out.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.KeyDataDTO;
import com.gic.haoban.manage.api.enums.KeyDataEnum;
......@@ -17,8 +19,21 @@ public class KeyDataApiServiceImpl implements KeyDataApiService {
private KeyDataService keyDataService;
@Override
public ServiceResponse<KeyDataDTO> saveData(String data, KeyDataEnum dataEnum) {
return ServiceResponse.success(this.keyDataService.saveData(data, dataEnum));
public ServiceResponse<KeyDataDTO> saveHmData(String unionid, Long linkId, Long hmId) {
JSONObject json = new JSONObject();
json.put("unid", unionid);
json.put("ljid", linkId);
json.put("hmid", hmId);
return ServiceResponse.success(this.keyDataService.saveData(json.toString(), KeyDataEnum.DYNAMIC_HM));
}
@Override
public ServiceResponse<String> saveMobileData(Long linkId, String mobile) {
JSONObject json = new JSONObject();
json.put("ph", mobile);
json.put("ljid", linkId);
KeyDataDTO keyData = this.keyDataService.saveData(json.toString(), KeyDataEnum.MOBILE) ;
return ServiceResponse.success(keyData.getDataKey().split("_")[1]);
}
@Override
......@@ -30,4 +45,15 @@ public class KeyDataApiServiceImpl implements KeyDataApiService {
return ServiceResponse.failure(HaoBanErrCode.ERR_OTHER.getCode(), "数据不存在");
}
@Override
public ServiceResponse<String> getMobile(Long linkId, String key) {
key = linkId + "_" + key;
KeyDataDTO data = this.keyDataService.getDataByKey(key, KeyDataEnum.MOBILE);
if (null != data) {
JSONObject json = JSON.parseObject(data.getData());
return ServiceResponse.success(json.getString("ph"));
}
return null;
}
}
......@@ -54,4 +54,11 @@ public class HmLinkApiServiceImpl implements HmLinkApiService {
return ServiceResponse.success(this.hmLinkService.listPage(qdto, basePageInfo));
}
@Override
public ServiceResponse<HmLinkDTO> getLinkHmFromWxa(String enterpriseId, String wxaLinkId) {
// hm_hmlinkid_xxx
wxaLinkId.split("_") ;
return null;
}
}
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.Test;
......@@ -111,10 +110,9 @@ public class HmLinkTest {
@Test
public void test3() {
this.keyDataApiService.saveData("15990160154", KeyDataEnum.MOBILE);
this.keyDataApiService.saveMobileData(10000L, "15999") ;
System.out.println(this.keyDataApiService.getDataByKey("679f17d8c2e940a28dc484689c0339db", KeyDataEnum.MOBILE));
;
}
@Test
......
......@@ -5,6 +5,7 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -42,7 +43,7 @@ public class HmLinkController extends WebBaseController {
private WelcomeApiService welcomeApiService;
@RequestMapping("add")
public HaobanResponse save(HmLinkDTO dto) {
public HaobanResponse save(@RequestBody HmLinkDTO dto) {
WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
dto.setCreatorId(loginUser.getClerkId());
dto.setCreatorName(loginUser.getClerkName());
......@@ -55,7 +56,7 @@ public class HmLinkController extends WebBaseController {
}
@RequestMapping("update")
public HaobanResponse update(HmLinkDTO dto) {
public HaobanResponse update(@RequestBody HmLinkDTO dto) {
WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
dto.setModifierId(loginUser.getClerkId());
dto.setModifierName(loginUser.getClerkName());
......@@ -91,10 +92,10 @@ public class HmLinkController extends WebBaseController {
}
// 查询欢迎语
String welcomeId = link.getWelcomeId();
if(StringUtils.isNotBlank(welcomeId)) {
if (StringUtils.isNotBlank(welcomeId)) {
ServiceResponse<WelcomeDetailDTO> resp = this.welcomeApiService.getWelcome(welcomeId, enterpriseId);
if(resp.isSuccess() && null != resp.getResult()) {
retMap.put("welcome", resp.getResult()) ;
if (resp.isSuccess() && null != resp.getResult()) {
retMap.put("welcome", resp.getResult());
}
}
return this.success(retMap);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment