Quellcode durchsuchen

新增京东商品

詹子聪 vor 5 Jahren
Ursprung
Commit
ab39e801d9

+ 148 - 0
src/main/java/com/miekir/shibei/bean/GoodsBean.java

@@ -0,0 +1,148 @@
+package com.miekir.shibei.bean;
+
+import javax.persistence.*;
+
+/**
+ *
+ *
+ * @author Miekir
+ * @date 2020/7/5 21:50
+ * Description: 商品实体
+ */
+@Entity
+@Table(name = "t_goods", schema = "shibei", catalog = "")
+public class GoodsBean {
+    public static final int TYPE_RECOMMEND = 0;
+    public static final int TYPE_TECHNOLOGY = 1;
+    public static final int TYPE_LIFE = 2;
+    public static final int TYPE_NETWORK = 3;
+
+    @Id
+    @GeneratedValue(strategy= GenerationType.AUTO)
+    @Column(name = "id", nullable = false, insertable = true, updatable = false)
+    public long id;
+
+
+    /**
+     * 封面图片地址
+     */
+    @Basic
+    @Column(name = "coverImageUrl", nullable = true, insertable = true, updatable = true)
+    public String coverImageUrl;
+    /**
+     * 标题
+     */
+    @Basic
+    @Column(name = "title", nullable = true, insertable = true, updatable = true)
+    public String title;
+    /**
+     * 商品描述
+     */
+    @Basic
+    @Column(name = "description", nullable = true, insertable = true, updatable = true)
+    public String description;
+    /**
+     * 商品推荐理由(一句话推荐、推荐者心声)
+     */
+    @Basic
+    @Column(name = "reason", nullable = true, insertable = true, updatable = true)
+    public String reason;
+    /**
+     * 原价
+     */
+    @Basic
+    @Column(name = "oldPrice", nullable = true, insertable = true, updatable = true)
+    public long oldPrice;
+    /**
+     * 现价
+     */
+    @Basic
+    @Column(name = "nowPrice", nullable = true, insertable = true, updatable = true)
+    public long nowPrice;
+    /**
+     * 返利
+     */
+    @Basic
+    @Column(name = "rebate", nullable = true, insertable = true, updatable = true)
+    public long rebate;
+    /**
+     * 店名
+     */
+    @Basic
+    @Column(name = "shopName", nullable = true, insertable = true, updatable = true)
+    public String shopName;
+    /**
+     * 商店所属省份
+     */
+    @Basic
+    @Column(name = "province", nullable = true, insertable = true, updatable = true)
+    public String province;
+    /**
+     * 是否自营
+     */
+    @Basic
+    @Column(name = "isSelfBusiness", nullable = true, insertable = true, updatable = true)
+    public boolean isSelfBusiness;
+    /**
+     * 是否有券
+     */
+    @Basic
+    @Column(name = "hasCoupon", nullable = true, insertable = true, updatable = true)
+    public boolean hasCoupon;
+    /**
+     * 优惠券信息
+     */
+    @Basic
+    @Column(name = "couponInfo", nullable = true, insertable = true, updatable = true)
+    public String couponInfo;
+    /**
+     * 所属类型
+     */
+    @Basic
+    @Column(name = "goodsType", nullable = true, insertable = true, updatable = true)
+    public int goodsType;
+    /**
+     * 商品链接
+     */
+    @Basic
+    @Column(name = "goodsUrl", nullable = true, insertable = true, updatable = true)
+    public String goodsUrl;
+    /**
+     * 月销量
+     */
+    @Basic
+    @Column(name = "salesPerMonth", nullable = true, insertable = true, updatable = true)
+    public long salesPerMonth;
+
+    /**
+     * 评论条数
+     */
+    @Basic
+    @Column(name = "commentNum", nullable = true, insertable = true, updatable = true)
+    public long commentNum;
+
+    /**
+     * 好评率
+     */
+    @Basic
+    @Column(name = "goodCommentPercent", nullable = true, insertable = true, updatable = true)
+    public double goodCommentPercent;
+
+    /**
+     * 创建时间
+     */
+    @Basic
+    @Column(name = "createTimeMillis", nullable = true, insertable = true, updatable = true)
+    public long createTimeMillis;
+
+    /**
+     * 更新时间
+     */
+    @Basic
+    @Column(name = "updateTimeMillis", nullable = true, insertable = true, updatable = true)
+    public long updateTimeMillis;
+
+    @Basic
+    @Column(name = "enable", nullable = true, insertable = true, updatable = true)
+    public boolean enable;
+}

+ 1 - 1
src/main/java/com/miekir/shibei/bean/ResponseResult.java

@@ -1,7 +1,7 @@
 package com.miekir.shibei.bean;
 
 public class ResponseResult<T> {
-    private int code = -1;
+    private int code = ResultCode.FAILED_COMMON;
     private String message;
     private String extra;
     private T content;

+ 156 - 0
src/main/java/com/miekir/shibei/controller/api/GoodsController.java

@@ -0,0 +1,156 @@
+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.repository.GoodsRepository;
+import com.miekir.shibei.repository.UserRepository;
+import com.miekir.shibei.tool.TextUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+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 java.util.List;
+import java.util.Map;
+
+@Controller
+public class GoodsController {
+
+    // 自动装配
+    @Autowired
+    private GoodsRepository goodsRepository;
+
+    @Autowired
+    private UserRepository userRepository;
+
+    /**
+     * 新增京东商品
+     */
+    @RequestMapping(value = "/api/addGoods", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
+    @ResponseBody
+    public String addGoods(@RequestBody GoodsBean goodsBean) {
+        ResponseResult<String> responseResult = new ResponseResult<String>();
+        responseResult.setMessage("新增商品失败");
+
+        if (goodsBean == null) {
+            return JSON.toJSONString(responseResult);
+        }
+
+        try {
+            goodsRepository.save(goodsBean);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return JSON.toJSONString(responseResult);
+        }
+
+        responseResult.setContent("新增商品成功");
+        responseResult.setCode(ResultCode.SUCCESS);
+        responseResult.setMessage("新增商品成功");
+        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/getNote", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
+//    @ResponseBody
+//    public String getNote(String email, String token) {
+//        ResponseResult<String> responseResult = new ResponseResult<String>();
+//        responseResult.setMessage("获取失败");
+//
+//        List<NoteBean> noteBeanList;
+//        try {
+//            noteBeanList = goodsRepository.findNotesByEmail(email);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            return JSON.toJSONString(responseResult);
+//        }
+//
+//        try {
+//            responseResult.setContent(JSON.toJSONString(noteBeanList));
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            return JSON.toJSONString(responseResult);
+//        }
+//
+//        responseResult.setCode(ResultCode.SUCCESS);
+//        responseResult.setMessage("获取成功");
+//        return JSON.toJSONString(responseResult);
+//    }
+//
+//    /**
+//     * 更新密码记事
+//     */
+//    @RequestMapping(value = "/api/updateNote", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
+//    @ResponseBody
+//    public String updateNote(String email, String token, String note_bean) {
+//        ResponseResult<String> responseResult = new ResponseResult<String>();
+//        responseResult.setMessage("更新失败");
+//
+//        NoteBean clientBean;
+//        try {
+//            clientBean = JSON.parseObject(note_bean, NoteBean.class);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            return JSON.toJSONString(responseResult);
+//        }
+//
+//        // 发送方的用户和该记事的所有者不是同一个人,没有权限
+//        NoteBean oldBean = goodsRepository.findNoteBeanById(clientBean.getId());
+//        if (!TextUtils.equals(email, oldBean.getUserId())) {
+//            return JSON.toJSONString(responseResult);
+//        }
+//
+//
+//        try {
+//            goodsRepository.updateNoteBean(clientBean.getContent(), clientBean.getId(), System.currentTimeMillis());
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            return JSON.toJSONString(responseResult);
+//        }
+//
+//        responseResult.setCode(ResultCode.SUCCESS);
+//        responseResult.setMessage("更新成功");
+//        return JSON.toJSONString(responseResult);
+//    }
+}

+ 0 - 165
src/main/java/com/miekir/shibei/controller/api/NoteController.java

@@ -1,165 +0,0 @@
-package com.miekir.shibei.controller.api;
-
-import com.alibaba.fastjson.JSON;
-import com.miekir.shibei.bean.NoteBean;
-import com.miekir.shibei.bean.ResponseResult;
-import com.miekir.shibei.bean.ResultCode;
-import com.miekir.shibei.repository.NoteRepository;
-import com.miekir.shibei.repository.UserRepository;
-import com.miekir.shibei.tool.TextUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import java.util.List;
-
-@Controller
-public class NoteController {
-
-    // 自动装配
-    @Autowired
-    private NoteRepository noteRepository;
-
-    @Autowired
-    private UserRepository userRepository;
-
-    /**
-     * 新增记事,接收的是纯JSON数据  严格来说,也要传递id和token过来校验的
-     */
-    @RequestMapping(value = "/api/addNote", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
-    @ResponseBody
-    public String addNote(String email, String token, String note_bean) {
-        ResponseResult<String> responseResult = new ResponseResult<String>();
-        responseResult.setMessage("保存失败");
-
-        NoteBean bean;
-        try {
-            bean = JSON.parseObject(note_bean, NoteBean.class);
-            bean.setUpdateTime(System.currentTimeMillis());
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        NoteBean dbNOteBean;
-        try {
-            dbNOteBean = noteRepository.save(bean);
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        try {
-            responseResult.setContent(JSON.toJSONString(dbNOteBean));
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        responseResult.setCode(ResultCode.SUCCESS);
-        responseResult.setMessage("保存成功");
-        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 = noteRepository.findNoteBeanById(noteId);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        // 密码不属于该用户
-        if (dbNoteBean == null || !TextUtils.equals(email, dbNoteBean.getUserId())) {
-            return JSON.toJSONString(responseResult);
-        }
-
-
-        try {
-            noteRepository.delete(noteId);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        responseResult.setCode(ResultCode.SUCCESS);
-        responseResult.setMessage("删除成功");
-        return JSON.toJSONString(responseResult);
-    }
-
-    /**
-     * 查询密码记事
-     */
-    @RequestMapping(value = "/api/getNote", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
-    @ResponseBody
-    public String getNote(String email, String token) {
-        ResponseResult<String> responseResult = new ResponseResult<String>();
-        responseResult.setMessage("获取失败");
-
-        List<NoteBean> noteBeanList;
-        try {
-            noteBeanList = noteRepository.findNotesByEmail(email);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        try {
-            responseResult.setContent(JSON.toJSONString(noteBeanList));
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        responseResult.setCode(ResultCode.SUCCESS);
-        responseResult.setMessage("获取成功");
-        return JSON.toJSONString(responseResult);
-    }
-
-    /**
-     * 更新密码记事
-     */
-    @RequestMapping(value = "/api/updateNote", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
-    @ResponseBody
-    public String updateNote(String email, String token, String note_bean) {
-        ResponseResult<String> responseResult = new ResponseResult<String>();
-        responseResult.setMessage("更新失败");
-
-        NoteBean clientBean;
-        try {
-            clientBean = JSON.parseObject(note_bean, NoteBean.class);
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        // 发送方的用户和该记事的所有者不是同一个人,没有权限
-        NoteBean oldBean = noteRepository.findNoteBeanById(clientBean.getId());
-        if (!TextUtils.equals(email, oldBean.getUserId())) {
-            return JSON.toJSONString(responseResult);
-        }
-
-
-        try {
-            noteRepository.updateNoteBean(clientBean.getContent(), clientBean.getId(), System.currentTimeMillis());
-        } catch (Exception e) {
-            e.printStackTrace();
-            return JSON.toJSONString(responseResult);
-        }
-
-        responseResult.setCode(ResultCode.SUCCESS);
-        responseResult.setMessage("更新成功");
-        return JSON.toJSONString(responseResult);
-    }
-}

+ 41 - 0
src/main/java/com/miekir/shibei/repository/GoodsRepository.java

@@ -0,0 +1,41 @@
+package com.miekir.shibei.repository;
+
+import com.miekir.shibei.bean.GoodsBean;
+import com.miekir.shibei.bean.NoteBean;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Created by sjj on 2015/10/24 0024.
+ */
+// 添加注解
+@Repository
+public interface GoodsRepository extends JpaRepository<GoodsBean, Integer> {
+    // 说明该方法是事务性操作
+//    @Transactional
+//    // 根据邮件查询用户所有密码记事
+//    // @Param注解用于提取参数
+//    @Query(value="select note from NoteBean note where note.userId=:email order by note.updateTime desc")
+//    public List<NoteBean> findNotesByEmail(@Param("email") String email);
+//
+//    // 根据密码Id查询密码记事
+//    // 说明该方法是事务性操作
+//    @Transactional
+//    // @Param注解用于提取参数
+//    @Query(value="select note from NoteBean note where note.id=:id")
+//    public NoteBean findNoteBeanById(@Param("id") Integer id);
+//
+//    // 修改密码记事
+//    @Modifying
+//    // 说明该方法是事务性操作
+//    @Transactional
+//    // @Param注解用于提取参数
+//    @Query("update NoteBean note set note.content=:content, note.updateTime=:updateTime where note.id=:noteId")
+//    public int updateNoteBean(@Param("content") String content, @Param("noteId") Integer noteId, @Param("updateTime") Long updateTime);
+}

+ 0 - 40
src/main/java/com/miekir/shibei/repository/NoteRepository.java

@@ -1,40 +0,0 @@
-package com.miekir.shibei.repository;
-
-import com.miekir.shibei.bean.NoteBean;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-/**
- * Created by sjj on 2015/10/24 0024.
- */
-// 添加注解
-@Repository
-public interface NoteRepository extends JpaRepository<NoteBean, Integer> {
-    // 说明该方法是事务性操作
-    @Transactional
-    // 根据邮件查询用户所有密码记事
-    // @Param注解用于提取参数
-    @Query(value="select note from NoteBean note where note.userId=:email order by note.updateTime desc")
-    public List<NoteBean> findNotesByEmail(@Param("email") String email);
-
-    // 根据密码Id查询密码记事
-    // 说明该方法是事务性操作
-    @Transactional
-    // @Param注解用于提取参数
-    @Query(value="select note from NoteBean note where note.id=:id")
-    public NoteBean findNoteBeanById(@Param("id") Integer id);
-
-    // 修改密码记事
-    @Modifying
-    // 说明该方法是事务性操作
-    @Transactional
-    // @Param注解用于提取参数
-    @Query("update NoteBean note set note.content=:content, note.updateTime=:updateTime where note.id=:noteId")
-    public int updateNoteBean(@Param("content") String content, @Param("noteId") Integer noteId, @Param("updateTime") Long updateTime);
-}