From 70ebe043e6b62756be9e257fe954c747d46568b9 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 16 九月 2022 19:00:59 +0800
Subject: [PATCH] 商品ID字符串化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java |  323 +++++++++++++++++++++++++++--------------------------
 1 files changed, 164 insertions(+), 159 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java
index e677d83..12d50ba 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/CommonGoodsServiceImpl.java
@@ -1,10 +1,12 @@
 package com.yeshi.fanli.service.impl.goods;
 
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
 import javax.annotation.Resource;
 
+import com.yeshi.fanli.util.CommonGoodsUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.yeshi.utils.StringUtil;
@@ -17,168 +19,171 @@
 @Service
 public class CommonGoodsServiceImpl implements CommonGoodsService {
 
-	@Resource
-	private CommonGoodsMapper commonGoodsMapper;
-
-	
-	@Override
-	public CommonGoods selectByPrimaryKey(Long id) {
-		return commonGoodsMapper.selectByPrimaryKey(id);
-	}
-	
-	
-	
-	/**
-	 * 楠岃瘉鏁版嵁姝g‘鎬�
-	 * 
-	 * @param commonGoods
-	 * @throws CommonGoodsException
-	 */
-	private void filterCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
-		// 鍒ゆ柇淇℃伅鏄惁瀹屾垚
-		if (commonGoods == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓虹┖");
-		if (commonGoods.getGoodsId() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getGoodsType() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (StringUtil.isNullOrEmpty(commonGoods.getPicture()))
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getPrice() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getRate() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getSales() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getSellerId() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getSellerName() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (commonGoods.getShopType() == null)
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-		if (StringUtil.isNullOrEmpty(commonGoods.getTitle()))
-			throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
-	}
-
-	@Override
-	public CommonGoods addOrUpdateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
-		// 楠岃瘉鏁版嵁瀹屾暣鎬�
-		filterCommonGoods(commonGoods);
-		
-		CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(),
-				commonGoods.getGoodsType());
-		if (goods != null) {
-			updateCommonGoods(commonGoods);
-			commonGoods.setId(goods.getId());
-			return commonGoods;
-		}
-		commonGoods.setCreateTime(new Date());
-		commonGoods.setUpdateTime(new Date());
-		commonGoodsMapper.insertSelective(commonGoods);
-		return commonGoods;
-	}
-	
-	
-	@Override
-	public CommonGoods addCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
-		// 楠岃瘉鏁版嵁瀹屾暣鎬�
-		filterCommonGoods(commonGoods);
-		
-		CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(),
-				commonGoods.getGoodsType());
-		if (goods != null) {
-			commonGoods.setId(goods.getId());
-			return commonGoods;
-		}
-		commonGoods.setCreateTime(new Date());
-		commonGoods.setUpdateTime(new Date());
-		commonGoodsMapper.insertSelective(commonGoods);
-		return commonGoods;
-	}
+    @Resource
+    private CommonGoodsMapper commonGoodsMapper;
 
 
-	@Override
-	public void updateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
-		// 鍒ゆ柇淇℃伅鏄惁瀹屾暣
-		filterCommonGoods(commonGoods);
-		
-		CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(),
-				commonGoods.getGoodsType());
-		if (goods == null) {
-			throw new CommonGoodsException(3, "鍟嗗搧涓嶅瓨鍦�");
-		}
-		// 鏇存柊鍟嗗搧淇℃伅
-		commonGoods.setId(goods.getId());
-		commonGoods.setCreateTime(null);
-		commonGoods.setUpdateTime(new Date());
-		commonGoodsMapper.updateByPrimaryKeySelective(commonGoods);
-	}
+    @Override
+    public CommonGoods selectByPrimaryKey(Long id) {
+        return commonGoodsMapper.selectByPrimaryKey(id);
+    }
 
-	@Override
-	public void offlineCommonGoods(String goodsId, Integer goodsType) {
-		CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(goodsId, goodsType);
-		if (goods == null)
-			return;
-		CommonGoods update = new CommonGoods();
-		update.setId(goods.getId());
-		update.setUpdateTime(new Date());
-		update.setState(CommonGoods.STATE_OFFLINE);
-		commonGoodsMapper.updateByPrimaryKeySelective(update);
-	}
 
-	@Override
-	public CommonGoods getCommonGoodsByGoodsIdAndGoodsType(String goodsId, Integer goodsType) {
-		return commonGoodsMapper.selectByGoodsIdAndGoodsType(goodsId, goodsType);
-	}
+    /**
+     * 楠岃瘉鏁版嵁姝g‘鎬�
+     *
+     * @param commonGoods
+     * @throws CommonGoodsException
+     */
+    private void filterCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
+        // 鍒ゆ柇淇℃伅鏄惁瀹屾垚
+        if (commonGoods == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓虹┖");
+        if (commonGoods.getGoodsId() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getGoodsType() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (StringUtil.isNullOrEmpty(commonGoods.getPicture()))
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getPrice() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getRate() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getSales() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getSellerId() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getSellerName() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (commonGoods.getShopType() == null)
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+        if (StringUtil.isNullOrEmpty(commonGoods.getTitle()))
+            throw new CommonGoodsException(1, "鍟嗗搧淇℃伅涓嶅畬鏁�");
+    }
 
-	@Override
-	@Transactional
-	public void updateBatchCommonGoods(List<CommonGoods> listCommonGoods) {
-		
-		if (listCommonGoods == null || listCommonGoods.size() == 0) {
-			return;
-		}
-		
-		for (CommonGoods commonGoods: listCommonGoods) {
-			try {
-				updateCommonGoods(commonGoods);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-	}
-	
-	@Override
-	@Transactional
-	public void addBatchCommonGoods(List<CommonGoods> listCommonGoods) {
-		
-		if (listCommonGoods == null || listCommonGoods.size() == 0) {
-			return;
-		}
-		
-		for (CommonGoods commonGoods: listCommonGoods) {
-			try {
-				addCommonGoods(commonGoods);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
-		}
-	}
-	
-	
-	@Override
-	public List<CommonGoods> listBySellerId(Long sellerId, Integer goodsType) {
-		return commonGoodsMapper.listBySellerId(sellerId, goodsType);
-	} 
-	
-	@Override
-	public long countBySellerIdAndHasCoupon(Long sellerId, Integer goodsType) {
-		return commonGoodsMapper.countBySellerIdAndHasCoupon(sellerId, goodsType);
-	}
-	
-	@Override
-	public List<CommonGoods> getByListGoodsId(List<String> list, Integer goodsType) {
-		return commonGoodsMapper.getByListGoodsId(list, goodsType);
-	}
-	
+    @Override
+    public CommonGoods addOrUpdateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
+        // 楠岃瘉鏁版嵁瀹屾暣鎬�
+        filterCommonGoods(commonGoods);
+
+        CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(),
+                commonGoods.getGoodsType());
+        if (goods != null) {
+            updateCommonGoods(commonGoods);
+            commonGoods.setId(goods.getId());
+            return commonGoods;
+        }
+        commonGoods.setCreateTime(new Date());
+        commonGoods.setUpdateTime(new Date());
+        commonGoodsMapper.insertSelective(commonGoods);
+        return commonGoods;
+    }
+
+
+    @Override
+    public CommonGoods addCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
+        // 楠岃瘉鏁版嵁瀹屾暣鎬�
+        filterCommonGoods(commonGoods);
+
+        CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(),
+                commonGoods.getGoodsType());
+        if (goods != null) {
+            commonGoods.setId(goods.getId());
+            return commonGoods;
+        }
+        commonGoods.setCreateTime(new Date());
+        commonGoods.setUpdateTime(new Date());
+        commonGoodsMapper.insertSelective(commonGoods);
+        return commonGoods;
+    }
+
+
+    @Override
+    public void updateCommonGoods(CommonGoods commonGoods) throws CommonGoodsException {
+        // 鍒ゆ柇淇℃伅鏄惁瀹屾暣
+        filterCommonGoods(commonGoods);
+
+        CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(commonGoods.getGoodsId(),
+                commonGoods.getGoodsType());
+        if (goods == null) {
+            throw new CommonGoodsException(3, "鍟嗗搧涓嶅瓨鍦�");
+        }
+        // 鏇存柊鍟嗗搧淇℃伅
+        commonGoods.setId(goods.getId());
+        commonGoods.setCreateTime(null);
+        commonGoods.setUpdateTime(new Date());
+        commonGoodsMapper.updateByPrimaryKeySelective(commonGoods);
+    }
+
+    @Override
+    public void offlineCommonGoods(String goodsId, Integer goodsType) {
+        CommonGoods goods = commonGoodsMapper.selectByGoodsIdAndGoodsType(CommonGoodsUtil.getGoodsId(goodsId, goodsType), goodsType);
+        if (goods == null)
+            return;
+        CommonGoods update = new CommonGoods();
+        update.setId(goods.getId());
+        update.setUpdateTime(new Date());
+        update.setState(CommonGoods.STATE_OFFLINE);
+        commonGoodsMapper.updateByPrimaryKeySelective(update);
+    }
+
+    @Override
+    public CommonGoods getCommonGoodsByGoodsIdAndGoodsType(String goodsId, Integer goodsType) {
+        return commonGoodsMapper.selectByGoodsIdAndGoodsType(CommonGoodsUtil.getGoodsId(goodsId, goodsType), goodsType);
+    }
+
+    @Override
+    @Transactional
+    public void updateBatchCommonGoods(List<CommonGoods> listCommonGoods) {
+
+        if (listCommonGoods == null || listCommonGoods.size() == 0) {
+            return;
+        }
+
+        for (CommonGoods commonGoods : listCommonGoods) {
+            try {
+                updateCommonGoods(commonGoods);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    @Override
+    @Transactional
+    public void addBatchCommonGoods(List<CommonGoods> listCommonGoods) {
+
+        if (listCommonGoods == null || listCommonGoods.size() == 0) {
+            return;
+        }
+
+        for (CommonGoods commonGoods : listCommonGoods) {
+            try {
+                addCommonGoods(commonGoods);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+
+    @Override
+    public List<CommonGoods> listBySellerId(Long sellerId, Integer goodsType) {
+        return commonGoodsMapper.listBySellerId(sellerId, goodsType);
+    }
+
+    @Override
+    public long countBySellerIdAndHasCoupon(Long sellerId, Integer goodsType) {
+        return commonGoodsMapper.countBySellerIdAndHasCoupon(sellerId, goodsType);
+    }
+
+    @Override
+    public List<CommonGoods> getByListGoodsId(List<String> list, Integer goodsType) {
+        List<String> goodsIdList = new ArrayList<>();
+        for (String st : list) {
+            goodsIdList.add(CommonGoodsUtil.getGoodsId(st, goodsType));
+        }
+        return commonGoodsMapper.getByListGoodsId(goodsIdList, goodsType);
+    }
+
 }

--
Gitblit v1.8.0