|
@@ -15,59 +15,77 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import com.fuzamei.constant.HintMSG;
|
|
|
+import com.fuzamei.entity.UserDetail;
|
|
|
import com.fuzamei.service.TrueFalseSelectService;
|
|
|
+import com.fuzamei.service.UserAuthoricationService;
|
|
|
import com.fuzamei.utils.HashXiZhiUtil;
|
|
|
import com.fuzamei.utils.JSONUtil;
|
|
|
+import com.fuzamei.utils.ValidationUtil;
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author chb & ylx
|
|
|
+ * @describe 真伪查询模块
|
|
|
+ * @date 2018-1-4 12:17
|
|
|
+ */
|
|
|
@Controller
|
|
|
-@RequestMapping(value = "/TrueFalseSelect")
|
|
|
+@RequestMapping(value = "/query_true_or_false")
|
|
|
public class TrueFalseSelectAction {
|
|
|
+
|
|
|
@Autowired
|
|
|
private TrueFalseSelectService trueFalseSelectService;
|
|
|
+
|
|
|
+ private static final String SP = File.separator;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserAuthoricationService userAuthoricationService;
|
|
|
/**
|
|
|
* 真伪查询 上传文件 产生一条哈希值
|
|
|
+ * 判断hash值是否有效???
|
|
|
* @param
|
|
|
* @param
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@RequestMapping(value="/trueFalseSelect",method=RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
- public Map<String,Object> trueFalseSelect(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws IOException{
|
|
|
+ public Map<String,Object> trueFalseSelect(@RequestParam("file") MultipartFile file,
|
|
|
+ HttpServletRequest request,
|
|
|
+ @RequestParam("userId") Object uId) throws IOException{
|
|
|
try {
|
|
|
- String path = "D:\\tomcate\\apache-tomcat-8.5.24\\webapps"+request.getServletContext().getContextPath()+"\\Ceshi";
|
|
|
- File dir = new File(path);
|
|
|
- if(!dir.exists()){
|
|
|
- dir.mkdirs();
|
|
|
- }
|
|
|
- //MultipartFile自带的解析方法
|
|
|
- String fileName = file.getOriginalFilename();
|
|
|
- String pathFile=path+"/"+fileName;
|
|
|
- File newfile = new File(pathFile);
|
|
|
- file.transferTo(newfile);
|
|
|
-
|
|
|
- Map<String, Object> map = new LinkedHashMap<String, Object>();
|
|
|
- map.put("attachment_name", fileName);
|
|
|
- map.put("url",fileName);
|
|
|
- trueFalseSelectService.insertTrueFalseSelect(map);
|
|
|
-
|
|
|
- //是上传文件之后才会产生一条哈希值的 然后在对哈希值做操作
|
|
|
- // HashXiZhiUtil.getMd5("D:\\xiangnu\\123.doc");
|
|
|
- String hash=HashXiZhiUtil.getMD5Checksum(pathFile);//调用方法 对(文件)产生一条哈希值
|
|
|
-
|
|
|
- System.out.println( HashXiZhiUtil.getMD5Checksum(pathFile)+"--哈希值");//测试
|
|
|
- Map<String, Object> mapResult=JSONUtil.getJsonMap(200, true, "上传成功", null);//将查询出来的结果封装成map数据返回
|
|
|
- //mapResult.put("hash", hash);返回哈希值给前端
|
|
|
- return mapResult ;
|
|
|
- }
|
|
|
- catch (Exception e) {
|
|
|
- Map<String, Object> mapResult=JSONUtil.getJsonMap(500, true, "上传失败"+e.getMessage(), null);
|
|
|
- return mapResult ;
|
|
|
+ //非空校验
|
|
|
+ if(file.isEmpty()){
|
|
|
+ throw new RuntimeException("上传文件不能为空");
|
|
|
+ }
|
|
|
+ int userId = ValidationUtil.checkAndAssignInt(uId);//对用户id进行校验
|
|
|
+ UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId);//获取用户详细信息
|
|
|
+
|
|
|
+ String path = request.getServletContext().getRealPath("")+SP+"content"; //==>>待定TODO
|
|
|
+
|
|
|
+ //MultipartFile自带的解析方法
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ String pathFile=path+"/"+fileName;
|
|
|
+ File newfile = new File(pathFile);
|
|
|
+ File dir = new File(path);
|
|
|
+ //======文件开始上传=======
|
|
|
+ if(!dir.exists()){
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ file.transferTo(newfile);
|
|
|
+ //======文件上传结束=======
|
|
|
+ //是上传文件之后才会产生一条哈希值的 然后在对哈希值做操作
|
|
|
+ // HashXiZhiUtil.getMd5("D:\\xiangnu\\123.doc");
|
|
|
+ String hash=HashXiZhiUtil.getMD5Checksum(pathFile);//调用方法 对(文件)产生一条哈希值
|
|
|
+ newfile.delete();
|
|
|
+ Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
|
|
|
+ mapToService.put("hash", hash);
|
|
|
+ mapToService.put("userDetail", userDetail);
|
|
|
+ boolean flag=trueFalseSelectService.insertTrueFalseSelect(mapToService);
|
|
|
+ System.out.println(hash);
|
|
|
+ return JSONUtil.getJsonMap(200, true, HintMSG.CHECK_SUCCESS, flag);
|
|
|
+ }catch (Exception e) {
|
|
|
+ return JSONUtil.getJsonMap(500, false, HintMSG.CHECK_FAIL+":"+e.getMessage(), null);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|