fanli/src/main/java/com/yeshi/fanli/controller/admin/BrandShopAdminController.java
@@ -495,6 +495,26 @@ } /** * 修改排序 * * @param callback * @param goodsClass * @param out */ @RequestMapping(value = "updateOrderBrand") public void updateOrderBrand(String callback, Long id, Integer moveType, PrintWriter out) { try { brandInfoService.updateOrder(id, moveType); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功")); } catch (BrandInfoException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败")); e.printStackTrace(); } } /** * 品牌信息查询 * @param callback * @param pageIndex fanli/src/main/java/com/yeshi/fanli/dao/brand/BrandGoodsCaheDao.java
@@ -68,7 +68,7 @@ */ public void removeByBrandId(Long brandId) { Query query = new Query(); query.addCriteria(Criteria.where("brandId").lt(brandId)); query.addCriteria(Criteria.where("brandId").is(brandId)); mongoTemplate.remove(query, BrandGoodsCahe.class); } fanli/src/main/java/com/yeshi/fanli/dao/brand/BrandShopCaheDao.java
@@ -63,7 +63,7 @@ */ public void removeByBrandId(Long brandId) { Query query = new Query(); query.addCriteria(Criteria.where("brandId").lt(brandId)); query.addCriteria(Criteria.where("brandId").is(brandId)); mongoTemplate.remove(query, BrandShopCahe.class); } fanli/src/main/java/com/yeshi/fanli/dao/mybatis/brand/BrandInfoMapper.java
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param; import com.yeshi.fanli.dao.BaseMapper; import com.yeshi.fanli.entity.brand.BrandClass; import com.yeshi.fanli.entity.brand.BrandInfo; import com.yeshi.fanli.vo.brand.BrandInfoVO; @@ -26,6 +27,11 @@ int deleteBatchByPrimaryKey(List<Long> list); BrandInfo getByAdjoinOrder(@Param("cid") Long cid, @Param("order") double order, @Param("type") Integer type); /** * 查询返回前端品牌 * @param start fanli/src/main/java/com/yeshi/fanli/mapping/brand/BrandInfoMapper.xml
@@ -123,7 +123,7 @@ SELECT * FROM yeshi_ec_brand_info d WHERE d.`bf_state` = 1 AND d.bf_goods_total <![CDATA[>=]]> 3 AND d.bf_shop_total <![CDATA[>]]> 0 <if test="cid != null">AND d.`bf_cid` = #{cid} </if> ORDER BY d.`bf_weight` DESC,d.bf_id ORDER BY d.`bf_weight` LIMIT ${start},${count} </select> @@ -137,7 +137,7 @@ SELECT * FROM yeshi_ec_brand_info d WHERE d.`bf_state` = 1 AND d.`bf_cid` = #{cid} AND d.bf_goods_total <![CDATA[>=]]>3 AND d.bf_shop_total <![CDATA[>]]> 0 ORDER BY d.`bf_weight` DESC ORDER BY d.`bf_weight` </select> <select id="countValidByCid" resultType="Long"> @@ -170,7 +170,7 @@ <if test="cid != null"> AND bf_cid = #{cid} </if> ORDER BY bf_weight DESC ORDER BY bf_weight LIMIT ${start},${count} </select> @@ -187,4 +187,19 @@ AND bf_cid = #{cid} </if> </select> <select id="getByAdjoinOrder" resultMap="BaseResultMap"> SELECT * FROM yeshi_ec_brand_info WHERE bf_cid = #{cid} <if test="type == -1"> AND bf_weight <![CDATA[<]]> #{order} ORDER BY bf_weight desc </if> <if test="type == 1"> AND bf_weight <![CDATA[>]]> #{order} ORDER BY bf_weight </if> LIMIT 1 </select> </mapper> fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandGoodsCaheServiceImpl.java
@@ -49,16 +49,19 @@ @Override public int addBrandGoods(BrandInfo brandInfo) { int count = 0; public BrandInfo addBrandGoods(BrandInfo brandInfo) { // 淘宝 count += addBrandGoodsTB(brandInfo); BrandInfo goodsTB = addBrandGoodsTB(brandInfo); // 京东 count += addBrandGoodsJD(brandInfo); BrandInfo goodsJD = addBrandGoodsJD(brandInfo); // 拼多多 count += addBrandGoodsPDD(brandInfo); BrandInfo goodsPDD = addBrandGoodsPDD(brandInfo); return count; int goodsTotal = goodsTB.getGoodsTotal() + goodsJD.getGoodsTotal() + goodsPDD.getGoodsTotal(); int shopTotal = goodsTB.getShopTotal() + goodsJD.getShopTotal() + goodsPDD.getShopTotal(); goodsTB.setGoodsTotal(goodsTotal); goodsTB.setShopTotal(shopTotal); return goodsTB; } @@ -67,16 +70,19 @@ * @param brandInfo * @return */ private int addBrandGoodsTB(BrandInfo brandInfo) { private BrandInfo addBrandGoodsTB(BrandInfo brandInfo) { BrandInfo numInfo = new BrandInfo(); Date date = new Date(); String shopKey = brandInfo.getShopKey(); if (StringUtil.isNullOrEmpty(shopKey)) { // 删除之前的 brandGoodsCaheDao.removeByDate(brandInfo.getId(), 1 , date); // 删除店铺 brandShopCaheService.removeByDateAndType(brandInfo.getId(), 11, date); return 0; numInfo.setShopTotal(0); numInfo.setGoodsTotal(0); return numInfo; } String searchKey = brandInfo.getSearchKey(); @@ -96,6 +102,7 @@ // 组织商品 + 添加店铺 int count = 0; int countShop = 0; if (searchResult != null && searchResult.getTaoBaoGoodsBriefs() != null && searchResult.getTaoBaoGoodsBriefs().size() > 0) { boolean addShop = true; @@ -107,6 +114,9 @@ && shopTitle.toLowerCase().contains(shopKey.toLowerCase())) { addShop = brandShopCaheService.addBrandShopTB(brandInfo, goods.getAuctionId(), goods.getSellerId()); if (!addShop) countShop = 1; } // 添加商品 @@ -116,7 +126,7 @@ brandGoods.setWeight((int) (Math.random() * 1000)); brandGoods.setGoodsType(1); brandGoods.setGoodsTB(goods); brandGoods.setCreateTime(date); brandGoods.setCreateTime(new Date()); brandGoodsCaheDao.insert(brandGoods); count ++; } else if (!addShop) { @@ -128,7 +138,9 @@ // 删除之前的 brandGoodsCaheDao.removeByDate(brandInfo.getId(), 1 , date); return count; numInfo.setShopTotal(countShop); numInfo.setGoodsTotal(count); return numInfo; } @@ -138,7 +150,8 @@ * @param brandInfo * @return */ private int addBrandGoodsJD(BrandInfo brandInfo) { private BrandInfo addBrandGoodsJD(BrandInfo brandInfo) { BrandInfo numInfo = new BrandInfo(); Date date = new Date(); String shopKey = brandInfo.getShopKeyJD(); if (StringUtil.isNullOrEmpty(shopKey)) { @@ -146,7 +159,9 @@ brandShopCaheService.removeByDateAndType(brandInfo.getId(), 20, date); // 删除之前 brandGoodsCaheDao.removeByDate(brandInfo.getId(), 2 , date); return 0; numInfo.setShopTotal(0); numInfo.setGoodsTotal(0); return numInfo; } String searchKey = brandInfo.getSearchKeyJD(); @@ -154,6 +169,7 @@ searchKey = brandInfo.getName(); int count = 0; int countShop = 0; JDSearchResult result = null; String way = configService.get("jd_api_search_key"); @@ -190,7 +206,7 @@ brandGoods.setWeight((int) (Math.random() * 1000)); brandGoods.setGoodsJD(goods); brandGoods.setGoodsType(2); brandGoods.setCreateTime(date); brandGoods.setCreateTime(new Date()); brandGoodsCaheDao.insert(brandGoods); JDShopInfo shopInfo = goods.getShopInfo(); @@ -200,6 +216,7 @@ if (!StringUtil.isNullOrEmpty(shopName) && shopName.toLowerCase().contains(shopKey.toLowerCase())) { addShop = false; brandShopCaheService.addBrandShopJD(brandInfo, shopInfo); countShop = 1; } } @@ -210,11 +227,12 @@ } } } // 删除之前 brandGoodsCaheDao.removeByDate(brandInfo.getId(), 2 , date); return count; numInfo.setShopTotal(countShop); numInfo.setGoodsTotal(count); return numInfo; } @@ -223,15 +241,18 @@ * @param brandInfo * @return */ private int addBrandGoodsPDD(BrandInfo brandInfo) { private BrandInfo addBrandGoodsPDD(BrandInfo brandInfo) { Date date = new Date(); BrandInfo numInfo = new BrandInfo(); String shopKey = brandInfo.getShopKeyPDD(); if (StringUtil.isNullOrEmpty(shopKey)) { // 删除之前 brandGoodsCaheDao.removeByDate(brandInfo.getId(), 3, date); // 删除之前店铺 brandShopCaheService.removeByDateAndType(brandInfo.getId(), 30, date); return 0; numInfo.setShopTotal(0); numInfo.setGoodsTotal(0); return numInfo; } String searchKey = brandInfo.getSearchKeyPDD(); @@ -256,7 +277,7 @@ brandGoods.setWeight((int) (Math.random() * 1000)); brandGoods.setGoodsType(3); brandGoods.setGoodsPDD(goods); brandGoods.setCreateTime(date); brandGoods.setCreateTime(new Date()); brandGoodsCaheDao.insert(brandGoods); count ++; if (count >= 50) { @@ -270,9 +291,11 @@ // 删除之前店铺 brandShopCaheService.removeByDateAndType(brandInfo.getId(), 30, date); // 添加店铺 brandShopCaheService.addBrandShopPDD(brandInfo); int countShop = brandShopCaheService.addBrandShopPDD(brandInfo); return count; numInfo.setShopTotal(countShop); numInfo.setGoodsTotal(count); return numInfo; } fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandInfoServiceImpl.java
@@ -19,6 +19,7 @@ import com.yeshi.fanli.dao.mybatis.brand.BrandInfoMapper; import com.yeshi.fanli.dto.ConfigParamsDTO; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.entity.brand.BrandClass; import com.yeshi.fanli.entity.brand.BrandGoodsCahe; import com.yeshi.fanli.entity.brand.BrandInfo; import com.yeshi.fanli.entity.brand.BrandShopCahe; @@ -81,6 +82,10 @@ if (StringUtil.isNullOrEmpty(name)) throw new BrandInfoException(1, "名称不能为空"); BrandClass brandClass = record.getBrandClass(); if (brandClass ==null || brandClass.getId() == null) throw new BrandInfoException(1, "分类不能为空"); String shopKey = record.getShopKey(); if (StringUtil.isNullOrEmpty(shopKey)) record.setShopKey(name); @@ -90,9 +95,10 @@ record.setSearchKey(name); Integer state = record.getState(); if (state == null) record.setState(0); if (state == null) { state = 0; record.setState(state); } // 图片上传 String picture = null; if (file != null) { @@ -106,8 +112,15 @@ Long id = record.getId(); if (id == null) { record.setCreateTime(new Date()); record.setGoodsTotal(0); record.setShopTotal(0); record.setUpdateTime(new Date()); brandInfoMapper.insert(record); BrandInfo resultObj = new BrandInfo(); resultObj.setId(record.getId()); resultObj.setWeight(Double.valueOf(record.getId())); brandInfoMapper.updateByPrimaryKeySelective(resultObj); } else { BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id); if (resultObj == null) @@ -123,15 +136,19 @@ } else { record.setIcon(resultObj.getIcon()); } if (state == 0){ record.setGoodsTotal(0); record.setShopTotal(0); } else { record.setGoodsTotal(resultObj.getGoodsTotal()); record.setShopTotal(resultObj.getShopTotal()); } record.setWeight(resultObj.getWeight()); record.setCreateTime(resultObj.getCreateTime()); record.setUpdateTime(new Date()); brandInfoMapper.updateByPrimaryKey(record); if (state == 0){ executor.execute(new Runnable() { @@ -148,16 +165,13 @@ executor.execute(new Runnable() { @Override public void run() { int goodsTotal = brandGoodsCaheService.addBrandGoods(record); record.setGoodsTotal(goodsTotal); BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(record); List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(record.getId()); if (listshop == null) { record.setShopTotal(0); } else { record.setShopTotal(listshop.size()); } brandInfoMapper.updateByPrimaryKeySelective(record); BrandInfo update = new BrandInfo(); update.setId(record.getId()); update.setGoodsTotal(numInfo.getGoodsTotal()); update.setShopTotal(numInfo.getShopTotal()); brandInfoMapper.updateByPrimaryKeySelective(update); } }); } @@ -199,6 +213,36 @@ return brandInfoMapper.deleteBatchByPrimaryKey(list); } @Override public void updateOrder(Long id, Integer moveType) throws BrandInfoException { if (moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) throw new BrandInfoException(1, "传递的类型不正确"); if (id == null) throw new BrandInfoException(1, "ID不能为空"); BrandInfo resultObj = brandInfoMapper.selectByPrimaryKey(id); if (resultObj == null) throw new BrandInfoException(1, "操作数据已不存在"); Double oldOrder = resultObj.getWeight(); BrandInfo changeObj = brandInfoMapper.getByAdjoinOrder(resultObj.getBrandClass().getId(),oldOrder, moveType); if (changeObj == null ) throw new BrandInfoException(1, "已经在最边缘,无可交换的位置"); BrandInfo changeObj1 = new BrandInfo(); changeObj1.setId(id); changeObj1.setWeight(changeObj.getWeight()); BrandInfo changeObj2 = new BrandInfo(); changeObj2.setId(changeObj.getId()); changeObj2.setWeight(oldOrder); brandInfoMapper.updateByPrimaryKeySelective(changeObj1); brandInfoMapper.updateByPrimaryKeySelective(changeObj2); } @Override public List<BrandInfo> listQuery(long start, int count, String key, Long cid, Integer state) { @@ -321,17 +365,11 @@ continue; // 添加商品 int goodsTotal = brandGoodsCaheService.addBrandGoods(brandInfo); BrandInfo numInfo = brandGoodsCaheService.addBrandGoods(brandInfo); brandInfo.setGoodsTotal(goodsTotal); brandInfo.setGoodsTotal(numInfo.getGoodsTotal()); brandInfo.setShopTotal(numInfo.getShopTotal()); brandInfo.setUpdateTime(new Date()); List<BrandShopCahe> listshop = brandShopCaheService.getByBrandId(brandInfo.getId()); if (listshop == null) { brandInfo.setShopTotal(0); } else { brandInfo.setShopTotal(listshop.size()); } brandInfoMapper.updateByPrimaryKeySelective(brandInfo); } } fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandShopCaheServiceImpl.java
@@ -80,10 +80,10 @@ * @return */ @Override public void addBrandShopPDD(BrandInfo brandInfo) { public int addBrandShopPDD(BrandInfo brandInfo) { String shopKey = brandInfo.getShopKeyPDD(); if (StringUtil.isNullOrEmpty(shopKey)) return; return 0; String searchKey = brandInfo.getSearchKeyPDD(); if (StringUtil.isNullOrEmpty(searchKey)) @@ -124,7 +124,9 @@ brandShop.setShop(shopInfoVO); brandShop.setCreateTime(new Date()); brandShopCaheDao.insert(brandShop); return 1; } return 0; } fanli/src/main/java/com/yeshi/fanli/service/inter/brand/BrandGoodsCaheService.java
@@ -14,7 +14,7 @@ */ public interface BrandGoodsCaheService { public int addBrandGoods(BrandInfo brandInfo); public BrandInfo addBrandGoods(BrandInfo brandInfo); /** * 查询品牌商品 fanli/src/main/java/com/yeshi/fanli/service/inter/brand/BrandInfoService.java
@@ -112,4 +112,7 @@ */ public void removeAgoByDate(Date date); public void updateOrder(Long id, Integer moveType) throws BrandInfoException; } fanli/src/main/java/com/yeshi/fanli/service/inter/brand/BrandShopCaheService.java
@@ -42,7 +42,7 @@ * 添加拼多多店铺 * @param brandInfo */ public void addBrandShopPDD(BrandInfo brandInfo); public int addBrandShopPDD(BrandInfo brandInfo); /** * 删除之前的