Commit ef275933 by 张新旗

代码永远在路上

parent 059709dc
...@@ -39,11 +39,23 @@ public class WeixinController { ...@@ -39,11 +39,23 @@ public class WeixinController {
String iv = param.getString("iv"); String iv = param.getString("iv");
String source = param.getString("source"); String source = param.getString("source");
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
String token = weixinService.login(code,encryptedData,iv,source); Map<String,String> map = weixinService.login(code,encryptedData,iv,source);
ajax.put(Constants.TOKEN, map.get("token"));
ajax.put("phoneNumber", map.get("phoneNumber"));
return ajax;
}
@PostMapping("/refreshToken")
public AjaxResult getRefreshToken(@RequestBody String body){
JSONObject param = JSONObject.parseObject(body);
String phoneNumber = param.getString("phoneNumber");
String token = weixinService.refresh(phoneNumber);
AjaxResult ajax = AjaxResult.success();
ajax.put(Constants.TOKEN, token); ajax.put(Constants.TOKEN, token);
return ajax; return ajax;
} }
/** /**
* 支付通知 * 支付通知
* 微信支付通过支付通知接口将用户支付成功消息通知给商户 * 微信支付通过支付通知接口将用户支付成功消息通知给商户
......
...@@ -127,6 +127,7 @@ public class WeixinServiceImpl { ...@@ -127,6 +127,7 @@ public class WeixinServiceImpl {
String url = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code"; String url = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code";
String replaceUrl = url.replace("{0}", appid).replace("{1}", secret).replace("{2}", code); String replaceUrl = url.replace("{0}", appid).replace("{1}", secret).replace("{2}", code);
String res = restTemplate.getForObject(replaceUrl,String.class); String res = restTemplate.getForObject(replaceUrl,String.class);
log.info("微信返回的信息为:【{}】",res);
return res; return res;
} }
@PostConstruct @PostConstruct
...@@ -147,11 +148,12 @@ public class WeixinServiceImpl { ...@@ -147,11 +148,12 @@ public class WeixinServiceImpl {
} }
public String login(String code, String encryptedData, String iv, String source) { public Map<String,String> login(String code, String encryptedData, String iv, String source) {
try{ try{
String sessionKeyOrOpenId = getSessionKeyOrOpenId(code); String sessionKeyOrOpenId = getSessionKeyOrOpenId(code);
JSONObject openInfo = JSONObject.parseObject(sessionKeyOrOpenId); JSONObject openInfo = JSONObject.parseObject(sessionKeyOrOpenId);
String cutomerId = openInfo.getString("openid"); String cutomerId = openInfo.getString("openid");
// Thread.sleep(1000);
String encData = this.wxDecrypt(encryptedData, sessionKeyOrOpenId, iv); String encData = this.wxDecrypt(encryptedData, sessionKeyOrOpenId, iv);
log.info("当前用户的信息为:【{}】",encData); log.info("当前用户的信息为:【{}】",encData);
Customer customer = customerMapper.selectCustomerById(cutomerId); Customer customer = customerMapper.selectCustomerById(cutomerId);
...@@ -160,9 +162,8 @@ public class WeixinServiceImpl { ...@@ -160,9 +162,8 @@ public class WeixinServiceImpl {
customer = new Customer(); customer = new Customer();
customer.setId(cutomerId); customer.setId(cutomerId);
customer.setHeadSculpturePath(encDataInf.getString("avatarUrl")); customer.setHeadSculpturePath(encDataInf.getString("avatarUrl"));
customer.setUserName(encDataInf.getString("nickName"));
customer.setPhone(encDataInf.getString("phoneNumber"));
customer.setUserName("小呼噜"+customer.getPhone().substring(customer.getPhone().length()-4)); customer.setUserName("小呼噜"+customer.getPhone().substring(customer.getPhone().length()-4));
customer.setPhone(encDataInf.getString("phoneNumber"));
customer.setCreateTime(new Date()); customer.setCreateTime(new Date());
if(StringUtils.isNotEmpty(source)){ if(StringUtils.isNotEmpty(source)){
customer.setSoucre(source); customer.setSoucre(source);
...@@ -170,23 +171,22 @@ public class WeixinServiceImpl { ...@@ -170,23 +171,22 @@ public class WeixinServiceImpl {
customerMapper.insertCustomer(customer); customerMapper.insertCustomer(customer);
} }
return tokenService.createToken(transLoginUser(customer,encData)); String token = tokenService.createToken(transLoginUser(customer));
Map map = new HashMap();
map.put("token",token);
map.put("phoneNumber",encDataInf.getString("phoneNumber"));
return map;
}catch (Exception e){ }catch (Exception e){
log.error("微信登录发生异常",e); log.error("微信登录发生异常",e);
throw new ServiceException("微信登录异常,请重新登录"); throw new ServiceException("微信登录异常,请重新登录");
} }
} }
private LoginUser transLoginUser(Customer customer,String encData){ private LoginUser transLoginUser(Customer customer){
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setUserName(customer.getUserName()); user.setUserName(customer.getUserName());
LoginUser loginUser = new LoginUser(user,null); LoginUser loginUser = new LoginUser(user,null);
loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setOpenId(customer.getId()); loginUser.setOpenId(customer.getId());
loginUser.setExt(encData);
return loginUser; return loginUser;
} }
...@@ -456,9 +456,6 @@ public class WeixinServiceImpl { ...@@ -456,9 +456,6 @@ public class WeixinServiceImpl {
orderOperationLogService.insertOrderOperationLog("已付款",order.getId(),"付款成功",order.getUserName(),"付款"); orderOperationLogService.insertOrderOperationLog("已付款",order.getId(),"付款成功",order.getUserName(),"付款");
machineApiService.updateOrder(order); machineApiService.updateOrder(order);
//极光推送 //极光推送
jiGuangPushService.pushOrderState(order); jiGuangPushService.pushOrderState(order);
} }
} finally { } finally {
...@@ -663,4 +660,30 @@ public class WeixinServiceImpl { ...@@ -663,4 +660,30 @@ public class WeixinServiceImpl {
{ {
return d * Math.PI / 180.0; return d * Math.PI / 180.0;
} }
public String refresh(String phoneNumber) {
Customer customer = new Customer();
customer.setPhone(phoneNumber);
List<Customer> customers = customerMapper.selectCustomerList(customer);
if(customers!=null &&!customers.isEmpty()){
Customer customer1 = customers.get(0);
return tokenService.createToken(transLoginUser(customer));
}
throw new ServiceException("该用户没有注册,请先注册");
}
public String getPhone(String code, String iv, String encryptedData) {
try{
String sessionKeyOrOpenId = getSessionKeyOrOpenId(code);
String infoString = this.wxDecrypt(encryptedData, sessionKeyOrOpenId, iv);
JSONObject info = JSONObject.parseObject(infoString);
return info.getString("phoneNumber");
}catch (Exception e){
log.error("获取手机号异常",e);
throw new ServiceException("获取手机号异常");
}
}
} }
...@@ -124,6 +124,7 @@ public class JiGuangPushServiceImpl implements JiGuangPushService { ...@@ -124,6 +124,7 @@ public class JiGuangPushServiceImpl implements JiGuangPushService {
data.put("orderId",order.getId()); data.put("orderId",order.getId());
data.put("orderNo",order.getOrderNo()); data.put("orderNo",order.getOrderNo());
data.put("state",order.getState()); data.put("state",order.getState());
jsonObject.put("data",data);
PushBean pushBean = new PushBean(); PushBean pushBean = new PushBean();
pushBean.setMessageCount(jsonObject); pushBean.setMessageCount(jsonObject);
pushAndroid(pushBean,machine.getRegister()); pushAndroid(pushBean,machine.getRegister());
......
...@@ -9,6 +9,7 @@ import cn.jpush.api.push.model.Platform; ...@@ -9,6 +9,7 @@ import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload; import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience; import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification; import cn.jpush.api.push.model.notification.Notification;
import com.alibaba.fastjson.JSONObject;
import com.soss.system.domain.vo.PushBean; import com.soss.system.domain.vo.PushBean;
import com.soss.system.jiguang.MyJiGuangPushService; import com.soss.system.jiguang.MyJiGuangPushService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -87,6 +88,7 @@ public class MyJiGuangPushServiceImpl implements MyJiGuangPushService { ...@@ -87,6 +88,7 @@ public class MyJiGuangPushServiceImpl implements MyJiGuangPushService {
public boolean pushAndroid(PushBean pushBean, String ... registids){ public boolean pushAndroid(PushBean pushBean, String ... registids){
Message build = new Message.Builder().setMsgContent(pushBean.getMessageCount().toJSONString()).build(); Message build = new Message.Builder().setMsgContent(pushBean.getMessageCount().toJSONString()).build();
log.info("极光推送的内容为:【{}】::[{}]",registids[0], JSONObject.toJSONString(build));
return sendPush(PushPayload.newBuilder() return sendPush(PushPayload.newBuilder()
.setPlatform(Platform.android()) .setPlatform(Platform.android())
.setAudience(Audience.registrationId(registids)) .setAudience(Audience.registrationId(registids))
......
...@@ -14,26 +14,23 @@ import java.util.stream.Collectors; ...@@ -14,26 +14,23 @@ import java.util.stream.Collectors;
public class AppServiceImpl { public class AppServiceImpl {
@Autowired @Autowired
private ShopMapper shopMapper; private ShopMapper shopMapper;
public List<Shop> getShop(String lng,String lat) { public Shop getShop(String lng,String lat) {
if(StringUtils.isEmpty(lng)||StringUtils.isEmpty(lat)){
Shop shop = new Shop(); Shop shop = new Shop();
shop.setState("1"); shop.setState("1");
shop.setIsDefault(0L);
shop.setIsDefault(1L); shop.setIsDefault(1L);
List<Shop> shops = shopMapper.selectShopList(shop); List<Shop> shops = shopMapper.selectShopList(shop);
return shops; if(shops !=null &&!shops.isEmpty()){
} Shop shop1 = shops.get(0);
Shop shop = new Shop(); double v = GetDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop1.getLng()), Double.parseDouble(shop1.getLat()));
shop.setState("1"); DecimalFormat df = new DecimalFormat("0.00");
shop.setIsDefault(0L); shop1.setDistance(df.format(v));
List<Shop> shops = shopMapper.selectShopList(shop); return shop1;
for (Shop shop1 : shops) { }else{
double v = GetDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop1.getLng()), Double.parseDouble(shop1.getLat())); return new Shop();
DecimalFormat df = new DecimalFormat("0.00"); }
shop1.setDistance(df.format(v));
} //return shops.stream().sorted((x, y) -> x.getDistance().compareTo(y.getDistance())).collect(Collectors.toList());
return shops.stream().sorted((x, y) -> x.getDistance().compareTo(y.getDistance())).collect(Collectors.toList());
} }
......
...@@ -14,6 +14,7 @@ import com.soss.common.utils.StringUtils; ...@@ -14,6 +14,7 @@ import com.soss.common.utils.StringUtils;
import com.soss.system.domain.*; import com.soss.system.domain.*;
import com.soss.system.service.IGoodsService; import com.soss.system.service.IGoodsService;
import com.soss.system.mapper.*; import com.soss.system.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T; import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
* @date 2022-04-28 * @date 2022-04-28
*/ */
@Service @Service
@Slf4j
public class GoodsServiceImpl implements IGoodsService public class GoodsServiceImpl implements IGoodsService
{ {
@Autowired @Autowired
...@@ -44,8 +46,6 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -44,8 +46,6 @@ public class GoodsServiceImpl implements IGoodsService
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Autowired @Autowired
private GoodsCategoryMapper goodsCategoryMapper; private GoodsCategoryMapper goodsCategoryMapper;
ThreadLocal<BigDecimal> discountThread = new ThreadLocal();
ThreadLocal<BigDecimal> priceThread = new ThreadLocal();
/** /**
...@@ -154,18 +154,12 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -154,18 +154,12 @@ public class GoodsServiceImpl implements IGoodsService
} }
private void createSku(List<RuleNode> ruleNodeList, long goodsId, BigDecimal discount,BigDecimal price) { private void createSku(List<RuleNode> ruleNodeList, long goodsId, BigDecimal discount,BigDecimal price) {
for (RuleNode<SpecRule> ruleNode : ruleNodeList) { for (RuleNode<SpecRule> ruleNode : ruleNodeList) {
List<SpecRule> specRuleList = new ArrayList<>(); List<SpecRule> specRuleList = new ArrayList<>();
RuleNode<SpecRule> parentRuleNode = ruleNode.getParentRuleNode(); RuleNode<SpecRule> parentRuleNode = ruleNode.getParentRuleNode();
specRuleList.add(ruleNode.getRuleNode()); specRuleList.add(ruleNode.getRuleNode());
priceThread.set(price);
discountThread.set(discount);
priceThread.set(priceThread.get().add(ruleNode.getRuleNode().getAmount()));
discountThread.set(discountThread.get().add(ruleNode.getRuleNode().getAmount()));
System.err.println(priceThread.get());
System.err.println(discountThread.get());
if(parentRuleNode!=null){ if(parentRuleNode!=null){
findPartentRuleNode(parentRuleNode,specRuleList); findPartentRuleNode(parentRuleNode,specRuleList);
} }
...@@ -175,8 +169,16 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -175,8 +169,16 @@ public class GoodsServiceImpl implements IGoodsService
goodsSku.setCreatedAt(new Date()); goodsSku.setCreatedAt(new Date());
goodsSku.setIsDeleted("0"); goodsSku.setIsDeleted("0");
goodsSku.setUpdatedAt(new Date()); goodsSku.setUpdatedAt(new Date());
goodsSku.setPrice(priceThread.get()); BigDecimal price1 = new BigDecimal(price.toPlainString());
goodsSku.setDiscount(discountThread.get()); BigDecimal discount1 = new BigDecimal(discount.toPlainString());
log.info("商品价格为:{},{}",price.toPlainString(),discount.toPlainString());
for (SpecRule specRule : specRuleList) {
price1 = price1.add(specRule.getAmount());
discount1 = discount1.add(specRule.getAmount());
}
log.info("产品价格为:{},{}",price.toPlainString(),discount.toPlainString());
goodsSku.setPrice(price1);
goodsSku.setDiscount(discount1);
goodsSku.setRuleList(JSONArray.toJSONString(specRuleList)); goodsSku.setRuleList(JSONArray.toJSONString(specRuleList));
goodsSkuMapper.insertGoodsSku(goodsSku); goodsSkuMapper.insertGoodsSku(goodsSku);
} }
...@@ -184,8 +186,6 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -184,8 +186,6 @@ public class GoodsServiceImpl implements IGoodsService
private void findPartentRuleNode(RuleNode<SpecRule> ruleRuleNode, List<SpecRule> specRuleList) { private void findPartentRuleNode(RuleNode<SpecRule> ruleRuleNode, List<SpecRule> specRuleList) {
specRuleList.add(ruleRuleNode.getRuleNode()); specRuleList.add(ruleRuleNode.getRuleNode());
priceThread.set(priceThread.get().add(ruleRuleNode.getRuleNode().getAmount()));
discountThread.set(discountThread.get().add(ruleRuleNode.getRuleNode().getAmount()));
RuleNode<SpecRule> parentRuleNode = ruleRuleNode.getParentRuleNode(); RuleNode<SpecRule> parentRuleNode = ruleRuleNode.getParentRuleNode();
if(parentRuleNode!=null){ if(parentRuleNode!=null){
findPartentRuleNode(parentRuleNode,specRuleList); findPartentRuleNode(parentRuleNode,specRuleList);
......
...@@ -81,11 +81,13 @@ public class MachineApiServiceImpl { ...@@ -81,11 +81,13 @@ public class MachineApiServiceImpl {
if(order1==null){ if(order1==null){
throw new ServiceException("该订单不存在"); throw new ServiceException("该订单不存在");
} }
Order order = new Order(); Order order = new Order();
order.setId(orderID); order.setId(orderID);
order.setState(status); order.setState(status);
order.setUpdatedAt(new Date()); order.setUpdatedAt(new Date());
if("6".equals(status)){
order.setFinishTime(new Date());
}
int i = orderMapper.updateOrder(order); int i = orderMapper.updateOrder(order);
jiGuangPushService.pushOrderState(order); jiGuangPushService.pushOrderState(order);
return i+""; return i+"";
...@@ -169,13 +171,13 @@ public class MachineApiServiceImpl { ...@@ -169,13 +171,13 @@ public class MachineApiServiceImpl {
public ResultVo sendRequest(String param,String interfaceName){ public ResultVo sendRequest(String param,String interfaceName){
try{ try{
String postUrl = url+interfaceName; String postUrl = url+interfaceName;
log.info("请求创建订单接口:【{}】",param); log.info("请求订单接口[{}]:【{}】",postUrl,param);
HttpHeaders requestHeaders = new HttpHeaders(); HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity requestEntity = new HttpEntity(param,requestHeaders); HttpEntity requestEntity = new HttpEntity(param,requestHeaders);
JSONObject.toJSONString(param); JSONObject.toJSONString(param);
ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(postUrl, requestEntity, String.class); ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(postUrl, requestEntity, String.class);
log.info("请求创建订单接口返回结果为:【{}】",stringResponseEntity.getBody()); log.info("请求接口返回结果为[{}]:【{}】",postUrl,stringResponseEntity.getBody());
ResultVo resultVo = JSONObject.parseObject(stringResponseEntity.getBody(), ResultVo.class); ResultVo resultVo = JSONObject.parseObject(stringResponseEntity.getBody(), ResultVo.class);
return resultVo; return resultVo;
}catch (Exception e){ }catch (Exception e){
......
...@@ -58,7 +58,7 @@ public class ShopRecommendServiceImpl implements IShopRecommendService ...@@ -58,7 +58,7 @@ public class ShopRecommendServiceImpl implements IShopRecommendService
List<Goods> goodsList = shopRecommendMapper.selectShopRecommendGoods(shopRecommend.getShopId(),shopRecommend.getType()); List<Goods> goodsList = shopRecommendMapper.selectShopRecommendGoods(shopRecommend.getShopId(),shopRecommend.getType());
goodsList = goodsList.stream().distinct().collect(Collectors.toList()); goodsList = goodsList.stream().distinct().collect(Collectors.toList());
for (Goods goods : goodsList) { for (Goods goods : goodsList) {
goods.setCategoryName(goodsCategoryMapper.selectGoodsCategoryById(String.valueOf(goods.getId())).getName()); goods.setCategoryName(goodsCategoryMapper.selectGoodsCategoryById(String.valueOf(goods.getCategory())).getName());
goods.setSalesVolume(orderMapper.selectSalesVolume(Long.parseLong(shopRecommend.getShopId()),goods.getId())); goods.setSalesVolume(orderMapper.selectSalesVolume(Long.parseLong(shopRecommend.getShopId()),goods.getId()));
} }
return goodsList; return goodsList;
......
package com.soss.system.service.impl; package com.soss.system.service.impl;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -227,7 +228,17 @@ public class ShopServiceImpl implements IShopService ...@@ -227,7 +228,17 @@ public class ShopServiceImpl implements IShopService
public String turn(Long shopId, Long goodsId, String pointer) { public String turn(Long shopId, Long goodsId, String pointer) {
ShopGoods shopGoods = new ShopGoods(); ShopGoods shopGoods = new ShopGoods();
shopGoods.setShopId(shopId); shopGoods.setShopId(shopId);
Goods goods = goodsMapper.selectGoodsById(String.valueOf(goodsId));
List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods); List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods);
shopGoodsList = shopGoodsList.stream().filter(e->{
String category = goodsMapper.selectGoodsById(String.valueOf(goodsId)).getCategory();
if(category.equals(goods.getCategory())){
return true;
}else{
return false;
}
}).collect(Collectors.toList());
int size = shopGoodsList.size(); int size = shopGoodsList.size();
Long lastGoodsId = null; Long lastGoodsId = null;
for(int i =0;i<size;i++){ for(int i =0;i<size;i++){
......
...@@ -13,10 +13,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -13,10 +13,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="bindTime" column="bind_time" /> <result property="bindTime" column="bind_time" />
<result property="createdAt" column="created_at" /> <result property="createdAt" column="created_at" />
<result property="updatedAt" column="updated_at" /> <result property="updatedAt" column="updated_at" />
<result property="register" column="register"></result>
</resultMap> </resultMap>
<sql id="selectMachineVo"> <sql id="selectMachineVo">
select id, shop_id, code, type, state, bind_time, created_at, updated_at from machine select id, shop_id, code, type, state, bind_time, created_at, updated_at,register from machine
</sql> </sql>
<select id="selectMachineList" parameterType="Machine" resultMap="MachineResult"> <select id="selectMachineList" parameterType="Machine" resultMap="MachineResult">
......
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