package com.yeshi.fanli.service.impl.homemodule;
|
|
import java.io.InputStream;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.UUID;
|
|
import javax.annotation.Resource;
|
import javax.transaction.Transactional;
|
|
import org.springframework.stereotype.Service;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import com.yeshi.fanli.dao.mybatis.homemodule.SwiperPictureMapper;
|
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
|
import com.yeshi.fanli.exception.banner.SwiperPictureException;
|
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
|
import com.yeshi.fanli.util.StringUtil;
|
|
import org.yeshi.utils.tencentcloud.COSManager;
|
|
@Service
|
public class SwiperPictureServiceImpl implements SwiperPictureService {
|
|
@Resource
|
private SwiperPictureMapper swiperPictureMapper;
|
|
@Override
|
public int deleteByPrimaryKey(Long id) throws SwiperPictureException{
|
return swiperPictureMapper.deleteByPrimaryKey(id);
|
}
|
|
@Override
|
public int insert(SwiperPicture record) throws SwiperPictureException{
|
return swiperPictureMapper.insert(record);
|
}
|
|
@Override
|
public int insertSelective(SwiperPicture record) throws SwiperPictureException{
|
return swiperPictureMapper.insertSelective(record);
|
}
|
|
@Override
|
public SwiperPicture selectByPrimaryKey(Long id) throws SwiperPictureException{
|
return swiperPictureMapper.selectByPrimaryKey(id);
|
}
|
|
@Override
|
public int updateByPrimaryKeySelective(SwiperPicture record) throws SwiperPictureException{
|
return swiperPictureMapper.updateByPrimaryKeySelective(record);
|
}
|
|
@Override
|
public int updateByPrimaryKey(SwiperPicture record) throws SwiperPictureException{
|
return swiperPictureMapper.updateByPrimaryKey(record);
|
}
|
|
@Override
|
public List<SwiperPicture> queryByBannerID(long start, int count, Long bannerId) throws SwiperPictureException{
|
return swiperPictureMapper.queryByBannerID(start, count, bannerId);
|
}
|
|
@Override
|
public long countQueryByBannerID(Long bannerId) throws SwiperPictureException{
|
return swiperPictureMapper.countQueryByBannerID(bannerId);
|
}
|
|
@Override
|
@Transactional
|
public int deleteBatchByPrimaryKey(List<Long> list) throws SwiperPictureException{
|
|
List<SwiperPicture> listSwiper = swiperPictureMapper.queryByListPrimaryKey(list);
|
for (SwiperPicture swiperPicture: listSwiper) {
|
String src = swiperPicture.getSrc();
|
if (!StringUtil.isNullOrEmpty(src)) {
|
COSManager.getInstance().deleteFile(src);
|
}
|
}
|
|
return swiperPictureMapper.deleteBatchByPrimaryKey(list);
|
}
|
|
@Override
|
public int deleteBatchByBannerID(List<Long> list) throws SwiperPictureException{
|
return swiperPictureMapper.deleteBatchByBannerID(list);
|
}
|
|
@Override
|
public List<SwiperPicture> queryByListBannerID(List<Long> list) throws Exception{
|
return swiperPictureMapper.queryByListBannerID(list);
|
}
|
|
@Override
|
public void uploadPicture(MultipartFile file, SwiperPicture record) throws Exception {
|
|
InputStream inputStream = file.getInputStream();
|
String contentType = file.getContentType();
|
String type = contentType.substring(contentType.indexOf("/") + 1);
|
// 上传文件相对位置
|
String fileUrl="swiperPic/"+UUID.randomUUID().toString().replace("-", "") + "." + type;
|
|
/* 修改图片时,先删除已存在图片 */
|
String src = record.getSrc();
|
if (!StringUtil.isNullOrEmpty(src)) {
|
COSManager.getInstance().deleteFile(src);
|
}
|
|
String uploadFilePath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
|
|
/* 更新数据库信息 */
|
if (!StringUtil.isNullOrEmpty(uploadFilePath)) {
|
record.setSrc(uploadFilePath);
|
record.setUpdatetime(new Date());
|
updateByPrimaryKeySelective(record);
|
}
|
}
|
|
@Override
|
public List<SwiperPicture> getOrderByBannerID(Long bannerId, Integer type, Integer order) throws SwiperPictureException {
|
return swiperPictureMapper.getOrderByBannerID(bannerId, type, order);
|
}
|
|
@Override
|
public int getMaxOrderByBannerID(Long bannerId) throws SwiperPictureException {
|
return swiperPictureMapper.getMaxOrderByBannerID(bannerId);
|
}
|
|
@Override
|
public List<SwiperPicture> getByBannerCard(String card) throws SwiperPictureException {
|
return swiperPictureMapper.getByBannerCard(card);
|
}
|
|
}
|
|