Skip to content

Commit 92db58a

Browse files
author
xiaowei
committed
modify web bugs
1 parent dc2461a commit 92db58a

11 files changed

Lines changed: 117 additions & 115 deletions

File tree

src/main/java/com/changyu/foryou/controller/FoodController.java

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

src/main/java/com/changyu/foryou/controller/OrderController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ public JSONArray getSalesByDate(@RequestParam Integer campusId, String month){
15511551
paramMap.put("dateStart", dateStart);
15521552
paramMap.put("dateEnd", dateEnd);
15531553
TradeInfo todayInfo = new TradeInfo();
1554-
todayInfo.setInfoDateType("当天");
1554+
todayInfo.setInfoDateType("今天");
15551555
todayInfo.setOrderCount(orderService.getSalesInfoByCampusId(paramMap)); //获取指定时间段和指定校区的订单总数
15561556
todayInfo.setTradeVolume(orderService.getTradeVolumeByCampusId(paramMap)); //获取指定时间段和指定校区的订单交易额
15571557
paramMap.put("payWay", 1); //payWay:0,没有; 1,支付宝; 2,微信
@@ -1567,7 +1567,7 @@ public JSONArray getSalesByDate(@RequestParam Integer campusId, String month){
15671567
paramMap.put("dateStart", dateStart);
15681568
paramMap.put("dateEnd", dateEnd);
15691569
TradeInfo weekInfo = new TradeInfo();
1570-
weekInfo.setInfoDateType("当周");
1570+
weekInfo.setInfoDateType("本周");
15711571
weekInfo.setOrderCount(orderService.getSalesInfoByCampusId(paramMap));//获取指定时间段和指定校区的订单总数
15721572
weekInfo.setTradeVolume(orderService.getTradeVolumeByCampusId(paramMap));//获取指定时间段和指定校区的订单交易额
15731573
paramMap.put("payWay", 1); //payWay:0,没有; 1,支付宝; 2,微信
@@ -1583,7 +1583,7 @@ public JSONArray getSalesByDate(@RequestParam Integer campusId, String month){
15831583
paramMap.put("dateStart", dateStart);
15841584
paramMap.put("dateEnd", dateEnd);
15851585
TradeInfo monthInfo = new TradeInfo();
1586-
monthInfo.setInfoDateType("当月");
1586+
monthInfo.setInfoDateType("本月");
15871587
monthInfo.setOrderCount(orderService.getSalesInfoByCampusId(paramMap));//获取指定时间段和指定校区的订单总数
15881588
monthInfo.setTradeVolume(orderService.getTradeVolumeByCampusId(paramMap));//获取指定时间段和指定校区的订单交易额
15891589
paramMap.put("payWay", 1); //payWay:0,没有; 1,支付宝; 2,微信

src/main/java/com/changyu/foryou/mapper/FoodMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ public interface FoodMapper {
5252
Integer addFoodCountById(Map<String, Object> paramMap);//添加库存
5353

5454
Integer addFoodCount(Map<String, Object> paramMap);
55+
56+
String getFoodHomeImage(Map<String, Object> paramMap);
5557
}

src/main/java/com/changyu/foryou/mapping/FoodCommentMapper.xml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,15 @@
121121
nickname,
122122
is_hidden
123123
FROM
124-
food_comment,
125-
users,
126-
food
124+
food_comment
125+
left join users on food_comment.phone = users.phone
126+
left join food on food_comment.food_id=food.food_id and food.campus_id=food_comment.campus_id
127127
<where>
128-
food_comment.phone = users.phone and
129-
food_comment.food_id=food.food_id
130-
and food.campus_id=food_comment.campus_id
131-
and comment is not null and comment !=""
128+
comment is not null and comment !=""
132129
and food.campus_id=#{campusId,jdbcType=INTEGER}
133130
<if test="search != null and search !='' ">
134-
and food_id =
135-
#{search,jdbcType=INTEGER})
131+
and food.food_id =
132+
#{search,jdbcType=INTEGER}
136133
</if>
137134
</where>
138135
<if test="sort != null">
@@ -151,16 +148,13 @@
151148
SELECT
152149
count(*)
153150
FROM
154-
food_comment,
155-
users,
156-
food
151+
food_comment
157152
<where>
158-
food_comment.phone = users.phone and food.campus_id=food_comment.campus_id and
159-
food_comment.food_id=food.food_id and comment is not null and comment !=""
160-
and food.campus_id=#{campusId,jdbcType=INTEGER}
153+
comment is not null and comment !=""
154+
and campus_id=#{campusId,jdbcType=INTEGER}
161155
<if test="search != null and search !='' ">
162156
and food_id =
163-
#{search,jdbcType=VARCHAR})
157+
#{search,jdbcType=VARCHAR}
164158
</if>
165159
</where>
166160
</select>

src/main/java/com/changyu/foryou/mapping/FoodMapper.xml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -484,37 +484,33 @@
484484

485485
</select>
486486

487-
<update id="uploadHomeFoodByFoodId">
487+
<update id="uploadHomeFoodByFoodId">
488488
update food set
489-
<if test="toHome != null">
490-
to_home=#{toHome, jdbcType=SMALLINT}
491-
</if>
489+
to_home=#{toHome, jdbcType=SMALLINT}
492490
<if test="homeImage != null">
493491
, home_image=#{homeImage, jdbcType=VARCHAR}
494492
</if>
495-
where food_id=#{foodId, jdbcType=BIGINT}
493+
where food_id=#{foodId, jdbcType=BIGINT} and campus_id=#{campusId,jdbcType=INTEGER}
496494
</update>
497495

498496
<update id="updateInfoByFoodId">
499497
update food set
500498
<if test="info != null">
501499
info=#{info, jdbcType=VARCHAR}
502500
</if>
503-
where food_id=#{foodId, jdbcType=BIGINT}
501+
where food_id=#{foodId, jdbcType=BIGINT} and campus_id=#{campusId,jdbcType=INTEGER}
504502
</update>
505503

506504
<update id="cancelRecommend">
507-
update food set
508-
<if test="toHome != null">
505+
update food set
509506
to_home=#{toHome, jdbcType=SMALLINT}
510-
</if>
511-
where food_id=#{foodId, jdbcType=BIGINT}
507+
where food_id=#{foodId, jdbcType=BIGINT} and campus_id=#{campusId,jdbcType=INTEGER}
512508
</update>
513509

514510
<select id="getTopFive" resultMap="FoodWithSalesResultMap">
515511
SELECT orders.food_id,food.name as food_name,SUM(orders.order_count) as sales from orders,food
516512
<where>
517-
orders.food_id=food.food_id
513+
orders.food_id=food.food_id and orders.campus_id=#{campusId,jdbcType=INTEGER}
518514
<if test="dateStart!=null">
519515
AND together_date BETWEEN #{dateStart,jdbcType=TIMESTAMP}
520516
</if>
@@ -538,9 +534,18 @@
538534
<where>
539535
campus_id=#{campusId,jdbcType=INTEGER}
540536
<if test="foodId!=null">
541-
and fodd_id=#{foodId,jdbcType=BIGINT}
537+
and food_id=#{foodId,jdbcType=BIGINT}
542538
</if>
543539
</where>
544540
</update>
541+
542+
<select id="getFoodHomeImage" resultType="String">
543+
select
544+
home_image
545+
from food
546+
where
547+
campus_id=#{campusId,jdbcType=INTEGER} and food_id=#{foodId,jdbcType=BIGINT}
548+
limit 1
549+
</select>
545550
</mapper>
546551

src/main/java/com/changyu/foryou/mapping/OrderMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@
10521052
<!-- 获取指定时间段和指定校区的订单总数 -->
10531053
<select id="getSalesInfoByCampusId" resultType="Integer">
10541054
select COUNT(DISTINCT together_id) from orders
1055-
where campus_id=#{campusId}
1055+
where campus_id=#{campusId} and status=4
10561056
and together_date BETWEEN #{dateStart,jdbcType=TIMESTAMP}
10571057
and #{dateEnd,jdbcType=TIMESTAMP}
10581058
and tag=1
@@ -1063,7 +1063,7 @@
10631063
SELECT sum(total_price)
10641064
from together_order
10651065
<where>
1066-
campus_id=#{campusId,jdbcType=INTEGER}
1066+
campus_id=#{campusId,jdbcType=INTEGER} and status=4
10671067
<if test="dateStart!=null and dateEnd!=null">
10681068
and together_date BETWEEN #{dateStart,jdbcType=TIMESTAMP}
10691069
AND #{dateEnd,jdbcType=TIMESTAMP}

src/main/java/com/changyu/foryou/service/FoodService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ public interface FoodService {
110110
Integer addFoodCountById(Map<String, Object> paramMap);//添加库存
111111

112112
Integer addFoodCount(Map<String, Object> paramMap);//添加库存
113+
114+
String getFoodHomeImage(Map<String, Object> paramMap); //获取原来的首页图片
113115
}

src/main/java/com/changyu/foryou/serviceImpl/FoodServiceImpl.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,51 +246,48 @@ public Integer getAllCategoryCount() {
246246

247247
@Override
248248
public Integer uploadHomeFoodByFoodId(Map<String, Object> paramMap) {
249-
// TODO Auto-generated method stub
250249
return foodMapper.uploadHomeFoodByFoodId(paramMap);
251250
}
252251

253252
@Override
254253
public Integer updateInfoByFoodId(Map<String, Object> paramMap) {
255-
// TODO Auto-generated method stub
256254
return foodMapper.updateInfoByFoodId(paramMap);
257255
}
258256

259257
@Override
260258
public Integer cancelRecommend(Map<String, Object> paramMap) {
261-
// TODO Auto-generated method stub
262259
return foodMapper.cancelRecommend(paramMap);
263260
}
264261

265262
@Override
266263
public Integer calCommentCount(Map<String, Object> paramMap) {
267-
// TODO Auto-generated method stub
268264
return foodCommentMapper.calCommentCount(paramMap);
269265
}
270266

271267
@Override
272268
public Integer addCategoryWhenAddCampus(Map<String, Object> paramMap) {
273-
// TODO Auto-generated method stub
274269
return foodCategoryMapper.addCategoryWhenAddCampus(paramMap);
275270
}
276271

277272
@Override
278273
public List<FoodWithSales> getTopFive(Map<String, Object> paramMap) {
279-
// TODO Auto-generated method stub
280274
return foodMapper.getTopFive(paramMap);
281275
}
282276

283277
@Override
284278
public Integer addFoodCountById(Map<String, Object> paramMap) {
285-
// TODO Auto-generated method stub
286279
return foodMapper.addFoodCountById(paramMap);
287280
}
288281

289282
@Override
290283
public Integer addFoodCount(Map<String, Object> paramMap) {
291-
// TODO Auto-generated method stub
292284
return foodMapper.addFoodCount(paramMap);
293285
}
286+
287+
@Override
288+
public String getFoodHomeImage(Map<String, Object> paramMap) {
289+
return foodMapper.getFoodHomeImage(paramMap);
290+
}
294291

295292
}
296293

src/main/webapp/pages/food.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ <h4 class="modal-title" id="pushToHomeModalLabel">
285285
enctype="multipart/form-data"
286286
action="../service/uploadHomeImage.do">
287287
<div class="modal-body">
288+
<div class="control-group">
289+
<label class="control-label" for="campus-id">校区id</label>
290+
<div class="controls">
291+
<input type="text" id="campus-id"
292+
name="campusId" readonly>
293+
</div>
294+
</div>
288295
<div class="control-group">
289296
<label class="control-label" for="food-id">商品ID</label>
290297
<div class="controls">
@@ -991,12 +998,14 @@ <h3 class="modal-title" id="myModalLabel">编辑口味</h3>&nbsp;&nbsp;
991998
'click .toHomeOperate' : function(e, value, row, index){
992999
//alert(row);
9931000
$("#food-id").val(row.foodId);
1001+
$('#campus-id').val(getCookie('campusId'));
9941002
$("#homeImageFile").val("");
9951003
//$(this).modal('show');
9961004
},
9971005
'click .cancelRecommendOperate':function(e, value, row, index){
9981006
$.post("../service/cancelRecommend.do",{
999-
foodId : row.foodId
1007+
foodId : row.foodId,
1008+
campusId:getCookie("campusId")
10001009
},function(data){
10011010
setSuccess(data.message);
10021011
$table.bootstrapTable('refresh');

0 commit comments

Comments
 (0)