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.MwBusinessApproval; import cn.besteam.modules.medical.entity.MwWarningConfigItem; import cn.besteam.modules.medical.service.IMwBusinessApprovalService; import cn.besteam.modules.medical.service.IMwWarningConfigItemService; import cn.besteam.modules.shiro.authc.util.EnvUtils; import cn.besteam.modules.system.entity.SysDepartment; import cn.besteam.modules.system.entity.SysDictItem; import cn.besteam.modules.system.service.ISysDepartmentService; import cn.besteam.modules.system.service.ISysDictItemService; 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/mwWarningConfigItem") @Slf4j @Api(description = "预警-自定义配置") public class MwWarningConfigItemController { @Autowired private IMwWarningConfigItemService mwWarningConfigItemService; @Autowired private ISysDepartmentService sysDepartmentService; /** * 业务审批 */ @Autowired private IMwBusinessApprovalService businessApprovalService; @Autowired private ISysDictItemService sysDictItemService; /** * @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 MwWarningConfigItem mwWarningConfigItem) { if (mwWarningConfigItem.getType() == null) { throw new BusinessException(ErrorCode.ERR_500, "类型不能为空"); } // QueryWrapper queryWrapper = new QueryWrapper<>(); SysDepartment hospital = sysDepartmentService.getById(mwWarningConfigItem.getCustomHospitalId()); SysDepartment office = sysDepartmentService.getById(mwWarningConfigItem.getCustomOfficeId()); //未出医废 : 医院 + 科室 if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.NON_COLLECT.getType())) { if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { throw new BusinessException(ErrorCode.ERR_500, "医院不存在"); } if (office == null || !office.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) { throw new BusinessException(ErrorCode.ERR_500, "科室不存在"); } queryWrapper.lambda().eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getCustomOfficeId, mwWarningConfigItem.getCustomOfficeId()) .eq(MwWarningConfigItem::getApplyType,1); } else if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.CHECKOUT_OVER_TIME.getType())) { if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { throw new BusinessException(ErrorCode.ERR_500, "医院不存在"); } queryWrapper.lambda().eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getWasteType, mwWarningConfigItem.getWasteType()) .eq(MwWarningConfigItem::getApplyType,1); } Integer approvalCount=businessApprovalService.count(new QueryWrapper() .eq("hospital_id",mwWarningConfigItem.getCustomHospitalId()) .eq("office_id",mwWarningConfigItem.getCustomOfficeId()) .eq("status",0) .eq("type",2) .eq("apply_type",1) ); if (approvalCount > 0) { throw new BusinessException(ErrorCode.ERR_500, "自定义设置还在审核中"); } mwWarningConfigItem.setStatus(1); Boolean result=mwWarningConfigItemService.save(mwWarningConfigItem); // todo 未出医废预警设置时长 添加审批数据 if(mwWarningConfigItem.getType()==1){ mwWarningConfigItem.setStatus(0); MwBusinessApproval businessApproval = new MwBusinessApproval(); businessApproval.setHospitalId(mwWarningConfigItem.getCustomHospitalId()); businessApproval.setOfficeId(mwWarningConfigItem.getCustomOfficeId()); businessApproval.setOperatorId(EnvUtils.getUser().getId()); businessApproval.setLinkman(EnvUtils.getUser().getName()); businessApproval.setLinkphone(EnvUtils.getUser().getPhone()); businessApproval.setApplyType(mwWarningConfigItem.getApplyType()); if(mwWarningConfigItem.getApplyType()==1){//固定时长 businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置固定时长:"+mwWarningConfigItem.getCustomValue()+"天"); }else if(mwWarningConfigItem.getApplyType()==2){//节假日 SysDictItem sysDictItem=sysDictItemService.getById(mwWarningConfigItem.getCustomValue()); businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置节假日:"+sysDictItem.getItemText()+"("+sysDictItem.getDescription()+")"); }else if(mwWarningConfigItem.getApplyType()==3){//临时时长 businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置临时时长:"+mwWarningConfigItem.getCustomValue()+"天"); } if(mwWarningConfigItem.getRemarks()!=null){ businessApproval.setApplyMark(mwWarningConfigItem.getRemarks()); }else { businessApproval.setApplyMark("无"); } businessApproval.setStatus(0); businessApproval.setType(2); businessApproval.setApplyDataId(mwWarningConfigItem.getId()); businessApprovalService.save(businessApproval); mwWarningConfigItemService.updateById(mwWarningConfigItem); } return Result.ok(result); } /** * 编辑 * * @param mwWarningConfigItem * @return */ @PostMapping(value = "/edit") @AutoLog(value = "编辑预警-自定义配置") @ApiOperation(value = "编辑预警-自定义配置", notes = "编辑预警-自定义配置", produces = "application/json") public Result edit(@RequestBody MwWarningConfigItem mwWarningConfigItem) { MwWarningConfigItem mwWarningConfigItemEntity = mwWarningConfigItemService.getById(mwWarningConfigItem.getId()); if (mwWarningConfigItemEntity == null) { throw new BusinessException(ErrorCode.ERR_500, "自定义配置不存在"); } // int count = 0; QueryWrapper queryWrapper = new QueryWrapper<>(); SysDepartment hospital = sysDepartmentService.getById(mwWarningConfigItem.getCustomHospitalId()); SysDepartment office = sysDepartmentService.getById(mwWarningConfigItem.getCustomOfficeId()); //未出医废 : 医院 + 科室 if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.NON_COLLECT.getType())) { if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { throw new BusinessException(ErrorCode.ERR_500, "医院不存在"); } if (office == null || !office.getOrgType().equals(DepartmentEnum.OrgTypeEnum.OFFICE.getType())) { throw new BusinessException(ErrorCode.ERR_500, "科室不存在"); } queryWrapper.lambda().ne(MwWarningConfigItem::getId,mwWarningConfigItem.getId()).eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getCustomOfficeId, mwWarningConfigItem.getCustomOfficeId()) .eq(MwWarningConfigItem::getApplyType,1); count = mwWarningConfigItemService.count(queryWrapper); } else if (mwWarningConfigItem.getType().equals(MedicalWasteEnum.WarningConfigTypeEnum.CHECKOUT_OVER_TIME.getType())) { if (hospital == null || !hospital.getOrgType().equals(DepartmentEnum.OrgTypeEnum.HOSPITAL.getType())) { throw new BusinessException(ErrorCode.ERR_500, "医院不存在"); } queryWrapper.lambda().ne(MwWarningConfigItem::getId,mwWarningConfigItem.getId()).eq(MwWarningConfigItem::getCustomHospitalId, mwWarningConfigItem.getCustomHospitalId()).eq(MwWarningConfigItem::getWasteType, mwWarningConfigItem.getWasteType()) .eq(MwWarningConfigItem::getApplyType,1); count = mwWarningConfigItemService.count(queryWrapper); } if (count > 0) { throw new BusinessException(ErrorCode.ERR_500, "自定义设置已存在"); } // todo 未出医废预警设置时长 添加审批数据 if(mwWarningConfigItemEntity.getType()==1){ mwWarningConfigItem.setStatus(0); MwBusinessApproval businessApproval = new MwBusinessApproval(); businessApproval.setHospitalId(mwWarningConfigItem.getCustomHospitalId()); businessApproval.setOperatorId(EnvUtils.getUser().getId()); businessApproval.setLinkman(EnvUtils.getUser().getName()); businessApproval.setLinkphone(EnvUtils.getUser().getPhone()); if(mwWarningConfigItem.getApplyType()==1){//固定时长 businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置固定时长:"+mwWarningConfigItem.getCustomValue()+"小时"); }else if(mwWarningConfigItem.getApplyType()==2){//节假日 SysDictItem sysDictItem=sysDictItemService.getById(mwWarningConfigItem.getCustomValue()); businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置节假日:"+sysDictItem.getItemText()+"("+sysDictItem.getDescription()+")"); }else if(mwWarningConfigItem.getApplyType()==3){//临时时长 businessApproval.setApplyContent("科室("+office.getDepartName()+")申请未出医废预警自定义设置临时时长:"+mwWarningConfigItem.getCustomValue()+"小时"); } if(mwWarningConfigItem.getRemarks()!=null){ businessApproval.setApplyMark(mwWarningConfigItem.getRemarks()); }else { businessApproval.setApplyMark("无"); } businessApproval.setStatus(0); businessApproval.setType(2); businessApproval.setApplyDataId(mwWarningConfigItem.getId()); businessApprovalService.save(businessApproval); } 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) { MwWarningConfigItem mwWarningConfigItem = mwWarningConfigItemService.getById(idDTO.getId()); if (mwWarningConfigItem == null) { throw new BusinessException(ErrorCode.ERR_500, "自定义配置不存在"); } return Result.ok(mwWarningConfigItemService.removeById(idDTO.getId())); } }