TestApiController.java 3.82 KB
package com.yoho.search.consumer.test;

import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
import com.yoho.search.consumer.job.CleanDataJob;
import com.yoho.search.consumer.service.logicService.RecallStrategyLogicService;
import com.yoho.search.dal.SknImageVectorsMapper;
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;

@Controller
public class TestApiController {

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

    @Autowired
	private CleanDataJob cleanDataJobJob;
    @Autowired
    private CommonBulkService commonBulkService;
    @Autowired
    private SknImageVectorsMapper sknImageVectorsMapper;

	@RequestMapping(value = "/test")
	@ResponseBody
	public Map<String, Object> test() {
		Map<String, Object> testResult = new HashMap<String, Object>();
		testResult.put("data", null);
		testResult.put("code", 200);
		testResult.put("message", "success");
		return testResult;
	}

//    @RequestMapping(value = "/putImageVectorDataToDB")
//    @ResponseBody
//    public Map<String, Object> putData() throws UnsupportedEncodingException {
//        for (int j = 1; j <= 10; j++) {
//            String fileName = j + "_feat_out_32_.txt";
//            String filePath = this.getClass().getResource("/").getPath();
//            List<String> lines = FileUtils.readFile(filePath + fileName);
//            System.out.println("lines done " + j);
//            try {
//                List<SknImageVectors> sknImageVectorsList = new ArrayList<>();
//                for (int i = 0; i < lines.size(); i++) {
//                    String skn = lines.get(i).substring(0, 8);
//                    String factors = lines.get(i).substring(9);
//                    //Map<String, Object> indexData = new HashMap<String, Object>();
//                    //indexData.put("bin_sigs", factors);
//                    SknImageVectors sknImageVectors = new SknImageVectors();
//                    sknImageVectors.setProductSkn(Integer.valueOf(skn));
//                    sknImageVectors.setImgUrl("url");
//                    sknImageVectors.setVectors_32(factors);
//                    sknImageVectors.setVectors_128("");
//                    sknImageVectors.setCreateTime(DateUtil.getCurrentTimeSecond());
//                    sknImageVectorsList.add(sknImageVectors);
//                    //updateProductIndexWithDataMap(indexData, skn);
//                    if (i > 0) {
//                        if (i % 1000 == 0 || i == 9999) {
//                            sknImageVectorsMapper.insertBatch(sknImageVectorsList);
//                            sknImageVectorsList.clear();
//                            System.out.println("batch done_" + j + "_" + i);
//                        }
//                    }
//                }
//            } catch (Exception e) {
//                System.out.print(e.getMessage());
//            }
//        }
//        Map<String, Object> result = new HashMap<>();
//        result.put("code", 200);
//        result.put("message", "success");
//        return result;
//    }
//
//    protected final void updateProductIndexWithDataMap(Map<String, Object> indexData, String skn) {
//        JSONObject jsonObject = new JSONObject(indexData);
//        commonBulkService.add(new ESBluk(jsonObject.toJSONString(), skn, "images_test", "images_test", false));
//    }


	@Autowired
	private RecallStrategyLogicService recallStrategyLogicService;

	@RequestMapping(value = "/test2")
	@ResponseBody
	public String test2() {
		String result = recallStrategyLogicService.getRecallStrategyConfigInZk();
		return result;
	}
}