|
|
@@ -1,19 +1,14 @@
|
|
|
package com.miekir.shibei.controller.api;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.miekir.shibei.bean.GoodsBean;
|
|
|
-import com.miekir.shibei.bean.NoteBean;
|
|
|
-import com.miekir.shibei.bean.ResponseResult;
|
|
|
-import com.miekir.shibei.bean.ResultCode;
|
|
|
+import com.miekir.shibei.bean.*;
|
|
|
import com.miekir.shibei.repository.GoodsRepository;
|
|
|
import com.miekir.shibei.repository.UserRepository;
|
|
|
import com.miekir.shibei.tool.TextUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -33,11 +28,28 @@ public class GoodsController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/api/addGoods", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
|
- public String addGoods(@RequestBody GoodsBean goodsBean) {
|
|
|
+ public String addGoods(@RequestHeader HttpHeaders header, @RequestBody GoodsBean goodsBean) {
|
|
|
ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
responseResult.setMessage("操作失败");
|
|
|
|
|
|
- if (goodsBean == null) {
|
|
|
+ String token = header.getFirst("token");
|
|
|
+ String email = header.getFirst("email");
|
|
|
+
|
|
|
+ if (goodsBean == null || TextUtils.isEmpty(token) || TextUtils.isEmpty(email)) {
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据email查找用户,查询用户的token是否相同
|
|
|
+ User dbUserBean;
|
|
|
+ try {
|
|
|
+ dbUserBean = userRepository.findUserByEmail(email);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户token不一致
|
|
|
+ if (dbUserBean == null || !TextUtils.equals(token, dbUserBean.getToken())) {
|
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
|
|
|
|
@@ -54,40 +66,61 @@ public class GoodsController {
|
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 删除密码记事
|
|
|
-// */
|
|
|
-// @RequestMapping(value = "/api/delNote", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
|
|
|
-// @ResponseBody
|
|
|
-// public String delNote(String email, String token, int noteId) {
|
|
|
-// ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
-// responseResult.setMessage("操作失败");
|
|
|
-//
|
|
|
-// NoteBean dbNoteBean;
|
|
|
-// try {
|
|
|
-// dbNoteBean = goodsRepository.findNoteBeanById(noteId);
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// return JSON.toJSONString(responseResult);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 密码不属于该用户
|
|
|
-// if (dbNoteBean == null || !TextUtils.equals(email, dbNoteBean.getUserId())) {
|
|
|
-// return JSON.toJSONString(responseResult);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// try {
|
|
|
-// goodsRepository.delete(noteId);
|
|
|
-// } catch (Exception e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// return JSON.toJSONString(responseResult);
|
|
|
-// }
|
|
|
-//
|
|
|
-// responseResult.setCode(ResultCode.SUCCESS);
|
|
|
-// responseResult.setMessage("删除成功");
|
|
|
-// return JSON.toJSONString(responseResult);
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 删除京东商品
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/api/deleteGoodsById", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
+ @ResponseBody
|
|
|
+ public String delNote(@RequestHeader HttpHeaders header, long goodsId) {
|
|
|
+ ResponseResult<String> responseResult = new ResponseResult<String>();
|
|
|
+ responseResult.setMessage("删除失败");
|
|
|
+
|
|
|
+ String token = header.getFirst("token");
|
|
|
+ String email = header.getFirst("email");
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(token) || TextUtils.isEmpty(email)) {
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据email查找用户,查询用户的token是否相同
|
|
|
+ User dbUserBean;
|
|
|
+ try {
|
|
|
+ dbUserBean = userRepository.findUserByEmail(email);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 用户token不一致
|
|
|
+ if (dbUserBean == null || !TextUtils.equals(token, dbUserBean.getToken())) {
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找对应的商品
|
|
|
+ GoodsBean dbGoodsBean;
|
|
|
+ try {
|
|
|
+ dbGoodsBean = goodsRepository.findGoodsById(goodsId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 找不到对应商品
|
|
|
+ if (dbGoodsBean == null) {
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ goodsRepository.delete(dbGoodsBean);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
+ responseResult.setMessage("删除成功");
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
//
|
|
|
// /**
|
|
|
// * 查询密码记事
|