feat: 1.商店基础档案 2.增加响应枚举类

This commit is contained in:
Yifei Kuang 2025-01-01 19:37:43 +08:00
parent 1463f6022b
commit ffdef043fc
8 changed files with 393 additions and 3 deletions

View File

@ -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;
/**
* <p>商店档案</p>
* @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<IPage<BasShop>> 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<BasShop> pageRequest = new Page<>(page, pageSize);
LambdaQueryWrapper<BasShop> queryWrapper = new LambdaQueryWrapper<BasShop>()
.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<BasShop> getShopById(@Parameter(description = "店铺ID") @PathVariable Long id) {
return Response.responseData(shopService.getById(id));
}
@Operation(summary = "根据编码获取店铺信息")
@GetMapping("/code/{code}")
public Response<BasShop> getShopByCode(@Parameter(description = "店铺编码") @PathVariable String code) {
return Response.responseData(shopService.getShopByCode(code));
}
@Operation(summary = "根据名称搜索店铺")
@GetMapping("/search")
public Response<List<BasShop>> searchShopByName(@Parameter(description = "店铺名称") @RequestParam String name) {
return Response.responseData(shopService.getShopListByName(name));
}
@Operation(summary = "添加店铺")
@PostMapping("/add")
public Response<Boolean> addShop(@RequestBody BasShop shop) {
return Response.responseData(shopService.addShop(shop));
}
@Operation(summary = "批量添加店铺")
@PostMapping("/batch")
public Response<Boolean> batchAddShop(@RequestBody List<BasShop> shopList) {
return Response.responseData(shopService.batchAddShop(shopList));
}
@Operation(summary = "更新店铺信息")
@PutMapping("/update")
public Response<Boolean> updateShop(@RequestBody BasShop shop) {
return Response.responseData(shopService.updateShop(shop));
}
@Operation(summary = "删除店铺")
@DeleteMapping("/delete/{id}")
public Response<Boolean> deleteShop(@Parameter(description = "店铺ID") @PathVariable Long id) {
return Response.responseData(shopService.deleteShop(id));
}
@Operation(summary = "根据渠道获取店铺列表")
@GetMapping("/channel/{channel}")
public Response<List<BasShop>> getShopListByChannel(@Parameter(description = "渠道") @PathVariable String channel) {
return Response.responseData(shopService.getShopListByChannel(channel));
}
}

View File

@ -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

View File

@ -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> {
/**
* 根据店铺编码查询店铺信息
*/
BasShop getShopByCode(@Param("code") String code);
/**
* 根据店铺名称模糊查询店铺列表
*/
List<BasShop> getShopListByName(@Param("name") String name);
/**
* 根据渠道查询店铺列表
*/
List<BasShop> getShopListByChannel(@Param("channel") String channel);
/**
* 批量插入店铺信息
*/
int batchInsert(@Param("shopList") List<BasShop> shopList);
}

View File

@ -0,0 +1,81 @@
<?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.wansenai.mappers.shop.BasShopMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.wansenai.entities.shop.BasShop">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="name" property="name"/>
<result column="channel" property="channel"/>
<result column="type" property="type"/>
<result column="address_id" property="addressId"/>
<result column="price_type" property="priceType"/>
<result column="field_1" property="field1"/>
<result column="field_2" property="field2"/>
<result column="field_3" property="field3"/>
<result column="field_4" property="field4"/>
<result column="field_5" property="field5"/>
<result column="field_6" property="field6"/>
<result column="field_7" property="field7"/>
<result column="field_8" property="field8"/>
<result column="field_9" property="field9"/>
<result column="field_10" property="field10"/>
<result column="create_time" property="createTime"/>
<result column="create_by" property="createBy"/>
<result column="update_time" property="updateTime"/>
<result column="update_by" property="updateBy"/>
<result column="remark" property="remark"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
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
</sql>
<!-- 根据店铺编码查询店铺信息 -->
<select id="getShopByCode" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM bas_shop
WHERE code = #{code}
</select>
<!-- 根据店铺名称模糊查询店铺列表 -->
<select id="getShopListByName" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM bas_shop
WHERE name LIKE CONCAT('%', #{name}, '%')
</select>
<!-- 根据渠道查询店铺列表 -->
<select id="getShopListByChannel" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM bas_shop
WHERE channel = #{channel}
</select>
<!-- 批量插入店铺信息 -->
<insert id="batchInsert">
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
<foreach collection="shopList" item="shop" separator=",">
(
#{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}
)
</foreach>
</insert>
</mapper>

View File

@ -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;
}

View File

@ -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<BasShop> {
/**
* 根据店铺编码获取店铺信息
*
* @param code 店铺编码
* @return 店铺信息
*/
BasShop getShopByCode(String code);
/**
* 根据店铺名称查询店铺列表
*
* @param name 店铺名称
* @return 店铺列表
*/
List<BasShop> getShopListByName(String name);
/**
* 根据渠道查询店铺列表
*
* @param channel 渠道
* @return 店铺列表
*/
List<BasShop> getShopListByChannel(String channel);
/**
* 批量添加店铺信息
*
* @param shopList 店铺列表
* @return 是否成功
*/
boolean batchAddShop(List<BasShop> shopList);
/**
* 添加店铺信息
*
* @param shop 店铺信息
* @return 是否成功
*/
boolean addShop(BasShop shop);
/**
* 更新店铺信息
*
* @param shop 店铺信息
* @return 是否成功
*/
boolean updateShop(BasShop shop);
/**
* 删除店铺信息
*
* @param id 店铺ID
* @return 是否成功
*/
boolean deleteShop(Long id);
}

View File

@ -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<BasShopMapper, BasShop> implements BasShopService {
@Override
public BasShop getShopByCode(String code) {
return baseMapper.getShopByCode(code);
}
@Override
public List<BasShop> getShopListByName(String name) {
return baseMapper.getShopListByName(name);
}
@Override
public List<BasShop> getShopListByChannel(String channel) {
return baseMapper.getShopListByChannel(channel);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean batchAddShop(List<BasShop> 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);
}
}

View File

@ -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;
}
}