|
|
@@ -1,5 +1,6 @@
|
|
|
package com.kxs.store.biz.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
import cn.hutool.core.util.EnumUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
@@ -36,6 +37,7 @@ import com.kxs.store.biz.service.*;
|
|
|
import com.kxs.system.api.feign.RemoteUserMsgService;
|
|
|
import com.kxs.system.api.model.KxsUserMsg;
|
|
|
import com.kxs.system.api.util.MsgTemplateUtil;
|
|
|
+import com.kxs.system.api.util.ParamResolver;
|
|
|
import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
import com.kxs.user.api.model.KxsUser;
|
|
|
import com.kxs.user.api.model.KxsUserAdvance;
|
|
|
@@ -275,15 +277,18 @@ public class KxsMachineApplyServiceImpl extends ServiceImpl<KxsMachineApplyMappe
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @GlobalTransactional(rollbackFor = Exception.class)
|
|
|
public R applyVhostGdSn(ApplyMachineDTO param) {
|
|
|
Long userId = SecurityUtils.getUser().getId();
|
|
|
+ //虚拟仓库ID
|
|
|
+ Integer whsId = ParamResolver.getInteger("GD_VHOST_STORE_ID", 8664);
|
|
|
//订单号
|
|
|
Snowflake snowflake = IdUtil.getSnowflake(1, userId);
|
|
|
long orderSn = snowflake.nextId();
|
|
|
|
|
|
KxsMachineApply order = new KxsMachineApply();
|
|
|
BeanUtils.copyProperties(param, order);
|
|
|
- order.setOrderSn("BA" + orderSn);
|
|
|
+ order.setOrderSn("VH" + orderSn);
|
|
|
//查询申请用户
|
|
|
R<KxsUser> userResult = remoteKxsUserService.loadUserById(userId.intValue(), SecurityConstants.FROM_IN);
|
|
|
KxsUser user = RetOps.of(userResult)
|
|
|
@@ -292,7 +297,69 @@ public class KxsMachineApplyServiceImpl extends ServiceImpl<KxsMachineApplyMappe
|
|
|
order.setUserId(userId.intValue());
|
|
|
order.setUsername(user.getUsername());
|
|
|
order.setUserCode(user.getUserCode());
|
|
|
- return null;
|
|
|
+ order.setStatus(MachineOrderStatusEnum.APPLY_SUCCESSFUL.getType());
|
|
|
+ order.setWarehouseId(whsId);
|
|
|
+ //查询品牌
|
|
|
+ R<KxsBrand> kxsBrandR = remoteKxsProductService.loadByBrand(param.getBrandId(), SecurityConstants.FROM_IN);
|
|
|
+ KxsBrand brand = RetOps.of(kxsBrandR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.DATA_ERROR.getDescription()));
|
|
|
+ order.setBrandName(brand.getName());
|
|
|
+ //添加订单
|
|
|
+ baseMapper.insert(order);
|
|
|
+ for (int i = 0; i < param.getSnList().size(); i++) {
|
|
|
+
|
|
|
+ //查询广电的虚拟SN在库
|
|
|
+ R<KxsMachine> machineResult = remoteKxsProductService.loadByWhsGdSn(whsId, SecurityConstants.FROM_IN);
|
|
|
+ KxsMachine machine = RetOps.of(machineResult)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.MACHINE_IS_NULL.getDescription()));
|
|
|
+
|
|
|
+ String sn = param.getSnList().get(i);
|
|
|
+ //新增订单详情
|
|
|
+ KxsMachineApplyDetail orderDetail = new KxsMachineApplyDetail();
|
|
|
+ orderDetail.setOrderId(order.getId());
|
|
|
+ orderDetail.setApplyType(param.getApplyType());
|
|
|
+ //兑换券申请
|
|
|
+ R<KxsTicket> ticketResult = remoteKxsProductService.loadTicketBySn(sn, SecurityConstants.FROM_IN);
|
|
|
+ KxsTicket ticket = RetOps.of(ticketResult)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.TICKET_NOT_FIND.getDescription()));
|
|
|
+
|
|
|
+ //券码被使用返回错误
|
|
|
+ if (!ticket.getStatus().equals(TicketStatusEnum.TICKET_UNUSED.getType())) {
|
|
|
+ throw new GlobalCustomerException(StoreErrorTypeEnum.TICKET_CODE_UN.getDescription());
|
|
|
+ }
|
|
|
+ //冻结券码,发货后 驳回改回未使用 通过修改为已使用
|
|
|
+ ticket.setStatus(TicketStatusEnum.TICKET_FREEZE.getType());
|
|
|
+ R<Boolean> result = remoteKxsProductService.updateByTicket(ticket, SecurityConstants.FROM_IN);
|
|
|
+ if (!result.getData()) {
|
|
|
+ throw new GlobalCustomerException(StoreErrorTypeEnum.DATA_ERROR.getDescription());
|
|
|
+ }
|
|
|
+ orderDetail.setTicketId(ticket.getId());
|
|
|
+ orderDetail.setTicketCode(sn);
|
|
|
+ orderDetail.setMachineId(machine.getId());
|
|
|
+ orderDetail.setPosSn(machine.getPosSn());
|
|
|
+ kxsMachineApplyDetailMapper.insert(orderDetail);
|
|
|
+
|
|
|
+ machine.setUserId(userId.intValue());
|
|
|
+ //盟主标识
|
|
|
+ machine.setLeaderId(ticket.getLeaderId());
|
|
|
+ machine.setPartnerId(ticket.getPartnerId());
|
|
|
+ //修改为申请的机具类型
|
|
|
+ machine.setMachineType(param.getApplyType());
|
|
|
+ //修改机具已出库
|
|
|
+ machine.setStatus(MachineTypeEnum.STATUS_OUT.getType());
|
|
|
+ machine.setRecycleEndTime(LocalDateTime.now().plusDays(ParamResolver.getInteger("RECYC_POS_MAX_DAY", 365)));
|
|
|
+ R<Boolean> booleanR = remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
|
|
|
+ if(!booleanR.getData()){
|
|
|
+ throw new GlobalCustomerException(ErrorTypeEnum.REMOTE_DATA_ERROR.getDescription());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //发货统计
|
|
|
+ kxsSendTotalService.shipmentStatistics(param.getSnList().size(), whsId, order.getBrandId());
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -340,7 +407,16 @@ public class KxsMachineApplyServiceImpl extends ServiceImpl<KxsMachineApplyMappe
|
|
|
machine.setStatus(MachineTypeEnum.STATUS_OUT.getType());
|
|
|
//如果为兑换机设置循环时间并设置为可循环申请
|
|
|
if (order.getApplyType().equals(MachineOrderEnum.M_TYPE_SN.getType())) {
|
|
|
- machine.setRecycleEndTime(LocalDateTime.now().plusDays(StoreConstants.RECYC_MAX_DAY));
|
|
|
+ machine.setRecycleEndTime(LocalDateTime.now().plusDays(ParamResolver.getInteger("RECYC_POS_MAX_DAY", 365)));
|
|
|
+ //查询券
|
|
|
+ R<KxsTicket> kxsTicketR = remoteKxsProductService.loadTicketBySn(orderDetail.getTicketCode(), SecurityConstants.FROM_IN);
|
|
|
+
|
|
|
+ KxsTicket ticket = RetOps.of(kxsTicketR)
|
|
|
+ .getData()
|
|
|
+ .orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.TICKET_NOT_FIND.getDescription()));
|
|
|
+ //盟主标识
|
|
|
+ machine.setLeaderId(ticket.getLeaderId());
|
|
|
+ machine.setPartnerId(ticket.getPartnerId());
|
|
|
}else{
|
|
|
//如果循环机则继承上级的循环时间
|
|
|
R<KxsMachine> recycleMachineResult = remoteKxsProductService.loadMachineById(orderDetail.getRecycleMachineId(), SecurityConstants.FROM_IN);
|
|
|
@@ -348,6 +424,9 @@ public class KxsMachineApplyServiceImpl extends ServiceImpl<KxsMachineApplyMappe
|
|
|
.getData()
|
|
|
.orElseThrow(() -> new GlobalCustomerException(StoreErrorTypeEnum.SN_FIND_NULL.getDescription()));
|
|
|
machine.setRecycleEndTime(recycleMachine.getRecycleEndTime());
|
|
|
+ //盟主标识
|
|
|
+ machine.setLeaderId(recycleMachine.getLeaderId());
|
|
|
+ machine.setPartnerId(recycleMachine.getPartnerId());
|
|
|
//增加循环记录表
|
|
|
KxsMachineCirculationLog machineCirculationLog = new KxsMachineCirculationLog();
|
|
|
R<KxsMachineCirculationLog> result = remoteKxsProductService.loadCirculationLogByMachineId(recycleMachine.getId(), SecurityConstants.FROM_IN);
|
|
|
@@ -369,6 +448,7 @@ public class KxsMachineApplyServiceImpl extends ServiceImpl<KxsMachineApplyMappe
|
|
|
|
|
|
}
|
|
|
machine.setDeliveryTime(LocalDateTime.now());
|
|
|
+
|
|
|
remoteKxsProductService.updateByMachine(machine, SecurityConstants.FROM_IN);
|
|
|
|
|
|
//订单详情绑定机具
|
|
|
@@ -521,7 +601,7 @@ public class KxsMachineApplyServiceImpl extends ServiceImpl<KxsMachineApplyMappe
|
|
|
UserApplyMachineDetailVO userApplyMachineDetailVO = new UserApplyMachineDetailVO();
|
|
|
KxsMachineApply order = baseMapper.selectById(id);
|
|
|
Optional.ofNullable(order).orElseThrow(() -> new GlobalCustomerException(ErrorTypeEnum.PARAM_ERROR.getDescription()));
|
|
|
- BeanUtils.copyProperties(order, userApplyMachineDetailVO);
|
|
|
+ BeanUtil.copyProperties(order, userApplyMachineDetailVO);
|
|
|
//查询仓库
|
|
|
KxsWarehouse warehouse = kxsWarehouseMapper.selectById(order.getWarehouseId());
|
|
|
userApplyMachineDetailVO.setWarehouseName(warehouse.getWarehouseName() + "--" + warehouse.getBrandName());
|