Commit 13bc26af authored by shiyu's avatar shiyu

bug修复2

parent d2376720
package com.wwdz.ch.core.entity;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.List;
@Data
public class LogisticsInfo implements Entity {
private String logisticCode;
private String logisticName;
private String waybill;
private String state;
private String stateName;
private List<TrailInfo> trailInfoList;
}
package com.wwdz.ch.core.entity;
import com.xxdxxs.entity.Entity;
import lombok.Data;
@Data
public class LogisticsRequestDto implements Entity {
private String logisticsCode;
private String waybill;
}
package com.wwdz.ch.core.entity;
import com.xxdxxs.entity.Entity;
import lombok.Data;
@Data
public class TrailInfo implements Entity {
private String createTime;
private String desc;
}
......@@ -24,6 +24,11 @@ dts:
#分销拍卖业务,众号消息点击后跳转到小程序页面的链接
auction-msg-url: pages/saleAuctionDetail/index
#快递鸟
kuaidiniao-id: 1622726
apikey: be9b8745-a47e-4d4d-afba-e55aab4bca74
# 商户证书文件路径
# 请参考“商户证书”一节 https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=4_3
key-path: xxxxx
......
......@@ -9,6 +9,11 @@ dts:
get-access-token-url: https://api.weixin.qq.com/cgi-bin/stable_token
#快递鸟
kuaidiniao-id: 1622726
apikey: be9b8745-a47e-4d4d-afba-e55aab4bca74
#公众号消息点击后跳转到小程序页面的链接
msg-url: pages/consignNodeDetail/index
#分销业务,公众号消息点击后跳转到小程序页面的链接
......
......@@ -52,5 +52,7 @@ public interface SupplierItemDao {
*/
List<SupplierItem> findForHomePage(SupplierItemRequestDto supplierItemRequestDto);
long countByCreatorId(long creatorId);
}
......@@ -101,4 +101,16 @@ public class SupplierItemDaoImpl implements SupplierItemDao {
PageHelper.startPage(dto.getPage(), dto.getLimit());
return supplierItemMapper.selectByExampleWithBLOBs(supplierItemExample);
}
@Override
public long countByCreatorId(long creatorId) {
SupplierItemExample supplierItemExample = new SupplierItemExample();
SupplierItemExample.Criteria criteria = supplierItemExample.createCriteria();
criteria.andCreatorIdEqualTo(creatorId);
criteria.andTypeEqualTo(3);
criteria.andIsDeletedEqualTo(false);
criteria.andIsOnSaleEqualTo(true);
return supplierItemMapper.countByExample(supplierItemExample);
}
}
package com.wwdz.ch.wx.api;
import com.wwdz.ch.core.consts.LogisticsEnum;
import com.wwdz.ch.core.entity.LogisticsInfo;
import com.wwdz.ch.core.entity.LogisticsRequestDto;
import com.wwdz.ch.core.entity.TrailInfo;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.Base64;
import com.wwdz.ch.core.util.OkHttpUtil;
import com.xxdxxs.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class LogisticsApi {
private static final Logger logger = LoggerFactory.getLogger(LogisticsApi.class);
@Value("${dts.wx.kuaidiniao-id}")
private String KUAIDINIAO_ID;
@Value("${dts.wx.apikey}")
private String APIKEY;
private final static String GET_TRAIL_URL = "https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
/**
* 查询物流轨迹
*/
public Result findTrails(LogisticsRequestDto dto){
try {
String RequestData = "{" +
"'ShipperCode': '"
+ dto.getLogisticsCode()
+ "',"
+
"'LogisticCode': '"
+ dto.getWaybill() + "',"
+
"}";
// 组装系统级参数
Map<String, String> params = new HashMap<String, String>();
params.put("RequestData", urlEncoder(RequestData, "UTF-8"));
params.put("EBusinessID", KUAIDINIAO_ID);
params.put("RequestType", "8001");
String dataSign = encrypt(RequestData, APIKEY, "UTF-8");
params.put("DataSign", urlEncoder(dataSign, "UTF-8"));
params.put("DataType", "2");
String result = sendPost(GET_TRAIL_URL, params);
logger.info("findTrails response :{}", result);
String isSuccess = JsonUtils.getValueByPath(result, "Success");
if ("true".equals(isSuccess)) {
LogisticsInfo logisticsInfo = new LogisticsInfo();
String trails = JsonUtils.getValueByPath(result, "Traces");
List<TrailInfo> trailInfoList = new ArrayList<>();
List<Map<String, Object>> list = JsonUtils.toMapList(trails);
list.forEach(map -> {
TrailInfo trailInfo = new TrailInfo();
trailInfo.setCreateTime((String) map.get("AcceptTime"));
trailInfo.setDesc((String) map.get("AcceptStation"));
trailInfoList.add(trailInfo);
});
String state = JsonUtils.getValueByPath(result, "State");
logisticsInfo.setLogisticCode(dto.getLogisticsCode());
logisticsInfo.setLogisticName(LogisticsEnum.getNameByCode(dto.getLogisticsCode()));
logisticsInfo.setWaybill(dto.getWaybill());
logisticsInfo.setTrailInfoList(trailInfoList);
logisticsInfo.setState(state);
return Result.success(logisticsInfo);
}
return Result.failed();
} catch (Exception e) {
logger.error("查询物流轨迹error :{}", e);
}
return Result.failed();
}
/**
* MD5加密
* str 内容
* charset 编码方式
* @throws Exception
*/
@SuppressWarnings("unused")
private String MD5(String str, String charset) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes(charset));
byte[] result = md.digest();
StringBuffer sb = new StringBuffer(32);
for (int i = 0; i < result.length; i++) {
int val = result[i] & 0xff;
if (val <= 0xf) {
sb.append("0");
}
sb.append(Integer.toHexString(val));
}
return sb.toString().toLowerCase();
}
/**
* base64编码
* str 内容
* charset 编码方式
* @throws UnsupportedEncodingException
*/
private String base64(String str, String charset) throws UnsupportedEncodingException {
String encoded = Base64.encode(str.getBytes(charset));
return encoded;
}
private String urlEncoder(String str, String charset) throws UnsupportedEncodingException {
String result = URLEncoder.encode(str, charset);
return result;
}
/**
* Sign签名生成
* content 内容
* keyValue ApiKey
* charset 编码方式
* @throws UnsupportedEncodingException ,Exception
* @return DataSign签名
*/
private String encrypt(String content, String keyValue , String charset) throws UnsupportedEncodingException, Exception
{
if (keyValue != null)
{
return base64(MD5(content + keyValue, charset), charset);
}
return base64(MD5(content, charset), charset);
}
/**
* 向指定 URL 发送POST方法的请求
* url 发送请求的 URL
* params 请求的参数集合
* @return 远程资源的响应结果
*/
private String sendPost(String url, Map<String, String> params) {
OutputStreamWriter out = null;
BufferedReader in = null;
StringBuilder result = new StringBuilder();
try {
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// POST方法
conn.setRequestMethod("POST");
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.connect();
// 获取URLConnection对象对应的输出流
out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
// 发送请求参数
if (params != null) {
StringBuilder param = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
if (param.length() > 0) {
param.append("&");
}
param.append(entry.getKey());
param.append("=");
param.append(entry.getValue());
System.out.println(entry.getKey() + ":" + entry.getValue());
}
System.out.println("param:" + param.toString());
out.write(param.toString());
}
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
if ( in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result.toString();
}
}
......@@ -8,6 +8,7 @@ import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.db.bean.DistributionOrderNum;
import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.domain.distribution.AuctionConfig;
import com.wwdz.ch.db.domain.distribution.AuctionRecord;
import com.wwdz.ch.db.domain.distribution.CollectionShareRecord;
......@@ -60,6 +61,9 @@ public class SelfPageServiceImpl implements SelfPageService {
@Autowired
CollectionShareRecordDao collectionShareRecordDao;
@Autowired
SupplierItemDao supplierItemDao;
@Override
......@@ -158,8 +162,11 @@ public class SelfPageServiceImpl implements SelfPageService {
} else {
map.put("isMine", true);
}
String avatar = cacheUtil.getAppletUserById(itemUserId).getAvatar();
map.put("avatar", StringUtils.isEmpty(avatar) ? CommConsts.DEFAULT_AVATAR_URL : avatar);
User user = cacheUtil.getAppletUserById(itemUserId);
map.put("avatar", StringUtils.isEmpty(user.getAvatar()) ? CommConsts.DEFAULT_AVATAR_URL : user.getAvatar());
map.put("name", StringUtils.isEmpty(user.getNickname()) ? "微信用户" : user.getNickname());
long count = supplierItemDao.countByCreatorId(itemUserId);
map.put("count", count);
return Result.success(map);
} catch (Exception e) {
logger.error("判断主客态 error : {}", e);
......
......@@ -188,6 +188,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
SupplierItem supplierItem = supplierItemDao.findById(itemId);
SupplierItemVo supplierItemVo = new SupplierItemVo();
if (StringUtils.hasLength(shareRecordId)) {
if (distributorShareRecord.getDistributorId() != dto.getUserId()) {
//做浏览记录
boolean flag = userRecentBrowseDao.isExisted(dto.getUserId(), distributorShareRecord.getDistributorId());
if (!flag) {
......@@ -202,6 +203,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
userRecentBrowseDao.insert(newRecord);
}
}
}
//用户点击链接进入详情页需要记录
if (!dto.getIsShop()) {
......@@ -405,6 +407,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
itemId = dto.getId();
}
if (StringUtils.hasLength(shareRecordId)) {
if (distributorShareRecord.getDistributorId() != dto.getUserId()) {
//做浏览记录
boolean flag = userRecentBrowseDao.isExisted(dto.getUserId(), distributorShareRecord.getDistributorId());
if (!flag) {
......@@ -419,6 +422,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
userRecentBrowseDao.insert(newRecord);
}
}
}
//查询商品竞拍信息
AuctionConfig auctionConfig = auctionConfigDao.findByItemId(itemId);
......@@ -653,6 +657,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
}
//如果是客态,需要记录浏览记录
if (StringUtils.hasLength(dto.getShareRecordId())) {
if (collectionShareRecord.getItemUserId().longValue() != dto.getUserId()) {
boolean isExisted = userRecentBrowseDao.isExistedBySharedUserId(userId, collectionShareRecord.getItemUserId());
if (!isExisted) {
UserRecentBrowse userRecentBrowse = new UserRecentBrowse();
......@@ -666,6 +671,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
userRecentBrowseDao.insert(userRecentBrowse);
}
}
}
} else {
supplierItemVo.setIsMine(true);
//查询收藏该商品的最新的五个用户
......@@ -767,10 +773,10 @@ public class SupplierItemServiceImpl implements SupplierItemService {
List<Long> distributorShareItemIds = distributorShareRecordList.stream().filter(StringUtil.distinctByKey(DistributorShareRecord::getItemId)).map(DistributorShareRecord::getItemId).collect(Collectors.toList());
//浏览记录是用户上传的
List<Long> uploadUserIdList = userRecentBrowseList.stream().filter(a -> a.getType() == DistributionEnum.UserBrowseTypeEnum.USER_ITEM.getCode()).map(UserRecentBrowse::getSharedUserId).collect(Collectors.toList());
/* List<Long> uploadUserIdList = userRecentBrowseList.stream().filter(a -> a.getType() == DistributionEnum.UserBrowseTypeEnum.USER_ITEM.getCode()).map(UserRecentBrowse::getSharedUserId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(uploadUserIdList)) {
uploadUserIdList.add(sellerId);
}
}*/
searchDto.setIds(distributorShareItemIds);
Map<Long, DistributorShareRecord> map = distributorShareRecordList.stream().collect(Collectors.toMap(DistributorShareRecord::getItemId, Function.identity(), (k1, k2) -> k1));
searchDto.setIsOnSale(true);
......@@ -780,7 +786,6 @@ public class SupplierItemServiceImpl implements SupplierItemService {
} else {
searchDto.setTypeList(Arrays.asList(DistributionEnum.DistributionTypeEnum.AUCTION.getCode()));
}
searchDto.setCreatorIdList(uploadUserIdList);
searchDto.setStock(0);//库存大于0
searchDto.setPage(dto.getPage());
searchDto.setLimit(dto.getLimit());
......
package com.wwdz.ch.wx.api;
import com.wwdz.ch.core.entity.LogisticsRequestDto;
import com.wwdz.ch.core.type.Result;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class LogisticsApiTest {
private static final Logger logger = LoggerFactory.getLogger(LogisticsApiTest.class);
@Autowired
LogisticsApi logisticsApi;
@Test
public void findTrails() {
LogisticsRequestDto dto = new LogisticsRequestDto();
dto.setLogisticsCode("YTO");
dto.setWaybill("YT1160805180957");
Result result = logisticsApi.findTrails(dto);
logger.info("物流轨迹: {}" + result);
}
}
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