no message

This commit is contained in:
cb 2025-06-16 15:37:36 +08:00
parent cedc78e76e
commit dfcf26d976
8 changed files with 265 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package com.ghy.web.controller;
import com.ghy.shop.domain.Shop;
import com.ghy.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 店铺管理接口
*/
@RestController
@RequestMapping("/shop")
public class ShopController {
@Autowired
private ShopService shopService;
@PostMapping("/add")
public ResponseEntity<Shop> addShop(@RequestBody Shop shop) {
Shop result = shopService.addShop(shop);
return ResponseEntity.ok(result);
}
@GetMapping("/list")
public ResponseEntity<List<Shop>> listShops() {
return ResponseEntity.ok(shopService.listShops());
}
@GetMapping("/{id}")
public ResponseEntity<Shop> getShop(@PathVariable Long id) {
Shop shop = shopService.getShop(id);
if (shop == null) return ResponseEntity.notFound().build();
return ResponseEntity.ok(shop);
}
@PostMapping("/update")
public ResponseEntity<Shop> updateShop(@RequestBody Shop shop) {
Shop result = shopService.updateShop(shop);
if (result == null) return ResponseEntity.notFound().build();
return ResponseEntity.ok(result);
}
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteShop(@PathVariable Long id) {
shopService.deleteShop(id);
return ResponseEntity.ok().build();
}
}

44
ghy-shop/pom.xml Normal file
View File

@ -0,0 +1,44 @@
<?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>
<artifactId>ghy</artifactId>
<groupId>com.ghy</groupId>
<version>1.0.0</version>
</parent>
<artifactId>ghy-shop</artifactId>
<packaging>jar</packaging>
<name>ghy-shop</name>
<description>店铺服务模块</description>
<dependencies>
<!-- Spring Boot 基础依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- MySQL 驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- 其他依赖可根据需要添加 -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,30 @@
package com.ghy.shop.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* 店铺信息实体类
*/
@Data
@TableName("shop")
public class Shop implements Serializable {
@TableId
private Long shopId; // 店铺ID
private String shopName; // 店铺名称
private String imageUrl; // 店铺图片
private Long provinceId;
private String provinceName;
private Long cityId;
private String cityName;
private Long countryId;
private String countryName;
private Long streetId;
private String streetName;
private String address; // 详细地址
private String phone; // 联系电话
}

View File

@ -0,0 +1,15 @@
package com.ghy.shop.mapper;
import com.ghy.shop.domain.Shop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface ShopMapper {
int insert(Shop shop);
int update(Shop shop);
int delete(@Param("shopId") Long shopId);
Shop select(@Param("shopId") Long shopId);
List<Shop> selectAll();
}

View File

@ -0,0 +1,12 @@
package com.ghy.shop.service;
import com.ghy.shop.domain.Shop;
import java.util.List;
public interface ShopService {
int addShop(Shop shop);
int updateShop(Shop shop);
int deleteShop(Long shopId);
Shop getShop(Long shopId);
List<Shop> listShops();
}

View File

@ -0,0 +1,40 @@
package com.ghy.shop.service.impl;
import com.ghy.shop.domain.Shop;
import com.ghy.shop.mapper.ShopMapper;
import com.ghy.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ShopServiceImpl implements ShopService {
@Autowired
private ShopMapper shopMapper;
@Override
public int addShop(Shop shop) {
return shopMapper.insert(shop);
}
@Override
public int updateShop(Shop shop) {
return shopMapper.update(shop);
}
@Override
public int deleteShop(Long shopId) {
return shopMapper.delete(shopId);
}
@Override
public Shop getShop(Long shopId) {
return shopMapper.select(shopId);
}
@Override
public List<Shop> listShops() {
return shopMapper.selectAll();
}
}

View File

@ -0,0 +1,67 @@
<?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.ghy.shop.mapper.ShopMapper">
<!-- 基础resultMap可扩展自定义SQL -->
<resultMap id="ShopResultMap" type="com.ghy.shop.domain.Shop">
<id property="shopId" column="shop_id"/>
<result property="shopName" column="shop_name"/>
<result property="imageUrl" column="image_url"/>
<result property="provinceId" column="province_id"/>
<result property="provinceName" column="province_name"/>
<result property="cityId" column="city_id"/>
<result property="cityName" column="city_name"/>
<result property="countryId" column="country_id"/>
<result property="countryName" column="country_name"/>
<result property="streetId" column="street_id"/>
<result property="streetName" column="street_name"/>
<result property="address" column="address"/>
<result property="phone" column="phone"/>
</resultMap>
<!-- 可在此处添加自定义SQL语句 -->
<!--
<select id="selectByCityId" resultMap="ShopResultMap">
SELECT * FROM shop WHERE city_id = #{cityId}
</select>
-->
<insert id="insert" parameterType="com.ghy.shop.domain.Shop">
INSERT INTO shop (
shop_name, image_url, province_id, province_name, city_id, city_name, country_id, country_name, street_id, street_name, address, phone
) VALUES (
#{shopName}, #{imageUrl}, #{provinceId}, #{provinceName}, #{cityId}, #{cityName}, #{countryId}, #{countryName}, #{streetId}, #{streetName}, #{address}, #{phone}
)
</insert>
<update id="update" parameterType="com.ghy.shop.domain.Shop">
UPDATE shop
SET shop_name = #{shopName},
image_url = #{imageUrl},
province_id = #{provinceId},
province_name = #{provinceName},
city_id = #{cityId},
city_name = #{cityName},
country_id = #{countryId},
country_name = #{countryName},
street_id = #{streetId},
street_name = #{streetName},
address = #{address},
phone = #{phone}
WHERE shop_id = #{shopId}
</update>
<delete id="delete" parameterType="long">
DELETE FROM shop WHERE shop_id = #{shopId}
</delete>
<select id="select" parameterType="long" resultMap="ShopResultMap">
SELECT * FROM shop WHERE shop_id = #{shopId}
</select>
<select id="selectAll" resultMap="ShopResultMap">
SELECT * FROM shop
</select>
</mapper>

View File

@ -333,6 +333,13 @@
<version>${ghy.version}</version>
</dependency>
<dependency>
<groupId>com.ghy</groupId>
<artifactId>ghy-shop</artifactId>
<version>${ghy.version}</version>
</dependency>
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-apache-httpclient</artifactId>
@ -367,6 +374,7 @@
<module>ghy-custom</module>
<module>ghy-worker</module>
<module>ghy-message</module>
<module>ghy-shop</module>
</modules>
<packaging>pom</packaging>