Commit c8166fe9 by caiyt

新增测试接口,修改短信模板编码

parent 2e51d49a
......@@ -75,14 +75,14 @@ public class AppController extends BaseController {
JSONArray goods = jsonObject.getJSONArray("goods");
List<OrderDetail> orderDetails = new ArrayList<>();
order.setOrderDetails(orderDetails);
for(int i =0;i<goods.size();i++){
for (int i = 0; i < goods.size(); i++) {
OrderDetail orderDetail = new OrderDetail();
orderDetail.setGoodsId(goods.getJSONObject(i).getLong("goodsId"));
orderDetail.setNum(goods.getJSONObject(i).getInteger("num"));
orderDetails.add(orderDetail);
}
String info = orderService.getWaitTime(order);
return AjaxResult.success("操作成功",info);
int waitTime = orderService.getWaitTime(order);
return AjaxResult.success("操作成功", waitTime);
}
@RequestMapping("/getWaitTineByOrderId")
......
......@@ -8,13 +8,12 @@ import com.soss.common.utils.StringUtils;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Customer;
import com.soss.system.domain.Order;
import com.soss.system.domain.Shop;
import com.soss.system.service.ICustomerService;
import com.soss.system.service.impl.AppServiceImpl;
import com.soss.system.service.impl.OrderTakingServiceImpl;
import com.soss.system.utils.SendSmsUtil;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -67,7 +66,7 @@ public class WeixinController {
}
@PostMapping("/refreshToken")
public AjaxResult getRefreshToken(@RequestBody String body){
public AjaxResult getRefreshToken(@RequestBody String body) {
JSONObject param = JSONObject.parseObject(body);
String phoneNumber = param.getString("phoneNumber");
String token = weixinService.refresh(phoneNumber);
......@@ -76,7 +75,12 @@ public class WeixinController {
return ajax;
}
@GetMapping("/token/create/{custId}")
@ApiOperation(value = "根据用户id创建token,测试用", hidden = true)
public AjaxResult createToken4Test(@PathVariable String custId) {
String token = weixinService.createToken4Test(custId);
return AjaxResult.success("", token);
}
/**
* 支付通知
......@@ -92,10 +96,10 @@ public class WeixinController {
* 测试支付通知
* 微信支付通过支付通知接口将用户支付成功消息通知给商户
*/
@PostMapping("/native/notify/test")
public String wxNotifyTest(@RequestBody Order order) throws Exception {
@GetMapping("/native/notify/test/{orderNo}")
public String wxNotifyTest(@PathVariable String orderNo) throws Exception {
System.out.println("微信发送的回调");
return weixinService.wxNotifyTest(order);
return weixinService.wxNotifyTest(orderNo);
}
......@@ -139,15 +143,14 @@ public class WeixinController {
*/
@RequestMapping(method = RequestMethod.POST, value = "/refundNotify")
public String refundNotify(@RequestBody String xmlData) {
log.info("微信退款回调数据为;【{}】",xmlData);
log.info("微信退款回调数据为;【{}】", xmlData);
return weixinService.refundNotify(xmlData);
}
@Autowired
/*@Autowired
private SendSmsUtil sendSmsUtil;
@RequestMapping("/test")
public void test(){
sendSmsUtil.sendSms("15726637040","SMS_243650242",null);
}
}*/
}
......@@ -39,6 +39,7 @@ import com.soss.system.weixin.entity.QueryReturnInfo;
import com.soss.system.weixin.util.RandomStringGenerator;
import com.soss.system.weixin.util.Signature;
import com.thoughtworks.xstream.XStream;
import io.jsonwebtoken.lang.Assert;
import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -435,7 +436,7 @@ public class WeixinServiceImpl {
return returnXml;
}
public String wxNotifyTest(Order orderPo) throws Exception {
public String wxNotifyTest(String orderNo) throws Exception {
// Map<String, String> returnMap = new HashMap<>();//应答对象
//处理通知参数
......@@ -466,7 +467,7 @@ public class WeixinServiceImpl {
//获取商户订单号
// String orderNo = notifyMap.get("out_trade_no");
Order order = new Order();
order.setOrderNo(orderPo.getOrderNo());
order.setOrderNo(orderNo);
List<Order> orders = orderService.selectOrderList(order);
if(orders.isEmpty()){
return "没有该订单";
......@@ -717,25 +718,30 @@ public class WeixinServiceImpl {
zone.put("name",JSONPath.read(areaData,String.format(zoneString,province,shop1.getCity(),shop1.getZone())));
List<Shop> shopList = new ArrayList<>();
shopList.add(shop1);
zone.put("shops",shopList);
zone.put("shops", shopList);
List<JSONObject> zones = new ArrayList<>();
zones.add(zone);
city.put("children",zones);
city.put("children", zones);
}
}
return proviceList;
}
public String createToken4Test(String custId) {
Customer customer = customerMapper.selectCustomerById(custId);
Assert.notNull(customer, "未查询到匹配的用户信息[" + custId + "]");
LoginUser loginUser = transLoginUser(customer);
return tokenService.createToken(loginUser);
}
public String refresh(String phoneNumber) {
Customer customer = new Customer();
customer.setPhone(phoneNumber);
List<Customer> customers = customerMapper.selectCustomerList(customer);
if(customers!=null &&!customers.isEmpty()){
if (customers != null && !customers.isEmpty()) {
Customer customer1 = customers.get(0);
log.info("当前登录的用户为:【{}】",customer1.getUserName());
log.info("当前登录的用户为:【{}】", customer1.getUserName());
return tokenService.createToken(transLoginUser(customer1));
}
......
......@@ -94,4 +94,6 @@ public interface OrderMapper {
* @return 返回用户下单数,下单金额
*/
Map<String, Object> getCustOrderSimpleStat(@Param("custId") String custId);
void updateCustName(@Param("userName") String userName, @Param("userId") String userId);
}
......@@ -26,12 +26,15 @@ public class AppServiceImpl {
public Shop getShop(String lng, String lat, Boolean testFlag) {
Shop shop = new Shop();
boolean unAuthed = StringUtils.isEmpty(lng) || StringUtils.isEmpty(lat);
Comparator<Shop> shopComparator = Comparator.comparing(Shop::getRealDistance);
if (unAuthed) {
shop.setIsDefault(1L);
} else if (BooleanUtils.isTrue(testFlag)) {
shop.setStates(Arrays.asList(ShopState.TESTING.getState(), ShopState.OPEN.getState()));
} else {
shop.setState(ShopState.OPEN.getState());
shop.setStates(Arrays.asList(ShopState.OPEN.getState(), ShopState.CLOSE.getState()));
shopComparator = Comparator.comparing(Shop::getState).thenComparing(Shop::getRealDistance);
}
List<Shop> shops = shopMapper.selectShopList(shop);
......@@ -50,7 +53,7 @@ public class AppServiceImpl {
String distanceDesc = DistanceUtil.getDistanceDesc(realDistance);
sp.setDistance(distanceDesc);
});
shops.sort(Comparator.comparing(Shop::getRealDistance));
shops.sort(shopComparator);
return shops.get(0);
}
}
......@@ -2,6 +2,7 @@ package com.soss.system.service.impl;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.DateUtils;
import com.soss.common.utils.StringUtils;
import com.soss.system.constants.OrderStatusConstant;
import com.soss.system.domain.Customer;
import com.soss.system.domain.Order;
......@@ -14,11 +15,13 @@ import com.soss.system.service.ICustomerService;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 用户信息Service业务层处理
......@@ -102,7 +105,16 @@ public class CustomerServiceImpl implements ICustomerService
* @return 结果
*/
@Override
@Transactional
public int updateCustomer(Customer customer) {
Customer customerExist = this.selectCustById(customer.getId());
if (customerExist == null) {
throw new ServiceException("用户不存在");
}
// 用户修改昵称时,修改订单冗余字段-用户昵称
if (StringUtils.isNotEmpty(customer.getUserName()) && !Objects.equals(customerExist.getUserName(), customer.getUserName())) {
orderMapper.updateCustName(customer.getUserName(), customer.getId());
}
return customerMapper.updateCustomer(customer);
}
......
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.CouponUserState;
import com.soss.common.enums.ShopState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.DateUtils;
import com.soss.common.utils.StringUtils;
......@@ -224,6 +225,9 @@ public class OrderServiceImpl implements IOrderService {
if (startBusiness.getTimeInMillis() > l || endBusiness.getTimeInMillis() < l) {
throw new ServiceException("当前时间本店休息中,暂停点单~");
}
if (!Objects.equals(ShopState.OPEN.getState(), shop.getState())) {
throw new ServiceException("店铺非营业状态不能下单");
}
if (shop.getDistanceLimit() != null && shop.getDistanceLimit() > 0) {
double distance = DistanceUtil.getRealDistance(order.getLng().doubleValue(), order.getLat().doubleValue(), Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()));
if (distance > shop.getDistanceLimit() * 1000) {
......@@ -360,7 +364,7 @@ public class OrderServiceImpl implements IOrderService {
wechatMessageService.insertWechatMessage(order.getUserId(), order.getId(), "制作完成,您的订单已经制作完成,现在可以去取餐啦!");
if (BooleanUtils.isTrue(order.getSendMsgFlag2())) {
sendMessageUtils.sendWxMsg(order);
sendSmsUtil.sendSms(order.getUserPhone(), "SMS_243650242", null);
sendSmsUtil.sendSms(order.getUserPhone(), "SMS_254715682", null);
}
}
......@@ -610,10 +614,9 @@ public class OrderServiceImpl implements IOrderService {
map.put("orderNum", order.getOrderNum());
map.put("state", order.getState());
return map;
}
public String getWaitTime(Order order) {
public int getWaitTime(Order order) {
Long shopId = order.getShopId();
List<String> status = Arrays.asList(OrderStatusConstant.Paid, OrderStatusConstant.production);
List<Order> orders = orderMapper.selectOrderByShopId(status, shopId);
......@@ -638,8 +641,7 @@ public class OrderServiceImpl implements IOrderService {
takeTimeCount += takeTime;
}
return String.valueOf((int) (takeTimeCount / 60));
return (int) (takeTimeCount / 60);
}
public String getWaitTimeByOrderId(Long orderId) {
......
......@@ -12,10 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -155,6 +152,7 @@ public class OrderTakingServiceImpl {
});
List<GoodsCategory> shopCategories = goodsCategoryMapper.selectGoodsCategoryByIds(categoryIds);
if (!CollectionUtils.isEmpty(shopCategories)) {
shopCategories.sort(Comparator.comparing(GoodsCategory::getTurn));
for (GoodsCategory category : shopCategories) {
CategoryVo categoryVo = new CategoryVo();
categoryVo.setId(category.getId());
......@@ -194,7 +192,6 @@ public class OrderTakingServiceImpl {
goodsVoList.add(goodsVo);
}
}
categoryVos.add(categoryVo);
}
}
......
......@@ -13,6 +13,7 @@ import com.soss.system.domain.vo.orderTaking.*;
import com.soss.system.jiguang.impl.JiGuangPushServiceImpl;
import com.soss.system.mapper.*;
import com.soss.system.service.IShopService;
import com.soss.system.utils.ArrayUtil;
import jodd.util.StringPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -309,37 +310,37 @@ public class ShopServiceImpl implements IShopService
@Override
public String turn(Long shopId, Long goodsId, String pointer) {
Goods goods = goodsMapper.selectGoodsById(goodsId);
ShopGoods shopGoods = new ShopGoods();
shopGoods.setShopId(shopId);
Goods goods = goodsMapper.selectGoodsById(goodsId);
List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods);
shopGoodsList = shopGoodsList.stream().filter(e->{
String category = goodsMapper.selectGoodsById(e.getGoodsId()).getCategory();
if(category.equals(goods.getCategory())){
return true;
}else{
shopGoodsList = shopGoodsList.stream().filter(e -> {
Goods shopGood = goodsMapper.selectGoodsById(e.getGoodsId());
if (shopGood == null) {
return false;
}
return ArrayUtil.hasCommonElement(shopGood.getCategory().split(","),
goods.getCategory().split(","));
}).collect(Collectors.toList());
int size = shopGoodsList.size();
Long lastGoodsId = null;
for(int i =0;i<size;i++){
for (int i = 0; i < size; i++) {
ShopGoods shopGood = shopGoodsList.get(i);
if(goodsId.equals(shopGood.getGoodsId())){
if("1".equals(pointer)){
int index = i-1;
if(index<0){
lastGoodsId =shopGood.getGoodsId();
}else{
if (goodsId.equals(shopGood.getGoodsId())) {
if ("1".equals(pointer)) {
int index = i - 1;
if (index < 0) {
lastGoodsId = shopGood.getGoodsId();
} else {
lastGoodsId = shopGoodsList.get(index).getGoodsId();
}
}else if("2".equals(pointer)){
int index=i+1;
if(index>=size){
lastGoodsId =shopGood.getGoodsId();
}else{
} else if ("2".equals(pointer)) {
int index = i + 1;
if (index >= size) {
lastGoodsId = shopGood.getGoodsId();
} else {
lastGoodsId = shopGoodsList.get(index).getGoodsId();
}
}
......
......@@ -79,4 +79,22 @@ public class ArrayUtil {
public static <T> boolean isEmpty(T[] ts) {
return ts == null || ts.length == 0;
}
public static boolean hasCommonElement(String[] arr1, String[] arr2) {
if (arr1 == null || arr2 == null) {
return false;
}
for (String target : arr1) {
if (Objects.equals(target, "")) {
continue;
}
for (String source : arr2) {
if (Objects.equals(target, source)) {
return true;
}
}
}
return false;
}
}
......@@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectGoodsCategoryByIds" resultMap="GoodsCategoryResult">
select id, name, icon from goods_category where id in
select id, name, icon, turn from goods_category where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select>
......
......@@ -327,4 +327,8 @@
<select id="getCustOrderSimpleStat" resultType="java.util.Map">
select count(*) orderCount, sum(amount) orderAmount from `order` where user_id = #{custId}
</select>
<update id="updateCustName">
update `order` set user_name = #{userName} WHERE user_id = #{userId}
</update>
</mapper>
\ No newline at end of file
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