use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class DietOrderService method saveDietOrder.
/**
* 保存订单信息
*
* @param saveDietOrderModel
* @return
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest saveDietOrder(SaveDietOrderModel saveDietOrderModel) {
BigInteger tenantId = saveDietOrderModel.getTenantId();
String tenantCode = saveDietOrderModel.getTenantCode();
BigInteger branchId = saveDietOrderModel.getBranchId();
BigInteger userId = saveDietOrderModel.getUserId();
List<BigInteger> goodsIds = new ArrayList<BigInteger>();
List<BigInteger> goodsSpecificationIds = new ArrayList<BigInteger>();
List<BigInteger> goodsFlavorGroupIds = new ArrayList<BigInteger>();
List<BigInteger> goodsFlavorIds = new ArrayList<BigInteger>();
List<SaveDietOrderModel.GroupInfo> groupInfos = saveDietOrderModel.getGroupInfos();
for (SaveDietOrderModel.GroupInfo groupInfo : groupInfos) {
List<SaveDietOrderModel.DetailInfo> detailInfos = groupInfo.getDetailInfos();
for (SaveDietOrderModel.DetailInfo detailInfo : detailInfos) {
goodsIds.add(detailInfo.getGoodsId());
goodsSpecificationIds.add(detailInfo.getGoodsSpecificationId());
List<SaveDietOrderModel.FlavorInfo> flavorInfos = detailInfo.getFlavorInfos();
if (CollectionUtils.isNotEmpty(flavorInfos)) {
for (SaveDietOrderModel.FlavorInfo flavorInfo : flavorInfos) {
goodsFlavorGroupIds.add(flavorInfo.getFlavorGroupId());
goodsFlavorIds.add(flavorInfo.getFlavorId());
}
}
}
}
// 查询出订单中包含的所有商品
SearchModel goodsSearchModel = new SearchModel(true);
goodsSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsIds);
List<Goods> goodses = goodsMapper.findAll(goodsSearchModel);
// 查询出订单中包含的所有商品规格
SearchModel goodsSpecificationSearchModel = new SearchModel(true);
goodsSpecificationSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsSpecificationSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsSpecificationSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsSpecificationIds);
List<GoodsSpecification> goodsSpecifications = goodsSpecificationMapper.findAll(goodsSpecificationSearchModel);
// 查询出订单中包含的所有口味组
List<GoodsFlavorGroup> goodsFlavorGroups = new ArrayList<GoodsFlavorGroup>();
if (CollectionUtils.isNotEmpty(goodsFlavorGroupIds)) {
SearchModel goodsFlavorGroupSearchModel = new SearchModel(true);
goodsFlavorGroupSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsFlavorGroupSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsFlavorGroupSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsFlavorGroupIds);
goodsFlavorGroups = goodsFlavorGroupMapper.findAll(goodsFlavorGroupSearchModel);
}
// 查询出订单中包含的所有口味
List<GoodsFlavor> goodsFlavors = new ArrayList<GoodsFlavor>();
if (CollectionUtils.isNotEmpty(goodsFlavorIds)) {
SearchModel goodsFlavorSearchModel = new SearchModel(true);
goodsFlavorSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsFlavorSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsFlavorSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsFlavorIds);
goodsFlavors = goodsFlavorMapper.findAll(goodsFlavorSearchModel);
}
// 封装商品id与商品之间的map
Map<BigInteger, Goods> goodsMap = new HashMap<BigInteger, Goods>();
for (Goods goods : goodses) {
goodsMap.put(goods.getId(), goods);
}
// 封装商品规格id与商品规格之间的map
Map<BigInteger, GoodsSpecification> goodsSpecificationMap = new HashMap<BigInteger, GoodsSpecification>();
for (GoodsSpecification goodsSpecification : goodsSpecifications) {
goodsSpecificationMap.put(goodsSpecification.getId(), goodsSpecification);
}
// 封装商品口味组id与商品口味组之间的map
Map<BigInteger, GoodsFlavorGroup> goodsFlavorGroupMap = new HashMap<BigInteger, GoodsFlavorGroup>();
for (GoodsFlavorGroup goodsFlavorGroup : goodsFlavorGroups) {
goodsFlavorGroupMap.put(goodsFlavorGroup.getId(), goodsFlavorGroup);
}
// 封装商品口味id与商品口味之间的map
Map<BigInteger, GoodsFlavor> goodsFlavorMap = new HashMap<BigInteger, GoodsFlavor>();
for (GoodsFlavor goodsFlavor : goodsFlavors) {
goodsFlavorMap.put(goodsFlavor.getId(), goodsFlavor);
}
DietOrder dietOrder = new DietOrder();
dietOrder.setTenantId(tenantId);
dietOrder.setTenantCode(tenantCode);
dietOrder.setBranchId(branchId);
String orderNumberPrefix = null;
Integer orderType = saveDietOrderModel.getOrderType();
if (orderType == DietOrderConstants.ORDER_TYPE_SCAN_CODE_ORDER) {
orderNumberPrefix = "SC";
}
Integer daySerialNumber = sequenceMapper.nextValue(SerialNumberGenerator.generatorTodaySequenceName(tenantId, branchId, "diet_order_number"));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
String orderNumber = orderNumberPrefix + simpleDateFormat.format(new Date()) + SerialNumberGenerator.nextSerialNumber(8, daySerialNumber);
dietOrder.setOrderNumber(orderNumber);
dietOrder.setOrderType(orderType);
dietOrder.setOrderStatus(DietOrderConstants.ORDER_STATUS_PENDING);
dietOrder.setPayStatus(DietOrderConstants.PAY_STATUS_UNPAID);
dietOrder.setRefundStatus(DietOrderConstants.REFUND_STATUS_NO_REFUND);
dietOrder.setDaySerialNumber(daySerialNumber.toString());
boolean invoiced = saveDietOrderModel.getInvoiced();
dietOrder.setInvoiced(invoiced);
if (invoiced) {
dietOrder.setInvoiceType(saveDietOrderModel.getInvoiceType());
dietOrder.setInvoice(saveDietOrderModel.getInvoice());
}
dietOrder.setCreateUserId(userId);
dietOrder.setLastUpdateUserId(userId);
dietOrder.setLastUpdateRemark("保存订单信息!");
dietOrderMapper.insert(dietOrder);
BigDecimal dietOrderTotalAmount = BigDecimal.ZERO;
BigInteger dietOrderId = dietOrder.getId();
// 存放订单优惠金额
BigDecimal dietOrderDiscountAmount = BigDecimal.ZERO;
// 存放赠品订单详情
List<DietOrderDetail> giveDietOrderDetails = new ArrayList<DietOrderDetail>();
// 用来保存订单活动
Map<BigInteger, DietOrderActivity> dietOrderActivityMap = new HashMap<BigInteger, DietOrderActivity>();
for (SaveDietOrderModel.GroupInfo groupInfo : groupInfos) {
DietOrderGroup dietOrderGroup = DietOrderUtils.constructDietOrderGroup(tenantId, tenantCode, branchId, dietOrderId, groupInfo.getName(), groupInfo.getType(), userId, "保存订单分组信息!");
dietOrderGroupMapper.insert(dietOrderGroup);
List<SaveDietOrderModel.DetailInfo> detailInfos = groupInfo.getDetailInfos();
for (SaveDietOrderModel.DetailInfo detailInfo : detailInfos) {
Goods goods = goodsMap.get(detailInfo.getGoodsId());
Validate.notNull(goods, "商品不存在!");
GoodsSpecification goodsSpecification = goodsSpecificationMap.get(detailInfo.getGoodsSpecificationId());
Validate.notNull(goodsSpecification, "商品规格不存在!");
BigDecimal flavorIncrease = BigDecimal.ZERO;
List<SaveDietOrderModel.FlavorInfo> flavorInfos = detailInfo.getFlavorInfos();
List<DietOrderDetailGoodsFlavor> dietOrderDetailGoodsFlavors = new ArrayList<DietOrderDetailGoodsFlavor>();
if (CollectionUtils.isNotEmpty(flavorInfos)) {
for (SaveDietOrderModel.FlavorInfo flavorInfo : flavorInfos) {
GoodsFlavorGroup goodsFlavorGroup = goodsFlavorGroupMap.get(flavorInfo.getFlavorGroupId());
Validate.notNull(goodsFlavorGroup, "口味组不存在!");
GoodsFlavor goodsFlavor = goodsFlavorMap.get(flavorInfo.getFlavorId());
Validate.notNull(goodsFlavor, "口味不存在!");
flavorIncrease = flavorIncrease.add(goodsFlavor.getPrice());
DietOrderDetailGoodsFlavor dietOrderDetailGoodsFlavor = DietOrderUtils.constructDietOrderDetailGoodsFlavor(tenantId, tenantCode, branchId, dietOrderId, dietOrderGroup.getId(), null, goodsFlavorGroup.getId(), goodsFlavorGroup.getName(), goodsFlavor.getId(), goodsFlavor.getName(), goodsFlavor.getPrice(), userId, "保存订单口味信息!");
dietOrderDetailGoodsFlavors.add(dietOrderDetailGoodsFlavor);
}
}
BigDecimal quantity = BigDecimal.valueOf(detailInfo.getQuantity());
BigDecimal price = goodsSpecification.getPrice();
BigDecimal totalAmount = price.add(flavorIncrease).multiply(quantity);
BigDecimal discountAmount = BigDecimal.ZERO;
// 处理特价商品
SpecialGoodsActivityBean specialGoodsActivityBean = DietOrderUtils.findSpecialGoodsActivityBean(tenantId, branchId, goods.getId(), goodsSpecification.getId());
if (specialGoodsActivityBean != null) {
Integer discountType = specialGoodsActivityBean.getDiscountType();
if (discountType == 1) {
discountAmount = price.subtract(specialGoodsActivityBean.getSpecialPrice()).multiply(quantity);
} else {
discountAmount = price.subtract(price.multiply(specialGoodsActivityBean.getDiscountRate()).divide(HUNDRED));
}
BigInteger activityId = specialGoodsActivityBean.getActivityId();
DietOrderActivity dietOrderActivity = dietOrderActivityMap.get(activityId);
if (dietOrderActivity == null) {
dietOrderActivity = DietOrderUtils.constructDietOrderActivity(tenantId, tenantCode, branchId, dietOrderId, activityId, specialGoodsActivityBean.getActivityName(), specialGoodsActivityBean.getActivityType(), discountAmount.multiply(MINUS_ONE), userId, "保存订单活动信息!");
dietOrderActivityMap.put(activityId, dietOrderActivity);
} else {
dietOrderActivity.setAmount(dietOrderActivity.getAmount().multiply(discountAmount.multiply(MINUS_ONE)));
}
}
dietOrderDiscountAmount = dietOrderDiscountAmount.add(discountAmount);
BigDecimal payableAmount = totalAmount.subtract(discountAmount);
DietOrderDetail dietOrderDetail = DietOrderUtils.constructDietOrderDetail(tenantId, tenantCode, branchId, dietOrderId, dietOrderGroup.getId(), goods.getId(), goods.getName(), goodsSpecification.getId(), goodsSpecification.getName(), goods.getCategoryId(), goodsSpecification.getPrice(), flavorIncrease, detailInfo.getQuantity(), totalAmount, discountAmount, payableAmount, userId, "保存订单详情信息!");
dietOrderDetailMapper.insert(dietOrderDetail);
if (CollectionUtils.isNotEmpty(dietOrderDetailGoodsFlavors)) {
for (DietOrderDetailGoodsFlavor dietOrderDetailGoodsFlavor : dietOrderDetailGoodsFlavors) {
dietOrderDetailGoodsFlavor.setDietOrderDetailId(dietOrderDetail.getId());
}
dietOrderDetailGoodsFlavorMapper.insertAll(dietOrderDetailGoodsFlavors);
}
dietOrderTotalAmount = dietOrderTotalAmount.add(totalAmount);
// 处理买A赠B活动
BuyGiveActivityBean buyGiveActivityBean = DietOrderUtils.findBuyGiveActivityBean(tenantId, branchId, goods.getId(), goodsSpecification.getId(), detailInfo.getQuantity());
if (buyGiveActivityBean != null) {
DietOrderDetail giveDietOrderDetail = DietOrderUtils.constructDietOrderDetail(tenantId, tenantCode, branchId, dietOrderId, null, buyGiveActivityBean.getGiveGoodsId(), buyGiveActivityBean.getGiveGoodsName(), buyGiveActivityBean.getGiveGoodsSpecificationId(), buyGiveActivityBean.getGiveGoodsSpecificationName(), BigInteger.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, buyGiveActivityBean.getGiveQuantity(), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, userId, "保存订单详情信息!");
giveDietOrderDetails.add(giveDietOrderDetail);
if (!dietOrderActivityMap.containsKey(buyGiveActivityBean.getActivityId())) {
DietOrderActivity dietOrderActivity = DietOrderUtils.constructDietOrderActivity(tenantId, tenantCode, branchId, dietOrderId, buyGiveActivityBean.getActivityId(), buyGiveActivityBean.getActivityName(), buyGiveActivityBean.getActivityType(), BigDecimal.ZERO, userId, "保存订单活动信息!");
dietOrderActivityMap.put(buyGiveActivityBean.getActivityId(), dietOrderActivity);
}
}
}
}
if (CollectionUtils.isNotEmpty(giveDietOrderDetails)) {
DietOrderGroup giveDietOrderGroup = DietOrderUtils.constructDietOrderGroup(tenantId, tenantCode, branchId, dietOrderId, "赠品", "discount", userId, "保存订单分组信息!");
dietOrderGroupMapper.insert(giveDietOrderGroup);
for (DietOrderDetail giveDietOrderDetail : giveDietOrderDetails) {
giveDietOrderDetail.setDietOrderGroupId(giveDietOrderGroup.getId());
}
dietOrderDetailMapper.insertAll(giveDietOrderDetails);
}
// 处理整单优惠活动
FullReductionActivityBean fullReductionActivityBean = DietOrderUtils.findFullReductionActivityBean(dietOrderTotalAmount, tenantId.toString(), branchId.toString());
if (fullReductionActivityBean != null) {
Integer discountType = fullReductionActivityBean.getDiscountType();
BigDecimal fullReductionActivityDiscountAmount = null;
if (discountType == 1) {
fullReductionActivityDiscountAmount = fullReductionActivityBean.getDiscountAmount();
} else if (discountType == 2) {
fullReductionActivityDiscountAmount = dietOrderTotalAmount.multiply(fullReductionActivityBean.getDiscountRate()).divide(HUNDRED);
}
dietOrderDiscountAmount = dietOrderDiscountAmount.add(fullReductionActivityDiscountAmount);
DietOrderActivity dietOrderActivity = DietOrderUtils.constructDietOrderActivity(tenantId, tenantCode, branchId, dietOrderId, fullReductionActivityBean.getActivityId(), fullReductionActivityBean.getActivityName(), fullReductionActivityBean.getActivityType(), fullReductionActivityDiscountAmount.multiply(MINUS_ONE), userId, "保存订单活动信息!");
dietOrderActivityMap.put(fullReductionActivityBean.getActivityId(), dietOrderActivity);
}
if (MapUtils.isNotEmpty(dietOrderActivityMap)) {
dietOrderActivityMapper.insertAll(new ArrayList<DietOrderActivity>(dietOrderActivityMap.values()));
}
dietOrder.setTotalAmount(dietOrderTotalAmount);
dietOrder.setDiscountAmount(dietOrderDiscountAmount);
dietOrder.setPayableAmount(dietOrderTotalAmount.subtract(dietOrderDiscountAmount));
dietOrder.setPaidAmount(BigDecimal.ZERO);
dietOrderMapper.update(dietOrder);
Map<String, Object> data = new HashMap<String, Object>();
data.put("id", dietOrder.getId());
data.put("orderNumber", dietOrder.getOrderNumber());
return new ApiRest(data, "保存订单成功!");
}
use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class GoodsService method saveGoods.
/**
* 保存菜品信息
*
* @param saveGoodsModel
* @return
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest saveGoods(SaveGoodsModel saveGoodsModel) {
BigInteger tenantId = saveGoodsModel.getTenantId();
String tenantCode = saveGoodsModel.getTenantCode();
BigInteger branchId = saveGoodsModel.getBranchId();
BigInteger userId = saveGoodsModel.getUserId();
if (saveGoodsModel.getId() != null) {
BigInteger goodsId = saveGoodsModel.getId();
SearchModel goodsSearchModel = new SearchModel(true);
goodsSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, goodsId);
Goods goods = goodsMapper.find(goodsSearchModel);
Validate.notNull(goods, "商品不存在!");
// 验证商品是否可以编辑
validateCanNotOperate(tenantId, branchId, "goods", goodsId, 1);
goods.setName(saveGoodsModel.getName());
goods.setCategoryId(saveGoodsModel.getCategoryId());
goods.setImageUrl(saveGoodsModel.getImageUrl());
goodsMapper.update(goods);
// 删除需要删除的规格
if (CollectionUtils.isNotEmpty(saveGoodsModel.getDeleteGoodsSpecificationIds())) {
UpdateModel updateModel = new UpdateModel(true);
updateModel.setTableName("goods_specification");
updateModel.addContentValue("last_update_user_id", userId);
updateModel.addContentValue("last_update_remark", "删除商品规格信息!");
updateModel.addContentValue("deleted", 1);
updateModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
updateModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
updateModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, saveGoodsModel.getDeleteGoodsSpecificationIds());
universalMapper.universalUpdate(updateModel);
}
// 删除需要删除的口味组及其下的口味
if (CollectionUtils.isNotEmpty(saveGoodsModel.getDeleteGoodsFlavorGroupIds())) {
UpdateModel deleteGoodsFlavorGroupUpdateModel = new UpdateModel(true);
deleteGoodsFlavorGroupUpdateModel.setTableName("goods_flavor_group");
deleteGoodsFlavorGroupUpdateModel.addContentValue("last_update_user_id", userId);
deleteGoodsFlavorGroupUpdateModel.addContentValue("last_update_remark", "删除商品口味组信息!");
deleteGoodsFlavorGroupUpdateModel.addContentValue("delete", 1);
deleteGoodsFlavorGroupUpdateModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
deleteGoodsFlavorGroupUpdateModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
deleteGoodsFlavorGroupUpdateModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, saveGoodsModel.getDeleteGoodsFlavorGroupIds());
universalMapper.universalUpdate(deleteGoodsFlavorGroupUpdateModel);
UpdateModel deleteGoodsFlavorUpdateModel = new UpdateModel(true);
deleteGoodsFlavorUpdateModel.setTableName("goods_flavor");
deleteGoodsFlavorUpdateModel.addContentValue("last_update_user_id", userId);
deleteGoodsFlavorUpdateModel.addContentValue("last_update_remark", "删除商品口味信息!");
deleteGoodsFlavorUpdateModel.addContentValue("delete", 1);
deleteGoodsFlavorUpdateModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
deleteGoodsFlavorUpdateModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
deleteGoodsFlavorUpdateModel.addSearchCondition("goods_flavor_group_id", Constants.SQL_OPERATION_SYMBOL_IN, saveGoodsModel.getDeleteGoodsFlavorGroupIds());
universalMapper.universalUpdate(deleteGoodsFlavorUpdateModel);
}
// 查询出需要修改的商品规格
List<SaveGoodsModel.GoodsSpecificationInfo> goodsSpecificationInfos = saveGoodsModel.getGoodsSpecificationInfos();
List<BigInteger> goodsSpecificationIds = new ArrayList<BigInteger>();
for (SaveGoodsModel.GoodsSpecificationInfo goodsSpecificationInfo : goodsSpecificationInfos) {
if (goodsSpecificationInfo.getId() != null) {
goodsSpecificationIds.add(goodsSpecificationInfo.getId());
}
}
Map<BigInteger, GoodsSpecification> goodsSpecificationMap = new HashMap<BigInteger, GoodsSpecification>();
if (CollectionUtils.isNotEmpty(goodsSpecificationIds)) {
SearchModel searchModel = new SearchModel(true);
searchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
searchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
searchModel.addSearchCondition("goods_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, goodsId);
searchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsSpecificationIds);
List<GoodsSpecification> goodsSpecifications = goodsSpecificationMapper.findAll(searchModel);
for (GoodsSpecification goodsSpecification : goodsSpecifications) {
goodsSpecificationMap.put(goodsSpecification.getId(), goodsSpecification);
}
}
// 处理所有规格,修改与更新
for (SaveGoodsModel.GoodsSpecificationInfo goodsSpecificationInfo : goodsSpecificationInfos) {
List<GoodsSpecification> insertGoodsSpecifications = new ArrayList<GoodsSpecification>();
if (goodsSpecificationInfo.getId() != null) {
GoodsSpecification goodsSpecification = goodsSpecificationMap.get(goodsSpecificationInfo.getId());
Validate.notNull(goodsSpecification, "商品规格不存在!");
goodsSpecification.setName(goodsSpecificationInfo.getName());
goodsSpecification.setPrice(goodsSpecificationInfo.getPrice());
goodsSpecificationMapper.update(goodsSpecification);
} else {
GoodsSpecification goodsSpecification = buildGoodsSpecification(tenantId, tenantCode, branchId, goodsId, goodsSpecificationInfo, userId);
insertGoodsSpecifications.add(goodsSpecification);
}
if (CollectionUtils.isNotEmpty(insertGoodsSpecifications)) {
goodsSpecificationMapper.insertAll(insertGoodsSpecifications);
}
}
List<SaveGoodsModel.FlavorGroupInfo> flavorGroupInfos = saveGoodsModel.getFlavorGroupInfos();
if (CollectionUtils.isNotEmpty(flavorGroupInfos)) {
// 用来保存需要修改的口味组id
List<BigInteger> goodsFlavorGroupIds = new ArrayList<BigInteger>();
// 用来保存需要删除的口味id
List<BigInteger> deleteGoodsFlavorIds = new ArrayList<BigInteger>();
// 用来保存需要修改的口味id
List<BigInteger> goodsFlavorIds = new ArrayList<BigInteger>();
for (SaveGoodsModel.FlavorGroupInfo goodsFlavorGroupInfo : flavorGroupInfos) {
if (goodsFlavorGroupInfo.getId() != null) {
goodsFlavorGroupIds.add(goodsFlavorGroupInfo.getId());
if (CollectionUtils.isNotEmpty(goodsFlavorGroupInfo.getDeleteGoodsFlavorIds())) {
deleteGoodsFlavorIds.addAll(goodsFlavorGroupInfo.getDeleteGoodsFlavorIds());
}
for (SaveGoodsModel.FlavorInfo flavorGroupInfo : goodsFlavorGroupInfo.getFlavorInfos()) {
if (flavorGroupInfo.getId() != null) {
goodsFlavorIds.add(flavorGroupInfo.getId());
}
}
}
}
// 删除需要删除的口味
if (CollectionUtils.isNotEmpty(deleteGoodsFlavorIds)) {
UpdateModel deleteGoodsFlavorUpdateModel = new UpdateModel(true);
deleteGoodsFlavorUpdateModel.setTableName("goods_flavor");
deleteGoodsFlavorUpdateModel.addContentValue("last_update_user_id", userId);
deleteGoodsFlavorUpdateModel.addContentValue("last_update_remark", "删除商品口味信息!");
deleteGoodsFlavorUpdateModel.addContentValue("delete", 1);
deleteGoodsFlavorUpdateModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
deleteGoodsFlavorUpdateModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
deleteGoodsFlavorUpdateModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, deleteGoodsFlavorIds);
universalMapper.universalUpdate(deleteGoodsFlavorUpdateModel);
}
// 查询出需要修改的口味组
SearchModel goodsFlavorGroupSearchModel = new SearchModel(true);
goodsFlavorGroupSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsFlavorGroupSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsFlavorGroupSearchModel.addSearchCondition("goods_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, goodsId);
goodsFlavorGroupSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsFlavorGroupIds);
List<GoodsFlavorGroup> goodsFlavorGroups = goodsFlavorGroupMapper.findAll(goodsFlavorGroupSearchModel);
Map<BigInteger, GoodsFlavorGroup> goodsFlavorGroupMap = new HashMap<BigInteger, GoodsFlavorGroup>();
for (GoodsFlavorGroup goodsFlavorGroup : goodsFlavorGroups) {
goodsFlavorGroupMap.put(goodsFlavorGroup.getId(), goodsFlavorGroup);
}
// 查询出需要修改的口味
SearchModel goodsFlavorSearchModel = new SearchModel(true);
goodsFlavorSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsFlavorSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
goodsFlavorSearchModel.addSearchCondition("goods_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, goodsId);
goodsFlavorSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsFlavorIds);
List<GoodsFlavor> goodsFlavors = goodsFlavorMapper.findAll(goodsFlavorSearchModel);
Map<BigInteger, GoodsFlavor> goodsFlavorMap = new HashMap<BigInteger, GoodsFlavor>();
for (GoodsFlavor goodsFlavor : goodsFlavors) {
goodsFlavorMap.put(goodsFlavor.getId(), goodsFlavor);
}
for (SaveGoodsModel.FlavorGroupInfo flavorGroupInfo : flavorGroupInfos) {
// 用来保存需要新增的口味,便于批量插入
List<GoodsFlavor> insertGoodsFlavors = new ArrayList<GoodsFlavor>();
if (flavorGroupInfo.getId() != null) {
GoodsFlavorGroup goodsFlavorGroup = goodsFlavorGroupMap.get(flavorGroupInfo.getId());
Validate.notNull(goodsFlavorGroup, "口味组不存在!");
goodsFlavorGroup.setName(flavorGroupInfo.getName());
goodsFlavorGroup.setLastUpdateUserId(userId);
goodsFlavorGroup.setLastUpdateRemark("修改口味组信息!");
goodsFlavorGroupMapper.update(goodsFlavorGroup);
for (SaveGoodsModel.FlavorInfo flavorInfo : flavorGroupInfo.getFlavorInfos()) {
if (flavorInfo.getId() != null) {
GoodsFlavor goodsFlavor = goodsFlavorMap.get(flavorInfo.getId());
Validate.notNull(goodsFlavor, "商品口味不存在!");
goodsFlavor.setName(flavorInfo.getName());
goodsFlavor.setPrice(flavorInfo.getPrice() == null ? BigDecimal.ZERO : flavorInfo.getPrice());
goodsFlavor.setLastUpdateUserId(userId);
goodsFlavor.setLastUpdateRemark("修改口味信息!");
goodsFlavorMapper.update(goodsFlavor);
} else {
GoodsFlavor goodsFlavor = buildGoodsFlavor(flavorInfo, tenantId, tenantCode, branchId, goodsId, goodsFlavorGroup.getId(), userId);
insertGoodsFlavors.add(goodsFlavor);
// goodsFlavorMapper.insert(goodsFlavor);
}
}
} else {
GoodsFlavorGroup goodsFlavorGroup = buildGoodsFlavorGroup(tenantId, tenantCode, branchId, goodsId, flavorGroupInfo, userId);
goodsFlavorGroupMapper.insert(goodsFlavorGroup);
for (SaveGoodsModel.FlavorInfo flavorInfo : flavorGroupInfo.getFlavorInfos()) {
GoodsFlavor goodsFlavor = buildGoodsFlavor(flavorInfo, tenantId, tenantCode, branchId, goodsId, goodsFlavorGroup.getId(), userId);
insertGoodsFlavors.add(goodsFlavor);
// goodsFlavorMapper.insert(goodsFlavor);
}
}
if (CollectionUtils.isNotEmpty(insertGoodsFlavors)) {
goodsFlavorMapper.insertAll(insertGoodsFlavors);
}
}
}
} else {
// 新增商品
Goods goods = new Goods();
goods.setTenantId(tenantId);
goods.setTenantCode(tenantCode);
goods.setBranchId(branchId);
goods.setName(saveGoodsModel.getName());
goods.setType(saveGoodsModel.getType());
goods.setCategoryId(saveGoodsModel.getCategoryId());
goods.setImageUrl(saveGoodsModel.getImageUrl());
goods.setCreateUserId(userId);
goods.setLastUpdateUserId(userId);
goods.setLastUpdateRemark("新增商品信息!");
goodsMapper.insert(goods);
BigInteger goodsId = goods.getId();
// 新增所有规格
List<GoodsSpecification> insertGoodsSpecifications = new ArrayList<GoodsSpecification>();
List<SaveGoodsModel.GoodsSpecificationInfo> goodsSpecificationInfos = saveGoodsModel.getGoodsSpecificationInfos();
for (SaveGoodsModel.GoodsSpecificationInfo goodsSpecificationInfo : goodsSpecificationInfos) {
GoodsSpecification goodsSpecification = buildGoodsSpecification(tenantId, tenantCode, branchId, goodsId, goodsSpecificationInfo, userId);
insertGoodsSpecifications.add(goodsSpecification);
}
goodsSpecificationMapper.insertAll(insertGoodsSpecifications);
List<SaveGoodsModel.FlavorGroupInfo> flavorGroupInfos = saveGoodsModel.getFlavorGroupInfos();
if (CollectionUtils.isNotEmpty(flavorGroupInfos)) {
List<GoodsFlavor> insertGoodsFlavors = new ArrayList<GoodsFlavor>();
for (SaveGoodsModel.FlavorGroupInfo flavorGroupInfo : flavorGroupInfos) {
GoodsFlavorGroup goodsFlavorGroup = buildGoodsFlavorGroup(tenantId, tenantCode, branchId, goodsId, flavorGroupInfo, userId);
goodsFlavorGroupMapper.insert(goodsFlavorGroup);
for (SaveGoodsModel.FlavorInfo flavorInfo : flavorGroupInfo.getFlavorInfos()) {
GoodsFlavor goodsFlavor = buildGoodsFlavor(flavorInfo, tenantId, tenantCode, branchId, goodsId, goodsFlavorGroup.getId(), userId);
insertGoodsFlavors.add(goodsFlavor);
}
}
goodsFlavorMapper.insertAll(insertGoodsFlavors);
}
}
ApiRest apiRest = new ApiRest();
apiRest.setMessage("保存商品信息成功!");
apiRest.setSuccessful(true);
return apiRest;
}
use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class GoodsService method deleteGoodsSpecification.
/**
* 删除菜品规格
* @param deleteGoodsSpecificationModel
* @return
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest deleteGoodsSpecification(DeleteGoodsSpecificationModel deleteGoodsSpecificationModel) {
SearchModel searchModel = new SearchModel(true);
searchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, deleteGoodsSpecificationModel.getGoodsSpecificationId());
searchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, deleteGoodsSpecificationModel.getTenantId());
searchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, deleteGoodsSpecificationModel.getBranchId());
GoodsSpecification goodsSpecification = goodsSpecificationMapper.find(searchModel);
Validate.notNull(goodsSpecification, "菜品规格不存在!");
goodsSpecification.setDeleted(true);
goodsSpecification.setLastUpdateUserId(deleteGoodsSpecificationModel.getUserId());
goodsSpecification.setLastUpdateRemark("删除菜品规格信息!");
goodsSpecificationMapper.update(goodsSpecification);
ApiRest apiRest = new ApiRest();
apiRest.setMessage("删除菜品规格成功!");
apiRest.setSuccessful(true);
return apiRest;
}
use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class ActivityService method saveSpecialGoodsActivity.
/**
* 保存特价商品活动
*
* @param saveSpecialGoodsActivityModel
* @return
* @throws ParseException
*/
public ApiRest saveSpecialGoodsActivity(SaveSpecialGoodsActivityModel saveSpecialGoodsActivityModel) throws ParseException {
BigInteger tenantId = saveSpecialGoodsActivityModel.getTenantId();
String tenantCode = saveSpecialGoodsActivityModel.getTenantCode();
BigInteger branchId = saveSpecialGoodsActivityModel.getBranchId();
BigInteger userId = saveSpecialGoodsActivityModel.getUserId();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.DEFAULT_DATE_PATTERN);
Date startTime = simpleDateFormat.parse(saveSpecialGoodsActivityModel.getStartTime() + " 00:00:00");
Date endTime = simpleDateFormat.parse(saveSpecialGoodsActivityModel.getEndTime() + " 23:59:59");
Validate.isTrue(endTime.after(startTime), "活动结束时间必须大于开始时间!");
String sql = "SELECT * " + "FROM activity " + "WHERE tenant_id = #{tenantId} " + "AND branch_id = #{branchId} " + "AND deleted = 0 " + "AND type = 3 " + "AND status IN (1, 2) " + "AND ((start_time <= #{startTime} AND end_time >= #{endTime}) OR (start_time >= #{startTime} AND start_time <= #{endTime}) OR (end_time >= #{startTime} AND end_time <= #{endTime})) " + "LIMIT 0, 1";
Map<String, Object> findActivityParameters = new HashMap<String, Object>();
findActivityParameters.put("sql", sql);
findActivityParameters.put("tenantId", tenantId);
findActivityParameters.put("branchId", branchId);
findActivityParameters.put("startTime", startTime);
findActivityParameters.put("endTime", endTime);
Map<String, Object> activityMap = universalMapper.executeUniqueResultQuery(findActivityParameters);
if (MapUtils.isNotEmpty(activityMap)) {
throw new RuntimeException("活动日期与促销活动【" + activityMap.get("name") + "】在时间上冲突!");
}
List<SaveSpecialGoodsActivityModel.SpecialGoodsActivityInfo> specialGoodsActivityInfos = saveSpecialGoodsActivityModel.getSpecialGoodsActivityInfos();
List<BigInteger> goodsIds = new ArrayList<BigInteger>();
List<BigInteger> goodsSpecificationIds = new ArrayList<BigInteger>();
for (SaveSpecialGoodsActivityModel.SpecialGoodsActivityInfo specialGoodsActivityInfo : specialGoodsActivityInfos) {
goodsIds.add(specialGoodsActivityInfo.getGoodsId());
goodsSpecificationIds.add(specialGoodsActivityInfo.getGoodsSpecificationId());
}
// 查询出涉及的所有商品
SearchModel goodsSearchModel = new SearchModel(true);
goodsSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsIds);
goodsSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
List<Goods> goodses = goodsMapper.findAll(goodsSearchModel);
// 封装商品id与商品之间的map
Map<BigInteger, Goods> goodsMap = new HashMap<BigInteger, Goods>();
for (Goods goods : goodses) {
goodsMap.put(goods.getId(), goods);
}
SearchModel canNotOperateReasonSearchModel = new SearchModel();
canNotOperateReasonSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
canNotOperateReasonSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
canNotOperateReasonSearchModel.addSearchCondition("table_id", Constants.SQL_OPERATION_SYMBOL_IN, goodsIds);
canNotOperateReasonSearchModel.addSearchCondition("operate_type", Constants.SQL_OPERATION_SYMBOL_EQUALS, 4);
CanNotOperateReason persistenceCanNotOperateReason = canNotOperateReasonMapper.find(canNotOperateReasonSearchModel);
if (persistenceCanNotOperateReason != null) {
Goods goods = goodsMap.get(persistenceCanNotOperateReason.getTableId());
Validate.notNull(goods, "商品不存在!");
throw new RuntimeException(String.format(persistenceCanNotOperateReason.getReason(), goods.getName()));
}
// 查询出涉及的所有商品规格
SearchModel goodsSpecificationSearchModel = new SearchModel(true);
goodsSpecificationSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_IN, goodsSpecificationIds);
goodsSpecificationSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
goodsSpecificationSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
List<GoodsSpecification> goodsSpecifications = goodsSpecificationMapper.findAll(goodsSpecificationSearchModel);
// 封装商品规格id与商品规格之间的map
Map<BigInteger, GoodsSpecification> goodsSpecificationMap = new HashMap<BigInteger, GoodsSpecification>();
for (GoodsSpecification goodsSpecification : goodsSpecifications) {
goodsSpecificationMap.put(goodsSpecification.getId(), goodsSpecification);
}
Activity activity = ActivityUtils.constructActivity(tenantId, tenantCode, branchId, saveSpecialGoodsActivityModel.getName(), 3, startTime, endTime, userId, "保存活动信息!");
activityMapper.insert(activity);
List<SpecialGoodsActivity> specialGoodsActivities = new ArrayList<SpecialGoodsActivity>();
List<CanNotOperateReason> canNotOperateReasons = new ArrayList<CanNotOperateReason>();
for (SaveSpecialGoodsActivityModel.SpecialGoodsActivityInfo specialGoodsActivityInfo : specialGoodsActivityInfos) {
Goods goods = goodsMap.get(specialGoodsActivityInfo.getGoodsId());
Validate.notNull(goods, "商品不存在!");
GoodsSpecification goodsSpecification = goodsSpecificationMap.get(specialGoodsActivityInfo.getGoodsSpecificationId());
Validate.notNull(goodsSpecification, "商品规格不存在!");
SpecialGoodsActivity specialGoodsActivity = new SpecialGoodsActivity();
specialGoodsActivity.setTenantId(tenantId);
specialGoodsActivity.setTenantCode(tenantCode);
specialGoodsActivity.setBranchId(branchId);
specialGoodsActivity.setActivityId(activity.getId());
specialGoodsActivity.setGoodsId(goods.getId());
specialGoodsActivity.setGoodsSpecificationId(goodsSpecification.getId());
int discountType = specialGoodsActivityInfo.getDiscountType();
specialGoodsActivity.setDiscountType(discountType);
if (discountType == 1) {
specialGoodsActivity.setSpecialPrice(specialGoodsActivityInfo.getSpecialPrice());
} else if (discountType == 2) {
specialGoodsActivity.setDiscountRate(specialGoodsActivityInfo.getDiscountRate());
}
specialGoodsActivity.setCreateUserId(userId);
specialGoodsActivity.setLastUpdateUserId(userId);
specialGoodsActivity.setLastUpdateRemark("保存特价商品活动!");
specialGoodsActivities.add(specialGoodsActivity);
String reason = "该商品已参与促销活动【" + activity.getName() + "】,活动期间不可%s!如需更改,请先取消活动!";
CanNotOperateReason canNotOperateReason = CanNotOperateReasonUtils.constructCanNotOperateReason(tenantId, tenantCode, branchId, goods.getId(), "goods", activity.getId(), "activity", 3, reason);
canNotOperateReasons.add(canNotOperateReason);
String usedOtherActivityReason = "商品【%s】已参与促销活动【" + activity.getName() + "】,不可参与其他促销活动!";
CanNotOperateReason canNotUsedOtherActivityReason = CanNotOperateReasonUtils.constructCanNotOperateReason(tenantId, tenantCode, branchId, goods.getId(), "goods", activity.getId(), "activity", 4, usedOtherActivityReason);
canNotOperateReasons.add(canNotUsedOtherActivityReason);
}
specialGoodsActivityMapper.insertAll(specialGoodsActivities);
canNotOperateReasonMapper.insertAll(canNotOperateReasons);
ApiRest apiRest = new ApiRest();
apiRest.setMessage("保存特价商品活动成功!");
apiRest.setSuccessful(true);
return apiRest;
}
use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class AnubisService method order.
/**
* 蜂鸟配送
*
* @param orderModel
* @return
* @throws IOException
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest order(OrderModel orderModel) throws IOException {
BigInteger tenantId = orderModel.getTenantId();
BigInteger branchId = orderModel.getBranchId();
BigInteger userId = orderModel.getUserId();
BigInteger dietOrderId = orderModel.getDietOrderId();
// 查询门店信息
SearchModel branchSearchModel = new SearchModel(true);
branchSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
branchSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
Branch branch = branchMapper.find(branchSearchModel);
Validate.notNull(branch, "门店不存在!");
// 查询订单信息
SearchModel dietOrderSearchModel = new SearchModel(true);
dietOrderSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
dietOrderSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
dietOrderSearchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, dietOrderId);
DietOrder dietOrder = dietOrderMapper.find(dietOrderSearchModel);
Validate.notNull(dietOrder, "订单不存在!");
SearchModel dietOrderGroupSearchModel = new SearchModel(true);
dietOrderGroupSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
dietOrderGroupSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
dietOrderGroupSearchModel.addSearchCondition("diet_order_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, dietOrderId);
List<DietOrderGroup> dietOrderGroups = dietOrderGroupMapper.findAll(dietOrderGroupSearchModel);
// 查询出订单详情信息
SearchModel dietOrderDetailSearchModel = new SearchModel(true);
dietOrderDetailSearchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, tenantId);
dietOrderDetailSearchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, branchId);
dietOrderDetailSearchModel.addSearchCondition("diet_order_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, dietOrderId);
List<DietOrderDetail> dietOrderDetails = dietOrderDetailMapper.findAll(dietOrderDetailSearchModel);
Map<String, Object> data = new HashMap<String, Object>();
ApplicationHandler.ifNotNullPut(data, "partner_remark", orderModel.getPartnerRemark());
data.put("partner_order_code", dietOrder.getOrderNumber());
String notifyUrl = SystemPartitionUtils.getUrl(ConfigurationUtils.getConfiguration(Constants.PARTITION_CODE), Constants.SERVICE_NAME_CATERING, "anubis", "anubisCallback");
data.put("notify_url", notifyUrl);
data.put("order_type", 1);
data.put("chain_store_code", branch.getTenantCode() + "Z" + branch.getCode());
Map<String, Object> transportInfo = new HashMap<String, Object>();
transportInfo.put("transport_name", branch.getTenantCode() + "Z" + branch.getCode() + "Z" + branch.getName());
transportInfo.put("transport_address", branch.getProvinceName() + branch.getCityName() + branch.getDistrictName() + branch.getAddress());
transportInfo.put("transport_longitude", branch.getLongitude());
transportInfo.put("transport_latitude", branch.getLatitude());
transportInfo.put("position_source", Constants.POSITION_SOURCE_BAIDU_MAP);
transportInfo.put("transport_tel", branch.getContactPhone());
ApplicationHandler.ifNotNullPut(transportInfo, "transport_remark", orderModel.getTransportRemark());
data.put("transport_info", transportInfo);
data.put("order_add_time", dietOrder.getActiveTime().getTime());
data.put("order_total_amount", dietOrder.getTotalAmount());
data.put("order_actual_amount", dietOrder.getPayableAmount());
data.put("order_weight", 1);
data.put("order_remark", dietOrder.getRemark());
boolean invoiced = dietOrder.isInvoiced();
data.put("is_invoiced", invoiced ? 1 : 0);
if (invoiced) {
data.put("invoice", dietOrder.getInvoice());
}
data.put("order_payment_status", 1);
data.put("order_payment_method", 1);
data.put("is_agent_payment", 0);
// 需要代收时客户应付金额
// data.put("require_payment_pay", 10);
data.put("goods_count", dietOrderGroups.size());
data.put("require_receive_time", dietOrder.getDeliverTime().getTime());
Map<String, Object> receiverInfo = new HashMap<String, Object>();
receiverInfo.put("receiver_name", dietOrder.getConsignee());
receiverInfo.put("receiver_primary_phone", dietOrder.getTelephoneNumber());
// 收货人备用联系方式
// receiverInfo.put("receiver_second_phone", dietOrder.getTelephoneNumber());
receiverInfo.put("receiver_address", dietOrder.getDeliveryAddress());
receiverInfo.put("receiver_longitude", dietOrder.getDeliveryLongitude());
receiverInfo.put("receiver_latitude", dietOrder.getDeliveryLatitude());
receiverInfo.put("position_source", Constants.POSITION_SOURCE_BAIDU_MAP);
data.put("receiver_info", receiverInfo);
List<Map<String, Object>> itemInfos = new ArrayList<Map<String, Object>>();
for (DietOrderDetail dietOrderDetail : dietOrderDetails) {
Map<String, Object> itemInfo = new HashMap<String, Object>();
itemInfo.put("item_id", dietOrderDetail.getGoodsId() + "_" + dietOrderDetail.getGoodsSpecificationId());
String itemName = dietOrderDetail.getGoodsName();
if (StringUtils.isNotBlank(dietOrderDetail.getGoodsSpecificationName())) {
itemName = itemName + "_" + dietOrderDetail.getGoodsSpecificationName();
}
itemInfo.put("item_name", itemName);
itemInfo.put("item_quantity", dietOrderDetail.getQuantity());
itemInfo.put("item_price", dietOrderDetail.getTotalAmount());
itemInfo.put("item_actual_price", dietOrderDetail.getPayableAmount());
// 商品尺寸
// itemInfo.put("item_size", 10);
// 商品备注
// itemInfo.put("item_remark", "商品备注");
itemInfo.put("is_need_package", 0);
itemInfo.put("is_agent_purchase", 0);
// 代购进价, 如果需要代购 此项必填
// itemInfo.put("agent_purchase_price", 10);
itemInfos.add(itemInfo);
}
data.put("items_json", itemInfos);
data.put("serial_number", dietOrder.getDaySerialNumber());
String url = ConfigurationUtils.getConfiguration(Constants.ANUBIS_SERVICE_URL) + Constants.ANUBIS_ORDER_URI;
String appId = ConfigurationUtils.getConfiguration(Constants.ANUBIS_APP_ID);
ApiRest apiRest = AnubisUtils.callAnubisSystem(url, appId, data);
return apiRest;
}
Aggregations