Search in sources :

Example 21 with SearchModel

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, "查询菜品分类成功!");
}
Also used : SearchModel(build.dream.common.utils.SearchModel) ArrayList(java.util.ArrayList) ZTreeNode(build.dream.catering.beans.ZTreeNode) ApiRest(build.dream.common.api.ApiRest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with SearchModel

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;
}
Also used : SearchModel(build.dream.common.utils.SearchModel) SaveBuyGiveActivityModel(build.dream.catering.models.activity.SaveBuyGiveActivityModel) ApiRest(build.dream.common.api.ApiRest) BigInteger(java.math.BigInteger) SimpleDateFormat(java.text.SimpleDateFormat) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SearchModel (build.dream.common.utils.SearchModel)22 ApiRest (build.dream.common.api.ApiRest)19 Transactional (org.springframework.transaction.annotation.Transactional)17 BigInteger (java.math.BigInteger)16 JSONObject (net.sf.json.JSONObject)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)3 Pos (build.dream.common.erp.catering.domains.Pos)2 Vip (build.dream.common.erp.catering.domains.Vip)2 UpdateModel (build.dream.common.utils.UpdateModel)2 HashMap (java.util.HashMap)2 BuyGiveActivityBean (build.dream.catering.beans.BuyGiveActivityBean)1 FullReductionActivityBean (build.dream.catering.beans.FullReductionActivityBean)1 SpecialGoodsActivityBean (build.dream.catering.beans.SpecialGoodsActivityBean)1 ZTreeNode (build.dream.catering.beans.ZTreeNode)1 CanNotDeleteException (build.dream.catering.exceptions.CanNotDeleteException)1 CanNotEditAndDeleteException (build.dream.catering.exceptions.CanNotEditAndDeleteException)1 CanNotEditException (build.dream.catering.exceptions.CanNotEditException)1 SaveBuyGiveActivityModel (build.dream.catering.models.activity.SaveBuyGiveActivityModel)1 SaveSpecialGoodsActivityModel (build.dream.catering.models.activity.SaveSpecialGoodsActivityModel)1