@@ -1179,29 +1179,56 @@ public String updateFoods(@RequestParam MultipartFile[] myfile,HttpServletReques
11791179 @ RequestMapping ("/uploadHomeImage" )
11801180 public String updateHomeImageByFoodId (@ RequestParam MultipartFile homeImageFile , HttpServletRequest request ) throws IOException {
11811181 String foodId = request .getParameter ("foodId" );
1182- if (homeImageFile .isEmpty ()){
1182+ Integer campusId =Integer .valueOf (request .getParameter ("campusId" ));
1183+ System .out .println (campusId );
1184+ String imageUrl =null ;
1185+ Map <String , Object > paramMap = new HashMap <String , Object >();
1186+ paramMap .put ("foodId" , foodId );
1187+ //这个toHome值在后台修改
1188+ paramMap .put ("toHome" , 1 );
1189+ paramMap .put ("campusId" , campusId ); //校区号
1190+
1191+ if (homeImageFile .isEmpty ()){ //不更新主页图片
11831192 System .out .println ("文件未上传" );
1184- }else {
1193+
1194+
1195+ int flag = foodService .uploadHomeFoodByFoodId (paramMap );
1196+ if (flag !=0 &&flag !=-1 ){
1197+ return "redirect:/pages/food.html" ;
1198+ }
1199+ }else { //更新主页图片
11851200 String contentType = homeImageFile .getContentType ();
11861201 if (contentType .startsWith ("image" )){
11871202 String realPath = request .getSession ().getServletContext ().getRealPath ("/" );
11881203 realPath = realPath .replace ("foryou" , "ForyouImage" );
1189- realPath .concat ("food" );
1204+ realPath = realPath .concat ("food/ " );
11901205 String newFileName = new Date ().getTime () + "" + new Random ().nextInt () + ".jpg" ;
11911206 FileUtils .copyInputStreamToFile (homeImageFile .getInputStream (), new File (realPath , newFileName ));
1192- String imageUrl = Constants .localIp +"/food/" +newFileName ;
1193- Map <String , Object > paramMap = new HashMap <String , Object >();
1194- paramMap .put ("foodId" , foodId );
1195- //这个toHome值在后台修改
1196- paramMap .put ("toHome" , 1 );
1197- paramMap .put ("homeImage" , imageUrl );
1207+ imageUrl = Constants .localIp +"/food/" +newFileName ;
1208+ //获取原来的图片
1209+ String oldImgUrl =foodService .getFoodHomeImage (paramMap );
1210+
1211+ paramMap .put ("homeImage" , imageUrl );
11981212 int flag = foodService .uploadHomeFoodByFoodId (paramMap );
1213+
1214+ if (imageUrl !=null &&oldImgUrl !=null ){
1215+ String [] temp =oldImgUrl .split ("/" );
1216+ String imageName =temp [(temp .length -1 )];
1217+
1218+ String name2 =realPath +imageName ;
1219+
1220+ File file =new File (name2 );
1221+ if (file .isFile ()){
1222+ file .delete ();//删除
1223+ }
1224+ }
1225+
11991226 if (flag !=0 &&flag !=-1 ){
12001227 return "redirect:/pages/food.html" ;
12011228 }
12021229 }
12031230 }
1204- return "redirect:/pages/uploadError .html" ;
1231+ return "redirect:/pages/food .html" ;
12051232 }
12061233
12071234 /**
@@ -1221,7 +1248,7 @@ public String uploadDetailImageByFoodId(@RequestParam MultipartFile[] detailImag
12211248
12221249 for (MultipartFile detailImageFile : detailImageFiles ) {
12231250 if (detailImageFile .isEmpty ()){
1224- System .out .println ("文件2未上传 " );
1251+ System .out .println ("文件未上传 " );
12251252 }else {
12261253 String contentType = detailImageFile .getContentType ();
12271254 if (contentType .startsWith ("image" )){
@@ -1262,14 +1289,19 @@ public String uploadDetailImageByFoodId(@RequestParam MultipartFile[] detailImag
12621289 return (JSONArray ) JSON .toJSON (foodCategories );
12631290 }
12641291
1292+ /**
1293+ * 对应校区
1294+ * @param foodId
1295+ * @return
1296+ */
12651297 @ RequestMapping ("cancelRecommend" )
1266- public @ ResponseBody Map <String , Object > cancelRecommend (@ RequestParam Long foodId ){
1298+ public @ ResponseBody Map <String , Object > cancelRecommend (@ RequestParam Long foodId , @ RequestParam Integer campusId ){
12671299 Map <String , Object > responseMap = new HashMap <String , Object >();
12681300 Map <String , Object > paramMap = new HashMap <String , Object >();
12691301
12701302 paramMap .put ("foodId" , foodId );
12711303 paramMap .put ("toHome" , 0 );
1272-
1304+ paramMap . put ( "campusId" , campusId );
12731305 Integer cancel = foodService .cancelRecommend (paramMap );
12741306 if (cancel ==-1 ||cancel ==0 ){
12751307 responseMap .put (Constants .STATUS , Constants .FAILURE );
@@ -1281,8 +1313,16 @@ public String uploadDetailImageByFoodId(@RequestParam MultipartFile[] detailImag
12811313 return responseMap ;
12821314 }
12831315
1316+ /**
1317+ *
1318+ * @param dateStart
1319+ * @param dateEnd
1320+ * @param page
1321+ * @param limit
1322+ * @return
1323+ */
12841324 @ RequestMapping ("getTopFive" )
1285- public @ ResponseBody Map <String , Object > getTopFive (@ RequestParam String dateStart ,@ RequestParam String dateEnd , Integer page , Integer limit ){
1325+ public @ ResponseBody Map <String , Object > getTopFive (@ RequestParam String dateStart ,@ RequestParam Integer campusId , @ RequestParam String dateEnd , Integer page , Integer limit ){
12861326 Map <String ,Object > requestMap = new HashMap <String , Object >();
12871327 Map <String ,Object > responseMap = new HashMap <String , Object >();
12881328
@@ -1292,6 +1332,7 @@ public String uploadDetailImageByFoodId(@RequestParam MultipartFile[] detailImag
12921332 requestMap .put ("dateEnd" , new SimpleDateFormat ("yyyy-MM-dd" ).parse (dateEnd ));
12931333 requestMap .put ("limit" , limit );
12941334 requestMap .put ("offset" , (page -1 )*limit );
1335+ requestMap .put ("campusId" , campusId );
12951336 JSONArray hotFive = (JSONArray ) JSONArray .toJSON (foodService .getTopFive (requestMap ));
12961337 responseMap .put ("hotFive" , hotFive );
12971338 } catch (ParseException e ) {
0 commit comments