use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class ElemeService method batchApplyCompensations.
/**
* 批量申请索赔
*
* @param batchApplyCompensations
* @return
* @throws IOException
*/
public ApiRest batchApplyCompensations(BatchApplyCompensationsModel batchApplyCompensations) throws IOException {
BigInteger tenantId = batchApplyCompensations.getTenantId();
BigInteger branchId = batchApplyCompensations.getBranchId();
Branch branch = findBranch(tenantId, branchId);
List<ElemeOrder> elemeOrders = findAllElemeOrders(tenantId, branchId, batchApplyCompensations.getElemeOrderIds());
Map<BigInteger, ElemeOrder> elemeOrderMap = new HashMap<BigInteger, ElemeOrder>();
for (ElemeOrder elemeOrder : elemeOrders) {
elemeOrderMap.put(elemeOrder.getId(), elemeOrder);
}
List<Map<String, Object>> requests = new ArrayList<Map<String, Object>>();
for (BatchApplyCompensationsModel.CompensationRequest compensationRequest : batchApplyCompensations.getRequests()) {
ElemeOrder elemeOrder = elemeOrderMap.get(compensationRequest.getElemeOrderId());
if (elemeOrder == null) {
continue;
}
Map<String, Object> request = new HashMap<String, Object>();
request.put("orderId", elemeOrder.getOrderId());
request.put("reason", compensationRequest.getReason());
request.put("description", compensationRequest.getDescription());
requests.add(request);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("requests", requests);
ApiRest callElemeSystemApiRest = ElemeUtils.callElemeSystem(tenantId.toString(), branchId.toString(), branch.getElemeAccountType(), "eleme.order.batchApplyCompensations", params);
Validate.isTrue(callElemeSystemApiRest.isSuccessful(), callElemeSystemApiRest.getError());
return new ApiRest(callElemeSystemApiRest.getData(), "批量申请索赔成功!");
}
use of build.dream.common.api.ApiRest in project erp-catering by liuyandong33.
the class ElemeService method deliveryBySelfLite.
/**
* 配送异常或者物流拒单后选择自行配送
*
* @param deliveryBySelfLiteModel
* @return
* @throws IOException
*/
public ApiRest deliveryBySelfLite(DeliveryBySelfLiteModel deliveryBySelfLiteModel) throws IOException {
BigInteger tenantId = deliveryBySelfLiteModel.getTenantId();
BigInteger branchId = deliveryBySelfLiteModel.getBranchId();
BigInteger elemeOrderId = deliveryBySelfLiteModel.getElemeOrderId();
Branch branch = findBranch(tenantId, branchId);
ElemeOrder elemeOrder = findElemeOrder(tenantId, branchId, elemeOrderId);
Map<String, Object> params = new HashMap<String, Object>();
params.put("orderId", elemeOrder.getOrderId());
ApiRest callElemeSystemApiRest = ElemeUtils.callElemeSystem(tenantId.toString(), branchId.toString(), branch.getElemeAccountType(), "eleme.order.deliveryBySelfLite", params);
Validate.isTrue(callElemeSystemApiRest.isSuccessful(), callElemeSystemApiRest.getError());
return new ApiRest(callElemeSystemApiRest.getData(), "配送异常或者物流拒单后选择自行配送成功!");
}
use of build.dream.common.api.ApiRest 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.api.ApiRest 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.api.ApiRest in project erp-catering by liuyandong33.
the class MeiTuanService method handleOrderRefundCallback.
/**
* 处理订单退款回调
*
* @param callbackParametersJsonObject
* @return
* @throws IOException
*/
@Transactional(rollbackFor = Exception.class)
public ApiRest handleOrderRefundCallback(JSONObject callbackParametersJsonObject, String uuid, int type) throws IOException {
String developerId = callbackParametersJsonObject.getString("developerId");
String ePoiId = callbackParametersJsonObject.getString("ePoiId");
String sign = callbackParametersJsonObject.getString("sign");
JSONObject orderRefundJsonObject = callbackParametersJsonObject.getJSONObject("orderCancel");
BigInteger orderId = BigInteger.valueOf(orderRefundJsonObject.getLong("orderId"));
MeiTuanOrder meiTuanOrder = findMeiTuanOrder(ePoiId, orderId);
String notifyType = orderRefundJsonObject.getString("notifyType");
int status = 0;
if ("agree".equals(notifyType)) {
} else if ("".equals(notifyType)) {
}
meiTuanOrder.setStatus(status);
meiTuanOrderMapper.update(meiTuanOrder);
// publishMeiTuanOrderMessage(meiTuanOrder.getTenantCode(), meiTuanOrder.getBranchCode(), meiTuanOrder.getId(), 2);
pushMeiTuanMessage(meiTuanOrder.getTenantId(), meiTuanOrder.getBranchId(), meiTuanOrder.getId(), type, uuid, 5, 60000);
ApiRest apiRest = new ApiRest();
apiRest.setMessage("美团订单退款回调处理成功!");
apiRest.setSuccessful(true);
return apiRest;
}
Aggregations