diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java b/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java new file mode 100644 index 00000000..1f848e8a --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/controller/ShopController.java @@ -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 addShop(@RequestBody Shop shop) { + Shop result = shopService.addShop(shop); + return ResponseEntity.ok(result); + } + + @GetMapping("/list") + public ResponseEntity> listShops() { + return ResponseEntity.ok(shopService.listShops()); + } + + @GetMapping("/{id}") + public ResponseEntity getShop(@PathVariable Long id) { + Shop shop = shopService.getShop(id); + if (shop == null) return ResponseEntity.notFound().build(); + return ResponseEntity.ok(shop); + } + + @PostMapping("/update") + public ResponseEntity 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 deleteShop(@PathVariable Long id) { + shopService.deleteShop(id); + return ResponseEntity.ok().build(); + } +} \ No newline at end of file diff --git a/ghy-shop/pom.xml b/ghy-shop/pom.xml new file mode 100644 index 00000000..2a579084 --- /dev/null +++ b/ghy-shop/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + ghy + com.ghy + 1.0.0 + + ghy-shop + jar + ghy-shop + 店铺服务模块 + + + + + org.springframework.boot + spring-boot-starter + + + + mysql + mysql-connector-java + runtime + + + + org.projectlombok + lombok + true + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java b/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java new file mode 100644 index 00000000..e9311f94 --- /dev/null +++ b/ghy-shop/src/main/java/com/ghy/shop/domain/Shop.java @@ -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; // 联系电话 +} \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java b/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java new file mode 100644 index 00000000..8014dd15 --- /dev/null +++ b/ghy-shop/src/main/java/com/ghy/shop/mapper/ShopMapper.java @@ -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 selectAll(); +} \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java b/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java new file mode 100644 index 00000000..12890ea8 --- /dev/null +++ b/ghy-shop/src/main/java/com/ghy/shop/service/ShopService.java @@ -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 listShops(); +} \ No newline at end of file diff --git a/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java b/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java new file mode 100644 index 00000000..ba6edcdd --- /dev/null +++ b/ghy-shop/src/main/java/com/ghy/shop/service/impl/ShopServiceImpl.java @@ -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 listShops() { + return shopMapper.selectAll(); + } +} \ No newline at end of file diff --git a/ghy-shop/src/main/resources/mapper/ShopMapper.xml b/ghy-shop/src/main/resources/mapper/ShopMapper.xml new file mode 100644 index 00000000..0be9af22 --- /dev/null +++ b/ghy-shop/src/main/resources/mapper/ShopMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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} + ) + + + + 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} + + + + DELETE FROM shop WHERE shop_id = #{shopId} + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index de2026c3..84dc7b26 100644 --- a/pom.xml +++ b/pom.xml @@ -333,6 +333,13 @@ ${ghy.version} + + + com.ghy + ghy-shop + ${ghy.version} + + com.github.wechatpay-apiv3 wechatpay-apache-httpclient @@ -367,6 +374,7 @@ ghy-custom ghy-worker ghy-message + ghy-shop pom