admin
2019-03-11 261609854ff8c912d70b12809153f1efc28e76ce
Merge remote-tracking branch 'origin/master'
9个文件已修改
354 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/client/GoodsClassController.java 177 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/GoodsClassMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/GoodsSubClassMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsClassMapper.xml 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsSubClassMapper.xml 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/GoodsClassService.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/GoodsSubClassService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/client/GoodsClassController.java
@@ -4,12 +4,14 @@
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -31,6 +33,7 @@
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.goods.ClassRecommendGoodsService;
@@ -46,6 +49,7 @@
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
import com.yeshi.fanli.service.inter.monitor.MonitorService;
import com.yeshi.fanli.util.CMQManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
@@ -108,7 +112,11 @@
    @Resource
    private MonitorService monitorService;
    @Resource(name = "taskExecutor")
    private TaskExecutor executor;
    /**
     * 获取主类目
     * 
@@ -117,26 +125,34 @@
     */
    @RequestMapping(value = "getgoodsclass", method = RequestMethod.POST)
    public void getGoodsClass(AcceptData acceptData, PrintWriter out) {
        System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        try {
            System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
            if (system == null) {
                out.print(JsonUtil.loadFalseResult("系统不存在"));
                return;
            }
            List<GoodsClass> goodsClassList = goodsClassService.getListClassCache(system.getId());
            if (goodsClassList == null || goodsClassList.size() == 0) {
                out.print(JsonUtil.loadFalseResult("暂无数据"));
                return;
            }
            JSONObject data = new JSONObject();
            data.put("count", goodsClassList.size());
            data.put("goodsClassList", goodsClassList);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("获取失败"));
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        List<SuperGoodsClass> superGoodsClassList = superGoodsClassService.getSuperGoodsClassBySystemId(system.getId());
        if (superGoodsClassList == null || superGoodsClassList.size() == 0) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
            return;
        }
        List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
        for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
            GoodsClass goodsClass = superGoodsClass.getGoodsClass();
            goodsClassList.add(goodsClass);
        }
        JSONObject data = new JSONObject();
        data.put("count", goodsClassList.size());
        data.put("goodsClassList", goodsClassList);
        String result = JsonUtil.loadTrueResult(data);
        out.print(result);
    }
    /**
@@ -157,35 +173,38 @@
                return;
            }
            if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
                Long androidClick = goodsClass.getAndroidClick();
                if (androidClick != null) {
                    goodsClass.setAndroidClick(androidClick + 1);
                } else {
                    goodsClass.setAndroidClick(1L);
                }
            } else if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
                Long iosClick = goodsClass.getIosClick();
                if (iosClick != null) {
                    goodsClass.setIosClick(iosClick + 1);
                } else {
                    goodsClass.setIosClick(1L);
                }
            }
            goodsClassService.updateByPrimaryKeySelective(goodsClass);
            List<GoodsSubClass> goodsSubClassList = goodsSubClassService.getSubClassCache(gcid, 1);
            if (goodsSubClassList == null || goodsSubClassList.size() == 0) {
                out.print(JsonUtil.loadFalseResult("暂无数据"));
                return;
            if (goodsSubClassList == null) {
                goodsSubClassList = new ArrayList<GoodsSubClass>();
            }
            JSONObject data = new JSONObject();
            data.put("count", goodsSubClassList.size());
            data.put("goodsSecondClassList", JsonUtil.getApiCommonGson().toJson(goodsSubClassList));
            out.print(JsonUtil.loadTrueResult(data));
            // 更新分类点击次数
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
                        Long androidClick = goodsClass.getAndroidClick();
                        if (androidClick != null) {
                            goodsClass.setAndroidClick(androidClick + 1);
                        } else {
                            goodsClass.setAndroidClick(1L);
                        }
                    } else if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
                        Long iosClick = goodsClass.getIosClick();
                        if (iosClick != null) {
                            goodsClass.setIosClick(iosClick + 1);
                        } else {
                            goodsClass.setIosClick(1L);
                        }
                    }
                    goodsClassService.updateByPrimaryKeySelective(goodsClass);
                }
            });
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
@@ -808,59 +827,31 @@
    @RequestMapping(value = { "getcategory" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST })
    public void getcategory(AcceptData acceptData, PrintWriter out) {
        com.yeshi.fanli.entity.system.System system = this.systemService.getSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
        try {
            com.yeshi.fanli.entity.system.System system = this.systemService.getSystemCache(acceptData.getPlatform(),
                    acceptData.getPackages());
            if (system == null) {
                out.print(JsonUtil.loadFalseResult("系统不存在"));
                return;
            }
        List<SuperGoodsClass> superGoodsClassList = this.superGoodsClassService
                .getSuperGoodsClassBySystemId(system.getId().longValue());
        if ((superGoodsClassList == null) || (superGoodsClassList.size() == 0)) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
            return;
        }
        List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
        for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
            GoodsClass goodsClass = superGoodsClass.getGoodsClass();
            goodsClassList.add(goodsClass);
        }
        JSONArray array = new JSONArray();
        Gson gson = new GsonBuilder().create();
        if (goodsClassList.size() > 0) {
            for (GoodsClass goodsClass : goodsClassList) {
                goodsClass.setKey(null);
                goodsClass.setCreatetime(0L);
                goodsClass.setSearchParam(null);
                goodsClass.setIosClick(null);
                goodsClass.setAndroidClick(null);
                JSONObject data = new JSONObject();
                data.put("gclass", goodsClass);
                long gcid = goodsClass.getId();
                try {
                    List<GoodsSubClass> subClassList = this.goodsSubClassService.getSubClassCache(Long.valueOf(gcid),
                            Integer.valueOf(1));
                    if ((subClassList == null) || (subClassList.size() == 0)) {
                        subClassList = new ArrayList<GoodsSubClass>();
                    }
                    data.put("subList", gson.toJson(subClassList));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                array.add(data);
            List<Map<String, Object>> listCache = goodsClassService.getClassListAllCache(system.getId());
            if (listCache == null) {
                listCache = new ArrayList<Map<String,Object>>();
            }
            JSONObject data = new JSONObject();
            data.put("categoryList", listCache);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("获取失败"));
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        JSONObject data = new JSONObject();
        data.put("categoryList", array);
        out.print(JsonUtil.loadTrueResult(data));
    }
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/GoodsClassMapper.java
@@ -2,8 +2,9 @@
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
public interface GoodsClassMapper {
@@ -15,4 +16,11 @@
    List<GoodsClass> queryAll();
    
    int updateByPrimaryKeySelective(GoodsClass record);
    /**
     * 根据系统id查询分类
     * @param systemId
     * @return
     */
    List<GoodsClass> listGoodsClassBySystemId(@Param("systemId") Long systemId);
}
fanli/src/main/java/com/yeshi/fanli/dao/mybatis/GoodsSubClassMapper.java
@@ -68,4 +68,11 @@
     */
    int getMaxWeightByPid(@Param("pid") Long pid);
    
    /**
     * 一级id查询
     * @param list
     * @return
     */
    List<GoodsSubClass> queryByListCid(List<Long> list);
}
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsClassMapper.xml
@@ -26,7 +26,14 @@
    
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select * from yeshi_ec_class where id = #{id,jdbcType=BIGINT}
      </select>
     </select>
     <select id="listGoodsClassBySystemId" resultMap="BaseResultMap">
         SELECT c.id,c.name,c.picture,c.url FROM `yeshi_ec_class` c
        RIGHT JOIN `yeshi_ec_super_goodsclass` sp ON sp.`goodsclass_id` = c.`id`
        WHERE sp.`system_id` = #{systemId}
        ORDER BY c.`orderby`
     </select>
    
</mapper>
fanli/src/main/java/com/yeshi/fanli/mapping/GoodsSubClassMapper.xml
@@ -25,6 +25,32 @@
    </association>
    
  </resultMap>
  <resultMap id="SimpleResultMap" type="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass">
    <id column="sub_id" property="id" jdbcType="BIGINT"/>
    <result column="sub_name" property="name" jdbcType="VARCHAR"/>
    <result column="sub_picture" property="picture" jdbcType="VARCHAR"/>
    <result column="sub_weight" property="weight" jdbcType="INTEGER"/>
    <result column="sub_level" property="level" jdbcType="INTEGER"/>
    <result column="sub_state" property="state" jdbcType="INTEGER"/>
    <result column="sub_key" property="key" jdbcType="VARCHAR"/>
    <result column="sub_search_json" property="searchJson" jdbcType="VARCHAR"/>
    <result column="sub_ios_click" property="iosClick" jdbcType="BIGINT"/>
    <result column="sub_android_click" property="androidClick" jdbcType="BIGINT"/>
    <result column="sub_createtime" property="createtime" jdbcType="TIMESTAMP"/>
    <result column="sub_updatetime" property="updatetime" jdbcType="TIMESTAMP"/>
    <association property="rootClass" column="sub_root_id" javaType="com.yeshi.fanli.entity.bus.clazz.GoodsClass">
        <id column="sub_root_id" property="id" jdbcType="BIGINT" />
    </association>
    <association property="parent" column="sub_pid" javaType="com.yeshi.fanli.entity.bus.clazz.GoodsSubClass">
        <id column="sub_pid" property="id" jdbcType="BIGINT" />
    </association>
  </resultMap>
  <sql id="Base_Column_List">sub_id,sub_name,sub_picture,sub_weight,sub_root_id,sub_pid,sub_level,sub_state,sub_key,sub_search_json,sub_ios_click,sub_android_click,sub_createtime,sub_updatetime</sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">select
    <include refid="Base_Column_List"/>from yeshi_ec_sub_class where sub_id = #{id,jdbcType=BIGINT}
@@ -89,9 +115,8 @@
    SELECT  <include refid="Base_Column_List" />  FROM yeshi_ec_sub_class 
        WHERE sub_root_id = #{rootId} 
        <if test="state != null">
            and sub_state = #{state}
            AND sub_state = #{state}
        </if>
        ORDER BY sub_weight,sub_updatetime
   </select>
   
@@ -138,13 +163,13 @@
   <select id="countByRootId" resultType="java.lang.Integer">
      <!-- 条件二级类别 -->
    SELECT  count(sub_id)  FROM yeshi_ec_sub_class 
        WHERE sub_root_id = ${rootId} ORDER BY sub_weight
        WHERE sub_root_id = ${rootId}
   </select>
   
   <select id="countByPid" resultType="java.lang.Integer">
      <!-- 条件二级类别 -->
    SELECT  count(sub_id)  FROM yeshi_ec_sub_class 
        WHERE sub_pid = ${pid} ORDER BY sub_weight
        WHERE sub_pid = ${pid}
   </select>
   
   
@@ -158,4 +183,13 @@
        SELECT IFNULL(MAX(c.`sub_weight`),0) FROM `yeshi_ec_sub_class` c WHERE c.`sub_root_id` = ${rootId}
   </select>
  
   <select id="queryByListCid" resultMap="SimpleResultMap">
       SELECT * FROM yeshi_ec_sub_class
       WHERE sub_root_id in
            <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
                ${item}
            </foreach>
      ORDER BY sub_weight
   </select>
</mapper>
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsClassServiceImpl.java
@@ -9,6 +9,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -27,17 +28,21 @@
import org.springframework.web.multipart.MultipartFile;
import org.yeshi.utils.tencentcloud.COSManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dao.goods.GoodsClassDao;
import com.yeshi.fanli.dao.mybatis.GoodsClassMapper;
import com.yeshi.fanli.dao.mybatis.lable.LabelClassMapper;
import com.yeshi.fanli.entity.admin.GoodsClassAdmin;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
import com.yeshi.fanli.entity.bus.su.clazz.SuperGoodsClass;
import com.yeshi.fanli.entity.system.System;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.goods.ClassRecommendGoodsService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
import com.yeshi.fanli.service.inter.goods.SuperGoodsClassService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -66,6 +71,10 @@
    
    @Resource
    private LabelClassMapper labelClassMapper;
    @Resource
    private GoodsSubClassService goodsSubClassService;
    
    public GoodsClass getGoodsClass(long gcid) {
@@ -555,15 +564,76 @@
        }
        
        deleteFile = COSManager.getInstance().deleteFile(fileUrl);
        if (deleteFile) {
            record.setPicture(null);
            // 更新数据库
             updateGoodsClass(record);
        } 
        return;
    }
    @Override
    @Cacheable(value="classCache",key="'getListClassCache-'+#systemId")
    public List<GoodsClass> getListClassCache(Long systemId) throws Exception {
        List<SuperGoodsClass> superGoodsClassList = superGoodsClassService.getSuperGoodsClassBySystemId(systemId);
        if (superGoodsClassList == null || superGoodsClassList.size() == 0) {
            return null;
        }
        List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
        for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
            GoodsClass goodsClass = superGoodsClass.getGoodsClass();
            goodsClassList.add(goodsClass);
        }
        return goodsClassList;
    }
    @Override
    @Cacheable(value="classCache",key="'getClassListAllCache-'+#systemId")
    public List<Map<String, Object>> getClassListAllCache(Long systemId) throws Exception {
        List<GoodsClass> goodsClassList = goodsClassMapper.listGoodsClassBySystemId(systemId);
        if (goodsClassList == null || goodsClassList.size() == 0) {
            return null;
        }
        List<Long> listID = new ArrayList<Long>();
        for (GoodsClass coodsClass : goodsClassList) {
            listID.add(coodsClass.getId());
        }
        List<GoodsSubClass> listSub = goodsSubClassService.queryByListCid(listID);
        Gson gson = new GsonBuilder().create();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (GoodsClass goodsClass : goodsClassList) {
            List<GoodsSubClass> subClassList = new ArrayList<GoodsSubClass>();
            if (listSub != null && listSub.size() > 0) {
                Iterator<GoodsSubClass> iterator = listSub.iterator();
                while (iterator.hasNext()) {
                    GoodsSubClass goodsSubClass = iterator.next();
                    GoodsClass goodsClassInner = goodsSubClass.getRootClass();
                    if (goodsClass.getId() == goodsClassInner.getId()) {
                        // 对应下子分类
                        subClassList.add(goodsSubClass);
                        iterator.remove();
                    }
                }
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("gclass", goodsClass);
            map.put("subList", gson.toJson(subClassList));
            list.add(map);
        }
        return list;
    }
    
}
fanli/src/main/java/com/yeshi/fanli/service/impl/goods/GoodsSubClassServiceImpl.java
@@ -292,4 +292,9 @@
        }
        goodsSubClassService.updateByPrimaryKeySelective(record);
    }
    @Override
    public List<GoodsSubClass> queryByListCid(List<Long> list){
        return goodsSubClassMapper.queryByListCid(list);
    }
}
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/GoodsClassService.java
@@ -1,8 +1,8 @@
package com.yeshi.fanli.service.inter.goods;
import java.util.List;
import java.util.Map;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.multipart.MultipartFile;
import com.yeshi.fanli.entity.admin.GoodsClassAdmin;
@@ -90,4 +90,21 @@
    public GoodsClass selectByPrimaryKey(Long gcid);
    /**
     *    根据系统ID查询所有分类-加入缓存
     * @param systemId 系统ID
     * @return
     * @throws Exception
     */
    public List<GoodsClass> getListClassCache(Long systemId) throws Exception;
    /**
     * 查询所有分类、主子类目
     * @param systemId
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> getClassListAllCache(Long systemId) throws Exception;
}
fanli/src/main/java/com/yeshi/fanli/service/inter/goods/GoodsSubClassService.java
@@ -138,4 +138,11 @@
     */
    public GoodsSubClass getSubClassByPrimaryKeyCache(Long id) throws Exception;
    /**
     * 查询一级下的子类
     * @param list
     * @return
     */
    public List<GoodsSubClass> queryByListCid(List<Long> list);
}