package cn.besteam.modules.medical.controller; import cn.besteam.common.api.vo.Result; import cn.besteam.common.aspect.annotation.AutoLog; import cn.besteam.common.constant.DepartmentEnum; import cn.besteam.common.constant.ErrorCode; import cn.besteam.common.constant.MedicalWasteEnum; import cn.besteam.common.dto.IdDTO; import cn.besteam.common.exception.BusinessException; import cn.besteam.modules.medical.entity.MwWarningConfigItemPlatform; import cn.besteam.modules.medical.service.IMwWarningConfigItemPlatformService; import cn.besteam.modules.system.entity.SysDepartment; import cn.besteam.modules.system.service.ISysDepartmentService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; /** * @Title: Controller * @Description: 预警-自定义配置-平台 * @author: besteam * @date: 2020-07-17 * @version: V1.0 */ @RestController @RequestMapping("/medical/mwWarningConfigItemPlatform") @Slf4j @Api(description = "预警-自定义配置-平台") public class MwWarningConfigItemPlatformController { @Autowired private IMwWarningConfigItemPlatformService mwWarningConfigItemService; @Autowired private ISysDepartmentService sysDepartmentService; /** * @param type * @return */ @GetMapping(value = "/listByType") @ApiOperation(value = "获取预警平台-自定义配置数据列表(新)", notes = "获取所有预警-自定义配置数据列表", produces = "application/json") public Object listByType(@RequestParam Integer type, Integer departmentId, Integer pageNo, Integer pageSize) { if(pageNo==null || pageSize==null){ return Result.ok(mwWarningConfigItemService.listByType(type, departmentId)); }else { return Result.ok(mwWarningConfigItemService.listByType(type, departmentId, pageNo, pageSize)); } } /** * 添加 * * @param mwWarningConfigItem * @return */ @PostMapping(value = "/add") @AutoLog(value = "添加预警平台-自定义配置(新)") @ApiOperation(value = "添加预警平台-自定义配置(新)", notes = "添加预警-自定义配置", produces = "application/json") public Result add(@RequestBody MwWarningConfigItemPlatform mwWarningConfigItem) { if (mwWarningConfigItem.getType() == null) { throw new BusinessException(ErrorCode.ERR_500, "类型不能为空"); } // QueryWrapper queryWrapper = new QueryWrapper<>(); SysDepartment department = sysDepartmentService.getById(mwWarningConfigItem.getCustomDepartmentId()); if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.NON_COLLECT.getType())) { if (department == null || !department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) { throw new BusinessException(ErrorCode.ERR_500, "区域不存在"); } queryWrapper.lambda().eq(MwWarningConfigItemPlatform::getCustomDepartmentId, mwWarningConfigItem.getCustomDepartmentId()).eq(MwWarningConfigItemPlatform::getCustomDepartmentId, mwWarningConfigItem.getCustomDepartmentId()) .eq(MwWarningConfigItemPlatform::getApplyType,1); } else if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.CHECKOUT_OVER_TIME.getType())) { if (department == null || !department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { throw new BusinessException(ErrorCode.ERR_500, "区域不存在"); } queryWrapper.lambda().eq(MwWarningConfigItemPlatform::getCustomDepartmentId, mwWarningConfigItem.getCustomDepartmentId()).eq(MwWarningConfigItemPlatform::getWasteType, mwWarningConfigItem.getWasteType()) .eq(MwWarningConfigItemPlatform::getApplyType,1); } mwWarningConfigItem.setStatus(1); Boolean result=mwWarningConfigItemService.save(mwWarningConfigItem); return Result.ok(result); } /** * 编辑 * * @param mwWarningConfigItem * @return */ @PostMapping(value = "/edit") @AutoLog(value = "编辑预警平台-自定义配置(新)") @ApiOperation(value = "编辑预警平台-自定义配置(新)", notes = "编辑预警-自定义配置", produces = "application/json") public Result edit(@RequestBody MwWarningConfigItemPlatform mwWarningConfigItem) { MwWarningConfigItemPlatform mwWarningConfigItemEntity = mwWarningConfigItemService.getById(mwWarningConfigItem.getId()); if (mwWarningConfigItemEntity == null) { throw new BusinessException(ErrorCode.ERR_500, "自定义配置不存在"); } int count = 0; QueryWrapper queryWrapper = new QueryWrapper<>(); SysDepartment department = sysDepartmentService.getById(mwWarningConfigItem.getCustomDepartmentId()); if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.NON_COLLECT.getType())) { if (department == null || !department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.AREA.getType())) { throw new BusinessException(ErrorCode.ERR_500, "区域不存在"); } queryWrapper.lambda().ne(MwWarningConfigItemPlatform::getId,mwWarningConfigItem.getId()).eq(MwWarningConfigItemPlatform::getCustomDepartmentId, mwWarningConfigItem.getCustomDepartmentId()).eq(MwWarningConfigItemPlatform::getCustomDepartmentId, mwWarningConfigItem.getCustomDepartmentId()) .eq(MwWarningConfigItemPlatform::getApplyType,1); count = mwWarningConfigItemService.count(queryWrapper); } else if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.CHECKOUT_OVER_TIME.getType())) { if (department == null || !department.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { throw new BusinessException(ErrorCode.ERR_500, "区域不存在"); } queryWrapper.lambda().ne(MwWarningConfigItemPlatform::getId,mwWarningConfigItem.getId()).eq(MwWarningConfigItemPlatform::getCustomDepartmentId, mwWarningConfigItem.getCustomDepartmentId()).eq(MwWarningConfigItemPlatform::getWasteType, mwWarningConfigItem.getWasteType()) .eq(MwWarningConfigItemPlatform::getApplyType,1); count = mwWarningConfigItemService.count(queryWrapper); } if (count > 0) { throw new BusinessException(ErrorCode.ERR_500, "自定义设置已存在"); } return Result.ok(mwWarningConfigItemService.updateById(mwWarningConfigItem)); } /** * 通过id删除 * * @param idDTO * @return */ @PostMapping(value = "/delete") @AutoLog(value = "删除预警平台-自定义配置(新)") @ApiOperation(value = "删除预警平台-自定义配置(新)", notes = "删除预警-自定义配置", produces = "application/json") public Result delete(@RequestBody IdDTO idDTO) { MwWarningConfigItemPlatform mwWarningConfigItem = mwWarningConfigItemService.getById(idDTO.getId()); if (mwWarningConfigItem == null) { throw new BusinessException(ErrorCode.ERR_500, "自定义配置不存在"); } return Result.ok(mwWarningConfigItemService.removeById(idDTO.getId())); } }