use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class GoodsService method listCategories.
@Transactional(readOnly = true)
public ApiRest listCategories(ListCategoriesModel listCategoriesModel) {
SearchModel searchModel = new SearchModel(true);
searchModel.addSearchCondition("tenant_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, listCategoriesModel.getTenantId());
searchModel.addSearchCondition("branch_id", Constants.SQL_OPERATION_SYMBOL_EQUALS, listCategoriesModel.getBranchId());
List<GoodsCategory> goodsCategories = goodsCategoryMapper.findAll(searchModel);
List<ZTreeNode> zTreeNodes = new ArrayList<ZTreeNode>();
for (GoodsCategory goodsCategory : goodsCategories) {
zTreeNodes.add(new ZTreeNode(goodsCategory.getId().toString(), goodsCategory.getName(), goodsCategory.getParentId().toString()));
}
return new ApiRest(zTreeNodes, "查询菜品分类成功!");
}
use of build.dream.common.utils.SearchModel in project erp-catering by liuyandong33.
the class ActivityService method saveBuyGiveActivity.
@Transactional(rollbackFor = Exception.class)
public ApiRest saveBuyGiveActivity(SaveBuyGiveActivityModel saveBuyGiveActivityModel) throws ParseException {
BigInteger tenantId = saveBuyGiveActivityModel.getTenantId();
String tenantCode = saveBuyGiveActivityModel.getTenantCode();
BigInteger branchId = saveBuyGiveActivityModel.getBranchId();
BigInteger userId = saveBuyGiveActivityModel.getUserId();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Constants.DEFAULT_DATE_PATTERN);
Date startTime = simpleDateFormat.parse(saveBuyGiveActivityModel.getStartTime() + " 00:00:00");
Date endTime = simpleDateFormat.parse(saveBuyGiveActivityModel.getEndTime() + " 23:59:59");
Validate.isTrue(endTime.after(startTime), "活动结束时间必须大于开始时间!");
List<SaveBuyGiveActivityModel.BuyGiveActivityInfo> buyGiveActivityInfos = saveBuyGiveActivityModel.getBuyGiveActivityInfos();
List<BigInteger> goodsIds = new ArrayList<BigInteger>();
List<BigInteger> goodsSpecificationIds = new ArrayList<BigInteger>();
for (SaveBuyGiveActivityModel.BuyGiveActivityInfo buyGiveActivityInfo : buyGiveActivityInfos) {
goodsIds.add(buyGiveActivityInfo.getBuyGoodsId());
goodsSpecificationIds.add(buyGiveActivityInfo.getBuyGoodsSpecificationId());
goodsIds.add(buyGiveActivityInfo.getGiveGoodsId());
goodsSpecificationIds.add(buyGiveActivityInfo.getGiveGoodsSpecificationId());
}
// 查询出涉及的所有商品
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, saveBuyGiveActivityModel.getName(), 1, startTime, endTime, userId, "保存活动信息!");
activityMapper.insert(activity);
List<BuyGiveActivity> buyGiveActivities = new ArrayList<BuyGiveActivity>();
List<CanNotOperateReason> canNotOperateReasons = new ArrayList<CanNotOperateReason>();
for (SaveBuyGiveActivityModel.BuyGiveActivityInfo buyGiveActivityInfo : buyGiveActivityInfos) {
Goods buyGoods = goodsMap.get(buyGiveActivityInfo.getBuyGoodsId());
Validate.notNull(buyGoods, "商品不存在!");
GoodsSpecification buyGoodsSpecification = goodsSpecificationMap.get(buyGiveActivityInfo.getBuyGoodsSpecificationId());
Validate.notNull(buyGoods, "商品规格不存在!");
Goods giveGoods = goodsMap.get(buyGiveActivityInfo.getGiveGoodsId());
Validate.notNull(buyGoods, "商品不存在!");
GoodsSpecification giveGoodsSpecification = goodsSpecificationMap.get(buyGiveActivityInfo.getGiveGoodsSpecificationId());
Validate.notNull(buyGoods, "商品规格不存在!");
BuyGiveActivity buyGiveActivity = new BuyGiveActivity();
buyGiveActivity.setTenantId(tenantId);
buyGiveActivity.setTenantCode(tenantCode);
buyGiveActivity.setBranchId(branchId);
buyGiveActivity.setActivityId(activity.getId());
buyGiveActivity.setBuyGoodsId(buyGoods.getId());
buyGiveActivity.setBuyGoodsSpecificationId(buyGoodsSpecification.getId());
buyGiveActivity.setBuyQuantity(buyGiveActivityInfo.getBuyQuantity());
buyGiveActivity.setGiveGoodsId(giveGoods.getId());
buyGiveActivity.setGiveGoodsSpecificationId(giveGoodsSpecification.getId());
buyGiveActivity.setGiveQuantity(buyGiveActivityInfo.getGiveQuantity());
buyGiveActivity.setCreateUserId(userId);
buyGiveActivity.setLastUpdateUserId(userId);
buyGiveActivity.setLastUpdateRemark("保存买A赠B活动!");
buyGiveActivities.add(buyGiveActivity);
String reason = "该商品已参与促销活动【" + activity.getName() + "】,活动期间不可%s!如需更改,请先取消活动!";
canNotOperateReasons.add(CanNotOperateReasonUtils.constructCanNotOperateReason(tenantId, tenantCode, tenantId, buyGoods.getId(), "goods", activity.getId(), "activity", 3, reason));
canNotOperateReasons.add(CanNotOperateReasonUtils.constructCanNotOperateReason(tenantId, tenantCode, tenantId, giveGoods.getId(), "goods", activity.getId(), "activity", 3, reason));
}
buyGiveActivityMapper.insertAll(buyGiveActivities);
canNotOperateReasonMapper.insertAll(canNotOperateReasons);
ApiRest apiRest = new ApiRest();
apiRest.setMessage("保存买A赠B活动成功!");
apiRest.setSuccessful(true);
return apiRest;
}
Aggregations