package com.yeshi.fanli.service.impl.brand;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.apache.commons.beanutils.PropertyUtils;
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.yeshi.utils.JsonUtil;
|
|
import com.yeshi.fanli.dao.mybatis.brand.BrandClassShopMapper;
|
import com.yeshi.fanli.entity.brand.BrandClass;
|
import com.yeshi.fanli.entity.brand.BrandClassShop;
|
import com.yeshi.fanli.entity.goods.CommonGoods;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
|
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
|
import com.yeshi.fanli.exception.brand.BrandClassShopException;
|
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
|
import com.yeshi.fanli.service.inter.brand.TaoBaoShopHistoryService;
|
import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
|
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
import com.yeshi.fanli.vo.brand.TaoBaoShopVO;
|
|
import net.sf.json.JSONObject;
|
|
@Service
|
public class BrandClassShopServiceImpl implements BrandClassShopService {
|
|
@Resource
|
private BrandClassShopMapper brandClassShopMapper;
|
|
@Resource
|
private CommonGoodsService commonGoodsService;
|
|
@Resource
|
private TaoBaoShopService taoBaoShopService;
|
|
@Resource
|
private TaoBaoShopHistoryService taoBaoShopHistoryService;
|
|
@Resource
|
private HongBaoManageService manageService;
|
|
@Resource
|
private QualityGoodsService qualityGoodsService;
|
|
@Resource
|
private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
|
|
@Override
|
public List<BrandClassShop> listEffective(long start, int count, Long cid) {
|
return brandClassShopMapper.listEffective(start, count, cid);
|
}
|
|
|
@Override
|
public long countEffective(Long cid) {
|
return brandClassShopMapper.countEffective(cid);
|
}
|
|
@Override
|
public List<BrandClassShop> getExistByShopIds(List<Long> list){
|
return brandClassShopMapper.getExistByShopIds(list);
|
}
|
|
|
@Override
|
@Transactional
|
public String saveShopInfo(Long cid, List<Long> list) throws BrandClassShopException{
|
if (list == null || list.size() == 0) {
|
throw new BrandClassShopException(1, "请选择店铺");
|
}
|
|
if (cid == null) {
|
throw new BrandClassShopException(1, "请选择店铺类型");
|
}
|
|
String shopIds = "";
|
BrandClass brandClass = new BrandClass(cid);
|
|
for (Long shopId: list) {
|
List<CommonGoods> listGoods= commonGoodsService.listBySellerId(shopId);
|
|
TaoBaoShop taoBaoShop = null;
|
for (CommonGoods commonGoods: listGoods) {
|
try {
|
taoBaoShop = TaoBaoUtil.getTaoBaoShopDetailByAuctionId(commonGoods.getGoodsId());
|
if (taoBaoShop != null && taoBaoShop.getId() != null) {
|
break;
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
if (taoBaoShop == null) {
|
shopIds = shopIds + "," + shopId;
|
continue;
|
}
|
|
TaoBaoShop current = taoBaoShopService.selectByPrimaryKey(shopId);
|
if (current == null) {
|
taoBaoShopService.insertSelective(taoBaoShop);
|
} else {
|
taoBaoShopService.updateByPrimaryKeySelective(taoBaoShop);
|
}
|
|
BrandClassShop brandClassShop = brandClassShopMapper.getByShopIdAndCid(cid, shopId);
|
if (brandClassShop == null) {
|
brandClassShop = new BrandClassShop();
|
brandClassShop.setOrderby(brandClassShopMapper.getMaxOrder(cid) + 1);
|
brandClassShop.setState(0);
|
brandClassShop.setTop(0);
|
brandClassShop.setBrandClass(brandClass);
|
brandClassShop.setShop(taoBaoShop);
|
brandClassShop.setCreateTime(new Date());
|
brandClassShop.setUpdateTime(new Date());
|
brandClassShopMapper.insertSelective(brandClassShop);
|
}
|
}
|
return shopIds;
|
}
|
|
|
@Override
|
@Transactional
|
public void changeShopInfo(MultipartFile file, Long id, Long cid, String shopName, Integer state, Integer top) throws BrandClassShopException{
|
|
if (id == null) {
|
throw new BrandClassShopException(1, "数据为空:请选择店铺");
|
}
|
|
if (cid == null) {
|
throw new BrandClassShopException(1, "请选择店铺类型");
|
}
|
|
BrandClassShop current = brandClassShopMapper.selectByPrimaryKey(id);
|
if (current == null) {
|
throw new BrandClassShopException(1, "该数据已不存在");
|
}
|
|
TaoBaoShop shop = current.getShop();
|
if (shop == null) {
|
throw new BrandClassShopException(1, "店铺信息已不存在");
|
}
|
|
// 自定义图片
|
taoBaoShopService.changeInfo(file, shop.getId(), shopName);
|
|
BrandClassShop updateshop = new BrandClassShop();
|
updateshop.setState(state);
|
updateshop.setTop(top);
|
updateshop.setId(current.getId());
|
updateshop.setBrandClass(new BrandClass(cid));
|
brandClassShopMapper.updateByPrimaryKeySelective(updateshop);
|
}
|
|
|
@Override
|
public List<BrandClassShop> listQuery(long start, int count, String key, Long cid, Integer state) {
|
List<BrandClassShop> listQuery = brandClassShopMapper.listQuery(start, count, key, cid, state);
|
if (listQuery == null || listQuery.size() == 0) {
|
return listQuery;
|
}
|
|
for (BrandClassShop brandClassShop : listQuery) {
|
TaoBaoShop shop = brandClassShop.getShop();
|
if (shop != null) {
|
long couponNum = commonGoodsService.countBySellerIdAndHasCoupon(shop.getId());
|
brandClassShop.setCouponNum(couponNum);
|
|
shop.setShopLink(TaoBaoUtil.getShopLink(shop.getId()));
|
|
String shopIconCustom = shop.getShopIconCustom();
|
if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
|
shop.setShopIcon(shopIconCustom);
|
}
|
}
|
}
|
return listQuery;
|
}
|
|
|
@Override
|
public long countQuery(String key, Long cid, Integer state) {
|
return brandClassShopMapper.countQuery(key, cid, state);
|
}
|
|
|
@Override
|
@Transactional
|
public void deleteBatchByPrimaryKey(List<Long> list) {
|
if (list == null || list.size() == 0) {
|
return;
|
}
|
for (Long id: list) {
|
brandClassShopMapper.deleteByPrimaryKey(id);
|
}
|
}
|
|
|
@Override
|
public void updateOrder(Long id, Integer moveType) throws BrandClassShopException, Exception{
|
|
if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) {
|
throw new BrandClassShopException(1, "传递的类型不正确");
|
}
|
|
if (id == null) {
|
throw new BrandClassShopException(1, "ID不能为空");
|
}
|
|
BrandClassShop resultObj = brandClassShopMapper.selectByPrimaryKey(id);
|
if (resultObj == null) {
|
throw new BrandClassShopException(1, "操作数据已不存在");
|
}
|
|
BrandClass brandClass = resultObj.getBrandClass();
|
if (brandClass == null) {
|
throw new BrandClassShopException(1, "分类数据已不存在");
|
}
|
|
Integer oldOrder = resultObj.getOrderby();
|
BrandClassShop changeObj = brandClassShopMapper.getByAdjoinOrder(brandClass.getId(),oldOrder, moveType);
|
|
if (changeObj == null ) {
|
throw new BrandClassShopException(1, "已经在最边缘,无可交换的位置");
|
}
|
// 交换排序序号
|
resultObj.setOrderby(changeObj.getOrderby());
|
changeObj.setOrderby(oldOrder);
|
|
brandClassShopMapper.updateByPrimaryKeySelective(changeObj);
|
brandClassShopMapper.updateByPrimaryKeySelective(resultObj);
|
}
|
|
@Override
|
@Cacheable(value = "brandCache", key = "'listEffectiveCache-'+#page+'-'+#cid")
|
public JSONObject listEffectiveCache(int page, Long cid) {
|
long count = 0;
|
int pageSize = Constant.PAGE_SIZE;
|
List<BrandClassShop> list = brandClassShopMapper.listEffective((page - 1) * pageSize, pageSize, cid);
|
if (list == null) {
|
list = new ArrayList<BrandClassShop>();
|
} else if (list.size() > 0) {
|
count = brandClassShopMapper.countEffective(cid);
|
}
|
|
JSONObject data = new JSONObject();
|
if (page == 1 && cid != null && cid > 0 && count > pageSize) {
|
List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
|
List<BrandClassShop> listBrand = brandClassShopMapper.listEffective(0, Integer.MAX_VALUE, cid);
|
for (BrandClassShop brandClassShop : listBrand) {
|
TaoBaoShop shop = brandClassShop.getShop();
|
if (shop != null) {
|
String shopIconCustom = shop.getShopIconCustom();
|
if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
|
shop.setShopIcon(shopIconCustom);
|
}
|
listShop.add(shop);
|
}
|
}
|
data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
|
} else if (page == 1 && cid != null && cid > 0) {
|
List<TaoBaoShop> listShop = new ArrayList<TaoBaoShop>();
|
for (BrandClassShop brandClassShop : list) {
|
TaoBaoShop shop = brandClassShop.getShop();
|
if (shop != null) {
|
String shopIconCustom = shop.getShopIconCustom();
|
if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
|
shop.setShopIcon(shopIconCustom);
|
}
|
listShop.add(shop);
|
}
|
}
|
data.put("listShop", JsonUtil.getApiCommonGson().toJson(listShop));
|
}
|
|
List<TaoBaoShopVO> listVO = new ArrayList<TaoBaoShopVO>();
|
for (BrandClassShop brandClassShop : list) {
|
TaoBaoShop shop = brandClassShop.getShop();
|
if (shop == null) {
|
continue;
|
}
|
|
String shopIconCustom = shop.getShopIconCustom();
|
if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
|
shop.setShopIcon(shopIconCustom);
|
}
|
|
|
List<Long> listgid = new ArrayList<Long>();
|
listgid.add(543572782962L);
|
listgid.add(578504974101L);
|
listgid.add(530275132249L);
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
|
List<TaoBaoGoodsBrief> listgd = taoBaoGoodsBriefService.listQueryByAuctionId(listgid);
|
for (TaoBaoGoodsBrief taoBaoGoodsBrief : listgd) {
|
listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
|
}
|
|
|
// List<QualityFactory> listFactory = qualityGoodsService.listByShopId(0, 3, shop.getId());
|
// if (listFactory == null || listFactory.size() < 3) {
|
// count --;
|
// continue;
|
// }
|
//
|
// List<TaoBaoGoodsBriefExtra> listGoods = new ArrayList<TaoBaoGoodsBriefExtra>();
|
// BigDecimal proportion = manageService.getFanLiRate();
|
// for (QualityFactory selectionGoods : listFactory) {
|
// TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
// if (taoBaoGoodsBrief == null) {
|
// break;
|
// }
|
// listGoods.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
|
// }
|
//
|
// if (listGoods == null || listGoods.size() < 3) {
|
// count --;
|
// continue;
|
// }
|
//
|
|
TaoBaoShopVO vo = new TaoBaoShopVO();
|
try {
|
PropertyUtils.copyProperties(vo, shop);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
vo.setListGoods(listGoods);
|
listVO.add(vo);
|
}
|
data.put("count", count);
|
data.put("list", JsonUtil.getApiCommonGson().toJson(listVO));
|
|
return data;
|
}
|
|
@Override
|
public void addClick(Long shopId) {
|
BrandClassShop brandClassShop = brandClassShopMapper.getByShopId(shopId);
|
if (brandClassShop != null) {
|
Long browseNum = brandClassShop.getBrowseNum();
|
if (browseNum == null) {
|
browseNum = 0L;
|
}
|
|
BrandClassShop classShop = new BrandClassShop();
|
classShop.setId(brandClassShop.getId());
|
classShop.setBrowseNum(browseNum ++);
|
brandClassShopMapper.updateByPrimaryKeySelective(classShop);
|
}
|
}
|
|
|
}
|