4.2 KiB
Refactor ClosedAreaCarApplyRepositoryImpl listPage Method
TL;DR
按照 ClosedAreaPersonApplyRepositoryImpl.listPage() 的实现方式重写 ClosedAreaCarApplyRepositoryImpl.listPage() 方法,添加 menuPerms 参数处理逻辑。
Deliverables:
- 修改
ClosedAreaCarApplyMapper.java- 添加 listPage 方法 - 修改
ClosedAreaCarApplyMapper.xml- 添加 SQL 查询 - 修改
ClosedAreaCarApplyRepositoryImpl.java- 重写 listPage 方法
Estimated Effort: Quick (3 files)
Context
Reference Implementation
ClosedAreaPersonApplyRepositoryImpl.listPage() 的实现模式:
- 使用
Page<Map<String, Object>>创建分页对象 - 获取
menuPerms参数:通过MenuEnum.getMenuKeyByPath()转换 - 调用 Mapper 的自定义
listPage方法 - 返回
PageHelper.pageToResponse()结果
Business Logic
String menuPerms = "";
if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))) {
menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString());
}
TODOs
-
1. Add listPage method to ClosedAreaCarApplyMapper.java
What to do: 添加
listPage方法签名,参考 ClosedAreaPersonApplyMapperFile:
web-infrastructure/src/main/java/com/zcloud/primeport/persistence/mapper/ClosedAreaCarApplyMapper.javaCode:
IPage<ClosedAreaCarApplyDO> listPage(Page<Map<String, Object>> page, Map<String, Object> params, String menuPerms);Imports to add:
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import java.util.Map; -
2. Add listPage SQL to ClosedAreaCarApplyMapper.xml
What to do: 添加分页查询 SQL,参考 ClosedAreaPersonApplyMapper.xml
File:
web-infrastructure/src/main/resources/mapper/ClosedAreaCarApplyMapper.xmlCode:
<select id="listPage" resultType="com.zcloud.primeport.persistence.dataobject.ClosedAreaCarApplyDO"> select * from closed_area_car_apply c where c.delete_enum = 'FALSE' <if test="params.processOrRecord != null"> <if test="params.processOrRecord == 1"> AND c.audit_flag = 1 </if> <if test="params.processOrRecord == 2"> AND c.audit_flag != 1 </if> </if> <if test="params.applyPersonUserName != null and params.applyPersonUserName != ''"> AND c.apply_person_user_name like CONCAT('%', #{params.applyPersonUserName}, '%') </if> <if test="params.licenceNo != null and params.licenceNo != ''"> AND c.licence_no like CONCAT('%', #{params.licenceNo}, '%') </if> </select> -
3. Rewrite listPage in ClosedAreaCarApplyRepositoryImpl.java
What to do: 按照 ClosedAreaPersonApplyRepositoryImpl 的模式重写 listPage 方法
File:
web-infrastructure/src/main/java/com/zcloud/primeport/persistence/repository/impl/ClosedAreaCarApplyRepositoryImpl.javaCode:
@Override public PageResponse<ClosedAreaCarApplyDO> listPage(Map<String, Object> params) { Page<Map<String, Object>> page = new Page<>(Integer.parseInt(params.get("pageIndex").toString()), Integer.parseInt(params.get("pageSize").toString())); String menuPerms = ""; if (!org.springframework.util.ObjectUtils.isEmpty(params.get("menuPath"))) { menuPerms = MenuEnum.getMenuKeyByPath(params.get("menuPath").toString()); } IPage<ClosedAreaCarApplyDO> result = closedAreaCarApplyMapper.listPage(page, params, menuPerms); return PageHelper.pageToResponse(result, result.getRecords()); }Imports to add:
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zcloud.primeport.domain.enums.MenuEnum;
Commit Strategy
- 1:
feat(closedArea): refactor ClosedAreaCarApplyRepositoryImpl listPage with menuPerms— 3 files
Success Criteria
Verification Commands
mvn compile -pl web-infrastructure
Final Checklist
- Mapper 接口添加 listPage 方法
- XML 添加对应 SQL
- Repository 实现重写完成
- 编译通过