diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java index 56e6b5e..028e14a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysPostController.java @@ -4,10 +4,13 @@ import java.util.List; import cn.dev33.satoken.annotation.SaCheckPermission; import com.ruoyi.common.core.constant.UserConstants; +import com.ruoyi.common.core.core.domain.R; +import com.ruoyi.common.excel.utils.ExcelUtil; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.orm.core.page.TableDataInfo; -import com.ruoyi.common.security.utils.LoginHelper; +import com.ruoyi.system.domain.bo.SysPostBo; +import com.ruoyi.system.domain.vo.SysPostVo; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -21,9 +24,6 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.web.core.BaseController; -import com.ruoyi.common.core.core.domain.AjaxResult; -import com.ruoyi.common.core.utils.poi.ExcelUtil; -import com.ruoyi.system.domain.SysPost; import com.ruoyi.system.service.ISysPostService; /** @@ -45,21 +45,18 @@ public class SysPostController extends BaseController */ @SaCheckPermission("system:post:list") @GetMapping("/list") - public TableDataInfo list(SysPost post) + public TableDataInfo list(SysPostBo postBo) { - startPage(); - List list = postService.selectPostList(post); - return getDataTable(list); + return postService.selectConfigPage(postBo); } @Log(title = "岗位管理", businessType = BusinessType.EXPORT) @SaCheckPermission("system:post:export") @PostMapping("/export") - public void export(HttpServletResponse response, SysPost post) + public void export(HttpServletResponse response, SysPostBo postBo) { - List list = postService.selectPostList(post); - ExcelUtil util = new ExcelUtil<>(SysPost.class); - util.exportExcel(response, list, "岗位数据"); + List list = postService.selectPostList(postBo); + ExcelUtil.exportExcel(list, "岗位管理数据", SysPostVo.class, response); } /** @@ -67,9 +64,9 @@ public class SysPostController extends BaseController */ @SaCheckPermission("system:post:query") @GetMapping(value = "/{postId}") - public AjaxResult getInfo(@PathVariable Long postId) + public R getInfo(@PathVariable Long postId) { - return success(postService.selectPostById(postId)); + return R.ok(postService.selectPostById(postId)); } /** @@ -78,18 +75,21 @@ public class SysPostController extends BaseController @SaCheckPermission("system:post:add") @Log(title = "岗位管理", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@Validated @RequestBody SysPost post) + public R add(@Validated @RequestBody SysPostBo postBo) { - if (!postService.checkPostNameUnique(post)) + if (!postService.checkPostNameUnique(postBo)) { - return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在"); + return R.fail("新增岗位'" + postBo.getPostName() + "'失败,岗位名称已存在"); } - else if (!postService.checkPostCodeUnique(post)) + else if (!postService.checkPostCodeUnique(postBo)) { - return error("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在"); + return R.fail("新增岗位'" + postBo.getPostName() + "'失败,岗位编码已存在"); } - post.setCreateBy(LoginHelper.getUserId()); - return toAjax(postService.insertPost(post)); + int insertedRows = postService.insertPost(postBo); + if (insertedRows != 1) { + return R.fail("新增岗位记录失败!"); + } + return R.ok(); } /** @@ -98,22 +98,25 @@ public class SysPostController extends BaseController @SaCheckPermission("system:post:edit") @Log(title = "岗位管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysPost post) + public R edit(@Validated @RequestBody SysPostBo postBo) { - if (!postService.checkPostNameUnique(post)) + if (!postService.checkPostNameUnique(postBo)) { - return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在"); + return R.fail("修改岗位'" + postBo.getPostName() + "'失败,岗位名称已存在"); } - else if (!postService.checkPostCodeUnique(post)) + else if (!postService.checkPostCodeUnique(postBo)) { - return error("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在"); + return R.fail("修改岗位'" + postBo.getPostName() + "'失败,岗位编码已存在"); } - else if (UserConstants.POST_DISABLE.equals(post.getStatus()) - && postService.countUserPostById(post.getPostId()) > 0) { - return error("该岗位下存在已分配用户,不能禁用!"); + else if (UserConstants.POST_DISABLE.equals(postBo.getStatus()) + && postService.countUserPostById(postBo.getPostId()) > 0) { + return R.fail("该岗位下存在已分配用户,不能禁用!"); } - post.setUpdateBy(LoginHelper.getUserId()); - return toAjax(postService.updatePost(post)); + Boolean updated = postService.updatePost(postBo); + if (!updated) { + R.fail("修改岗位记录失败!"); + } + return R.ok(); } /** @@ -122,20 +125,24 @@ public class SysPostController extends BaseController @SaCheckPermission("system:post:remove") @Log(title = "岗位管理", businessType = BusinessType.DELETE) @DeleteMapping("/{postIds}") - public AjaxResult remove(@PathVariable Long[] postIds) + public R remove(@PathVariable Long[] postIds) { - return toAjax(postService.deletePostByIds(postIds)); + boolean deleted = postService.deletePostByIds(postIds); + if (!deleted) { + R.fail("删除岗位记录失败!"); + } + return R.ok(); } /** * 获取岗位选择框列表 */ @GetMapping("/optionselect") - public AjaxResult optionselect() + public R> optionselect() { - SysPost sysPost = new SysPost(); - sysPost.setStatus(UserConstants.POST_NORMAL); - List posts = postService.selectPostList(sysPost); - return success(posts); + SysPostBo sysPostBo = new SysPostBo(); + sysPostBo.setStatus(UserConstants.POST_NORMAL); + List posts = postService.selectPostList(sysPostBo); + return R.ok(posts); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java index 2641d5e..e2225dd 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysPost.java @@ -1,8 +1,14 @@ package com.ruoyi.system.domain; +import com.mybatisflex.annotation.Column; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; @@ -16,125 +22,31 @@ import java.io.Serial; * * @author ruoyi */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "sys_post") public class SysPost extends BaseEntity { - @Serial - private static final long serialVersionUID = 1L; - /** 岗位序号 */ - @Excel(name = "岗位序号", cellType = ColumnType.NUMERIC) + @Id(keyType = KeyType.Auto) private Long postId; /** 岗位编码 */ - @Excel(name = "岗位编码") private String postCode; /** 岗位名称 */ - @Excel(name = "岗位名称") private String postName; /** 岗位排序 */ - @Excel(name = "岗位排序") private Integer postSort; /** 状态(0正常 1停用) */ - @Excel(name = "状态", readConverterExp = "0=正常,1=停用") private String status; - /** - * 备注 - */ + /** 备注 */ private String remark; /** 用户是否存在此岗位标识 默认不存在 */ + @Column(ignore = true) private boolean flag = false; - - public Long getPostId() - { - return postId; - } - - public void setPostId(Long postId) - { - this.postId = postId; - } - - @NotBlank(message = "岗位编码不能为空") - @Size(min = 0, max = 64, message = "岗位编码长度不能超过64个字符") - public String getPostCode() - { - return postCode; - } - - public void setPostCode(String postCode) - { - this.postCode = postCode; - } - - @NotBlank(message = "岗位名称不能为空") - @Size(min = 0, max = 50, message = "岗位名称长度不能超过50个字符") - public String getPostName() - { - return postName; - } - - public void setPostName(String postName) - { - this.postName = postName; - } - - @NotNull(message = "显示顺序不能为空") - public Integer getPostSort() - { - return postSort; - } - - public void setPostSort(Integer postSort) - { - this.postSort = postSort; - } - - public String getStatus() - { - return status; - } - - public void setStatus(String status) - { - this.status = status; - } - - public boolean isFlag() - { - return flag; - } - - public void setFlag(boolean flag) - { - this.flag = flag; - } - - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("postId", getPostId()) - .append("postCode", getPostCode()) - .append("postName", getPostName()) - .append("postSort", getPostSort()) - .append("status", getStatus()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .toString(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysPostVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysPostVo.java index 2c9f5e7..c1f5db3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysPostVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysPostVo.java @@ -21,7 +21,6 @@ import java.util.Date; */ @Data @ExcelIgnoreUnannotated -@AutoMapper(target = SysPost.class) public class SysPostVo implements Serializable { @Serial diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysPostMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysPostMapper.java index 19be227..9f8fc70 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysPostMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysPostMapper.java @@ -1,99 +1,33 @@ package com.ruoyi.system.mapper; import java.util.List; + +import com.mybatisflex.core.BaseMapper; import com.ruoyi.system.domain.SysPost; +import org.apache.ibatis.annotations.Mapper; /** * 岗位信息 数据层 - * - * @author ruoyi + * + * @author 数据小王子 */ -public interface SysPostMapper +@Mapper +public interface SysPostMapper extends BaseMapper { - /** - * 查询岗位数据集合 - * - * @param post 岗位信息 - * @return 岗位数据集合 - */ - public List selectPostList(SysPost post); - - /** - * 查询所有岗位 - * - * @return 岗位列表 - */ - public List selectPostAll(); - - /** - * 通过岗位ID查询岗位信息 - * - * @param postId 岗位ID - * @return 角色对象信息 - */ - public SysPost selectPostById(Long postId); - /** * 根据用户ID获取岗位选择框列表 - * + * * @param userId 用户ID * @return 选中岗位ID列表 */ - public List selectPostListByUserId(Long userId); + List selectPostListByUserId(Long userId); /** * 查询用户所属岗位组 - * + * * @param userName 用户名 * @return 结果 */ - public List selectPostsByUserName(String userName); + List selectPostsByUserName(String userName); - /** - * 删除岗位信息 - * - * @param postId 岗位ID - * @return 结果 - */ - public int deletePostById(Long postId); - - /** - * 批量删除岗位信息 - * - * @param postIds 需要删除的岗位ID - * @return 结果 - */ - public int deletePostByIds(Long[] postIds); - - /** - * 修改岗位信息 - * - * @param post 岗位信息 - * @return 结果 - */ - public int updatePost(SysPost post); - - /** - * 新增岗位信息 - * - * @param post 岗位信息 - * @return 结果 - */ - public int insertPost(SysPost post); - - /** - * 校验岗位名称 - * - * @param postName 岗位名称 - * @return 结果 - */ - public SysPost checkPostNameUnique(String postName); - - /** - * 校验岗位编码 - * - * @param postCode 岗位编码 - * @return 结果 - */ - public SysPost checkPostCodeUnique(String postCode); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java index 84779bf..5f794f4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysPostService.java @@ -1,99 +1,112 @@ package com.ruoyi.system.service; import java.util.List; + +import com.mybatisflex.core.service.IService; +import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.system.domain.SysPost; +import com.ruoyi.system.domain.bo.SysPostBo; +import com.ruoyi.system.domain.vo.SysPostVo; /** * 岗位信息 服务层 - * + * * @author ruoyi */ -public interface ISysPostService +public interface ISysPostService extends IService { /** * 查询岗位信息集合 - * + * * @param post 岗位信息 * @return 岗位列表 */ - public List selectPostList(SysPost post); + List selectPostList(SysPostBo post); + + /** + * 分页查询公告列表 + * + * @param postBo 公告信息 + * @return 公告集合 + */ + TableDataInfo selectConfigPage(SysPostBo postBo); /** * 查询所有岗位 - * + * * @return 岗位列表 */ - public List selectPostAll(); + List selectPostAll(); /** * 通过岗位ID查询岗位信息 - * + * * @param postId 岗位ID * @return 角色对象信息 */ - public SysPost selectPostById(Long postId); + SysPostVo selectPostById(Long postId); /** * 根据用户ID获取岗位选择框列表 - * + * * @param userId 用户ID * @return 选中岗位ID列表 */ - public List selectPostListByUserId(Long userId); + List selectPostListByUserId(Long userId); /** * 校验岗位名称 - * + * * @param post 岗位信息 * @return 结果 */ - public boolean checkPostNameUnique(SysPost post); + boolean checkPostNameUnique(SysPostBo post); /** * 校验岗位编码 - * + * * @param post 岗位信息 * @return 结果 */ - public boolean checkPostCodeUnique(SysPost post); + boolean checkPostCodeUnique(SysPostBo post); /** * 通过岗位ID查询岗位使用数量 - * + * * @param postId 岗位ID * @return 结果 */ - public int countUserPostById(Long postId); + int countUserPostById(Long postId); /** * 删除岗位信息 - * + * * @param postId 岗位ID - * @return 结果 + * @return 结果:true 删除成功,false 删除失败。 */ - public int deletePostById(Long postId); + boolean deletePostById(Long postId); /** * 批量删除岗位信息 - * + * * @param postIds 需要删除的岗位ID - * @return 结果 + * @return 结果:true 删除成功,false 删除失败。 */ - public int deletePostByIds(Long[] postIds); + boolean deletePostByIds(Long[] postIds); /** * 新增保存岗位信息 - * + * * @param post 岗位信息 * @return 结果 */ - public int insertPost(SysPost post); + int insertPost(SysPostBo post); /** * 修改保存岗位信息 - * + * * @param post 岗位信息 - * @return 结果 + * @return 结果:true 更新成功,false 更新失败 */ - public int updatePost(SysPost post); + boolean updatePost(SysPostBo post); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java index 8fd0e92..af76bc8 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java @@ -1,7 +1,18 @@ package com.ruoyi.system.service.impl; +import java.util.Arrays; import java.util.List; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.spring.service.impl.ServiceImpl; +import com.ruoyi.common.core.core.page.PageDomain; +import com.ruoyi.common.core.core.page.TableSupport; +import com.ruoyi.common.core.utils.MapstructUtils; +import com.ruoyi.common.core.utils.sql.SqlUtil; +import com.ruoyi.common.orm.core.page.TableDataInfo; +import com.ruoyi.system.domain.bo.SysPostBo; +import com.ruoyi.system.domain.vo.SysPostVo; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import com.ruoyi.common.core.constant.UserConstants; @@ -12,13 +23,15 @@ import com.ruoyi.system.mapper.SysPostMapper; import com.ruoyi.system.mapper.SysUserPostMapper; import com.ruoyi.system.service.ISysPostService; +import static com.ruoyi.system.domain.table.SysPostTableDef.SYS_POST; + /** * 岗位信息 服务层处理 * * @author ruoyi */ @Service -public class SysPostServiceImpl implements ISysPostService +public class SysPostServiceImpl extends ServiceImpl implements ISysPostService { @Resource private SysPostMapper postMapper; @@ -26,16 +39,64 @@ public class SysPostServiceImpl implements ISysPostService @Resource private SysUserPostMapper userPostMapper; + @Override + public QueryWrapper query() { + return super.query().from(SYS_POST); + } + + /** + * 根据postBo构建QueryWrapper查询条件 + * @param postBo + * @return + */ + private QueryWrapper buildQueryWrapper(SysPostBo postBo) { + QueryWrapper queryWrapper = query(); + PageDomain pageDomain = TableSupport.buildPageRequest(); + + if (StringUtils.isNotEmpty(postBo.getPostCode())) { + queryWrapper.and(SYS_POST.POST_CODE.like(postBo.getPostCode())); + } + if (StringUtils.isNotEmpty(postBo.getStatus())) { + queryWrapper.and(SYS_POST.STATUS.eq(postBo.getStatus())); + } + if (StringUtils.isNotEmpty(postBo.getPostName())) { + queryWrapper.and(SYS_POST.POST_NAME.like(postBo.getPostName())); + } + + if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) { + String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy()); + queryWrapper.orderBy(orderBy); + } + return queryWrapper; + } + /** * 查询岗位信息集合 * - * @param post 岗位信息 + * @param postBo 岗位信息 * @return 岗位信息集合 */ @Override - public List selectPostList(SysPost post) + public List selectPostList(SysPostBo postBo) { - return postMapper.selectPostList(post); + QueryWrapper queryWrapper = buildQueryWrapper(postBo); + return this.listAs(queryWrapper, SysPostVo.class); + } + + /** + * 分页查询公告列表 + * + * @param postBo 公告信息 + * @return 公告集合 + */ + @Override + public TableDataInfo selectConfigPage(SysPostBo postBo) { + QueryWrapper queryWrapper = buildQueryWrapper(postBo); + + PageDomain pageDomain = TableSupport.buildPageRequest(); + + Page page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysPostVo.class); + return TableDataInfo.build(page); } /** @@ -44,9 +105,9 @@ public class SysPostServiceImpl implements ISysPostService * @return 岗位列表 */ @Override - public List selectPostAll() + public List selectPostAll() { - return postMapper.selectPostAll(); + return this.listAs(query(), SysPostVo.class); } /** @@ -56,9 +117,9 @@ public class SysPostServiceImpl implements ISysPostService * @return 角色对象信息 */ @Override - public SysPost selectPostById(Long postId) + public SysPostVo selectPostById(Long postId) { - return postMapper.selectPostById(postId); + return this.getOneAs(query().where(SYS_POST.POST_ID.eq(postId)), SysPostVo.class); } /** @@ -80,10 +141,10 @@ public class SysPostServiceImpl implements ISysPostService * @return 结果 */ @Override - public boolean checkPostNameUnique(SysPost post) + public boolean checkPostNameUnique(SysPostBo post) { Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); - SysPost info = postMapper.checkPostNameUnique(post.getPostName()); + SysPost info = this.getOne(query().where(SYS_POST.POST_NAME.eq(post.getPostName()))); if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { return UserConstants.NOT_UNIQUE; @@ -98,10 +159,10 @@ public class SysPostServiceImpl implements ISysPostService * @return 结果 */ @Override - public boolean checkPostCodeUnique(SysPost post) + public boolean checkPostCodeUnique(SysPostBo post) { Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); - SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); + SysPost info = this.getOne(query().where(SYS_POST.POST_CODE.eq(post.getPostCode()))); if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { return UserConstants.NOT_UNIQUE; @@ -125,55 +186,57 @@ public class SysPostServiceImpl implements ISysPostService * 删除岗位信息 * * @param postId 岗位ID - * @return 结果 + * @return 结果:true 删除成功,false 删除失败。 */ @Override - public int deletePostById(Long postId) + public boolean deletePostById(Long postId) { - return postMapper.deletePostById(postId); + return this.removeById(postId); } /** * 批量删除岗位信息 * * @param postIds 需要删除的岗位ID - * @return 结果 + * @return 结果:true 删除成功,false 删除失败。 */ @Override - public int deletePostByIds(Long[] postIds) + public boolean deletePostByIds(Long[] postIds) { for (Long postId : postIds) { - SysPost post = selectPostById(postId); + SysPostVo post = selectPostById(postId); if (countUserPostById(postId) > 0) { throw new ServiceException(String.format("%1$s已分配,不能删除!", post.getPostName())); } } - return postMapper.deletePostByIds(postIds); + return this.removeByIds(Arrays.asList(postIds)); } /** * 新增保存岗位信息 * - * @param post 岗位信息 + * @param postBo 岗位信息 * @return 结果 */ @Override - public int insertPost(SysPost post) + public int insertPost(SysPostBo postBo) { - return postMapper.insertPost(post); + SysPost sysPost = MapstructUtils.convert(postBo, SysPost.class); + return postMapper.insert(sysPost,false); } /** * 修改保存岗位信息 * - * @param post 岗位信息 - * @return 结果 + * @param postBo 岗位信息 + * @return 结果:true 更新成功,false 更新失败 */ @Override - public int updatePost(SysPost post) + public boolean updatePost(SysPostBo postBo) { - return postMapper.updatePost(post); + SysPost sysPost = MapstructUtils.convert(postBo, SysPost.class); + return this.updateById(sysPost); } }