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.BanLiShopGoodsSetsMapper;
|
import com.yeshi.fanli.entity.shop.BanLiShopGoodsSets;
|
import com.yeshi.fanli.entity.shop.BanLiShopGoodsSetsPay;
|
import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetException;
|
import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException;
|
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetPayService;
|
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetService;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Service
|
public class BanLiShopGoodsSetServiceImpl implements BanLiShopGoodsSetService {
|
|
@Resource
|
private BanLiShopGoodsSetPayService banLiShopGoodsSetPayService;
|
|
@Resource
|
private BanLiShopGoodsSetsMapper banLiShopGoodsSetsMapper;
|
|
@Override
|
public List<BanLiShopGoodsSets> listByGoodsId(Long goodsId) {
|
return banLiShopGoodsSetsMapper.listByGoodsId(goodsId);
|
}
|
|
@Override
|
public int countByGoodsId(Long goodsId) {
|
return (int) banLiShopGoodsSetsMapper.countByGoodsId(goodsId);
|
}
|
|
@Override
|
public BanLiShopGoodsSets selectByPrimaryKey(Long id) {
|
return banLiShopGoodsSetsMapper.selectByPrimaryKey(id);
|
}
|
|
@Transactional(rollbackFor=Exception.class)
|
@Override
|
public void addSet(BanLiShopGoodsSets set) throws BanLiShopGoodsSetException, BanLiShopGoodsSetPayException {
|
if (set.getId() == null)// 添加
|
{
|
if (set.getGoods() == null || set.getGoods().getId() == null) {
|
throw new BanLiShopGoodsSetException(1, "请指定商品");
|
}
|
|
if (StringUtil.isNullOrEmpty(set.getName()))
|
throw new BanLiShopGoodsSetException(1, "缺少套餐名字");
|
|
if (set.getOriginalPrice() == null || set.getZkPrice() == null) {
|
throw new BanLiShopGoodsSetException(1, "价格信息不完整");
|
}
|
|
if (set.getStock() == null) {
|
throw new BanLiShopGoodsSetException(1, "缺少库存信息");
|
}
|
|
if (set.getSalesCount() == null)
|
set.setSalesCount(0L);
|
|
if (set.getCreateTime() == null)
|
set.setCreateTime(new Date());
|
|
banLiShopGoodsSetsMapper.insertSelective(set);
|
if (set.getWeight() == null) {// 权重更新
|
BanLiShopGoodsSets update = new BanLiShopGoodsSets();
|
update.setId(set.getId());
|
update.setWeight((int) set.getId().longValue());
|
banLiShopGoodsSetsMapper.updateByPrimaryKeySelective(update);
|
}
|
|
if (set.getPayList() != null && set.getPayList().size() > 0) {
|
for (BanLiShopGoodsSetsPay pay : set.getPayList())// 添加支付方式
|
{
|
pay.setGoodsSet(set);
|
banLiShopGoodsSetPayService.addSetPay(pay);
|
}
|
}
|
|
} else {// 修改
|
if (set.getUpdateTime() == null) {
|
set.setUpdateTime(new Date());
|
}
|
|
banLiShopGoodsSetsMapper.updateByPrimaryKeySelective(set);
|
|
// 更新支付方式
|
if (set.getPayList() != null && set.getPayList().size() > 0) {
|
for (BanLiShopGoodsSetsPay pay : set.getPayList())// 更新支付方式
|
banLiShopGoodsSetPayService.addSetPay(pay);
|
}
|
}
|
|
}
|
|
|
@Override
|
public void saveObject(BanLiShopGoodsSets record) throws BanLiShopGoodsSetException {
|
if (record.getGoods() == null || record.getGoods().getId() == null)
|
throw new BanLiShopGoodsSetException(1, "请指定商品");
|
|
if (StringUtil.isNullOrEmpty(record.getName()))
|
throw new BanLiShopGoodsSetException(1, "缺少套餐名字");
|
|
if (record.getOriginalPrice() == null || record.getZkPrice() == null)
|
throw new BanLiShopGoodsSetException(1, "价格信息不完整");
|
|
if (record.getStock() == null)
|
throw new BanLiShopGoodsSetException(1, "缺少库存信息");
|
|
record.setUpdateTime(new Date());
|
if (record.getId() == null) {
|
record.setCreateTime(new Date());
|
banLiShopGoodsSetsMapper.insertSelective(record);
|
|
if (record.getWeight() == null) {// 权重更新
|
BanLiShopGoodsSets update = new BanLiShopGoodsSets();
|
update.setId(record.getId());
|
update.setWeight((int) record.getId().longValue());
|
banLiShopGoodsSetsMapper.updateByPrimaryKeySelective(update);
|
}
|
} else {
|
BanLiShopGoodsSets resultObj = banLiShopGoodsSetsMapper.selectDetailByPrimaryKey(record.getId());
|
if (resultObj == null)
|
throw new BanLiShopGoodsSetException(1, "修改内容已不存在");
|
|
record.setCreateTime(resultObj.getCreateTime());
|
banLiShopGoodsSetsMapper.updateByPrimaryKey(record);
|
}
|
}
|
|
|
@Override
|
public void switchState(Long id) throws BanLiShopGoodsSetException {
|
if (id == null) {
|
throw new BanLiShopGoodsSetException(1, "请传递正确参数");
|
}
|
BanLiShopGoodsSets resultObj = banLiShopGoodsSetsMapper.selectByPrimaryKey(id);
|
if (resultObj == null) {
|
throw new BanLiShopGoodsSetException(1, "此内容已不存在");
|
}
|
|
Integer state = resultObj.getState();
|
if (state == null || state == 0) {
|
state = 1;
|
} else {
|
state = 0;
|
}
|
|
BanLiShopGoodsSets updateObj = new BanLiShopGoodsSets();
|
updateObj.setId(id);
|
updateObj.setState(state);
|
banLiShopGoodsSetsMapper.updateByPrimaryKeySelective(updateObj);
|
}
|
|
@Override
|
public void updateSelectiveByPrimaryKey(BanLiShopGoodsSets set) {
|
if (set.getId() == null)
|
return;
|
if (set.getUpdateTime() == null)
|
set.setUpdateTime(new Date());
|
banLiShopGoodsSetsMapper.updateByPrimaryKeySelective(set);
|
}
|
|
@Transactional
|
@Override
|
public void delete(List<Long> idsList) {
|
if (idsList != null)
|
for (Long id : idsList)
|
deleteByPrimaryKey(id);
|
}
|
|
@Transactional
|
@Override
|
public void deleteByPrimaryKey(Long id) {
|
banLiShopGoodsSetsMapper.deleteByPrimaryKey(id);
|
List<BanLiShopGoodsSetsPay> payList = banLiShopGoodsSetPayService.listByGoodsSetId(id);
|
if (payList != null)
|
for (BanLiShopGoodsSetsPay pay : payList) {// 删除支付方式
|
banLiShopGoodsSetPayService.deleteByPrimaryKey(pay.getId());
|
}
|
}
|
|
@Override
|
public List<BanLiShopGoodsSets> listQuery(int page, int pageSize, String key, Long goodsId) {
|
return banLiShopGoodsSetsMapper.listQuery((page - 1) * pageSize, pageSize, key, goodsId);
|
}
|
|
@Override
|
public long countQuery(String key, Long goodsId) {
|
return banLiShopGoodsSetsMapper.countQuery(key, goodsId);
|
}
|
|
@Override
|
public void addSalesCount(Long id, int count) {
|
BanLiShopGoodsSets set = banLiShopGoodsSetsMapper.selectByPrimaryKey(id);
|
BanLiShopGoodsSets update = new BanLiShopGoodsSets();
|
update.setId(set.getId());
|
update.setSalesCount(set.getSalesCount() + count);
|
update.setStock(set.getStock() - count);
|
banLiShopGoodsSetsMapper.updateByPrimaryKeySelective(update);
|
}
|
|
}
|