From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/shop/BanLiShopGoodsServiceImpl.java |  580 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 290 insertions(+), 290 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 ced65cf..356f38a 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,290 +1,290 @@
-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;
-import com.yeshi.fanli.entity.shop.BanLiShopGoodsImg;
-import com.yeshi.fanli.entity.shop.BanLiShopGoodsSets;
-import com.yeshi.fanli.exception.shop.BanLiShopGoodsException;
-import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetException;
-import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException;
-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
-public class BanLiShopGoodsServiceImpl implements BanLiShopGoodsService {
-
-	@Resource
-	private BanLiShopGoodsSetService banLiShopGoodsSetService;
-
-	@Resource
-	private BanLiShopGoodsImgService banLiShopGoodsImgService;
-
-	@Resource
-	private BanLiShopGoodsMapper banLiShopGoodsMapper;
-
-	@Override
-	public List<BanLiShopGoods> listGoods(String key, Integer state, int page, int pageSize) {
-		return banLiShopGoodsMapper.listGoods(key, state, (page - 1) * pageSize, pageSize);
-	}
-
-	@Override
-	public long countGoods(String key, Integer state) {
-		return banLiShopGoodsMapper.countGoods(key, state);
-	}
-
-	@Override
-	public BanLiShopGoods getGoodsDetail(Long goodsId) {
-		return banLiShopGoodsMapper.selectDetailByPrimaryKey(goodsId);
-	}
-
-	@Override
-	public BanLiShopGoods selectByPrimaryKey(Long id) {
-		return banLiShopGoodsMapper.selectByPrimaryKey(id);
-	}
-
-	@Override
-	public void addGoods(BanLiShopGoods goods)
-			throws BanLiShopGoodsException, BanLiShopGoodsSetException, BanLiShopGoodsSetPayException {
-		if (goods.getId() == null) {// 鏂板
-			if (goods.getGoodsClass() == null || goods.getGoodsClass().getId() == null) {
-				throw new BanLiShopGoodsSetException(1, "璇锋寚瀹氬晢鍝佸垎绫�");
-			}
-
-			if (StringUtil.isNullOrEmpty(goods.getTitle()))
-				throw new BanLiShopGoodsSetException(1, "缂哄皯鏍囬");
-
-			if (StringUtil.isNullOrEmpty(goods.getPicture()))
-				throw new BanLiShopGoodsSetException(1, "缂哄皯灏侀潰鍥�");
-
-			// 榛樿涓婄嚎
-			if (goods.getState() == null)
-				goods.setState(BanLiShopGoods.STATE_ONLINE);
-
-			if (goods.getSalesCount() == null)
-				goods.setSalesCount(0L);
-
-			if (goods.getCreateTime() == null)
-				goods.setCreateTime(new Date());
-
-			banLiShopGoodsMapper.insertSelective(goods);
-			if (goods.getWeight() == null) {// 鏉冮噸鏇存柊
-				BanLiShopGoods update = new BanLiShopGoods();
-				update.setId(goods.getId());
-				update.setWeight((int) goods.getId().longValue());
-				banLiShopGoodsMapper.updateByPrimaryKeySelective(update);
-			}
-
-			if (goods.getSetsList() != null && goods.getSetsList().size() > 0) {
-				for (BanLiShopGoodsSets set : goods.getSetsList())// 鏇存柊鏀粯鏂瑰紡
-				{
-					set.setGoods(goods);
-					banLiShopGoodsSetService.addSet(set);
-				}
-			}
-
-			// TODO 鏇存敼鍥剧墖
-			if (goods.getImgList() != null)
-				for (BanLiShopGoodsImg img : goods.getImgList()) {
-					banLiShopGoodsImgService.addImg(img.getUrl(), goods.getId());
-				}
-
-		} else {// 淇敼
-			updateSelectiveByPrimaryKey(goods);
-			// 鏇存柊鏀粯鏂瑰紡
-			if (goods.getSetsList() != null && goods.getSetsList().size() > 0) {
-				// 鍒犻櫎鍘熸湁濂楅
-				List<BanLiShopGoodsSets> setList = banLiShopGoodsSetService.listByGoodsId(goods.getId());
-				for (BanLiShopGoodsSets set : setList)
-					banLiShopGoodsSetService.deleteByPrimaryKey(set.getId());
-
-				// 娣诲姞鏂扮殑濂楅
-				for (BanLiShopGoodsSets set : goods.getSetsList())// 鏇存柊鏀粯鏂瑰紡
-					banLiShopGoodsSetService.addSet(set);
-			}
-
-			// 鏇存柊鍥剧墖
-			if (goods.getImgList() != null && goods.getImgList().size() > 0) {
-				// 鍒犻櫎鍘熸湁鍥剧墖
-				List<BanLiShopGoodsImg> imgList = banLiShopGoodsImgService.listByGoodsId(goods.getId());
-				for (BanLiShopGoodsImg img : imgList)
-					banLiShopGoodsImgService.deleteByPrimaryKey(img.getId());
-				// 娣诲姞鏂扮殑鍥剧墖
-				for (BanLiShopGoodsImg img : goods.getImgList())// 鏇存柊鏀粯鏂瑰紡
-					banLiShopGoodsImgService.addImg(img.getUrl(), goods.getId());
-			}
-
-		}
-
-	}
-
-	
-	@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);
-		}
-	}
-	
-	
-	@Override
-	public void switchState(Long id) throws BanLiShopGoodsException {
-		if (id == null) {
-			throw new BanLiShopGoodsException(1, "璇蜂紶閫掓纭弬鏁�");
-		}
-		BanLiShopGoods resultObj = banLiShopGoodsMapper.selectByPrimaryKey(id);
-		if (resultObj == null) {
-			throw new BanLiShopGoodsException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
-		}
-		
-		Integer state = resultObj.getState();
-		if (state == null || state == 0) {
-			state = 1;
-		} else {
-			state = 0;
-		}
-		
-		BanLiShopGoods updateObj = new BanLiShopGoods();
-		updateObj.setId(id);
-		updateObj.setState(state);
-		banLiShopGoodsMapper.updateByPrimaryKeySelective(updateObj);
-	}
-	
-	
-
-	/**
-	 * 涓婁紶鍥剧墖
-	 * @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
-	@Override
-	public void delete(List<Long> idsList) {
-		if (idsList != null)
-			for (Long id : idsList)
-				deleteByPrimaryKey(id);
-
-	}
-	
-	
-	
-
-	@Transactional
-	@Override
-	public void deleteByPrimaryKey(Long id) {
-		banLiShopGoodsMapper.deleteByPrimaryKey(id);
-		List<BanLiShopGoodsSets> setList = banLiShopGoodsSetService.listByGoodsId(id);
-		if (setList != null)
-			for (BanLiShopGoodsSets set : setList)
-				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);
-
-		}
-	}
-
-}
+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;
+import com.yeshi.fanli.entity.shop.BanLiShopGoodsImg;
+import com.yeshi.fanli.entity.shop.BanLiShopGoodsSets;
+import com.yeshi.fanli.exception.shop.BanLiShopGoodsException;
+import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetException;
+import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException;
+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
+public class BanLiShopGoodsServiceImpl implements BanLiShopGoodsService {
+
+	@Resource
+	private BanLiShopGoodsSetService banLiShopGoodsSetService;
+
+	@Resource
+	private BanLiShopGoodsImgService banLiShopGoodsImgService;
+
+	@Resource
+	private BanLiShopGoodsMapper banLiShopGoodsMapper;
+
+	@Override
+	public List<BanLiShopGoods> listGoods(String key, Integer state, int page, int pageSize) {
+		return banLiShopGoodsMapper.listGoods(key, state, (page - 1) * pageSize, pageSize);
+	}
+
+	@Override
+	public long countGoods(String key, Integer state) {
+		return banLiShopGoodsMapper.countGoods(key, state);
+	}
+
+	@Override
+	public BanLiShopGoods getGoodsDetail(Long goodsId) {
+		return banLiShopGoodsMapper.selectDetailByPrimaryKey(goodsId);
+	}
+
+	@Override
+	public BanLiShopGoods selectByPrimaryKey(Long id) {
+		return banLiShopGoodsMapper.selectByPrimaryKey(id);
+	}
+
+	@Override
+	public void addGoods(BanLiShopGoods goods)
+			throws BanLiShopGoodsException, BanLiShopGoodsSetException, BanLiShopGoodsSetPayException {
+		if (goods.getId() == null) {// 鏂板
+			if (goods.getGoodsClass() == null || goods.getGoodsClass().getId() == null) {
+				throw new BanLiShopGoodsSetException(1, "璇锋寚瀹氬晢鍝佸垎绫�");
+			}
+
+			if (StringUtil.isNullOrEmpty(goods.getTitle()))
+				throw new BanLiShopGoodsSetException(1, "缂哄皯鏍囬");
+
+			if (StringUtil.isNullOrEmpty(goods.getPicture()))
+				throw new BanLiShopGoodsSetException(1, "缂哄皯灏侀潰鍥�");
+
+			// 榛樿涓婄嚎
+			if (goods.getState() == null)
+				goods.setState(BanLiShopGoods.STATE_ONLINE);
+
+			if (goods.getSalesCount() == null)
+				goods.setSalesCount(0L);
+
+			if (goods.getCreateTime() == null)
+				goods.setCreateTime(new Date());
+
+			banLiShopGoodsMapper.insertSelective(goods);
+			if (goods.getWeight() == null) {// 鏉冮噸鏇存柊
+				BanLiShopGoods update = new BanLiShopGoods();
+				update.setId(goods.getId());
+				update.setWeight((int) goods.getId().longValue());
+				banLiShopGoodsMapper.updateByPrimaryKeySelective(update);
+			}
+
+			if (goods.getSetsList() != null && goods.getSetsList().size() > 0) {
+				for (BanLiShopGoodsSets set : goods.getSetsList())// 鏇存柊鏀粯鏂瑰紡
+				{
+					set.setGoods(goods);
+					banLiShopGoodsSetService.addSet(set);
+				}
+			}
+
+			// TODO 鏇存敼鍥剧墖
+			if (goods.getImgList() != null)
+				for (BanLiShopGoodsImg img : goods.getImgList()) {
+					banLiShopGoodsImgService.addImg(img.getUrl(), goods.getId());
+				}
+
+		} else {// 淇敼
+			updateSelectiveByPrimaryKey(goods);
+			// 鏇存柊鏀粯鏂瑰紡
+			if (goods.getSetsList() != null && goods.getSetsList().size() > 0) {
+				// 鍒犻櫎鍘熸湁濂楅
+				List<BanLiShopGoodsSets> setList = banLiShopGoodsSetService.listByGoodsId(goods.getId());
+				for (BanLiShopGoodsSets set : setList)
+					banLiShopGoodsSetService.deleteByPrimaryKey(set.getId());
+
+				// 娣诲姞鏂扮殑濂楅
+				for (BanLiShopGoodsSets set : goods.getSetsList())// 鏇存柊鏀粯鏂瑰紡
+					banLiShopGoodsSetService.addSet(set);
+			}
+
+			// 鏇存柊鍥剧墖
+			if (goods.getImgList() != null && goods.getImgList().size() > 0) {
+				// 鍒犻櫎鍘熸湁鍥剧墖
+				List<BanLiShopGoodsImg> imgList = banLiShopGoodsImgService.listByGoodsId(goods.getId());
+				for (BanLiShopGoodsImg img : imgList)
+					banLiShopGoodsImgService.deleteByPrimaryKey(img.getId());
+				// 娣诲姞鏂扮殑鍥剧墖
+				for (BanLiShopGoodsImg img : goods.getImgList())// 鏇存柊鏀粯鏂瑰紡
+					banLiShopGoodsImgService.addImg(img.getUrl(), goods.getId());
+			}
+
+		}
+
+	}
+
+	
+	@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);
+		}
+	}
+	
+	
+	@Override
+	public void switchState(Long id) throws BanLiShopGoodsException {
+		if (id == null) {
+			throw new BanLiShopGoodsException(1, "璇蜂紶閫掓纭弬鏁�");
+		}
+		BanLiShopGoods resultObj = banLiShopGoodsMapper.selectByPrimaryKey(id);
+		if (resultObj == null) {
+			throw new BanLiShopGoodsException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�");
+		}
+		
+		Integer state = resultObj.getState();
+		if (state == null || state == 0) {
+			state = 1;
+		} else {
+			state = 0;
+		}
+		
+		BanLiShopGoods updateObj = new BanLiShopGoods();
+		updateObj.setId(id);
+		updateObj.setState(state);
+		banLiShopGoodsMapper.updateByPrimaryKeySelective(updateObj);
+	}
+	
+	
+
+	/**
+	 * 涓婁紶鍥剧墖
+	 * @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
+	@Override
+	public void delete(List<Long> idsList) {
+		if (idsList != null)
+			for (Long id : idsList)
+				deleteByPrimaryKey(id);
+
+	}
+	
+	
+	
+
+	@Transactional
+	@Override
+	public void deleteByPrimaryKey(Long id) {
+		banLiShopGoodsMapper.deleteByPrimaryKey(id);
+		List<BanLiShopGoodsSets> setList = banLiShopGoodsSetService.listByGoodsId(id);
+		if (setList != null)
+			for (BanLiShopGoodsSets set : setList)
+				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