TblRelationController.java 3.25 KB
package com.yoho.search.consumer.restapi;

import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.consumer.index.increment.flow.ProductIndexHeatValueUpdateFlow;
import com.yoho.search.consumer.job.ProductHeatValueJob;
import com.yoho.search.consumer.service.logic.tbl.TblBrandRelationLogicService;
import com.yoho.search.consumer.service.logic.tbl.TblSortRelationLogicService;
import com.yoho.search.consumer.suggests.common.RetryBusinessFlowExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangnan on 2017/3/7.
 */
@Controller
public class TblRelationController {

    private static final Logger logger = LoggerFactory.getLogger(ProductHeatValueJob.class);


    @Autowired
    private TblSortRelationLogicService tblSortRelationLogicService;
    @Autowired
    private TblBrandRelationLogicService tblBrandRelationLogicService;

    private ProductIndexHeatValueUpdateFlow productIndexHeatValueUpdateFlow;

    @RequestMapping(value = "/doUpdateProductIndexHeatValue")
    @ResponseBody
    public Map<String, Object> doUpdateProductIndexHeatValue() {
        Map<String, Object> rt = new HashMap<String, Object>();
        try {
            long begin = System.currentTimeMillis();
            RetryBusinessFlowExecutor flowExecutor = new RetryBusinessFlowExecutor(productIndexHeatValueUpdateFlow, ISearchConstants.SEARCH_INDEX_BATCH_MAX_THREAD_SIZE, ISearchConstants.SEARCH_INDEX_BATCH_LIMIT);
            boolean result = flowExecutor.execute();
            logger.info("ProductHeatValueJob.doUpdateProductIndexHeatValue end----[result={}][cost={}]", result, System.currentTimeMillis() - begin);
            rt.put("code", 200);
            rt.put("message", "success");
        } catch (Exception e) {
            e.printStackTrace();
            rt.put("code", 400);
            rt.put("message", e.getMessage());
        }
        return rt;
    }


    @RequestMapping(value = "/tblSortRelation")
    @ResponseBody
    public Map<String, Object> loadSortRelationData() {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            tblSortRelationLogicService.loadSortRelationData();
            result.put("code", 200);
            result.put("message", "success");
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 400);
            result.put("message", e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/tblBrandRelation")
    @ResponseBody
    public Map<String, Object> loadBrandRelationData() {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            tblBrandRelationLogicService.loadBrandRelationData();
            result.put("data", "");
            result.put("code", 200);
            result.put("message", "success");
        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 400);
            result.put("message", e.getMessage());
        }
        return result;
    }
}