public voidimport4(){
FolderUtil fu=newFolderUtil();
List imgList=fu.refreshFileList("D:\\斑片影2", "jpg");int countadd=0;for(String imgUrl:imgList){
TagImg newImg=newTagImg();
newImg.setOrgId("4e252d02fc0d4855909496c977b1ba86");
newImg.setSetId("22636eb7d50447f39b24617fab3c8145");
newImg.setTypeId("37ec21d7745f4f6eb05aba506bc14048");
File imgFile= newFile(imgUrl);//生成缩略图
InputStream in = null;try{
in= newFileInputStream(imgFile);
String fileMd5Name=UploadFile.getFileMD5(in);if(in!=null)
in.close();//TagImgFilter imgfilter=new TagImgFilter();//imgfilter.setEq_imgMd5(fileMd5Name);//取tag_json
TagImgFilter imgfilter2=newTagImgFilter();
String imgId0= imgUrl.split("\\\\")[2]; //根据文件路径修改
String imgId1 = imgId0.split("\\_")[1];
String imgId= imgId1.split("\\.")[0];//System.out.println(imgUrl);
System.out.println(imgId0);
System.out.println(imgId1);
System.out.println(imgId);//imgfilter2.setEq_id(imgId);
imgfilter2.setEq_orgId("dd33751e9f9e464a9a8b2808d8aeb1cd");
imgfilter2.setEq_setId("aeb57e96903740f8ab35da63986d6e11");
imgfilter2.setEq_typeId("fc268bd0e55047199d43c9467f840c15");
imgfilter2.setEq_id(imgId);//imgfilter2.setEq_imgMd5(imgId);//imgId为名字里md5值,此处没改名,之前是id值
TagImg tagImg = tagImgService.selectAll(imgfilter2).get(0);
String tagJson=tagImg.getTagJson();
System.out.println(tagJson);//上传原图
String opath=this.upFile(imgUrl, "jpg");/*JSONObject obj=new JSONObject();
obj.put("x", 1);
obj.put("y", 1);
BufferedImage image = null;
try {
File wimgFile = new File(imgUrl);
image = ImageIO.read(wimgFile);
newImg.setThumbh(image.getHeight());
newImg.setThumbw(image.getWidth());
obj.put("width", image.getWidth()-1);
obj.put("height", image.getHeight()-1);
image = null;
} catch (IOException e) {
e.printStackTrace();
}
JSONArray ar=new JSONArray();
ar.add(obj);
newImg.setTagJson(ar.toJSONString());*/newImg.setTagJson(tagJson);
newImg.setImgUrl(opath);
newImg.setImgMd5(fileMd5Name);
newImg.setTagFlag(1);//缩略图
File simgFile=newFile(imgUrl);
Map map=ImageZipUtil.zipImageFileByte(simgFile,310, 0, 1f);byte[] bt = (byte[]) map.get("bt");
ByteArrayInputStream bin= newByteArrayInputStream(bt);
String spath= this.upFile(bin, bt.length, "jpg");
newImg.setImgUrlThumb(opath);
newImg.setCreateUser("originalbanpianying");
countadd++;
System.out.println(countadd);
bin.close();
bt=null;//tagImgService.save(newImg);
}catch(Exception e) {//TODO: handle exception
}
}
}public String upFile(InputStream in,long fileSize,String extName) throwsFileNotFoundException{
StorePath storePath= fastFileStorageClient.uploadFile(in,fileSize,extName,null);try{
in.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}finally{if(in!=null)try{
in.close();
}catch(IOException e) {
e.printStackTrace();
}
}if(storePath!=null){returnstorePath.getFullPath();
}else
return null;
}public String upFile(String path,String extName) throwsFileNotFoundException{
File file=newFile(path);if(file.exists()){
FileInputStream inputStream=newFileInputStream(file);
StorePath storePath= fastFileStorageClient.uploadFile(inputStream,file.length(),extName,null);try{
inputStream.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}finally{if(inputStream!=null)try{
inputStream.close();
}catch(IOException e) {//TODO Auto-generated catch block
e.printStackTrace();
}
}returnstorePath.getFullPath();
}else{return null;
}
}