受注ピクチャ(一対の多関係)、アドレスが1つのフィールドに保存されます(Json配列オブジェクトフォーマット)

5447 ワード

  ---->  (     ),          (Json      )
1、        :
jsp:
2、web : @RequestMapping(value = "/uploadPhoto", method = RequestMethod.POST) @ResponseBody public Object uploadPhoto(@RequestParam MultipartFile[] sourceFiles, int type, String orderid,Long id) throws IOException { // WLOrder wlOrder = new WLOrder(); wlOrder.setOrderid(orderid); List strlist=new ArrayList();// , ’-‘ , endport/bucketName/foldname/ 。 int uploadCount=0; String typeUrl = ""; for (int i = 0; i < sourceFiles.length; i++) { String fileName = sourceFiles[i].getOriginalFilename(); String suffixFileName =fileName.substring(fileName.lastIndexOf(".") + 1); // InputStream fileContent = sourceFiles[i].getInputStream(); String url= OSSUploadUtil.uploadFile(fileContent,suffixFileName,orderid,type); if(url!=null){ strlist.add(url); uploadCount++; } System.out.println("-----------"+url); } // List photos=null;// WLOrder wlo = wlOrderService.findWLOrderById(id); String JsonStr=null; if (0 == type) {// type=" "; JsonStr= wlo.getTransferorderphoto(); } else if (1 == type) {// type=" "; JsonStr=wlo.getWaybillnophoto(); } else if (2 == type) {// type=" "; JsonStr=wlo.getTemperreportphoto(); } if(StringUtils.isEmpty(JsonStr)){// photos=new ArrayList(); }else{ // , JSONArray jsonArray=JSONArray.fromObject(JsonStr); List> list2 = JSONArray.toList(jsonArray, new HashMap<>(), new JsonConfig()); photos=list2; } for (int i = 0; i photoAddress=new HashMap<>(); photoAddress.put("id", String.valueOf((photos.size()+i+1))); photoAddress.put("name", strlist.get(i)); //photoAddress.put(String.valueOf(i+1), strlist.get(i)); photos.add(photoAddress); } JSONArray listArray=JSONArray.fromObject(photos); System.out.println("==================------------------------------"+typeUrl); if (0 == type) { // type=" "; wlOrder.setTransferorderphoto(listArray.toString()); } else if (1 == type) { // type=" "; wlOrder.setWaybillnophoto(listArray.toString()); } else if (2 == type) { // type=" "; wlOrder.setTemperreportphoto(listArray.toString()); } else { return renderError(" "); } wlOrderService.updateWLOrderByOrderID(wlOrder); String typeStr = null; return renderSuccess(" :"+uploadCount); } //3、 : /** bucket * @author * @date * @param * @return */ @RequestMapping(value = "/getBucketKey", method = RequestMethod.POST) @ResponseBody public Object getBucketKey(String orderid,int type,Long id,String sort, String order) { List photos=null;// WLOrder wlo = wlOrderService.findWLOrderById(id); String JsonStr=null; if (0 == type) {// type=" "; JsonStr= wlo.getTransferorderphoto(); } else if (1 == type) {// type=" "; JsonStr=wlo.getWaybillnophoto(); } else if (2 == type) {// type=" "; JsonStr=wlo.getTemperreportphoto(); } if(StringUtils.isEmpty(JsonStr)){// photos=new ArrayList(); }else{ JSONArray jsonArray=JSONArray.fromObject(JsonStr); List> list2 = JSONArray.toList(jsonArray, new HashMap<>(), new JsonConfig()); photos=list2; } List> res= photos; return res; } //4、 : /*** * @param objectKey * @param type * @return */ @RequestMapping(value="/delPhoto",method=RequestMethod.GET) @ResponseBody public Object delPhoto(String objectKey,int type,Long id,String orderid){ boolean res= OSSUploadUtil.deleteFile(objectKey, type); if(!res){ return renderError(" "); } List photos=null;// WLOrder wlo = wlOrderService.findWLOrderById(id); String JsonStr=null; if (0 == type) {// type=" "; JsonStr= wlo.getTransferorderphoto(); } else if (1 == type) {// type=" "; JsonStr=wlo.getWaybillnophoto(); } else if (2 == type) {// type=" "; JsonStr=wlo.getTemperreportphoto(); } JSONArray jsonArray=JSONArray.fromObject(JsonStr); //List> list2 = JSONArray.toList(jsonArray, new HashMap<>(), new JsonConfig()); int index=-1; for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject = (JSONObject) jsonArray.get(i); //JSONObject jsonObject2 = jsonObject.discard("name"); String str= (String) jsonObject.get("name"); //jsonArray1.add(jsonObject2); if(objectKey.equals(str)){ index=i; } } jsonArray.remove(index); WLOrder wlOrder = new WLOrder(); wlOrder.setOrderid(orderid); if (0 == type) { // type=" "; wlOrder.setTransferorderphoto(jsonArray.toString()); } else if (1 == type) { // type=" "; wlOrder.setWaybillnophoto(jsonArray.toString()); } else if (2 == type) { // type=" "; wlOrder.setTemperreportphoto(jsonArray.toString()); } wlOrderService.updateWLOrderByOrderID(wlOrder); return renderSuccess(); }