Commit 9d57fc19 by 吕明尚

增加开放接口

parent e09b6835
package share.web.controller.system;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import share.common.core.domain.AjaxResult;
import share.common.core.domain.R;
import share.system.service.ISOrderService;
import share.system.service.OpenInterfaceService;
@RestController
@RequestMapping("/openInterface")
public class OpenInterfaceController {
@Autowired
private ISOrderService sOrderService;
private OpenInterfaceService openInterfaceService;
@GetMapping("/order/info")
public AjaxResult orderInfo(String orderNo) {
return AjaxResult.success(sOrderService.orderInfo(orderNo));
return AjaxResult.success(openInterfaceService.orderInfo(orderNo));
}
@RequestMapping(value = "/open/door", method = RequestMethod.GET)
public R<String> openDoor(@RequestParam("orderNo") String orderNo) {
return R.ok(openInterfaceService.openDoor(orderNo));
}
}
......@@ -58,7 +58,7 @@ public class SConsumerCoupon extends BaseEntity
* 适用门店id
*/
@Excel(name = "适用门店id")
private String storeIdEnum;
private String storeIds;
/** 优惠券编码 */
@Excel(name = "优惠券编码")
......
......@@ -105,7 +105,7 @@ public class SCoupon extends BaseEntity
* 适用门店id
*/
@Excel(name = "适用门店id")
private String storeIdEnum;
private String storeIds;
/** 是否可叠加使用(0:不可叠加,1:可叠加) */
@Excel(name = "是否可叠加使用(0:不可叠加,1:可叠加)")
......
......@@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import share.system.domain.SConsumerCoupon;
import share.system.domain.SOrder;
import share.system.domain.vo.OrderVo;
import share.system.domain.vo.SOrderVo;
......@@ -173,5 +174,10 @@ public interface ISOrderService extends IService<SOrder>
*/
List<SOrder> payedUnrefundListByUserId(Long userId);
OrderVo orderInfo(String orderNo);
boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon);
boolean isRefund(SOrder order, SConsumerCoupon coupon);
}
package share.system.service;
import share.system.domain.vo.OrderVo;
public interface OpenInterfaceService {
OrderVo orderInfo(String orderNo);
String openDoor(String orderNo);
}
package share.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import share.common.enums.DeviceType;
import share.common.enums.RoomType;
import share.common.exception.base.BaseException;
import share.common.utils.bean.BeanUtils;
import share.system.domain.*;
import share.system.domain.vo.OrderVo;
import share.system.domain.vo.SRoomVo;
import share.system.service.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class OpenInterfaceServiceImpl implements OpenInterfaceService {
@Autowired
private ISConsumerCouponService consumerCouponService;
@Autowired
private ISStoreService storeService;
@Autowired
private ISRoomService roomService;
@Autowired
private ISOrderService orderService;
@Autowired
private IPackService packService;
@Autowired
private DeviceService deviceService;
@Autowired
private DeviceOpService deviceOpService;
@Override
public OrderVo orderInfo(String orderNo) {
SOrder en = orderService.getByOrderNo(orderNo);
OrderVo vo = new OrderVo();
BeanUtils.copyProperties(en, vo);
SStore store = storeService.getById(en.getStoreId());
SRoom room = roomService.getById(en.getRoomId());
vo.setStoreName(store.getName());
vo.setAddress(store.getAddress());
vo.setRoomImages(room.getImages());
vo.setRoomName(room.getName());
vo.setRoomType(room.getRoomType());
vo.setRoomTypeName(RoomType.getNameByCode(room.getRoomType()));
vo.setLongitude(store.getLongitude());
vo.setLatitude(store.getLatitude());
if (ObjectUtil.isNotEmpty(en.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(en.getCouponId());
vo.setCouponName(consumerCoupon.getName());
// 判断是否可以退款
vo.setIsRefund(orderService.isRefund(en, consumerCoupon));
} else {
// 判断是否可以退款
vo.setIsRefund(orderService.isRefund(en, null));
}
if (ObjectUtil.isNotEmpty(en.getPackId())) {
SPack byId = packService.getById(en.getPackId());
vo.setPackName(byId.getName());
}
return vo;
}
@Override
public String openDoor(String orderNo) {
LambdaQueryWrapper<SOrder> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
orderLambdaQueryWrapper.eq(SOrder::getOrderNo, orderNo);
SOrder sOrder = orderService.getOne(orderLambdaQueryWrapper);
if (Objects.isNull(sOrder)) {
throw new BaseException("订单不存在!");
}
SRoomVo sRoomVo = roomService.selectSRoomById(sOrder.getRoomId());
if (Objects.isNull(sRoomVo)) {
throw new BaseException("房间不存在!");
}
LambdaQueryWrapper<Device> deviceLambdaQueryWrapper = new LambdaQueryWrapper<>();
deviceLambdaQueryWrapper.eq(Device::getRoomId, sOrder.getRoomId());
deviceLambdaQueryWrapper.in(Device::getDevType, DeviceType.DEVICE_CCEE.getCode(), DeviceType.DEVICE_0001.getCode());
List<Device> deviceList = deviceService.list(deviceLambdaQueryWrapper);
if (CollectionUtils.isEmpty(deviceList)) {
throw new BaseException("房间设备缺失!");
}
if (deviceList.stream().filter(device ->
device.getDevType().equals(DeviceType.DEVICE_CCEE.getCode())
).collect(Collectors.toList()).isEmpty()) {
throw new BaseException("房间门锁设备不存在!");
}
if (deviceList.stream().filter(item ->
item.getDevType().equals(DeviceType.DEVICE_0001.getCode())
).collect(Collectors.toList()).isEmpty()) {
throw new BaseException("房间取电设备不存在!");
}
deviceOpService.openDoor(sRoomVo.getId(), sOrder.getConsumerPhone());
return "开锁成功";
}
}
......@@ -118,7 +118,6 @@ public class QPServiceImpl implements QPService {
TuangouReceiptPrepareResponseEntityVo response = new TuangouReceiptPrepareResponseEntityVo();
SConsumerCoupon sConsumerCoupon = new SConsumerCoupon();
sConsumerCoupon.setConsumerId(user.getId());
sConsumerCoupon.setStoreId(sStore.getId());
sConsumerCoupon.setDealId(prepare.getDeal_id());
sConsumerCoupon.setCouponCode(code);
sConsumerCoupon.setName(prepare.getDeal_title());
......@@ -174,7 +173,7 @@ public class QPServiceImpl implements QPService {
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
sConsumerCoupon.setOrderType(sCoupon.getOrderType());
sConsumerCoupon.setDealgroupId(sCoupon.getDealgroupId());
sConsumerCoupon.setStoreIdEnum(sCoupon.getStoreIdEnum());
sConsumerCoupon.setStoreIds(sCoupon.getStoreIds());
sConsumerCoupon.setPackageId(sCoupon.getPackageId());
sConsumerCoupon.setRemark(sCoupon.getRemark());
}
......
......@@ -6,6 +6,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import cn.hutool.json.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -268,15 +269,17 @@ public class SConsumerCouponServiceImpl extends ServiceImpl<SConsumerCouponMappe
private Boolean checkStore(SConsumerCoupon item,CouponRequest couponRequest,List<SStore> sStores){
if (Objects.nonNull(item.getStoreId()) && item.getStoreId().compareTo(couponRequest.getStoreId()) != 0) {
SStore sStore = sStores.stream().filter(store -> store.getId().equals(item.getStoreId())).findFirst().orElse(null);
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("当前门店不可用,适用门店【"+sStore.getName()+"】");
if (StringUtils.isNotBlank(item.getStoreIds())) {
List<Long> storeIds = Arrays.asList(item.getStoreIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
if (!storeIds.contains(couponRequest.getStoreId())) {
List<String> storeNames = sStores.stream().filter(store -> storeIds.contains(store.getId())).map(SStore::getName).collect(Collectors.toList());
item.setIsAvailable(AvailableEnum.UNAVAILABLE.getCode());
item.setReason("优惠卷当前门店不可用,适用门店:" + storeNames.toString());
}
}
return item.getIsAvailable()==0;
}
@Override
public int give(SConsumerCoupon sConsumerCoupon) {
//根据优惠券id查询优惠券信息
......
......@@ -186,9 +186,9 @@ public class SCouponServiceImpl implements ISCouponService {
sCoupon.setCouponType(CouponTypeEnum.CASH.getCode());
sCouponList.put(item.getDealgroup_id(), sCoupon);
//从门店列表中获取门店id
sCoupon.setStoreIdEnum(String.valueOf(sStores.stream().filter(store -> store.getOpenShopUuid().equals(openShopUuid)).findFirst().get().getId()));
sCoupon.setStoreIds(String.valueOf(sStores.stream().filter(store -> store.getOpenShopUuid().equals(openShopUuid)).findFirst().get().getId()));
} else {
sCoupon1.setStoreIdEnum(sCoupon1.getStoreIdEnum() + "," + sStores.stream().filter(store -> store.getOpenShopUuid().equals(openShopUuid)).findFirst().get().getId());
sCoupon1.setStoreIds(sCoupon1.getStoreIds() + "," + sStores.stream().filter(store -> store.getOpenShopUuid().equals(openShopUuid)).findFirst().get().getId());
}
});
}
......
......@@ -184,7 +184,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
* @param coupon 优惠券信息
* @return
*/
private boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon) {
@Override
public boolean isRefund(SOrderVo orderVo, SConsumerCoupon coupon) {
if (coupon != null && !PlatformTypeEnum.SELF.getCode().equals(coupon.getPlatformType())) {
return Boolean.FALSE;
} else if (orderVo != null && OrderStatusEnum.UNUSED.getCode().equals(orderVo.getStatus())
......@@ -210,7 +211,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
* @param coupon 优惠券信息
* @return
*/
private boolean isRefund(SOrder order, SConsumerCoupon coupon) {
@Override
public boolean isRefund(SOrder order, SConsumerCoupon coupon) {
if (coupon != null && !PlatformTypeEnum.SELF.getCode().equals(coupon.getPlatformType())) {
return Boolean.FALSE;
} else if (order != null && OrderStatusEnum.UNUSED.getCode().equals(order.getStatus())) {
......@@ -869,37 +871,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
return list(queryWrapper);
}
@Override
public OrderVo orderInfo(String orderNo) {
SOrder en = getByOrderNo(orderNo);
OrderVo vo = new OrderVo();
BeanUtils.copyProperties(en, vo);
SStore store = storeService.getById(en.getStoreId());
SRoom room = roomService.getById(en.getRoomId());
vo.setStoreName(store.getName());
vo.setAddress(store.getAddress());
vo.setRoomImages(room.getImages());
vo.setRoomName(room.getName());
vo.setRoomType(room.getRoomType());
vo.setRoomTypeName(RoomType.getNameByCode(room.getRoomType()));
vo.setLongitude(store.getLongitude());
vo.setLatitude(store.getLatitude());
if (ObjectUtil.isNotEmpty(en.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(en.getCouponId());
vo.setCouponName(consumerCoupon.getName());
// 判断是否可以退款
vo.setIsRefund(isRefund(en, consumerCoupon));
} else {
// 判断是否可以退款
vo.setIsRefund(isRefund(en, null));
}
if (ObjectUtil.isNotEmpty(en.getPackId())) {
SPack byId = packService.getById(en.getPackId());
vo.setPackName(byId.getName());
}
return vo;
}
/**
* 订单DO集合转换VO集合,按距离排序
*
......
......@@ -11,7 +11,7 @@
<result property="storeId" column="store_id"/>
<result property="dealId" column="deal_id"/>
<result property="dealgroupId" column="dealgroup_id"/>
<result property="storeIdEnum" column="store_id_enum"/>
<result property="storeIds" column="store_ids"/>
<result property="couponCode" column="coupon_code" />
<result property="name" column="name" />
<result property="couponType" column="coupon_type" />
......@@ -49,7 +49,7 @@
store_id,
deal_id,
dealgroup_id,
store_id_enum,
store_ids,
coupon_code,
name,
coupon_type,
......@@ -167,7 +167,7 @@
<if test="orderType != null">order_type,</if>
<if test="packageId != null">package_id,</if>
<if test="dealgroupId != null">dealgroup_id,</if>
<if test="storeIdEnum != null">store_id_enum,</if>
<if test="storeIds != null">store_ids,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="consumerId != null">#{consumerId},</if>
......@@ -203,7 +203,7 @@
<if test="orderType != null">#{orderType},</if>
<if test="packageId != null">#{packageId},</if>
<if test="dealgroupId != null">#{dealgroupId},</if>
<if test="storeIdEnum != null">#{storeIdEnum},</if>
<if test="storeIds != null">#{storeIds},</if>
</trim>
</insert>
......@@ -243,7 +243,7 @@
<if test="orderType != null">order_type = #{orderType},</if>
<if test="packageId != null">package_id = #{packageId},</if>
<if test="dealgroupId != null">dealgroup_id = #{dealgroupId},</if>
<if test="storeIdEnum != null">store_id_enum = #{storeIdEnum},</if>
<if test="storeIds != null">store_ids = #{storeIds},</if>
</trim>
where id = #{id}
</update>
......
......@@ -17,7 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="orderType" column="order_type"/>
<result property="packageId" column="package_id"/>
<result property="dealgroupId" column="dealgroup_id"/>
<result property="storeIdEnum" column="store_id_enum"/>
<result property="storeIds" column="store_ids"/>
<result property="duration" column="duration" />
<result property="minDuration" column="min_duration" />
<result property="maxDuration" column="max_duration" />
......@@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order_type,
package_id,
dealgroup_id,
store_id_enum,
store_ids,
duration,min_duration,max_duration,
min_price,sub_price,is_overlay,
platform_type,number,create_by,
......@@ -64,7 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderType != null">and order_type = #{orderType}</if>
<if test="packageId != null">and package_id = #{packageId}</if>
<if test="dealgroupId != null">and dealgroup_id = #{dealgroupId}</if>
<if test="storeIdEnum != null">and store_id_enum = #{storeIdEnum}</if>
<if test="storeIds != null">and store_ids = #{storeIds}</if>
<if test="duration != null and duration != ''"> and duration = #{duration}</if>
<if test="minDuration != null and minDuration != ''"> and min_duration = #{minDuration}</if>
<if test="maxDuration != null and maxDuration != ''"> and max_duration = #{maxDuration}</if>
......@@ -121,7 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderType != null">order_type,</if>
<if test="packageId != null">package_id,</if>
<if test="dealgroupId != null">dealgroup_id,</if>
<if test="storeIdEnum != null">store_id_enum,</if>
<if test="storeIds != null">store_ids,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
......@@ -146,7 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderType != null">#{orderType},</if>
<if test="packageId != null">#{packageId},</if>
<if test="dealgroupId != null">#{dealgroupId},</if>
<if test="storeIdEnum != null">#{storeIdEnum},</if>
<if test="storeIds != null">#{storeIds},</if>
</trim>
</insert>
......@@ -163,7 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="couponType != null">coupon_type = #{couponType},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="packageId != null">package_id = #{packageId},</if>
<if test="storeIdEnum != null">store_id_enum = #{storeIdEnum},</if>
<if test="storeIds != null">store_ids = #{storeIds},</if>
<if test="dealgroupId != null">dealgroup_id = #{dealgroupId},</if>
<if test="duration != null and duration != ''">duration = #{duration},</if>
<if test="minDuration != null and minDuration != ''">min_duration = #{minDuration},</if>
......
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