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.BanLiShopGoodsImgMapper;
|
import com.yeshi.fanli.entity.shop.BanLiShopGoods;
|
import com.yeshi.fanli.entity.shop.BanLiShopGoodsImg;
|
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsImgService;
|
import com.yeshi.fanli.util.StringUtil;
|
|
@Service
|
public class BanLiShopGoodsImgServiceImpl implements BanLiShopGoodsImgService {
|
|
@Resource
|
private BanLiShopGoodsImgMapper banLiShopGoodsImgMapper;
|
|
// 添加图片
|
@Override
|
public void addImg(String pictureUrl, Long goodsId) {
|
if (StringUtil.isNullOrEmpty(pictureUrl) || goodsId == null) {
|
return;
|
}
|
String imgMD5 = StringUtil.Md5(pictureUrl);
|
BanLiShopGoodsImg img = new BanLiShopGoodsImg();
|
img.setCreateTime(new Date());
|
img.setGoods(new BanLiShopGoods(goodsId));
|
img.setUrl(pictureUrl);
|
img.setUrlMD5(imgMD5);
|
banLiShopGoodsImgMapper.insertSelective(img);
|
if (img.getWeight() == null) {
|
BanLiShopGoodsImg update = new BanLiShopGoodsImg();
|
update.setId(img.getId());
|
update.setWeight((int) img.getId().longValue());
|
banLiShopGoodsImgMapper.updateByPrimaryKeySelective(update);
|
}
|
}
|
|
@Override
|
public List<BanLiShopGoodsImg> listByGoodsId(Long goodsId) {
|
return banLiShopGoodsImgMapper.listByGoodsId(goodsId);
|
}
|
|
@Override
|
public BanLiShopGoodsImg selectByPrimaryKey(Long id) {
|
return banLiShopGoodsImgMapper.selectByPrimaryKey(id);
|
}
|
|
@Override
|
public void updateSelectiveByPrimaryKey(BanLiShopGoodsImg img) {
|
if (img == null || img.getId() == null)
|
return;
|
banLiShopGoodsImgMapper.updateByPrimaryKeySelective(img);
|
}
|
|
@Transactional
|
@Override
|
public void delete(List<Long> idsList) {
|
if (idsList != null)
|
for (Long id : idsList)
|
deleteByPrimaryKey(id);
|
}
|
|
@Override
|
public void deleteByPrimaryKey(Long id) {
|
banLiShopGoodsImgMapper.deleteByPrimaryKey(id);
|
}
|
|
}
|