feat(community): 添加小区管理功能模块

- 新增 ShopCommunity 实体类,定义小区基本信息字段
- 创建 ShopCommunityController 控制器,提供完整的 CRUD 操作接口
- 实现 ShopCommunityService 服务层接口及其实现类
- 配置 ShopCommunityMapper 数据访问层及对应的 XML 映射文件
- 添加 ShopCommunityParam 查询参数类
- 修改 ShopDealerUser 实体增加小区和店铺相关字段
- 更新 ShopDealerUserMapper.xml 添加店铺名称关联查询
This commit is contained in:
2026-01-30 10:30:42 +08:00
parent 6be4421ed9
commit 20a24a46c4
9 changed files with 414 additions and 1 deletions

View File

@@ -0,0 +1,120 @@
package com.gxwebsoft.shop.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.service.ShopCommunityService;
import com.gxwebsoft.shop.entity.ShopCommunity;
import com.gxwebsoft.shop.param.ShopCommunityParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 小区控制器
*
* @author 科技小王子
* @since 2026-01-29 20:48:32
*/
@Tag(name = "小区管理")
@RestController
@RequestMapping("/api/shop/shop-community")
public class ShopCommunityController extends BaseController {
@Resource
private ShopCommunityService shopCommunityService;
@Operation(summary = "分页查询小区")
@GetMapping("/page")
public ApiResult<PageResult<ShopCommunity>> page(ShopCommunityParam param) {
// 使用关联查询
return success(shopCommunityService.pageRel(param));
}
@Operation(summary = "查询全部小区")
@GetMapping()
public ApiResult<List<ShopCommunity>> list(ShopCommunityParam param) {
// 使用关联查询
return success(shopCommunityService.listRel(param));
}
@Operation(summary = "根据id查询小区")
@GetMapping("/{id}")
public ApiResult<ShopCommunity> get(@PathVariable("id") Integer id) {
// 使用关联查询
return success(shopCommunityService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('shop:shopCommunity:save')")
@OperationLog
@Operation(summary = "添加小区")
@PostMapping()
public ApiResult<?> save(@RequestBody ShopCommunity shopCommunity) {
if (shopCommunityService.save(shopCommunity)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopCommunity:update')")
@OperationLog
@Operation(summary = "修改小区")
@PutMapping()
public ApiResult<?> update(@RequestBody ShopCommunity shopCommunity) {
if (shopCommunityService.updateById(shopCommunity)) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopCommunity:remove')")
@OperationLog
@Operation(summary = "删除小区")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (shopCommunityService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('shop:shopCommunity:save')")
@OperationLog
@Operation(summary = "批量添加小区")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ShopCommunity> list) {
if (shopCommunityService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('shop:shopCommunity:update')")
@OperationLog
@Operation(summary = "批量修改小区")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<ShopCommunity> batchParam) {
if (batchParam.update(shopCommunityService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('shop:shopCommunity:remove')")
@OperationLog
@Operation(summary = "批量删除小区")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (shopCommunityService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -0,0 +1,53 @@
package com.gxwebsoft.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* 小区
*
* @author 科技小王子
* @since 2026-01-29 20:48:32
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(name = "ShopCommunity对象", description = "小区")
public class ShopCommunity implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "ID")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@Schema(description = "小区名称")
private String name;
@Schema(description = "小区编号")
private String code;
@Schema(description = "详细地址")
private String address;
@Schema(description = "排序(数字越小越靠前)")
private Integer sortNumber;
@Schema(description = "备注")
private String comments;
@Schema(description = "状态, 0正常, 1冻结")
private Integer status;
@Schema(description = "租户id")
private Integer tenantId;
@Schema(description = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
}

View File

@@ -83,6 +83,16 @@ public class ShopDealerUser implements Serializable {
@Schema(description = "成员数量(三级)")
private Integer thirdNum;
@Schema(description = "小区ID")
private Integer communityId;
@Schema(description = "店铺ID")
private Integer dealerUserId;
@Schema(description = "店铺名称")
@TableField(exist = false)
private String shopName;
@Schema(description = "专属二维码")
private String qrcode;

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.shop.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.shop.entity.ShopCommunity;
import com.gxwebsoft.shop.param.ShopCommunityParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 小区Mapper
*
* @author 科技小王子
* @since 2026-01-29 20:48:32
*/
public interface ShopCommunityMapper extends BaseMapper<ShopCommunity> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<ShopCommunity>
*/
List<ShopCommunity> selectPageRel(@Param("page") IPage<ShopCommunity> page,
@Param("param") ShopCommunityParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<ShopCommunity> selectListRel(@Param("param") ShopCommunityParam param);
}

View File

@@ -0,0 +1,54 @@
<?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.gxwebsoft.shop.mapper.ShopCommunityMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM shop_community a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.name != null">
AND a.name LIKE CONCAT('%', #{param.name}, '%')
</if>
<if test="param.code != null">
AND a.code LIKE CONCAT('%', #{param.code}, '%')
</if>
<if test="param.address != null">
AND a.address LIKE CONCAT('%', #{param.address}, '%')
</if>
<if test="param.sortNumber != null">
AND a.sort_number = #{param.sortNumber}
</if>
<if test="param.comments != null">
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
</if>
<if test="param.status != null">
AND a.status = #{param.status}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.name LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.ShopCommunity">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.shop.entity.ShopCommunity">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -4,9 +4,10 @@
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*, b.openid, b.avatar
SELECT a.*, b.openid, b.avatar, c.dealer_name AS shopName
FROM shop_dealer_user a
LEFT JOIN gxwebsoft_core.sys_user b ON a.user_id = b.user_id
LEFT JOIN shop_dealer_user c ON a.dealer_user_id = c.id
<where>
<if test="param.id != null">
AND a.id = #{param.id}

View File

@@ -0,0 +1,49 @@
package com.gxwebsoft.shop.param;
import java.math.BigDecimal;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 小区查询参数
*
* @author 科技小王子
* @since 2026-01-29 20:48:31
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(name = "ShopCommunityParam对象", description = "小区查询参数")
public class ShopCommunityParam extends BaseParam {
private static final long serialVersionUID = 1L;
@Schema(description = "ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@Schema(description = "小区名称")
private String name;
@Schema(description = "小区编号")
private String code;
@Schema(description = "详细地址")
private String address;
@Schema(description = "排序(数字越小越靠前)")
@QueryField(type = QueryType.EQ)
private Integer sortNumber;
@Schema(description = "备注")
private String comments;
@Schema(description = "状态, 0正常, 1冻结")
@QueryField(type = QueryType.EQ)
private Integer status;
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.shop.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.shop.entity.ShopCommunity;
import com.gxwebsoft.shop.param.ShopCommunityParam;
import java.util.List;
/**
* 小区Service
*
* @author 科技小王子
* @since 2026-01-29 20:48:32
*/
public interface ShopCommunityService extends IService<ShopCommunity> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<ShopCommunity>
*/
PageResult<ShopCommunity> pageRel(ShopCommunityParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<ShopCommunity>
*/
List<ShopCommunity> listRel(ShopCommunityParam param);
/**
* 根据id查询
*
* @param id ID
* @return ShopCommunity
*/
ShopCommunity getByIdRel(Integer id);
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.shop.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopCommunityMapper;
import com.gxwebsoft.shop.service.ShopCommunityService;
import com.gxwebsoft.shop.entity.ShopCommunity;
import com.gxwebsoft.shop.param.ShopCommunityParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 小区Service实现
*
* @author 科技小王子
* @since 2026-01-29 20:48:32
*/
@Service
public class ShopCommunityServiceImpl extends ServiceImpl<ShopCommunityMapper, ShopCommunity> implements ShopCommunityService {
@Override
public PageResult<ShopCommunity> pageRel(ShopCommunityParam param) {
PageParam<ShopCommunity, ShopCommunityParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<ShopCommunity> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<ShopCommunity> listRel(ShopCommunityParam param) {
List<ShopCommunity> list = baseMapper.selectListRel(param);
// 排序
PageParam<ShopCommunity, ShopCommunityParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}
@Override
public ShopCommunity getByIdRel(Integer id) {
ShopCommunityParam param = new ShopCommunityParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}