From 1ae670ded791b7a752ab8f8b4ac230446e3a8f6b Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 2 Jun 2022 09:05:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E2=80=9C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC=E5=90=8E=E5=9C=A8?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E2=80=9D?= =?UTF-8?q?=E4=B8=AD=E8=AE=B0=E5=BD=95=E7=9A=84=E5=8A=9F=E8=83=BD=202.?= =?UTF-8?q?=E5=88=A0=E9=99=A4update=E5=95=86=E5=93=81=E6=97=B6=E5=AF=B9?= =?UTF-8?q?=E5=8D=96=E5=AE=B6=E7=94=A8=E6=88=B7=E5=90=8D=E7=9A=84=E8=A6=81?= =?UTF-8?q?=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shop/controller/GoodsController.java | 17 +++- .../src/main/java/com/shop/entity/Goods.java | 15 ++++ .../java/com/shop/entity/PriceOperateLog.java | 44 ++++++++++ .../java/com/shop/mapper/GoodsMapper.java | 3 +- .../com/shop/mapper/PriceOperateLogDao.java | 19 ++++ .../java/com/shop/service/GoodsService.java | 6 +- .../shop/service/PriceOperateLogService.java | 13 +++ .../impl/PriceOperateLogServiceImpl.java | 40 +++++++++ .../{ => impl}/UnionPaymentServiceImpl.java | 3 +- .../src/main/resources/application-dev.yml | 2 +- .../main/resources/mapping/GoodsMapper.xml | 2 +- .../resources/mapping/PriceOperateLogDao.xml | 87 +++++++++++++++++++ 12 files changed, 241 insertions(+), 10 deletions(-) create mode 100644 back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java create mode 100644 back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java create mode 100644 back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java create mode 100644 back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java rename back-end_code/src/main/java/com/shop/service/{ => impl}/UnionPaymentServiceImpl.java (99%) create mode 100644 back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml diff --git a/back-end_code/src/main/java/com/shop/controller/GoodsController.java b/back-end_code/src/main/java/com/shop/controller/GoodsController.java index 0873d84..c17ee2f 100644 --- a/back-end_code/src/main/java/com/shop/controller/GoodsController.java +++ b/back-end_code/src/main/java/com/shop/controller/GoodsController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -19,7 +20,8 @@ import java.util.Map; public class GoodsController { @Autowired private GoodsService goodsService; - + @Autowired + private PriceOperateLogService priceOperateLogService; @Autowired private OrderService orderService; @@ -232,6 +234,17 @@ public class GoodsController { jsonObject.put("message",message); return jsonObject; } - + //修改商品价格 + @PutMapping(value = "/price") + public Object updatePrice(@RequestBody JSONObject jsonObject){ + int item_id = Integer.parseInt(jsonObject.getString("item_id")); + BigDecimal price_old = new BigDecimal(jsonObject.getString("price_old")); + BigDecimal price_new = new BigDecimal(jsonObject.getString("price_new")); + if (priceOperateLogService.setLog(item_id,price_old,price_new)==true) { + return Result.ok(); + }else { + return Result.fail(); + } + } } diff --git a/back-end_code/src/main/java/com/shop/entity/Goods.java b/back-end_code/src/main/java/com/shop/entity/Goods.java index ccdbde8..8d6baca 100644 --- a/back-end_code/src/main/java/com/shop/entity/Goods.java +++ b/back-end_code/src/main/java/com/shop/entity/Goods.java @@ -144,4 +144,19 @@ public class Goods { public void setGoods_state(GoodState goods_state) { this.goods_state = goods_state; } + + @Override + public String toString() { + return "Goods{" + + "item_id=" + item_id + + ", goods_name='" + goods_name + '\'' + + ", seller_username='" + seller_username + '\'' + + ", goods_stock=" + goods_stock + + ", goods_img='" + goods_img + '\'' + + ", goods_describe='" + goods_describe + '\'' + + ", goods_category=" + goods_category + + ", goods_price=" + goods_price + + ", goods_state=" + goods_state + + '}'; + } } diff --git a/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java b/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java new file mode 100644 index 0000000..0d70260 --- /dev/null +++ b/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java @@ -0,0 +1,44 @@ +package com.shop.entity; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import lombok.Data; + +/** + * price_operate_log + * @author + */ +@Data +public class PriceOperateLog implements Serializable { + private Long id; + + /** + * 商品id + */ + private Integer itemId; + + /** + * 改变前价格 + */ + private BigDecimal priceOld; + + /** + * 改变后价格 + */ + private BigDecimal priceNew; + + /** + * 创建时间 + */ + private Date createTime; + + public PriceOperateLog(Integer itemId, BigDecimal priceOld, BigDecimal priceNew, Date createTime) { + this.itemId = itemId; + this.priceOld = priceOld; + this.priceNew = priceNew; + this.createTime = createTime; + } + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/back-end_code/src/main/java/com/shop/mapper/GoodsMapper.java b/back-end_code/src/main/java/com/shop/mapper/GoodsMapper.java index 9c715a8..0d77979 100644 --- a/back-end_code/src/main/java/com/shop/mapper/GoodsMapper.java +++ b/back-end_code/src/main/java/com/shop/mapper/GoodsMapper.java @@ -32,12 +32,11 @@ public interface GoodsMapper { /** * 根据item_id(商品ID),newstate(商品状态)向Goods表中更新商品状态信息 - * @param seller_username * @param item_id * @param new_state * @return */ - int updateGoodsState(String seller_username,int item_id,int new_state); + int updateGoodsState(int item_id,int new_state); /** *根据username查找此用户是否有正在出售的商品 diff --git a/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java b/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java new file mode 100644 index 0000000..b1b1c19 --- /dev/null +++ b/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java @@ -0,0 +1,19 @@ +package com.shop.mapper; + +import com.shop.entity.PriceOperateLog; +import org.springframework.stereotype.Repository; + +@Repository +public interface PriceOperateLogDao { + int deleteByPrimaryKey(Long id); + + int insert(PriceOperateLog record); + + int insertSelective(PriceOperateLog record); + + PriceOperateLog selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(PriceOperateLog record); + + int updateByPrimaryKey(PriceOperateLog record); +} \ No newline at end of file diff --git a/back-end_code/src/main/java/com/shop/service/GoodsService.java b/back-end_code/src/main/java/com/shop/service/GoodsService.java index 134dcdb..9646290 100644 --- a/back-end_code/src/main/java/com/shop/service/GoodsService.java +++ b/back-end_code/src/main/java/com/shop/service/GoodsService.java @@ -23,15 +23,15 @@ public class GoodsService { } public Goods getNewItem(String goods_name, String goods_img,String goods_describe){ return goodsMapper.getNewItem(goods_name,goods_img,goods_describe);} public Goods searchGoods(int item_id){ return goodsMapper.searchGoods(item_id); } - public int updateGoodsState(String seller_username,int item_id,int new_state){return goodsMapper.updateGoodsState(seller_username,item_id, new_state);} + public int updateGoodsState(String seller_username,int item_id,int new_state){return goodsMapper.updateGoodsState(item_id, new_state);} public List searchSellingGoods(){return goodsMapper.searchSellingGoods();}//一页8条 public List searchFreezingGoods(String seller_username){return goodsMapper.searchFreezingGoods(seller_username);}//一页10条 public List searchHistoryGoods(String seller_username){ return goodsMapper.searchHistoryGoods(seller_username);}//一页10条 public int updateGoods(Goods newgoods){ if (newgoods.getGoods_stock() == 0){ - goodsMapper.updateGoodsState(newgoods.getSeller_username(),newgoods.getItem_id(),3); + goodsMapper.updateGoodsState(newgoods.getItem_id(),3); }else if (newgoods.getGoods_stock() > 0){ - goodsMapper.updateGoodsState(newgoods.getSeller_username(),newgoods.getItem_id(),1); + goodsMapper.updateGoodsState(newgoods.getItem_id(),1); } return goodsMapper.updateGoods(newgoods);} public List searchWelcomeGoods(){return goodsMapper.searchWelcomeGoods();} diff --git a/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java b/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java new file mode 100644 index 0000000..ef96e78 --- /dev/null +++ b/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java @@ -0,0 +1,13 @@ +package com.shop.service; + +import com.shop.entity.Goods; + +import java.math.BigDecimal; + +public interface PriceOperateLogService { + /** + * 新增一条记录 + */ + Boolean setLog(int item_id, BigDecimal price_old,BigDecimal price_new); + +} diff --git a/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java b/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java new file mode 100644 index 0000000..3ce1010 --- /dev/null +++ b/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java @@ -0,0 +1,40 @@ +package com.shop.service.impl; + +import com.shop.entity.Goods; +import com.shop.service.GoodsService; +import com.shop.service.PriceOperateLogService; +import com.shop.entity.PriceOperateLog; +import com.shop.mapper.PriceOperateLogDao; +import com.shop.service.SnapshotService; +import com.shop.utils.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.Date; +@Service +public class PriceOperateLogServiceImpl implements PriceOperateLogService { + @Autowired + private PriceOperateLogDao priceOperateLogDao; + @Autowired + private GoodsService goodsService; + @Autowired + private SnapshotService snapshotService; + @Override + public Boolean setLog(int item_id, BigDecimal price_old, BigDecimal price_new) { + Date day=new Date(); + PriceOperateLog priceOperateLog = new PriceOperateLog(item_id,price_old,price_new,day); + Goods good = new Goods(); + good.setGoods_price(price_new.floatValue()); + good.setItem_id(item_id); + System.out.println(good.toString()); + if (goodsService.updateGoods(good) >= 1) { + //snapshotService.addSnapshot(goodsService.getNewItem(good.getGoods_name(),good.getGoods_img(),good.getGoods_describe())); + priceOperateLogDao.insert(priceOperateLog); + return true; + }else { + return false; + } + + } +} diff --git a/back-end_code/src/main/java/com/shop/service/UnionPaymentServiceImpl.java b/back-end_code/src/main/java/com/shop/service/impl/UnionPaymentServiceImpl.java similarity index 99% rename from back-end_code/src/main/java/com/shop/service/UnionPaymentServiceImpl.java rename to back-end_code/src/main/java/com/shop/service/impl/UnionPaymentServiceImpl.java index 81e0faf..5980ddc 100644 --- a/back-end_code/src/main/java/com/shop/service/UnionPaymentServiceImpl.java +++ b/back-end_code/src/main/java/com/shop/service/impl/UnionPaymentServiceImpl.java @@ -1,5 +1,6 @@ -package com.shop.service; +package com.shop.service.impl; +import com.shop.service.OrderService; import com.shop.union.DemoBase; import com.shop.union.config.SDKConfig; import com.shop.union.constants.SDKConstants; diff --git a/back-end_code/src/main/resources/application-dev.yml b/back-end_code/src/main/resources/application-dev.yml index 0c5bdd4..a7529a5 100644 --- a/back-end_code/src/main/resources/application-dev.yml +++ b/back-end_code/src/main/resources/application-dev.yml @@ -6,7 +6,7 @@ spring: username: xiangwan password: dingwanren #url中database为对应的数据库名称 - url: jdbc:mysql://47.103.214.177:3306/service5.0?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC + url: jdbc:mysql://47.103.214.177:3306/service5.0?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8 driver-class-name: com.mysql.cj.jdbc.Driver devtools: restart: diff --git a/back-end_code/src/main/resources/mapping/GoodsMapper.xml b/back-end_code/src/main/resources/mapping/GoodsMapper.xml index 9e2df59..ba37601 100644 --- a/back-end_code/src/main/resources/mapping/GoodsMapper.xml +++ b/back-end_code/src/main/resources/mapping/GoodsMapper.xml @@ -105,7 +105,7 @@ goodsPrice = #{goods_price,jdbcType=REAL}, - where itemId = #{item_id,jdbcType=INTEGER} and sellerUsername = #{seller_username} + where itemId = #{item_id,jdbcType=INTEGER} diff --git a/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml b/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml new file mode 100644 index 0000000..415dda0 --- /dev/null +++ b/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + id, item_id, price_old, price_new, create_time + + + + delete from price_operate_log + where id = #{id,jdbcType=BIGINT} + + + insert into price_operate_log (item_id, price_old, price_new, + create_time) + values (#{itemId,jdbcType=INTEGER}, #{priceOld,jdbcType=DECIMAL}, #{priceNew,jdbcType=DECIMAL}, + #{createTime,jdbcType=TIMESTAMP}) + + + insert into price_operate_log + + + item_id, + + + price_old, + + + price_new, + + + create_time, + + + + + #{itemId,jdbcType=INTEGER}, + + + #{priceOld,jdbcType=DECIMAL}, + + + #{priceNew,jdbcType=DECIMAL}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + update price_operate_log + + + item_id = #{itemId,jdbcType=INTEGER}, + + + price_old = #{priceOld,jdbcType=DECIMAL}, + + + price_new = #{priceNew,jdbcType=DECIMAL}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=BIGINT} + + + update price_operate_log + set item_id = #{itemId,jdbcType=INTEGER}, + price_old = #{priceOld,jdbcType=DECIMAL}, + price_new = #{priceNew,jdbcType=DECIMAL}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file -- Gitee From fe1bba179d6f097a8aa699685b0a763a62395d4a Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 2 Jun 2022 10:30:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0"=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC=E4=BF=AE=E6=94=B9=E8=AE=B0?= =?UTF-8?q?=E5=BD=95"=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shop/controller/GoodsController.java | 12 ++++++++++++ .../main/java/com/shop/entity/PriceOperateLog.java | 3 +++ .../java/com/shop/mapper/PriceOperateLogDao.java | 5 ++++- .../com/shop/service/PriceOperateLogService.java | 7 ++++++- .../service/impl/PriceOperateLogServiceImpl.java | 7 +++++++ back-end_code/src/main/resources/application-dev.yml | 4 ++++ .../main/resources/mapping/PriceOperateLogDao.xml | 5 ++++- 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/back-end_code/src/main/java/com/shop/controller/GoodsController.java b/back-end_code/src/main/java/com/shop/controller/GoodsController.java index c17ee2f..b56ba26 100644 --- a/back-end_code/src/main/java/com/shop/controller/GoodsController.java +++ b/back-end_code/src/main/java/com/shop/controller/GoodsController.java @@ -246,5 +246,17 @@ public class GoodsController { return Result.fail(); } } + //获取商品价格操作记录 + @GetMapping("/price/log") + public Object getPriceOperateLog(@RequestParam String item_id){ + int id = Integer.parseInt(item_id); + try { + List logs = priceOperateLogService.selectByItemId(id); + return Result.ok(logs); + }catch (Exception e){ + e.printStackTrace(); + return Result.fail(); + } + } } diff --git a/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java b/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java index 0d70260..41c4564 100644 --- a/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java +++ b/back-end_code/src/main/java/com/shop/entity/PriceOperateLog.java @@ -40,5 +40,8 @@ public class PriceOperateLog implements Serializable { this.createTime = createTime; } + public PriceOperateLog() { + } + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java b/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java index b1b1c19..0b90e33 100644 --- a/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java +++ b/back-end_code/src/main/java/com/shop/mapper/PriceOperateLogDao.java @@ -3,6 +3,8 @@ package com.shop.mapper; import com.shop.entity.PriceOperateLog; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface PriceOperateLogDao { int deleteByPrimaryKey(Long id); @@ -10,10 +12,11 @@ public interface PriceOperateLogDao { int insert(PriceOperateLog record); int insertSelective(PriceOperateLog record); - + List selectByItemId(int item_id); PriceOperateLog selectByPrimaryKey(Long id); int updateByPrimaryKeySelective(PriceOperateLog record); int updateByPrimaryKey(PriceOperateLog record); + } \ No newline at end of file diff --git a/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java b/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java index ef96e78..c66fb7c 100644 --- a/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java +++ b/back-end_code/src/main/java/com/shop/service/PriceOperateLogService.java @@ -1,13 +1,18 @@ package com.shop.service; import com.shop.entity.Goods; +import com.shop.entity.PriceOperateLog; import java.math.BigDecimal; +import java.util.List; public interface PriceOperateLogService { /** * 新增一条记录 */ Boolean setLog(int item_id, BigDecimal price_old,BigDecimal price_new); - + /** + * 根据商品id获取更改记录 + */ + List selectByItemId(int item_id); } diff --git a/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java b/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java index 3ce1010..7431976 100644 --- a/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java +++ b/back-end_code/src/main/java/com/shop/service/impl/PriceOperateLogServiceImpl.java @@ -12,6 +12,8 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.Date; +import java.util.List; + @Service public class PriceOperateLogServiceImpl implements PriceOperateLogService { @Autowired @@ -37,4 +39,9 @@ public class PriceOperateLogServiceImpl implements PriceOperateLogService { } } + + @Override + public List selectByItemId(int item_id) { + return priceOperateLogDao.selectByItemId(item_id); + } } diff --git a/back-end_code/src/main/resources/application-dev.yml b/back-end_code/src/main/resources/application-dev.yml index a7529a5..82c7a43 100644 --- a/back-end_code/src/main/resources/application-dev.yml +++ b/back-end_code/src/main/resources/application-dev.yml @@ -8,6 +8,10 @@ spring: #url中database为对应的数据库名称 url: jdbc:mysql://47.103.214.177:3306/service5.0?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8 driver-class-name: com.mysql.cj.jdbc.Driver + jackson: + # json 序列化配置 + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 devtools: restart: enabled: true #设置开启热部署 diff --git a/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml b/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml index 415dda0..2a79938 100644 --- a/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml +++ b/back-end_code/src/main/resources/mapping/PriceOperateLogDao.xml @@ -17,7 +17,10 @@ from price_operate_log where id = #{id,jdbcType=BIGINT} - + + delete from price_operate_log where id = #{id,jdbcType=BIGINT} -- Gitee