diff --git a/core/api/src/main/java/com/wansenai/api/shop/ShopController.java b/core/api/src/main/java/com/wansenai/api/shop/ShopController.java index 073fdfc..d9d29d6 100644 --- a/core/api/src/main/java/com/wansenai/api/shop/ShopController.java +++ b/core/api/src/main/java/com/wansenai/api/shop/ShopController.java @@ -1,19 +1,95 @@ package com.wansenai.api.shop; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.wansenai.entities.shop.BasShop; +import com.wansenai.service.shop.BasShopService; +import com.wansenai.utils.response.Response; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; /** *

商店档案

* @author clunt */ +@Tag(name = "店铺管理接口") @RestController -@RequestMapping("shop") +@RequestMapping("basShop") @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class ShopController { + private final BasShopService shopService; + @Operation(summary = "获取店铺列表") + @GetMapping("/list") + public Response> getShopList( + @Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page, + @Parameter(description = "每页数量") @RequestParam(defaultValue = "10") Integer pageSize, + @Parameter(description = "店铺名称") @RequestParam(required = false) String name, + @Parameter(description = "店铺编码") @RequestParam(required = false) String code, + @Parameter(description = "渠道") @RequestParam(required = false) String channel) { + + Page pageRequest = new Page<>(page, pageSize); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .like(name != null, BasShop::getName, name) + .eq(code != null, BasShop::getCode, code) + .eq(channel != null, BasShop::getChannel, channel); + + return Response.responseData(shopService.page(pageRequest, queryWrapper)); + } + @Operation(summary = "根据ID获取店铺信息") + @GetMapping("/{id}") + public Response getShopById(@Parameter(description = "店铺ID") @PathVariable Long id) { + return Response.responseData(shopService.getById(id)); + } + + @Operation(summary = "根据编码获取店铺信息") + @GetMapping("/code/{code}") + public Response getShopByCode(@Parameter(description = "店铺编码") @PathVariable String code) { + return Response.responseData(shopService.getShopByCode(code)); + } + + @Operation(summary = "根据名称搜索店铺") + @GetMapping("/search") + public Response> searchShopByName(@Parameter(description = "店铺名称") @RequestParam String name) { + return Response.responseData(shopService.getShopListByName(name)); + } + + @Operation(summary = "添加店铺") + @PostMapping("/add") + public Response addShop(@RequestBody BasShop shop) { + return Response.responseData(shopService.addShop(shop)); + } + + @Operation(summary = "批量添加店铺") + @PostMapping("/batch") + public Response batchAddShop(@RequestBody List shopList) { + return Response.responseData(shopService.batchAddShop(shopList)); + } + + @Operation(summary = "更新店铺信息") + @PutMapping("/update") + public Response updateShop(@RequestBody BasShop shop) { + return Response.responseData(shopService.updateShop(shop)); + } + + @Operation(summary = "删除店铺") + @DeleteMapping("/delete/{id}") + public Response deleteShop(@Parameter(description = "店铺ID") @PathVariable Long id) { + return Response.responseData(shopService.deleteShop(id)); + } + + @Operation(summary = "根据渠道获取店铺列表") + @GetMapping("/channel/{channel}") + public Response> getShopListByChannel(@Parameter(description = "渠道") @PathVariable String channel) { + return Response.responseData(shopService.getShopListByChannel(channel)); + } } diff --git a/core/api/src/main/resources/application.yml b/core/api/src/main/resources/application.yml index f0207d4..f636075 100644 --- a/core/api/src/main/resources/application.yml +++ b/core/api/src/main/resources/application.yml @@ -63,3 +63,7 @@ springdoc: - group: '档案模块' paths-to-match: '/**' packages-to-scan: com.wansenai.api.support + - group: '商店模块' + paths-to-match: '/**' + packages-to-scan: com.wansenai.api.shop + diff --git a/core/dao/src/main/java/com/wansenai/mappers/shop/BasShopMapper.java b/core/dao/src/main/java/com/wansenai/mappers/shop/BasShopMapper.java new file mode 100644 index 0000000..6f3ed83 --- /dev/null +++ b/core/dao/src/main/java/com/wansenai/mappers/shop/BasShopMapper.java @@ -0,0 +1,32 @@ +package com.wansenai.mappers.shop; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.wansenai.entities.shop.BasShop; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface BasShopMapper extends BaseMapper { + + /** + * 根据店铺编码查询店铺信息 + */ + BasShop getShopByCode(@Param("code") String code); + + /** + * 根据店铺名称模糊查询店铺列表 + */ + List getShopListByName(@Param("name") String name); + + /** + * 根据渠道查询店铺列表 + */ + List getShopListByChannel(@Param("channel") String channel); + + /** + * 批量插入店铺信息 + */ + int batchInsert(@Param("shopList") List shopList); +} diff --git a/core/dao/src/main/resources/mapper_xml/shop/BasShopMapper.xml b/core/dao/src/main/resources/mapper_xml/shop/BasShopMapper.xml new file mode 100644 index 0000000..0568a43 --- /dev/null +++ b/core/dao/src/main/resources/mapper_xml/shop/BasShopMapper.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, code, name, channel, type, address_id, price_type, + field_1, field_2, field_3, field_4, field_5, field_6, field_7, field_8, field_9, field_10, + create_time, create_by, update_time, update_by, remark + + + + + + + + + + + + + + INSERT INTO bas_shop ( + code, name, channel, type, address_id, price_type, + field_1, field_2, field_3, field_4, field_5, + field_6, field_7, field_8, field_9, field_10, + create_time, create_by, remark + ) VALUES + + ( + #{shop.code}, #{shop.name}, #{shop.channel}, #{shop.type}, + #{shop.addressId}, #{shop.priceType}, + #{shop.field1}, #{shop.field2}, #{shop.field3}, #{shop.field4}, #{shop.field5}, + #{shop.field6}, #{shop.field7}, #{shop.field8}, #{shop.field9}, #{shop.field10}, + #{shop.createTime}, #{shop.createBy}, #{shop.remark} + ) + + + + diff --git a/core/domain/src/main/java/com/wansenai/entities/shop/BasShop.java b/core/domain/src/main/java/com/wansenai/entities/shop/BasShop.java index 270a0ed..61d20fd 100644 --- a/core/domain/src/main/java/com/wansenai/entities/shop/BasShop.java +++ b/core/domain/src/main/java/com/wansenai/entities/shop/BasShop.java @@ -2,6 +2,7 @@ package com.wansenai.entities.shop; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; import lombok.experimental.Accessors; @@ -16,62 +17,85 @@ import java.util.Date; @Builder @NoArgsConstructor @AllArgsConstructor +@Schema(description = "店铺基础信息表") public class BasShop implements Serializable { @Serial private static final long serialVersionUID = 1L; + @Schema(description = "主键ID") private Long id; + @Schema(description = "店铺编码") private String code; + @Schema(description = "店铺名称") private String name; + @Schema(description = "渠道") private String channel; + @Schema(description = "类型") private String type; + @Schema(description = "地址ID") private Long addressId; + @Schema(description = "价格类型") private String priceType; + @Schema(description = "自定义字段1") @TableField(value = "field_1") private String field1; + @Schema(description = "自定义字段2") @TableField(value = "field_2") private String field2; + @Schema(description = "自定义字段3") @TableField(value = "field_3") private String field3; + @Schema(description = "自定义字段4") @TableField(value = "field_4") private String field4; + @Schema(description = "自定义字段5") @TableField(value = "field_5") private String field5; + @Schema(description = "自定义字段6") @TableField(value = "field_6") private String field6; + @Schema(description = "自定义字段7") @TableField(value = "field_7") private String field7; + @Schema(description = "自定义字段8") @TableField(value = "field_8") private String field8; + @Schema(description = "自定义字段9") @TableField(value = "field_9") private String field9; + @Schema(description = "自定义字段10") @TableField(value = "field_10") private String field10; + @Schema(description = "创建时间") private Date createTime; + @Schema(description = "创建人") private String createBy; + @Schema(description = "更新时间") private Date updateTime; + @Schema(description = "更新人") private String updateBy; + @Schema(description = "备注") private String remark; } diff --git a/core/service/src/main/java/com/wansenai/service/shop/BasShopService.java b/core/service/src/main/java/com/wansenai/service/shop/BasShopService.java new file mode 100644 index 0000000..e60024d --- /dev/null +++ b/core/service/src/main/java/com/wansenai/service/shop/BasShopService.java @@ -0,0 +1,65 @@ +package com.wansenai.service.shop; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.wansenai.entities.shop.BasShop; + +import java.util.List; + +public interface BasShopService extends IService { + + /** + * 根据店铺编码获取店铺信息 + * + * @param code 店铺编码 + * @return 店铺信息 + */ + BasShop getShopByCode(String code); + + /** + * 根据店铺名称查询店铺列表 + * + * @param name 店铺名称 + * @return 店铺列表 + */ + List getShopListByName(String name); + + /** + * 根据渠道查询店铺列表 + * + * @param channel 渠道 + * @return 店铺列表 + */ + List getShopListByChannel(String channel); + + /** + * 批量添加店铺信息 + * + * @param shopList 店铺列表 + * @return 是否成功 + */ + boolean batchAddShop(List shopList); + + /** + * 添加店铺信息 + * + * @param shop 店铺信息 + * @return 是否成功 + */ + boolean addShop(BasShop shop); + + /** + * 更新店铺信息 + * + * @param shop 店铺信息 + * @return 是否成功 + */ + boolean updateShop(BasShop shop); + + /** + * 删除店铺信息 + * + * @param id 店铺ID + * @return 是否成功 + */ + boolean deleteShop(Long id); +} diff --git a/core/service/src/main/java/com/wansenai/service/shop/impl/BasShopServiceImpl.java b/core/service/src/main/java/com/wansenai/service/shop/impl/BasShopServiceImpl.java new file mode 100644 index 0000000..6a7b4f1 --- /dev/null +++ b/core/service/src/main/java/com/wansenai/service/shop/impl/BasShopServiceImpl.java @@ -0,0 +1,79 @@ +package com.wansenai.service.shop.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.wansenai.entities.shop.BasShop; +import com.wansenai.mappers.shop.BasShopMapper; +import com.wansenai.service.shop.BasShopService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.util.Date; +import java.util.List; + +@Slf4j +@Service +public class BasShopServiceImpl extends ServiceImpl implements BasShopService { + + @Override + public BasShop getShopByCode(String code) { + return baseMapper.getShopByCode(code); + } + + @Override + public List getShopListByName(String name) { + return baseMapper.getShopListByName(name); + } + + @Override + public List getShopListByChannel(String channel) { + return baseMapper.getShopListByChannel(channel); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean batchAddShop(List shopList) { + if (CollectionUtils.isEmpty(shopList)) { + return false; + } + + // 设置创建时间 + Date now = new Date(); + shopList.forEach(shop -> { + shop.setCreateTime(now); + // 这里可以设置创建人,通常从当前登录用户中获取 + // shop.setCreateBy(getCurrentUsername()); + }); + + return baseMapper.batchInsert(shopList) > 0; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean addShop(BasShop shop) { + // 设置创建时间 + shop.setCreateTime(new Date()); + // 这里可以设置创建人,通常从当前登录用户中获取 + // shop.setCreateBy(getCurrentUsername()); + + return save(shop); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean updateShop(BasShop shop) { + // 设置更新时间 + shop.setUpdateTime(new Date()); + // 这里可以设置更新人,通常从当前登录用户中获取 + // shop.setUpdateBy(getCurrentUsername()); + + return updateById(shop); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean deleteShop(Long id) { + return removeById(id); + } +} diff --git a/core/utils/src/main/java/com/wansenai/utils/response/ResponseCode.java b/core/utils/src/main/java/com/wansenai/utils/response/ResponseCode.java new file mode 100644 index 0000000..22283e1 --- /dev/null +++ b/core/utils/src/main/java/com/wansenai/utils/response/ResponseCode.java @@ -0,0 +1,29 @@ +package com.wansenai.utils.response; + +import lombok.Getter; + +/** + * 响应状态码枚举 + */ +@Getter +public enum ResponseCode { + + SUCCESS(200, "操作成功"), + ERROR(500, "操作失败"), + VALIDATE_FAILED(404, "参数检验失败"), + UNAUTHORIZED(401, "暂未登录或token已经过期"), + FORBIDDEN(403, "没有相关权限"), + + // 业务错误码 + SHOP_NOT_EXIST(1001, "店铺不存在"), + SHOP_CODE_DUPLICATE(1002, "店铺编码重复"), + SHOP_NAME_DUPLICATE(1003, "店铺名称重复"); + + private final Integer code; + private final String msg; + + ResponseCode(Integer code, String msg) { + this.code = code; + this.msg = msg; + } +} \ No newline at end of file