feat(order): 优化购物车报价单号生成逻辑
- 在ITBaseAreaService和ITBaseCustomerService接口中新增获取报价码方法getQuoteCode - TBaseAreaServiceImpl实现getQuoteCode,支持根据区域id集合获取报价码 - TBaseCustomerServiceImpl实现getQuoteCode,支持根据公司id列表获取对应区域报价码 - ShoppingController中使用getQuoteCode替换旧报价单号生成逻辑 - 购物单号前缀由“QO”改为“NFQ”,根据用户身份动态生成区域或公司报价码 - 引入Redis缓存报价单日期序号,避免单号冲突,提高性能 - 优化ShoppingCartPartVO金额乘以optionalRatio逻辑,防止负数金额错误乘算
This commit is contained in:
parent
88f1e8779e
commit
0d79babfac
|
|
@ -28,6 +28,7 @@ import com.nflg.mobilebroken.repository.service.*;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
@ -125,6 +126,12 @@ public class ShoppingController extends ControllerBase {
|
|||
@Resource
|
||||
private IDictionaryItemTranslateService dictionaryItemTranslateService;
|
||||
|
||||
@Resource
|
||||
private ITBaseAreaService areaService;
|
||||
|
||||
@Resource
|
||||
private RedisTemplate<String, Integer> redisTemplate;
|
||||
|
||||
/**
|
||||
* 购物车-获取报价主体
|
||||
*/
|
||||
|
|
@ -554,18 +561,7 @@ public class ShoppingController extends ControllerBase {
|
|||
.setCartId(cart.getId()))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
QuotationShoppingOrder last = CollectionUtil.get(shoppingOrderService.lambdaQuery().orderByDesc(QuotationShoppingOrder::getId).list(), 0);
|
||||
if (Objects.isNull(last)) {
|
||||
order.setNo("QO" + DateTimeUtil.format(LocalDate.now(), "yyyyMMdd") + "001");
|
||||
} else {
|
||||
String date = StrUtil.subWithLength(last.getNo(), 2, 8);
|
||||
int index = Integer.parseInt(StrUtil.subSufByLength(last.getNo(), 3));
|
||||
if (date.equals(DateTimeUtil.format(LocalDate.now(), "yyyyMMdd"))) {
|
||||
order.setNo("QO" + date + StrUtil.padPre(String.valueOf(index + 1), 3, '0'));
|
||||
} else {
|
||||
order.setNo("QO" + DateTimeUtil.format(LocalDate.now(), "yyyyMMdd") + "001");
|
||||
}
|
||||
}
|
||||
order.setNo(genOrderNo());
|
||||
shoppingOrderService.save(order);
|
||||
shoppingCartService.lambdaUpdate()
|
||||
.set(QuotationShoppingCart::getStatus, 1)
|
||||
|
|
@ -575,6 +571,32 @@ public class ShoppingController extends ControllerBase {
|
|||
return ApiResult.success(order.getId());
|
||||
}
|
||||
|
||||
private String genOrderNo() {
|
||||
VUtils.trueThrowBusinessError(AppUserUtil.isEndUser()).throwMessage("终端用户不能报价");
|
||||
String orderNo = "NFQ";
|
||||
if (AppUserUtil.isAgent()) {
|
||||
AppUser appUser = appUserService.getById(AppUserUtil.getUserId());
|
||||
orderNo += customerService.getQuoteCode(Arrays.stream(StrUtil.splitToInt(appUser.getCompanyId(), ",")).boxed().collect(Collectors.toList()));
|
||||
} else {
|
||||
AdminUser adminUser = adminUserService.getById(AppUserUtil.getUserId());
|
||||
orderNo += areaService.getQuoteCode(Arrays.stream(StrUtil.splitToInt(adminUser.getAreaIds(), ",")).boxed().collect(Collectors.toList()));
|
||||
}
|
||||
orderNo += DateTimeUtil.format(LocalDate.now(), "yyyyMMdd");
|
||||
String key = "quotation:order:no:" + orderNo;
|
||||
Integer index = redisTemplate.opsForValue().get(key);
|
||||
if (Objects.isNull(index)) {
|
||||
QuotationShoppingOrder lastOrder = shoppingOrderService.lambdaQuery()
|
||||
.likeRight(QuotationShoppingOrder::getNo, orderNo)
|
||||
.orderByDesc(QuotationShoppingOrder::getNo)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
index = Objects.isNull(lastOrder) ? 0 : Integer.parseInt(lastOrder.getQuotationCode().replace(orderNo, ""));
|
||||
}
|
||||
index++;
|
||||
redisTemplate.opsForValue().set(key, index);
|
||||
return orderNo + String.format("%05d", index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 报价单-查询报价单
|
||||
*/
|
||||
|
|
@ -923,7 +945,9 @@ public class ShoppingController extends ControllerBase {
|
|||
|
||||
private ShoppingCartPartVO convert(ModelConfigEffectiveDTO dto, BigDecimal optionalRatio) {
|
||||
ShoppingCartPartVO vo = Convert.convert(ShoppingCartPartVO.class, dto);
|
||||
vo.setAmount(NumberUtil.multiply(vo.getAmount(), optionalRatio));
|
||||
if (vo.getAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
vo.setAmount(NumberUtil.multiply(vo.getAmount(), optionalRatio));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.nflg.mobilebroken.repository.entity.TBaseArea;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -32,4 +33,6 @@ public interface ITBaseAreaService extends IService<TBaseArea> {
|
|||
void updateChildrenCategory(Integer id,Long categoryId);
|
||||
|
||||
void updateCustomerCategory(String areaCode, Long categoryId);
|
||||
|
||||
String getQuoteCode(Collection<Integer> ids);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,4 +36,6 @@ public interface ITBaseCustomerService extends IService<TBaseCustomer> {
|
|||
Collection<Integer> getAreaIds(List<Integer> companyIds);
|
||||
|
||||
List<TBaseCustomer> getForQuotation();
|
||||
|
||||
String getQuoteCode(List<Integer> companyIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import com.nflg.mobilebroken.repository.service.ITBaseAreaService;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -51,4 +53,17 @@ public class TBaseAreaServiceImpl extends ServiceImpl<TBaseAreaMapper, TBaseArea
|
|||
baseMapper.updateCustomerCategory(areaCode, categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuoteCode(Collection<Integer> ids) {
|
||||
return lambdaQuery()
|
||||
.select(TBaseArea::getAreaQuoteCode)
|
||||
.in(TBaseArea::getId, ids)
|
||||
.list()
|
||||
.stream()
|
||||
.map(TBaseArea::getAreaQuoteCode)
|
||||
.collect(Collectors.toSet())
|
||||
.iterator()
|
||||
.next();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,4 +149,27 @@ public class TBaseCustomerServiceImpl extends ServiceImpl<TBaseCustomerMapper, T
|
|||
.eq(TBaseCustomer::getQuotationUse, true)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuoteCode(List<Integer> companyIds) {
|
||||
Set<String> areaCodes = lambdaQuery()
|
||||
.select(TBaseCustomer::getAreaCode)
|
||||
.in(TBaseCustomer::getId, companyIds)
|
||||
.list()
|
||||
.stream()
|
||||
.map(TBaseCustomer::getAreaCode)
|
||||
.collect(Collectors.toSet());
|
||||
List<TBaseArea> areas = areaService.lambdaQuery()
|
||||
.in(TBaseArea::getAreaCode, areaCodes)
|
||||
.list();
|
||||
if (areas.size() == 1) {
|
||||
return areas.get(0).getAreaQuoteCode();
|
||||
}
|
||||
TBaseArea area = areas.stream().filter(a -> a.getParentAreaRowId() == 0).findFirst().orElse(null);
|
||||
if (Objects.nonNull(area)) {
|
||||
return area.getAreaQuoteCode();
|
||||
}
|
||||
area = areaService.getById(areas.get(0).getParentAreaRowId());
|
||||
return area.getAreaQuoteCode();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue