From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 18 一月 2020 12:06:27 +0800 Subject: [PATCH] 用户注册信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsServiceImpl.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 105 insertions(+), 0 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsServiceImpl.java index 9075634..f3837ac 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsServiceImpl.java @@ -1,12 +1,16 @@ package com.yeshi.fanli.service.impl.shop; +import java.io.InputStream; import java.util.Date; import java.util.List; +import java.util.UUID; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsMapper; import com.yeshi.fanli.entity.shop.BanLiShopGoods; @@ -18,6 +22,7 @@ import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsImgService; import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsService; import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetService; +import com.yeshi.fanli.util.FilePathEnum; import com.yeshi.fanli.util.StringUtil; @Service @@ -127,12 +132,100 @@ } + + @Override + public void saveObject(MultipartFile file, MultipartFile file2, BanLiShopGoods record) throws BanLiShopGoodsException, Exception{ + if (record.getGoodsClass() == null || record.getGoodsClass().getId() == null) + throw new BanLiShopGoodsException(1, "璇锋寚瀹氬晢鍝佸垎绫�"); + + if (StringUtil.isNullOrEmpty(record.getTitle())) + throw new BanLiShopGoodsException(1, "缂哄皯鏍囬"); + + if (file != null) + record.setPicture(uploadPicture(file)); + + if (file2 != null) + record.setSquarePicture(uploadPicture(file2)); + + if (record.getState() == null) + record.setState(BanLiShopGoods.STATE_ONLINE); + + if (record.getSalesCount() == null) + record.setSalesCount(0L); + + record.setUpdateTime(new Date()); + + if (record.getId() == null) { + if (StringUtil.isNullOrEmpty(record.getPicture())) + throw new BanLiShopGoodsException(1, "缂哄皯灏侀潰鍥�"); + + record.setCreateTime(new Date()); + banLiShopGoodsMapper.insertSelective(record); + } else { + BanLiShopGoods resultObj = banLiShopGoodsMapper.selectDetailByPrimaryKey(record.getId()); + if (resultObj == null) + throw new BanLiShopGoodsException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); + + if (StringUtil.isNullOrEmpty(record.getPicture())) { + record.setPicture(resultObj.getPicture()); + } else { + removePicture(resultObj.getPicture()); + } + + if (StringUtil.isNullOrEmpty(record.getSquarePicture())) { + record.setSquarePicture(resultObj.getSquarePicture()); + } else { + removePicture(resultObj.getSquarePicture()); + } + + if (StringUtil.isNullOrEmpty(record.getPicture())) + throw new BanLiShopGoodsException(1, "缂哄皯灏侀潰鍥�"); + + record.setCreateTime(resultObj.getCreateTime()); + banLiShopGoodsMapper.updateByPrimaryKey(record); + } + } + + + /** + * 涓婁紶鍥剧墖 + * @param file + * @return + * @throws Exception + */ + public String uploadPicture(MultipartFile file) throws Exception { + // 鏂囦欢瑙f瀽 + InputStream inputStream = file.getInputStream(); + String contentType = file.getContentType(); + String type = contentType.substring(contentType.indexOf("/") + 1); + // 鏂囦欢璺緞 + String filePath=FilePathEnum.banLiShopGoods.getPath() +UUID.randomUUID().toString().replace("-", "") + "." + type; + // 鎵ц涓婁紶 + String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + return fileLink; + } + + /** + * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱 + * @param record + * @throws Exception + */ + public void removePicture(String picture) throws Exception { + if (picture != null && picture.trim().length() > 0) { + COSManager.getInstance().deleteFile(picture); + } + } + + + @Override public void updateSelectiveByPrimaryKey(BanLiShopGoods goods) { if (goods == null || goods.getId() == null) return; if (goods.getUpdateTime() == null) goods.setUpdateTime(new Date()); + + banLiShopGoodsMapper.updateByPrimaryKeySelective(goods); } @Transactional @@ -154,4 +247,16 @@ banLiShopGoodsSetService.deleteByPrimaryKey(set.getId()); } + @Override + public void addSalesCount(Long id, int count) { + BanLiShopGoods goods = selectByPrimaryKey(id); + if (goods != null) { + BanLiShopGoods update = new BanLiShopGoods(id); + update.setSalesCount(goods.getSalesCount() + count); + update.setUpdateTime(new Date()); + updateSelectiveByPrimaryKey(goods); + + } + } + } -- Gitblit v1.8.0