售货机商品列表及购买功能
parent
08420bb7e1
commit
9f40ad6a5e
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.bwie</groupId>
|
||||||
|
<artifactId>bwie-models</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>bwie-buy</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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<DTOGoods> showGoodsList(VOGoods voGoods);
|
||||||
|
|
||||||
|
|
||||||
|
Shop findById(@Param("shopId") Integer shopId);
|
||||||
|
|
||||||
|
void buyGood(VOGoods voGoods);
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
|
@ -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 "删除成功";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.bwie.buy.dao.BuyDao">
|
||||||
|
<update id="buyGood">
|
||||||
|
|
||||||
|
UPDATE `shop_manage`.`t_goods` SET
|
||||||
|
`goods_num` = (`goods_num`-1)
|
||||||
|
WHERE
|
||||||
|
`shop_id` = #{shopId} and
|
||||||
|
`facility_id` = #{facilityId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="showGoodsList" resultType="com.bwie.common.pojo.DTO.DTOGoods">
|
||||||
|
select * from t_goods g
|
||||||
|
left join t_shop s on g.shop_id=s.shop_id
|
||||||
|
left join t_facility f on g.facility_id=f.facility_id
|
||||||
|
WHERE f.facility_id=#{facilityId}
|
||||||
|
</select>
|
||||||
|
<select id="findById" resultType="com.bwie.common.pojo.Shop">
|
||||||
|
select * from t_shop
|
||||||
|
where shop_id=${shopId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -10,6 +10,10 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>bwie-models</artifactId>
|
<artifactId>bwie-models</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>bwie-buy</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
|
Loading…
Reference in New Issue