添加机构
This commit is contained in:
parent
85edc7bd42
commit
7cef8f5008
@ -0,0 +1,104 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.org;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.org.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.org.OrgDO;
|
||||
import cn.iocoder.yudao.module.system.service.org.OrgService;
|
||||
|
||||
@Tag(name = "管理后台 - 机构")
|
||||
@RestController
|
||||
@RequestMapping("/system/org")
|
||||
@Validated
|
||||
public class OrgController {
|
||||
|
||||
@Resource
|
||||
private OrgService orgService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建机构")
|
||||
@PreAuthorize("@ss.hasPermission('system:org:create')")
|
||||
public CommonResult<Integer> createOrg(@Valid @RequestBody OrgSaveReqVO createReqVO) {
|
||||
return success(orgService.createOrg(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新机构")
|
||||
@PreAuthorize("@ss.hasPermission('system:org:update')")
|
||||
public CommonResult<Boolean> updateOrg(@Valid @RequestBody OrgSaveReqVO updateReqVO) {
|
||||
orgService.updateOrg(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除机构")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:org:delete')")
|
||||
public CommonResult<Boolean> deleteOrg(@RequestParam("id") Integer id) {
|
||||
orgService.deleteOrg(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除机构")
|
||||
@PreAuthorize("@ss.hasPermission('system:org:delete')")
|
||||
public CommonResult<Boolean> deleteOrgList(@RequestParam("ids") List<Integer> ids) {
|
||||
orgService.deleteOrgListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得机构")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:org:query')")
|
||||
public CommonResult<OrgRespVO> getOrg(@RequestParam("id") Integer id) {
|
||||
OrgDO org = orgService.getOrg(id);
|
||||
return success(BeanUtils.toBean(org, OrgRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得机构分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:org:query')")
|
||||
public CommonResult<PageResult<OrgRespVO>> getOrgPage(@Valid OrgPageReqVO pageReqVO) {
|
||||
PageResult<OrgDO> pageResult = orgService.getOrgPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, OrgRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出机构 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:org:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportOrgExcel(@Valid OrgPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<OrgDO> list = orgService.getOrgPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "机构.xls", "数据", OrgRespVO.class,
|
||||
BeanUtils.toBean(list, OrgRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.org.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 机构分页 Request VO")
|
||||
@Data
|
||||
public class OrgPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "机构ID", example = "31188")
|
||||
private Integer orgId;
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
private String orgName;
|
||||
|
||||
@Schema(description = "机构地址")
|
||||
private String orgAddress;
|
||||
|
||||
@Schema(description = "负责人")
|
||||
private String manager;
|
||||
|
||||
@Schema(description = "电话")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "上级机构ID", example = "12053")
|
||||
private Integer parentOrgId;
|
||||
|
||||
@Schema(description = "上级机构名称", example = "芋艿")
|
||||
private String parentOrgName;
|
||||
|
||||
@Schema(description = "是否为上级机构(0否1是)")
|
||||
private Integer isParent;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.org.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 机构 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class OrgRespVO {
|
||||
|
||||
@Schema(description = "主键ID,自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "27344")
|
||||
@ExcelProperty("主键ID,自增")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "机构ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31188")
|
||||
@ExcelProperty("机构ID")
|
||||
private Integer orgId;
|
||||
|
||||
@Schema(description = "机构名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@ExcelProperty("机构名称")
|
||||
private String orgName;
|
||||
|
||||
@Schema(description = "机构地址")
|
||||
@ExcelProperty("机构地址")
|
||||
private String orgAddress;
|
||||
|
||||
@Schema(description = "负责人")
|
||||
@ExcelProperty("负责人")
|
||||
private String manager;
|
||||
|
||||
@Schema(description = "电话")
|
||||
@ExcelProperty("电话")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "上级机构ID", example = "12053")
|
||||
@ExcelProperty("上级机构ID")
|
||||
private Integer parentOrgId;
|
||||
|
||||
@Schema(description = "上级机构名称", example = "芋艿")
|
||||
@ExcelProperty("上级机构名称")
|
||||
private String parentOrgName;
|
||||
|
||||
@Schema(description = "是否为上级机构(0否1是)")
|
||||
@ExcelProperty("是否为上级机构(0否1是)")
|
||||
private Integer isParent;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.org.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 机构新增/修改 Request VO")
|
||||
@Data
|
||||
public class OrgSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID,自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "27344")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "机构ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31188")
|
||||
@NotNull(message = "机构ID不能为空")
|
||||
private Integer orgId;
|
||||
|
||||
@Schema(description = "机构名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@NotEmpty(message = "机构名称不能为空")
|
||||
private String orgName;
|
||||
|
||||
@Schema(description = "机构地址")
|
||||
private String orgAddress;
|
||||
|
||||
@Schema(description = "负责人")
|
||||
private String manager;
|
||||
|
||||
@Schema(description = "电话")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "上级机构ID", example = "12053")
|
||||
private Integer parentOrgId;
|
||||
|
||||
@Schema(description = "上级机构名称", example = "芋艿")
|
||||
private String parentOrgName;
|
||||
|
||||
@Schema(description = "是否为上级机构(0否1是)")
|
||||
private Integer isParent;
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.org;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 机构 DO
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
@TableName("tb_org")
|
||||
@KeySequence("tb_org_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrgDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键ID,自增
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 机构ID
|
||||
*/
|
||||
private Integer orgId;
|
||||
/**
|
||||
* 机构名称
|
||||
*/
|
||||
private String orgName;
|
||||
/**
|
||||
* 机构地址
|
||||
*/
|
||||
private String orgAddress;
|
||||
/**
|
||||
* 负责人
|
||||
*/
|
||||
private String manager;
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String phone;
|
||||
/**
|
||||
* 上级机构ID
|
||||
*/
|
||||
private Integer parentOrgId;
|
||||
/**
|
||||
* 上级机构名称
|
||||
*/
|
||||
private String parentOrgName;
|
||||
/**
|
||||
* 是否为上级机构(0否1是)
|
||||
*/
|
||||
private Integer isParent;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.org;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.org.OrgDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.org.vo.*;
|
||||
|
||||
/**
|
||||
* 机构 Mapper
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrgMapper extends BaseMapperX<OrgDO> {
|
||||
|
||||
default PageResult<OrgDO> selectPage(OrgPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<OrgDO>()
|
||||
.eqIfPresent(OrgDO::getOrgId, reqVO.getOrgId())
|
||||
.likeIfPresent(OrgDO::getOrgName, reqVO.getOrgName())
|
||||
.eqIfPresent(OrgDO::getOrgAddress, reqVO.getOrgAddress())
|
||||
.eqIfPresent(OrgDO::getManager, reqVO.getManager())
|
||||
.eqIfPresent(OrgDO::getPhone, reqVO.getPhone())
|
||||
.eqIfPresent(OrgDO::getParentOrgId, reqVO.getParentOrgId())
|
||||
.likeIfPresent(OrgDO::getParentOrgName, reqVO.getParentOrgName())
|
||||
.eqIfPresent(OrgDO::getIsParent, reqVO.getIsParent())
|
||||
.betweenIfPresent(OrgDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(OrgDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.system.service.org;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.org.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.org.OrgDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 机构 Service 接口
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
public interface OrgService {
|
||||
|
||||
/**
|
||||
* 创建机构
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createOrg(@Valid OrgSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新机构
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateOrg(@Valid OrgSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除机构
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteOrg(Integer id);
|
||||
|
||||
/**
|
||||
* 批量删除机构
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteOrgListByIds(List<Integer> ids);
|
||||
|
||||
/**
|
||||
* 获得机构
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 机构
|
||||
*/
|
||||
OrgDO getOrg(Integer id);
|
||||
|
||||
/**
|
||||
* 获得机构分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 机构分页
|
||||
*/
|
||||
PageResult<OrgDO> getOrgPage(OrgPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
package cn.iocoder.yudao.module.system.service.org;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.org.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.org.OrgDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.org.OrgMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 机构 Service 实现类
|
||||
*
|
||||
* @author 艾康菲
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class OrgServiceImpl implements OrgService {
|
||||
|
||||
@Resource
|
||||
private OrgMapper orgMapper;
|
||||
|
||||
@Override
|
||||
public Integer createOrg(OrgSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
OrgDO org = BeanUtils.toBean(createReqVO, OrgDO.class);
|
||||
orgMapper.insert(org);
|
||||
// 返回
|
||||
return org.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOrg(OrgSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateOrgExists(updateReqVO.getId());
|
||||
// 更新
|
||||
OrgDO updateObj = BeanUtils.toBean(updateReqVO, OrgDO.class);
|
||||
orgMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteOrg(Integer id) {
|
||||
// 校验存在
|
||||
validateOrgExists(id);
|
||||
// 删除
|
||||
orgMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteOrgListByIds(List<Integer> ids) {
|
||||
// 校验存在
|
||||
validateOrgExists(ids);
|
||||
// 删除
|
||||
orgMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateOrgExists(List<Integer> ids) {
|
||||
List<OrgDO> list = orgMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(ORG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateOrgExists(Integer id) {
|
||||
if (orgMapper.selectById(id) == null) {
|
||||
throw exception(ORG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrgDO getOrg(Integer id) {
|
||||
return orgMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<OrgDO> getOrgPage(OrgPageReqVO pageReqVO) {
|
||||
return orgMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
<?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="cn.iocoder.yudao.module.system.dal.mysql.org.OrgMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user