use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class BranchService method handleRenewCallback.
/**
* 处理门店续费回调
*
* @param renewCallbackModel
* @return
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest handleRenewCallback(RenewCallbackModel renewCallbackModel) {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("sql", renewCallbackModel.getRenewSql());
parameters.put("tenantId", renewCallbackModel.getTenantId());
parameters.put("branchId", renewCallbackModel.getBranchId());
universalMapper.executeUpdate(parameters);
ApiRest apiRest = new ApiRest();
apiRest.setMessage("处理门店续费回调成功!");
apiRest.setSuccessful(true);
return apiRest;
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class BranchService method deleteBranch.
/**
* 删除门店信息
*
* @param deleteBranchModel
* @return
* @throws IOException
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest deleteBranch(DeleteBranchModel deleteBranchModel) throws IOException {
SearchModel searchModel = new SearchModel(true);
searchModel.addSearchCondition("id", Constants.SQL_OPERATION_SYMBOL_EQUALS, deleteBranchModel.getBranchId());
searchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, deleteBranchModel.getTenantId());
Branch branch = branchMapper.find(searchModel);
Validate.notNull(branch, "门店不存在!");
branch.setDeleted(true);
branch.setLastUpdateUserId(deleteBranchModel.getUserId());
branch.setLastUpdateRemark("删除门店信息!");
branchMapper.update(branch);
String findUserIdsSql = "SELECT user_id FROM merge_user_branch WHERE tenant_id = #{tenantId} AND branch_id = #{branchId} AND deleted = 0";
Map<String, Object> findUserIdsParameters = new HashMap<String, Object>();
findUserIdsParameters.put("sql", findUserIdsSql);
findUserIdsParameters.put("tenantId", deleteBranchModel.getTenantId());
findUserIdsParameters.put("branchId", deleteBranchModel.getBranchId());
List<Map<String, Object>> results = universalMapper.executeQuery(findUserIdsParameters);
List<BigInteger> userIds = new ArrayList<BigInteger>();
for (Map<String, Object> map : results) {
userIds.add(BigInteger.valueOf(MapUtils.getLongValue(map, "userId")));
}
String deleteMergeUserBranchSql = "UPDATE merge_user_branch SET deleted = 1 WHERE tenant_id = #{tenantId} AND branch_id = #{branchId} AND deleted = 0";
Map<String, Object> deleteMergeUserBranchParameters = new HashMap<String, Object>();
deleteMergeUserBranchParameters.put("sql", deleteMergeUserBranchSql);
deleteMergeUserBranchParameters.put("tenantId", deleteBranchModel.getTenantId());
deleteMergeUserBranchParameters.put("branchId", deleteBranchModel.getBranchId());
universalMapper.executeUpdate(deleteMergeUserBranchParameters);
Map<String, String> batchDeleteUserRequestParameters = new HashMap<String, String>();
batchDeleteUserRequestParameters.put("userIds", StringUtils.join(userIds, ","));
ApiRest batchDeleteUserApiRest = ProxyUtils.doPostWithRequestParameters(Constants.SERVICE_NAME_PLATFORM, "user", "batchDeleteUser", batchDeleteUserRequestParameters);
Validate.isTrue(batchDeleteUserApiRest.isSuccessful(), batchDeleteUserApiRest.getError());
ApiRest apiRest = new ApiRest();
apiRest.setMessage("删除门店信息成功!");
apiRest.setSuccessful(true);
return apiRest;
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class DataService method uploadData.
public ApiRest uploadData(UploadDataModel uploadDataModel) throws IOException {
String deploymentEnvironment = ConfigurationUtils.getConfiguration(Constants.DEPLOYMENT_ENVIRONMENT);
String partitionCode = ConfigurationUtils.getConfiguration(Constants.PARTITION_CODE);
String key = null;
String dataType = uploadDataModel.getDataType();
if (Constants.DATA_TYPE_DIET_ORDER.equals(dataType)) {
key = deploymentEnvironment + "_" + partitionCode + "_" + Constants.DIET_ORDER;
}
QueueUtils.rpush(key, uploadDataModel.getData());
ApiRest apiRest = new ApiRest();
apiRest.setMessage("数据上传成功!");
apiRest.setSuccessful(true);
return apiRest;
}
use of build.dream.common.api.ApiRest 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.api.ApiRest in project erp-catering by liuyandong33.
the class ElemeService method batchGetDeliveryStates.
/**
* 批量获取订单配送记录
*
* @param batchGetDeliveryStatesModel
* @return
* @throws IOException
*/
@Transactional(readOnly = true)
public ApiRest batchGetDeliveryStates(BatchGetDeliveryStatesModel batchGetDeliveryStatesModel) throws IOException {
BigInteger tenantId = batchGetDeliveryStatesModel.getTenantId();
BigInteger branchId = batchGetDeliveryStatesModel.getBranchId();
Branch branch = findBranch(tenantId, branchId);
List<ElemeOrder> elemeOrders = findAllElemeOrders(tenantId, branchId, batchGetDeliveryStatesModel.getElemeOrderIds());
List<String> orderIds = obtainOrderIds(elemeOrders);
Map<String, Object> params = new HashMap<String, Object>();
params.put("orderIds", orderIds);
ApiRest callElemeSystemApiRest = ElemeUtils.callElemeSystem(tenantId.toString(), branchId.toString(), branch.getElemeAccountType(), "eleme.order.batchGetDeliveryStates", params);
Validate.isTrue(callElemeSystemApiRest.isSuccessful(), callElemeSystemApiRest.getError());
return new ApiRest(callElemeSystemApiRest.getData(), "批量获取订单配送记录成功!");
}
Aggregations