Authored by wangnan

【图片搜索】 导数据到表

... ... @@ -21,4 +21,6 @@ public interface SknImageVectorsMapper {
List<SknImageVectors> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize);
int selectCount();
void insertBatch(List<SknImageVectors> list);
}
\ No newline at end of file
... ...
... ... @@ -13,6 +13,17 @@
product_skn, img_url, create_time, vectors
</sql>
<insert id="insertBatch" parameterType="java.util.List" timeout="20000">
insert ignore into skn_image_vectors (productSkn, imgUrl, createTime, vectors)
values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.productSkn, jdbcType=INTEGER},
#{item.imgUrl, jdbcType=VARCHAR},
#{item.createTime, jdbcType=INTEGER},
#{item.vectors, jdbcType=LONGVARCHAR}
</foreach>
</insert>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ...
package com.yoho.search.consumer.restapi;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.FileUtils;
import com.yoho.search.consumer.index.increment.bulks.CommonBulkService;
import com.yoho.search.consumer.index.rebuild.RebuildFlagService;
import com.yoho.search.consumer.job.TplAdaptorJob;
import com.yoho.search.core.es.model.ESBluk;
import com.yoho.search.dal.SknImageVectorsMapper;
import com.yoho.search.dal.model.SknImageVectors;
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.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
... ... @@ -18,6 +28,52 @@ public class TplAdaptorController {
@Autowired
private RebuildFlagService rebuildFlagService;
@Autowired
private CommonBulkService commonBulkService;
@Autowired
private SknImageVectorsMapper sknImageVectorsMapper;
@RequestMapping(value = "test/putData")
@ResponseBody
public Map<String, Object> putData() throws UnsupportedEncodingException {
final String fileName = "feat_out.txt";
String filePath = this.getClass().getResource("/").getPath();
List<String> lines = FileUtils.readFile(filePath + fileName);
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(factors);
sknImageVectors.setCreateTime(DateUtil.getCurrentTimeSecond());
sknImageVectorsList.add(sknImageVectors);
if(i%5000==0){
sknImageVectorsMapper.insertBatch(sknImageVectorsList);
sknImageVectorsList.clear();
}
//updateProductIndexWithDataMap(indexData, skn);
}
}catch (Exception e){
System.out.print(e.getMessage());
}
Map<String, Object> result = new HashMap<String, Object>();
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));
}
@RequestMapping(value = "/index/tplAdaptor")
@ResponseBody
public Map<String, Object> tplAdaptor() {
... ...