机构管理
This commit is contained in:
parent
f4c0c84373
commit
c71b5ca012
@ -0,0 +1,10 @@
|
||||
package cn.iocoder.yudao.module.tb.enums;
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
|
||||
public interface ErrorCodeConstants {
|
||||
ErrorCode INSPECT_ORG_NOT_EXISTS = new ErrorCode(10000, "机构不存在");
|
||||
ErrorCode HIGH_INSPECT_ORG_NOT_EXISTS = new ErrorCode(10010, "上级机构不存在");
|
||||
ErrorCode ORGSN_EXISTS = new ErrorCode(10020, "机构编号重复");
|
||||
ErrorCode ORGNAME_EXISTS = new ErrorCode(10021, "机构名称重复");
|
||||
ErrorCode HIGH_NOT_ALLOW_SELF = new ErrorCode(10030, "上级机构不能选择自己或子级机构");
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package cn.iocoder.yudao.module.inspect.controller.admin.inspectorg;
|
||||
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgPageReqVO;
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgRespVO;
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgSaveReqVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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 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.inspect.dal.dataobject.inspectorg.InspectOrgDO;
|
||||
import cn.iocoder.yudao.module.inspect.service.inspectorg.InspectOrgService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Tag(name = "管理后台 - 机构")
|
||||
@RestController
|
||||
@RequestMapping("/tb/inspect-org")
|
||||
@Validated
|
||||
public class InspectOrgController {
|
||||
|
||||
@Resource
|
||||
private InspectOrgService inspectOrgService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建机构")
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:create')")
|
||||
public CommonResult<Long> createInspectOrg(@Valid @RequestBody InspectOrgSaveReqVO createReqVO) {
|
||||
return success(inspectOrgService.createInspectOrg(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新机构")
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:update')")
|
||||
public CommonResult<Boolean> updateInspectOrg(@Valid @RequestBody InspectOrgSaveReqVO updateReqVO) {
|
||||
inspectOrgService.updateInspectOrg(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除机构")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:delete')")
|
||||
public CommonResult<Boolean> deleteInspectOrg(@RequestParam("id") Long id) {
|
||||
inspectOrgService.deleteInspectOrg(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得机构")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:query')")
|
||||
public CommonResult<InspectOrgRespVO> getInspectOrg(@RequestParam("id") Long id) {
|
||||
InspectOrgDO inspectOrg = inspectOrgService.getInspectOrg(id);
|
||||
return success(BeanUtils.toBean(inspectOrg, InspectOrgRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得机构分页")
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:query')")
|
||||
public CommonResult<PageResult<InspectOrgRespVO>> getInspectOrgPage(@Valid InspectOrgPageReqVO pageReqVO) {
|
||||
PageResult<InspectOrgDO> pageResult = inspectOrgService.getInspectOrgPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, InspectOrgRespVO.class));
|
||||
}
|
||||
@GetMapping("/all")
|
||||
@Operation(summary = "获得所有机构信息")
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:query')")
|
||||
public CommonResult<PageResult<InspectOrgRespVO>> getInspectOrgList(@Valid InspectOrgPageReqVO pageReqVO) {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
PageResult<InspectOrgDO> pageResult = inspectOrgService.getInspectOrgPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, InspectOrgRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出机构 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('tb:inspect-org:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportInspectOrgExcel(@Valid InspectOrgPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<InspectOrgDO> list = inspectOrgService.getInspectOrgPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "机构.xls", "数据", InspectOrgRespVO.class,
|
||||
BeanUtils.toBean(list, InspectOrgRespVO.class));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
@Schema(description = "管理后台 - tb_org分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InspectOrgPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
private String orgName;
|
||||
|
||||
@Schema(description = "机构地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
private String contactTel;
|
||||
|
||||
@Schema(description = "联系人姓名")
|
||||
private String contactPerson;
|
||||
|
||||
@Schema(description = "报告上显示的名称:一般跟机构名称一致", example = "芋艿")
|
||||
private String reportName;
|
||||
|
||||
@Schema(description = "上级判读医院机构ID", example = "28259")
|
||||
private Long highLevelOrgID;
|
||||
|
||||
@Schema(description = "上级机构的机构名称", example = "李四")
|
||||
private String highLevelOrgName;
|
||||
|
||||
@Schema(description = "机构编号:通常为一个4位数的短号 用于与其他系统的对接之用")
|
||||
private String orgSN;
|
||||
|
||||
@Schema(description = "机构logo的URL", example = "https://www.iocoder.cn")
|
||||
private String orgLogoUrl;
|
||||
|
||||
@Schema(description = "是否删除:1为删除 ")
|
||||
private String isdelete;
|
||||
|
||||
@Schema(description = "在his系统中的 hiscode 机构码")
|
||||
private String inHisCode;
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - tb_org Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class InspectOrgRespVO {
|
||||
|
||||
@Schema(description = "机构ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19567")
|
||||
@ExcelProperty("机构ID")
|
||||
private Long orgid;
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
@ExcelProperty("机构名称")
|
||||
private String orgName;
|
||||
|
||||
@Schema(description = "机构地址")
|
||||
@ExcelProperty("机构地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
@ExcelProperty("联系电话")
|
||||
private String contactTel;
|
||||
|
||||
@Schema(description = "联系人姓名")
|
||||
@ExcelProperty("联系人姓名")
|
||||
private String contactPerson;
|
||||
|
||||
@Schema(description = "上级判读医院机构ID", example = "28259")
|
||||
@ExcelProperty("上级判读医院机构ID")
|
||||
private Long highLevelOrgID;
|
||||
|
||||
@Schema(description = "上级机构的机构名称", example = "李四")
|
||||
@ExcelProperty("上级机构的机构名称")
|
||||
private String highLevelOrgName;
|
||||
|
||||
@Schema(description = "机构logo的URL", example = "https://www.iocoder.cn")
|
||||
@ExcelProperty("机构logo的URL")
|
||||
private String orgLogoUrl;
|
||||
|
||||
@Schema(description = "机构编号", example = "https://www.iocoder.cn")
|
||||
@ExcelProperty("机构编号")
|
||||
private String orgSN;
|
||||
|
||||
@Schema(description = "在his系统中的 hiscode 机构码")
|
||||
@ExcelProperty("在his系统中的 hiscode 机构码")
|
||||
private String inHisCode;
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - tb_org新增/修改 Request VO")
|
||||
@Data
|
||||
public class InspectOrgSaveReqVO {
|
||||
|
||||
@Schema(description = "机构ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19567")
|
||||
private Long orgid;
|
||||
|
||||
@Schema(description = "机构名称", example = "赵六")
|
||||
@NotBlank(message = "机构名称不能为空")
|
||||
private String orgName;
|
||||
|
||||
@Schema(description = "机构地址")
|
||||
// @NotBlank(message = "机构地址不能为空")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
@NotBlank(message = "联系电话不能为空")
|
||||
@Pattern(regexp = "^(1(3[0-9]|4[014-9]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\\d{8})$",message = "联系电话格式错误")
|
||||
private String contactTel;
|
||||
|
||||
@Schema(description = "联系人姓名")
|
||||
@NotBlank(message = "联系人姓名不能为空")
|
||||
private String contactPerson;
|
||||
|
||||
@Schema(description = "报告上显示的名称:一般跟机构名称一致", example = "芋艿")
|
||||
private String reportName;
|
||||
|
||||
@Schema(description = "上级判读医院机构ID", example = "28259")
|
||||
private Long highLevelOrgID;
|
||||
|
||||
@Schema(description = "上级机构的机构名称", example = "李四")
|
||||
private String highLevelOrgName;
|
||||
|
||||
@Schema(description = "机构编号:通常为一个4位数的短号 用于与其他系统的对接之用")
|
||||
@NotBlank(message = "机构编号不能为空")
|
||||
private String orgSN;
|
||||
|
||||
@Schema(description = "创建时间:年月日时分秒")
|
||||
private LocalDateTime createDate;
|
||||
|
||||
@Schema(description = "机构logo的URL", example = "https://www.iocoder.cn")
|
||||
private String orgLogoUrl;
|
||||
|
||||
@Schema(description = "在his系统中的 hiscode 机构码")
|
||||
private String inHisCode;
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package cn.iocoder.yudao.module.inspect.dal.dataobject.inspectorg;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* tb_org DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("tb_org")
|
||||
@KeySequence("tb_org_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class InspectOrgDO {
|
||||
|
||||
/**
|
||||
* 机构ID
|
||||
*/
|
||||
@TableId
|
||||
private Long orgid;
|
||||
/**
|
||||
* 机构名称
|
||||
*/
|
||||
@TableField("orgName")
|
||||
private String orgName;
|
||||
/**
|
||||
* 机构地址
|
||||
*/
|
||||
@TableField("address")
|
||||
private String address;
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@TableField("contactTel")
|
||||
private String contactTel;
|
||||
/**
|
||||
* 联系人姓名
|
||||
*/
|
||||
@TableField("contactPerson")
|
||||
private String contactPerson;
|
||||
/**
|
||||
* 报告上显示的名称:一般跟机构名称一致
|
||||
*/
|
||||
@TableField("reportName")
|
||||
private String reportName;
|
||||
/**
|
||||
* 上级判读医院机构ID
|
||||
*/
|
||||
@TableField(value = "highLevelOrgID",updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Long highLevelOrgID;
|
||||
/**
|
||||
* 上级机构的机构名称
|
||||
*/
|
||||
@TableField(value = "highLevelOrgName",updateStrategy = FieldStrategy.ALWAYS)
|
||||
private String highLevelOrgName;
|
||||
/**
|
||||
* 能收到微信消息提醒的微信列表,格式为:wxopenid1,wxopenid2,wxopenid3
|
||||
*/
|
||||
@TableField("wx_openidlist")
|
||||
private String wx_openidlist;
|
||||
/**
|
||||
* 机构编号:通常为一个4位数的短号 用于与其他系统的对接之用
|
||||
*/
|
||||
@TableField("orgSN")
|
||||
private String orgSN;
|
||||
/**
|
||||
* 创建时间:年月日时分秒
|
||||
*/
|
||||
@TableField("createDate")
|
||||
private LocalDateTime createDate;
|
||||
/**
|
||||
* 机构logo的URL
|
||||
*/
|
||||
@TableField("orgLogoUrl")
|
||||
private String orgLogoUrl;
|
||||
/**
|
||||
* 是否删除:1为删除
|
||||
*/
|
||||
@TableField("isdelete")
|
||||
private String isdelete;
|
||||
/**
|
||||
* dcm文件前缀名称
|
||||
*/
|
||||
@TableField("dcmprefix")
|
||||
private String dcmprefix;
|
||||
/**
|
||||
* dcm文件请求地址
|
||||
*/
|
||||
@TableField("dcmurl")
|
||||
private String dcmurl;
|
||||
/**
|
||||
* 是否启用云胶片:1为启用
|
||||
*/
|
||||
@TableField("enableCloudDicom")
|
||||
private String enableCloudDicom;
|
||||
/**
|
||||
* 云胶片地址
|
||||
*/
|
||||
@TableField("cloudDicom")
|
||||
private String cloudDicom;
|
||||
/**
|
||||
* 在his系统中的 hiscode 机构码
|
||||
*/
|
||||
@TableField("inHisCode")
|
||||
private String inHisCode;
|
||||
|
||||
public InspectOrgDO(Long orgid) {
|
||||
this.orgid = orgid;
|
||||
}
|
||||
|
||||
public InspectOrgDO(String orgSN) {
|
||||
this.orgSN = orgSN;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package cn.iocoder.yudao.module.inspect.dal.mysql.inspectorg;
|
||||
|
||||
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.inspect.controller.admin.inspectorg.vo.InspectOrgPageReqVO;
|
||||
import cn.iocoder.yudao.module.inspect.dal.dataobject.inspectorg.InspectOrgDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* tb_org Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface InspectOrgMapper extends BaseMapperX<InspectOrgDO> {
|
||||
|
||||
default PageResult<InspectOrgDO> selectPage(InspectOrgPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<InspectOrgDO>()
|
||||
.likeIfPresent(InspectOrgDO::getOrgName, reqVO.getOrgName())
|
||||
.eqIfPresent(InspectOrgDO::getAddress, reqVO.getAddress())
|
||||
.eqIfPresent(InspectOrgDO::getContactTel, reqVO.getContactTel())
|
||||
.eqIfPresent(InspectOrgDO::getContactPerson, reqVO.getContactPerson())
|
||||
.likeIfPresent(InspectOrgDO::getReportName, reqVO.getReportName())
|
||||
.eqIfPresent(InspectOrgDO::getHighLevelOrgID, reqVO.getHighLevelOrgID())
|
||||
.likeIfPresent(InspectOrgDO::getHighLevelOrgName, reqVO.getHighLevelOrgName())
|
||||
.eqIfPresent(InspectOrgDO::getOrgSN, reqVO.getOrgSN())
|
||||
.eqIfPresent(InspectOrgDO::getOrgLogoUrl, reqVO.getOrgLogoUrl())
|
||||
.eqIfPresent(InspectOrgDO::getIsdelete, 0)
|
||||
.eqIfPresent(InspectOrgDO::getInHisCode, reqVO.getInHisCode())
|
||||
.orderByDesc(InspectOrgDO::getOrgid));
|
||||
}
|
||||
default InspectOrgDO selectById(Long id){
|
||||
return selectOne(new LambdaQueryWrapperX<InspectOrgDO>()
|
||||
.eq(InspectOrgDO::getOrgid,id)
|
||||
.eq(InspectOrgDO::getIsdelete,0));
|
||||
}
|
||||
/**
|
||||
* 根据条件查询一个机构,添加行锁
|
||||
* @param inspectOrgDO
|
||||
* @return
|
||||
*/
|
||||
InspectOrgDO selectOneForLock(InspectOrgDO inspectOrgDO);
|
||||
|
||||
/**
|
||||
* 查询当前机构及其子级机构和所有子级的子级
|
||||
* @param orgid
|
||||
* @return
|
||||
*/
|
||||
List<InspectOrgDO> listChildrenWithSelf(Long orgid);
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cn.iocoder.yudao.module.inspect.service.inspectorg;
|
||||
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgPageReqVO;
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgSaveReqVO;
|
||||
import cn.iocoder.yudao.module.inspect.dal.dataobject.inspectorg.InspectOrgDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* tb_org Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface InspectOrgService {
|
||||
|
||||
/**
|
||||
* 创建tb_org
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createInspectOrg(@Valid InspectOrgSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新tb_org
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateInspectOrg(@Valid InspectOrgSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除tb_org
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteInspectOrg(Long id);
|
||||
|
||||
/**
|
||||
* 获得tb_org
|
||||
*
|
||||
* @param id 编号
|
||||
* @return tb_org
|
||||
*/
|
||||
InspectOrgDO getInspectOrg(Long id);
|
||||
|
||||
/**
|
||||
* 获得tb_org分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return tb_org分页
|
||||
*/
|
||||
PageResult<InspectOrgDO> getInspectOrgPage(InspectOrgPageReqVO pageReqVO);
|
||||
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package cn.iocoder.yudao.module.inspect.service.inspectorg;
|
||||
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgPageReqVO;
|
||||
import cn.iocoder.yudao.module.inspect.controller.admin.inspectorg.vo.InspectOrgSaveReqVO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import cn.iocoder.yudao.module.inspect.dal.dataobject.inspectorg.InspectOrgDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.inspect.dal.mysql.inspectorg.InspectOrgMapper;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.tb.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* tb_org Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class InspectOrgServiceImpl implements InspectOrgService {
|
||||
|
||||
@Resource
|
||||
private InspectOrgMapper inspectOrgMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Long createInspectOrg(InspectOrgSaveReqVO createReqVO) {
|
||||
Long highLevelOrgID = createReqVO.getHighLevelOrgID(); // 上级机构id
|
||||
if (highLevelOrgID != null) {
|
||||
// 上级机构
|
||||
InspectOrgDO highOrg = inspectOrgMapper.selectOneForLock(new InspectOrgDO().setOrgid(createReqVO.getHighLevelOrgID()));
|
||||
if (highOrg == null){
|
||||
throw exception(HIGH_INSPECT_ORG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
// 根据机构编号查询
|
||||
InspectOrgDO one = inspectOrgMapper.selectOneForLock(new InspectOrgDO().setOrgSN(createReqVO.getOrgSN()));
|
||||
if (one!=null){
|
||||
throw exception(ORGSN_EXISTS);
|
||||
}
|
||||
// 名称不允许重复
|
||||
one = inspectOrgMapper.selectOneForLock(new InspectOrgDO().setOrgName(createReqVO.getOrgName()));
|
||||
if (one!=null){
|
||||
throw exception(ORGNAME_EXISTS);
|
||||
}
|
||||
InspectOrgDO inspectOrg = BeanUtils.toBean(createReqVO, InspectOrgDO.class);
|
||||
inspectOrgMapper.insert(inspectOrg);
|
||||
// 返回
|
||||
return inspectOrg.getOrgid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateInspectOrg(InspectOrgSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateInspectOrgExists(updateReqVO.getOrgid());
|
||||
// 上级机构不能是自己
|
||||
if (Objects.equals(updateReqVO.getHighLevelOrgID(), updateReqVO.getOrgid())){
|
||||
throw exception(HIGH_NOT_ALLOW_SELF);
|
||||
}
|
||||
// 上级机构不能是自己的子级或子级的子级
|
||||
List<InspectOrgDO> childrenWithSelf = inspectOrgMapper.listChildrenWithSelf(updateReqVO.getOrgid());
|
||||
boolean match = childrenWithSelf
|
||||
.stream()
|
||||
.anyMatch(org -> Objects.equals(org.getOrgid(), updateReqVO.getHighLevelOrgID()));
|
||||
if (match){
|
||||
throw exception(HIGH_NOT_ALLOW_SELF);
|
||||
}
|
||||
// 无上级机构
|
||||
if (updateReqVO.getHighLevelOrgID()==null){
|
||||
updateReqVO.setHighLevelOrgName(null);
|
||||
}else {
|
||||
InspectOrgDO highOrg = inspectOrgMapper.selectOneForLock(new InspectOrgDO().setOrgid(updateReqVO.getHighLevelOrgID()));
|
||||
if (highOrg == null){
|
||||
throw exception(HIGH_INSPECT_ORG_NOT_EXISTS);
|
||||
}
|
||||
updateReqVO.setHighLevelOrgName(highOrg.getOrgName());
|
||||
}
|
||||
// 机构编号不能重复
|
||||
InspectOrgDO one = inspectOrgMapper.selectOneForLock(new InspectOrgDO().setOrgSN(updateReqVO.getOrgSN()));
|
||||
if (one != null && !Objects.equals(one.getOrgid(), updateReqVO.getOrgid())){
|
||||
throw exception(ORGSN_EXISTS);
|
||||
}
|
||||
// 名称不允许重复
|
||||
one = inspectOrgMapper.selectOneForLock(new InspectOrgDO().setOrgName(updateReqVO.getOrgName()));
|
||||
if (one != null && !Objects.equals(one.getOrgid(),updateReqVO.getOrgid())){
|
||||
throw exception(ORGNAME_EXISTS);
|
||||
}
|
||||
InspectOrgDO updateObj = BeanUtils.toBean(updateReqVO, InspectOrgDO.class);
|
||||
inspectOrgMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteInspectOrg(Long id) {
|
||||
// 校验存在
|
||||
validateInspectOrgExists(id);
|
||||
LambdaUpdateWrapper<InspectOrgDO> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(InspectOrgDO::getIsdelete,1).eq(InspectOrgDO::getOrgid,id);
|
||||
// 删除
|
||||
inspectOrgMapper.update(updateWrapper);
|
||||
}
|
||||
|
||||
private void validateInspectOrgExists(Long id) {
|
||||
if (inspectOrgMapper.selectById(id) == null) {
|
||||
throw exception(INSPECT_ORG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectOrgDO getInspectOrg(Long id) {
|
||||
InspectOrgDO inspectOrgDO = inspectOrgMapper.selectById(id);
|
||||
return inspectOrgDO == null?new InspectOrgDO():inspectOrgDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<InspectOrgDO> getInspectOrgPage(InspectOrgPageReqVO pageReqVO) {
|
||||
return inspectOrgMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?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.inspect.dal.mysql.inspectorg.InspectOrgMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
<select id="selectOneForLock"
|
||||
resultType="cn.iocoder.yudao.module.inspect.dal.dataobject.inspectorg.InspectOrgDO">
|
||||
select *
|
||||
from tb_org
|
||||
<where>
|
||||
<if test="orgid !=null">orgid = #{orgid}</if>
|
||||
<if test="orgSN !=null and orgSN!='' ">orgSN = #{orgSN}</if>
|
||||
<if test="orgName !=null and orgName!='' ">orgName = #{orgName}</if>
|
||||
</where>
|
||||
for update
|
||||
</select>
|
||||
<select id="listChildrenWithSelf"
|
||||
resultType="cn.iocoder.yudao.module.inspect.dal.dataobject.inspectorg.InspectOrgDO">
|
||||
WITH RECURSIVE OrgTree AS (
|
||||
SELECT orgid, highLevelOrgID
|
||||
FROM tb_org
|
||||
WHERE orgid = #{orgid}
|
||||
UNION ALL
|
||||
SELECT o.orgid, o.highLevelOrgID
|
||||
FROM tb_org o
|
||||
INNER JOIN OrgTree ot ON o.highLevelOrgID = ot.orgid -- 递归查询子级的子级
|
||||
)
|
||||
SELECT * FROM OrgTree;
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user