From 08420bb7e14d0e2d33bc7def37ff3b1017439d91 Mon Sep 17 00:00:00 2001 From: fangzhe <675599480@qq.com> Date: Sun, 17 Dec 2023 15:10:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=94=AE=E8=B4=A7=E6=9C=BA=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E5=8F=8A=E8=B4=AD=E4=B9=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/encodings.xml | 2 + .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../com/bwie/common/pojo/DTO/DTOGoods.java | 33 +++++ .../java/com/bwie/common/pojo/Facility.java | 28 ++++ .../main/java/com/bwie/common/pojo/Goods.java | 23 ++++ .../main/java/com/bwie/common/pojo/Shop.java | 23 ++++ .../java/com/bwie/common/pojo/VO/VOGoods.java | 27 ++++ .../bwie/buy/service/impl/BuyServiceImp.java | 50 +++++++ 8 files changed, 310 insertions(+) create mode 100644 .idea/uiDesigner.xml create mode 100644 bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOGoods.java create mode 100644 bwie-common/src/main/java/com/bwie/common/pojo/Facility.java create mode 100644 bwie-common/src/main/java/com/bwie/common/pojo/Goods.java create mode 100644 bwie-common/src/main/java/com/bwie/common/pojo/Shop.java create mode 100644 bwie-common/src/main/java/com/bwie/common/pojo/VO/VOGoods.java create mode 100644 bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index bb4e79a..6769d5e 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -4,7 +4,9 @@ + + diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOGoods.java b/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOGoods.java new file mode 100644 index 0000000..64b13e6 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOGoods.java @@ -0,0 +1,33 @@ +package com.bwie.common.pojo.DTO; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class DTOGoods { + private Integer goodsId; //商品设备中间id + private Integer shopId; //商品id + private Integer facilityId; //设备id + private Integer goodsNum; //库存 + private Integer goodsIsDelete; //上下架(逻辑字段: 0上架, 1下架) + private String shopName; //商品名称 + private Double shopPrice; //商品价格 + private Integer typeId; //商品类型id + private String facilityType; //设备类型 + private String facilitySite; //设备地址 + private Integer replenishmentUserId; //补货员工 + private Integer maintainUserId; //维修员工 + private String facilityStatic; //设备状态 + private Integer delId; //删除状态 + +} diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/Facility.java b/bwie-common/src/main/java/com/bwie/common/pojo/Facility.java new file mode 100644 index 0000000..a51451f --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/pojo/Facility.java @@ -0,0 +1,28 @@ +package com.bwie.common.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class Facility { + private Integer facilityId; //设备编号 + private String facilityType; //设备类型 + private String facilitySite; //设备地址 + private Integer replenishmentUserId; //补货员工 + private Integer maintainUserId; //维修员工 + private String facilityStatic; //设备状态 + private Integer delId; //删除状态 + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/Goods.java b/bwie-common/src/main/java/com/bwie/common/pojo/Goods.java new file mode 100644 index 0000000..32dff04 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/pojo/Goods.java @@ -0,0 +1,23 @@ +package com.bwie.common.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class Goods { + private Integer goodsId; //商品设备中间id + private Integer shopId; //商品id + private Integer facilityId; //设备id + private Integer goodsNum; //库存 + private Integer goodsIsDelete; //上下架(逻辑字段: 0上架, 1下架) +} diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/Shop.java b/bwie-common/src/main/java/com/bwie/common/pojo/Shop.java new file mode 100644 index 0000000..de761ea --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/pojo/Shop.java @@ -0,0 +1,23 @@ +package com.bwie.common.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class Shop { + private Integer shopId; //商品id + private String shopName; //商品名称 + private Double shopPrice; //商品价格 + private Integer typeId; //商品类型id + +} diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/VO/VOGoods.java b/bwie-common/src/main/java/com/bwie/common/pojo/VO/VOGoods.java new file mode 100644 index 0000000..78a91c0 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/pojo/VO/VOGoods.java @@ -0,0 +1,27 @@ +package com.bwie.common.pojo.VO; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class VOGoods { + private Integer goodsId; //商品设备中间id + private Integer shopId; //商品id + private Integer facilityId; //设备id + private Integer goodsNum; //库存 + private Integer goodsIsDelete; //上下架(逻辑字段: 0上架, 1下架) + private Double payForMoney; //支付金额 + + private Integer pageNum=1; + private Integer pageSize=3; +} diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java new file mode 100644 index 0000000..0d69400 --- /dev/null +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java @@ -0,0 +1,50 @@ +package com.bwie.buy.service.impl; + +import com.bwie.buy.dao.BuyDao; +import com.bwie.buy.service.BuyService; +import com.bwie.common.pojo.DTO.DTOGoods; +import com.bwie.common.pojo.Shop; +import com.bwie.common.pojo.VO.VOGoods; +import com.bwie.common.result.Result; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Service +public class BuyServiceImp implements BuyService { + @Autowired + private BuyDao dao; + + + @Override + public Result buyGood(VOGoods voGoods) { + if(null==voGoods.getFacilityId()||null==voGoods.getPayForMoney()){ + return Result.error("输入的值有误或未输入"); + } + Shop shop=dao.findById(voGoods.getShopId()); + if(shop.getShopPrice()>voGoods.getPayForMoney()){ + return Result.error("小老弟,钱不够"); + } + + //voGoods 参数有商品编号和售货机编号 + dao.buyGood(voGoods); + + return Result.success("购买成功"); + } + + @Override + public Result showGoodsList(VOGoods voGoods) { + PageHelper.startPage(voGoods.getPageNum(),voGoods.getPageSize()); + List list=dao.showGoodsList(voGoods); + PageInfo info = new PageInfo<>(list); + return Result.success(info); + } +} From 9f40ad6a5e989a63c4c116dc960722737874958d Mon Sep 17 00:00:00 2001 From: fangzhe <675599480@qq.com> Date: Sun, 17 Dec 2023 16:23:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=94=AE=E8=B4=A7=E6=9C=BA=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E5=8F=8A=E8=B4=AD=E4=B9=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bwie-models/bwie-buy/pom.xml | 20 +++++++ .../java/com/bwie/buy/BuyApplication.java | 18 ++++++ .../bwie/buy/controller/BuyController.java | 57 +++++++++++++++++++ .../main/java/com/bwie/buy/dao/BuyDao.java | 27 +++++++++ .../java/com/bwie/buy/service/BuyService.java | 15 +++++ .../main/java/com/bwie/buy/util/FastUtil.java | 55 ++++++++++++++++++ .../bwie-buy/src/main/resources/bootstrap.yml | 41 +++++++++++++ .../src/main/resources/mapper/BuyMapper.xml | 23 ++++++++ bwie-models/pom.xml | 4 ++ 9 files changed, 260 insertions(+) create mode 100644 bwie-models/bwie-buy/pom.xml create mode 100644 bwie-models/bwie-buy/src/main/java/com/bwie/buy/BuyApplication.java create mode 100644 bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java create mode 100644 bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java create mode 100644 bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/BuyService.java create mode 100644 bwie-models/bwie-buy/src/main/java/com/bwie/buy/util/FastUtil.java create mode 100644 bwie-models/bwie-buy/src/main/resources/bootstrap.yml create mode 100644 bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml diff --git a/bwie-models/bwie-buy/pom.xml b/bwie-models/bwie-buy/pom.xml new file mode 100644 index 0000000..3cc4cd5 --- /dev/null +++ b/bwie-models/bwie-buy/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + com.bwie + bwie-models + 1.0-SNAPSHOT + + + bwie-buy + + + 8 + 8 + UTF-8 + + + diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/BuyApplication.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/BuyApplication.java new file mode 100644 index 0000000..322bc35 --- /dev/null +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/BuyApplication.java @@ -0,0 +1,18 @@ +package com.bwie.buy; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@SpringBootApplication +@MapperScan("com.bwie.buy.dao") +public class BuyApplication { + public static void main(String[] args) { + SpringApplication.run(BuyApplication.class,args); + } +} diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java new file mode 100644 index 0000000..75506ff --- /dev/null +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java @@ -0,0 +1,57 @@ +package com.bwie.buy.controller; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.buy.service.BuyService; +import com.bwie.common.pojo.VO.VOGoods; +import com.bwie.common.result.Result; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Log4j2 +@RestController +@RequestMapping("/buy") +public class BuyController { + @Autowired + private BuyService service; + @Autowired + private HttpServletRequest request; + + + + @PostMapping("/showGoodsList") + public Result showGoodsList(@RequestBody VOGoods voGoods){ + + log.info("功能:{商品列表展示},请求URI:{},请求方法:{},请求参数:{}", + request.getRequestURI(), request.getMethod(),voGoods ); + Result result=service.showGoodsList(voGoods); + log.info("功能:{商品列表展示},请求URI:{},请求方法:{},响应参数:{}", + request.getRequestURI(), request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + + @PostMapping("/buyGood") + public Result buyGood(@RequestBody VOGoods voGoods){ + + log.info("功能:{购买商品},请求URI:{},请求方法:{},请求参数:{}", + request.getRequestURI(), request.getMethod(),voGoods ); + Result result=service.buyGood(voGoods); + log.info("功能:{购买商品},请求URI:{},请求方法:{},响应参数:{}", + request.getRequestURI(), request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + + +} diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java new file mode 100644 index 0000000..5b9023d --- /dev/null +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java @@ -0,0 +1,27 @@ +package com.bwie.buy.dao; + +import com.bwie.common.pojo.DTO.DTOGoods; +import com.bwie.common.pojo.Shop; +import com.bwie.common.pojo.VO.VOGoods; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +@Component +public interface BuyDao { + + + List showGoodsList(VOGoods voGoods); + + + Shop findById(@Param("shopId") Integer shopId); + + void buyGood(VOGoods voGoods); + +} diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/BuyService.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/BuyService.java new file mode 100644 index 0000000..68408b4 --- /dev/null +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/BuyService.java @@ -0,0 +1,15 @@ +package com.bwie.buy.service; + +import com.bwie.common.pojo.VO.VOGoods; +import com.bwie.common.result.Result; + +/** + * @author FangShiBa + * @date 2023/12/17 + * @apiNote + */ +public interface BuyService { + Result buyGood(VOGoods voGoods); + + Result showGoodsList(VOGoods voGoods); +} diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/util/FastUtil.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/util/FastUtil.java new file mode 100644 index 0000000..c9a5e45 --- /dev/null +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/util/FastUtil.java @@ -0,0 +1,55 @@ +package com.bwie.buy.util; + +import org.springframework.stereotype.Component; +import com.github.tobato.fastdfs.domain.fdfs.StorePath; +import com.github.tobato.fastdfs.service.FastFileStorageClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; + +/** + * @BelongsProject: 0107day02 + * @BelongsPackage: com.bw.config + * @Author: zhupengfei + * @CreateTime: 2023-02-01 08:52 + */ +@Component +public class FastUtil { + private static final Logger log = LoggerFactory.getLogger(FastUtil.class); + + @Resource + private FastFileStorageClient storageClient ; + + /** + * 上传文件 + */ + public String upload(MultipartFile multipartFile) throws Exception{ + String originalFilename = multipartFile.getOriginalFilename(). + substring(multipartFile.getOriginalFilename(). + lastIndexOf(".") + 1); + StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage( + multipartFile.getInputStream(), + multipartFile.getSize(),originalFilename , null); + return storePath.getFullPath() ; + } + /** + * 删除文件 + */ + public String deleteFile(String fileUrl) { + if (StringUtils.isEmpty(fileUrl)) { + log.info("fileUrl == >>文件路径为空..."); + return "文件路径不能为空"; + } + try { + StorePath storePath = StorePath.parseFromUrl(fileUrl); + storageClient.deleteFile(storePath.getGroup(), storePath.getPath()); + } catch (Exception e) { + log.error(e.getMessage()); + } + return "删除成功"; + } + +} diff --git a/bwie-models/bwie-buy/src/main/resources/bootstrap.yml b/bwie-models/bwie-buy/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..0afddb4 --- /dev/null +++ b/bwie-models/bwie-buy/src/main/resources/bootstrap.yml @@ -0,0 +1,41 @@ +# Tomcat +server: + port: 9004 +# Spring +spring: + main: + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-buy + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 110.42.214.8:8848 + config: + # 配置中心地址 + server-addr: 110.42.214.8:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +fdfs: + so-timeout: 1500 # socket 连接时长 + connect-timeout: 600 # 连接 tracker 服务器超时时长 + # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流 + tracker-list: 110.42.214.8:22122 + web-server-url: 110.42.214.8:8888 + pool: + jmx-enabled: false + # 生成缩略图 + thumb-image: + height: 500 + width: 500 diff --git a/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml b/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml new file mode 100644 index 0000000..2b177f4 --- /dev/null +++ b/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml @@ -0,0 +1,23 @@ + + + + + + UPDATE `shop_manage`.`t_goods` SET + `goods_num` = (`goods_num`-1) + WHERE + `shop_id` = #{shopId} and + `facility_id` = #{facilityId} + + + + + diff --git a/bwie-models/pom.xml b/bwie-models/pom.xml index 773a9c7..cd3e375 100644 --- a/bwie-models/pom.xml +++ b/bwie-models/pom.xml @@ -10,6 +10,10 @@ bwie-models + pom + + bwie-buy + 8 From 9234eb12b4b0ca373affe18de4674eca02b75b21 Mon Sep 17 00:00:00 2001 From: fangzhe <675599480@qq.com> Date: Mon, 18 Dec 2023 21:05:54 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=94=AE=E8=B4=A7=E6=9C=BA=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E5=8F=8A=E8=B4=AD=E4=B9=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD(=E5=AE=8C=E5=96=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bwie/common/pojo/DTO/DTOUser.java | 12 ++++++ .../main/java/com/bwie/common/pojo/Sell.java | 31 +++++++++++++++ bwie-models/bwie-buy/.gitignore | 38 +++++++++++++++++++ .../bwie/buy/controller/BuyController.java | 9 +++-- .../main/java/com/bwie/buy/dao/BuyDao.java | 2 + .../bwie/buy/service/impl/BuyServiceImp.java | 19 +++++++++- .../src/main/resources/mapper/BuyMapper.xml | 6 +++ 7 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 bwie-common/src/main/java/com/bwie/common/pojo/Sell.java create mode 100644 bwie-models/bwie-buy/.gitignore diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOUser.java b/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOUser.java index 39344e8..94bebf7 100644 --- a/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOUser.java +++ b/bwie-common/src/main/java/com/bwie/common/pojo/DTO/DTOUser.java @@ -1,9 +1,21 @@ package com.bwie.common.pojo.DTO; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + /** * @author FangShiBa * @date 2023/12/16 * @apiNote */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString public class DTOUser { + private Integer userId; + + } diff --git a/bwie-common/src/main/java/com/bwie/common/pojo/Sell.java b/bwie-common/src/main/java/com/bwie/common/pojo/Sell.java new file mode 100644 index 0000000..54c3cfc --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/pojo/Sell.java @@ -0,0 +1,31 @@ +package com.bwie.common.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +/** + * @author FangShiBa + * @date 2023/12/18 + * @apiNote + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class Sell { + private Integer sellId; + private Integer shopId; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + private Date sellTime; + private Integer userId; + private Integer facilityId; + + +} diff --git a/bwie-models/bwie-buy/.gitignore b/bwie-models/bwie-buy/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/bwie-models/bwie-buy/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java index 75506ff..da9a31f 100644 --- a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/controller/BuyController.java @@ -27,8 +27,9 @@ public class BuyController { @Autowired private HttpServletRequest request; - - + /* + 商品列表展示,购买商品时展示 + */ @PostMapping("/showGoodsList") public Result showGoodsList(@RequestBody VOGoods voGoods){ @@ -40,7 +41,9 @@ public class BuyController { return result; } - + /* + 购买商品 + */ @PostMapping("/buyGood") public Result buyGood(@RequestBody VOGoods voGoods){ diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java index 5b9023d..ef4ae53 100644 --- a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/dao/BuyDao.java @@ -1,6 +1,7 @@ package com.bwie.buy.dao; import com.bwie.common.pojo.DTO.DTOGoods; +import com.bwie.common.pojo.Sell; import com.bwie.common.pojo.Shop; import com.bwie.common.pojo.VO.VOGoods; import org.apache.ibatis.annotations.Param; @@ -24,4 +25,5 @@ public interface BuyDao { void buyGood(VOGoods voGoods); + void addSell(Sell sell); } diff --git a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java index 0d69400..edf1f2a 100644 --- a/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java +++ b/bwie-models/bwie-buy/src/main/java/com/bwie/buy/service/impl/BuyServiceImp.java @@ -1,16 +1,22 @@ package com.bwie.buy.service.impl; +import com.alibaba.fastjson.JSON; import com.bwie.buy.dao.BuyDao; import com.bwie.buy.service.BuyService; +import com.bwie.common.constants.JwtConstants; import com.bwie.common.pojo.DTO.DTOGoods; +import com.bwie.common.pojo.DTO.DTOUser; +import com.bwie.common.pojo.Sell; import com.bwie.common.pojo.Shop; import com.bwie.common.pojo.VO.VOGoods; import com.bwie.common.result.Result; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletRequest; import java.util.List; /** @@ -22,7 +28,10 @@ import java.util.List; public class BuyServiceImp implements BuyService { @Autowired private BuyDao dao; - + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private HttpServletRequest request; @Override public Result buyGood(VOGoods voGoods) { @@ -36,6 +45,14 @@ public class BuyServiceImp implements BuyService { //voGoods 参数有商品编号和售货机编号 dao.buyGood(voGoods); + String token = request.getHeader("token"); + String s = redisTemplate.opsForValue().get(JwtConstants.LOGIN_TOKEN + token); + DTOUser dtoUser = JSON.parseObject(s, DTOUser.class); + Sell sell = new Sell(); + sell.setFacilityId(voGoods.getFacilityId()); + sell.setShopId(voGoods.getShopId()); + sell.setUserId(dtoUser.getUserId()); + dao.addSell(sell); return Result.success("购买成功"); } diff --git a/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml b/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml index 2b177f4..93d3d47 100644 --- a/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml +++ b/bwie-models/bwie-buy/src/main/resources/mapper/BuyMapper.xml @@ -1,6 +1,12 @@ + + INSERT INTO `shop_manage`.`t_sell` + (`shop_id`, `sell_time`, `user_id`, `facility_id`) VALUES + (#{shopId}, now(), #{userId}, #{facilityId}); + + UPDATE `shop_manage`.`t_goods` SET