yujian
2020-04-02 0ec22dcf4fd9c4496e6f681e7fab89f56c6e4e8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
    }
 
}