admin
2024-10-16 62a447d89331aee1feae7724c7616aa1bb2cfe79
fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsSetPayServiceImpl.java
@@ -1,100 +1,156 @@
package com.yeshi.fanli.service.impl.shop;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsSetsPayMapper;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsSetsPay;
import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetPayService;
@Service
public class BanLiShopGoodsSetPayServiceImpl implements BanLiShopGoodsSetPayService {
   @Resource
   private BanLiShopGoodsSetsPayMapper banLiShopGoodsSetsPayMapper;
   @Override
   public List<BanLiShopGoodsSetsPay> listByGoodsSetId(Long goodsSetId) {
      return banLiShopGoodsSetsPayMapper.listByGoodsSetId(goodsSetId);
   }
   @Override
   public int countByGoodsSetId(Long goodsSetId) {
      return (int) banLiShopGoodsSetsPayMapper.countByGoodsSetId(goodsSetId);
   }
   @Override
   public BanLiShopGoodsSetsPay selectByPrimaryKey(Long id) {
      return banLiShopGoodsSetsPayMapper.selectByPrimaryKey(id);
   }
   @Transactional
   @Override
   public void addSetPay(BanLiShopGoodsSetsPay pay) throws BanLiShopGoodsSetPayException {
      if (pay.getId() == null)// 新增
      {
         // 判断参数是否齐全
         if (pay.getGoodsSet() == null || pay.getGoodsSet().getId() == null)
            throw new BanLiShopGoodsSetPayException(1, "套餐不存在");
         if (pay.getPayType() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定支付方式");
         if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO) {
            if (pay.getHongBaoPrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_BALANCE) {
            if (pay.getBalancePrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO_MONEY) {
            if (pay.getHongBaoPrice() == null || pay.getMoneyPrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_MONEY) {
            if (pay.getMoneyPrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         }
         if (pay.getCreateTime() == null)
            pay.setCreateTime(new Date());
         banLiShopGoodsSetsPayMapper.insertSelective(pay);
         if (pay.getWeight() == null) {// 权重更新
            BanLiShopGoodsSetsPay update = new BanLiShopGoodsSetsPay();
            update.setId(pay.getId());
            update.setWeight((int) pay.getId().longValue());
            banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(update);
         }
      } else {// 修改
         updateSelectiveByPrimaryKey(pay);
      }
   }
   @Override
   public void updateSelectiveByPrimaryKey(BanLiShopGoodsSetsPay pay) {
      if (pay.getId() == null)
         return;
      if (pay.getUpdateTime() == null)
         pay.setUpdateTime(new Date());
      banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(pay);
   }
   @Transactional
   @Override
   public void delete(List<Long> idsList) {
      if (idsList != null)
         for (Long id : idsList)
            deleteByPrimaryKey(id);
   }
   @Override
   public void deleteByPrimaryKey(Long id) {
      banLiShopGoodsSetsPayMapper.deleteByPrimaryKey(id);
   }
}
package com.yeshi.fanli.service.impl.shop;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsSetsPayMapper;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsSetsPay;
import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetPayService;
@Service
public class BanLiShopGoodsSetPayServiceImpl implements BanLiShopGoodsSetPayService {
   @Resource
   private BanLiShopGoodsSetsPayMapper banLiShopGoodsSetsPayMapper;
   @Override
   public List<BanLiShopGoodsSetsPay> listByGoodsSetId(Long goodsSetId) {
      return banLiShopGoodsSetsPayMapper.listByGoodsSetId(goodsSetId);
   }
   @Override
   public int countByGoodsSetId(Long goodsSetId) {
      return (int) banLiShopGoodsSetsPayMapper.countByGoodsSetId(goodsSetId);
   }
   @Override
   public BanLiShopGoodsSetsPay selectByPrimaryKey(Long id) {
      return banLiShopGoodsSetsPayMapper.selectByPrimaryKey(id);
   }
   @Transactional(rollbackFor=Exception.class)
   @Override
   public void addSetPay(BanLiShopGoodsSetsPay pay) throws BanLiShopGoodsSetPayException {
      if (pay.getId() == null)// 新增
      {
         // 判断参数是否齐全
         if (pay.getGoodsSet() == null || pay.getGoodsSet().getId() == null)
            throw new BanLiShopGoodsSetPayException(1, "套餐不存在");
         if (pay.getPayType() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定支付方式");
         if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO) {
            if (pay.getHongBaoPrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_BALANCE) {
            if (pay.getBalancePrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO_MONEY) {
            if (pay.getHongBaoPrice() == null || pay.getMoneyPrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_MONEY) {
            if (pay.getMoneyPrice() == null)
               throw new BanLiShopGoodsSetPayException(1, "请指定价格");
         }
         if (pay.getCreateTime() == null)
            pay.setCreateTime(new Date());
         banLiShopGoodsSetsPayMapper.insertSelective(pay);
         if (pay.getWeight() == null) {// 权重更新
            BanLiShopGoodsSetsPay update = new BanLiShopGoodsSetsPay();
            update.setId(pay.getId());
            update.setWeight((int) pay.getId().longValue());
            banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(update);
         }
      } else {// 修改
         updateSelectiveByPrimaryKey(pay);
      }
   }
   @Override
   public void saveObject(BanLiShopGoodsSetsPay record) throws BanLiShopGoodsSetPayException {
      // 判断参数是否齐全
      if (record.getGoodsSet() == null || record.getGoodsSet().getId() == null)
         throw new BanLiShopGoodsSetPayException(1, "套餐不存在");
      if (record.getPayType() == null)
         throw new BanLiShopGoodsSetPayException(1, "请指定支付方式");
      if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO) {
         if (record.getHongBaoPrice() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定红包支付价格");
      } else if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_BALANCE) {
         if (record.getBalancePrice() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定余额支付价格");
      } else if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO_MONEY) {
         if (record.getHongBaoPrice() == null || record.getMoneyPrice() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定红包、现金支付价格");
      } else if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_MONEY) {
         if (record.getMoneyPrice() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定现金支付价格");
      }
      record.setUpdateTime(new Date());
      if (record.getId() == null) {
         record.setCreateTime(new Date());
         banLiShopGoodsSetsPayMapper.insertSelective(record);
         if (record.getWeight() == null) {// 权重更新
            BanLiShopGoodsSetsPay update = new BanLiShopGoodsSetsPay();
            update.setId(record.getId());
            update.setWeight((int) record.getId().longValue());
            banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(update);
         }
      } else {
         BanLiShopGoodsSetsPay resultObj = banLiShopGoodsSetsPayMapper.selectByPrimaryKey(record.getId());
         if (resultObj == null)
            throw new BanLiShopGoodsSetPayException(1, "修改内容已不存在");
         record.setCreateTime(resultObj.getCreateTime());
         banLiShopGoodsSetsPayMapper.updateByPrimaryKey(record);
      }
   }
   @Override
   public void updateSelectiveByPrimaryKey(BanLiShopGoodsSetsPay pay) {
      if (pay.getId() == null)
         return;
      if (pay.getUpdateTime() == null)
         pay.setUpdateTime(new Date());
      banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(pay);
   }
   @Transactional
   @Override
   public void delete(List<Long> idsList) {
      if (idsList != null)
         for (Long id : idsList)
            deleteByPrimaryKey(id);
   }
   @Override
   public void deleteByPrimaryKey(Long id) {
      banLiShopGoodsSetsPayMapper.deleteByPrimaryKey(id);
   }
   @Override
   public List<BanLiShopGoodsSetsPay> listQuery(int page, int pageSize, String key, Integer payType, Long setId) {
      return banLiShopGoodsSetsPayMapper.listQuery((page - 1) * pageSize, pageSize, key, payType, setId);
   }
   @Override
   public long countQuery(String key, Integer payType, Long setId) {
      return banLiShopGoodsSetsPayMapper.countQuery(key, payType, setId);
   }
}