| | |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.model.SysOrganization; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.utils.AesUtils; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.usercenter.model.SysDepartment; |
| | | import com.kidgrow.usercenter.service.ISysDepartmentService; |
| | | import com.kidgrow.usercenter.service.ISysOrganizationService; |
| | |
| | | import org.springframework.validation.ObjectError; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | SysDepartment model = sysDepartmentService.getById(id); |
| | | return ResultBody.ok().data(model).msg("查询成功"); |
| | | } |
| | | |
| | | /** |
| | | * 查询 |
| | | */ |
| | | @ApiOperation(value = "更新支付功能的开通状态") |
| | | @GetMapping("/updatePay") |
| | | public ResultBody updatePay(Long departmentId,Boolean isPay) { |
| | | boolean isPays = sysDepartmentService.updatePay(departmentId,isPay); |
| | | public ResultBody updatePay(Long departmentId, Boolean isPay) { |
| | | boolean isPays = sysDepartmentService.updatePay(departmentId, isPay); |
| | | return ResultBody.ok().data(isPays).msg("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 查询 |
| | | */ |
| | |
| | | SysDepartment model = sysDepartmentService.getById(departmentId); |
| | | return ResultBody.ok().data(model.getIsPay()).msg("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 根据SysDepartment当做查询条件进行查询 |
| | | */ |
| | |
| | | */ |
| | | @ApiOperation(value = "检查科室名是否存在") |
| | | @GetMapping("/checkName") |
| | | public ResultBody checkDepName(Long hospitalId,String departmentName) { |
| | | if (departMentNameIsUsed(hospitalId,departmentName)) { |
| | | public ResultBody checkDepName(Long hospitalId, String departmentName) { |
| | | if (departMentNameIsUsed(hospitalId, departmentName)) { |
| | | return ResultBody.failed().msg(String.format("该医院下已经存在科室 %s", departmentName)); |
| | | } |
| | | return ResultBody.ok().msg(""); |
| | |
| | | |
| | | /** |
| | | * 检查科室名是否存在 |
| | | * |
| | | * @param hosId |
| | | * @param departmentName |
| | | * @return |
| | | */ |
| | | private Boolean departMentNameIsUsed(Long hosId,String departmentName) |
| | | { |
| | | String departName=sysDepartmentService.checkDepartmentName(hosId,departmentName); |
| | | private Boolean departMentNameIsUsed(Long hosId, String departmentName) { |
| | | String departName = sysDepartmentService.checkDepartmentName(hosId, departmentName); |
| | | return StringUtils.isNotBlank(departName); |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping("/{hosId}") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public ResultBody save(@Valid @RequestBody SysDepartment sysDepartment,@PathVariable Long hosId, BindingResult bindingResult,@LoginUser SysUser sysUser) { |
| | | public ResultBody save(@Valid @RequestBody SysDepartment sysDepartment, @PathVariable Long hosId, BindingResult bindingResult, @LoginUser SysUser sysUser) { |
| | | List<String> errMsg = new ArrayList<>(); |
| | | if (bindingResult.hasErrors()) { |
| | | for (ObjectError error : bindingResult.getAllErrors()) { |
| | |
| | | //先检查该医院该科室是否已经存在 |
| | | if (sysDepartment.getId() == null) { |
| | | |
| | | if (departMentNameIsUsed(hosId,sysDepartment.getDepartmentName())) { |
| | | if (departMentNameIsUsed(hosId, sysDepartment.getDepartmentName())) { |
| | | return ResultBody.failed().msg(String.format("该医院下已经存在科室 %s", sysDepartment.getDepartmentName())); |
| | | } |
| | | } |
| | |
| | | sysOrganization.setOrgLevel(2); |
| | | //临时暂用其它字段承载数据 |
| | | sysOrganization.setOrgParentId(sysDepartment.getUpdateUserId()); |
| | | if(!sysUser.getOrganizations().isEmpty()){ |
| | | if (!sysUser.getOrganizations().isEmpty()) { |
| | | sysOrganization.setCreateUserOrgCode(sysUser.getOrganizations().get(1).getOrgCode()); |
| | | } |
| | | } else { |
| | |
| | | public ResultBody findListByHospitalId(@RequestParam Map<String, Object> params) { |
| | | return sysDepartmentService.findListByHospitalId(params); |
| | | } |
| | | |
| | | @PostMapping |
| | | public ResultBody update(@RequestBody SysDepartment sysDepartment){ |
| | | if(sysDepartment.getId()==null){ |
| | | public ResultBody update(@RequestBody SysDepartment sysDepartment) { |
| | | if (sysDepartment.getId() == null) { |
| | | return ResultBody.failed("请输入id"); |
| | | } |
| | | QueryWrapper queryWrapper =new QueryWrapper(); |
| | | queryWrapper.eq("id",sysDepartment.getId()); |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("id", sysDepartment.getId()); |
| | | boolean update = sysDepartmentService.update(sysDepartment, queryWrapper); |
| | | if(update){ |
| | | if (update) { |
| | | return ResultBody.ok(); |
| | | }else { |
| | | } else { |
| | | return ResultBody.failed("更新数据失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | *运动处方调用 是否开通服务 |
| | | * 运动处方调用 是否开通服务 |
| | | */ |
| | | |
| | | @PostMapping("getHealth") |
| | | public ResultBody getHealth(@RequestBody SysDepartment sysDepartment){ |
| | | if(sysDepartment.getId()==null){ |
| | | public ResultBody getHealth(@RequestBody SysDepartment sysDepartment) { |
| | | if (sysDepartment.getId() == null) { |
| | | return ResultBody.failed("请输入id"); |
| | | } |
| | | return sysDepartmentService.getHealth(sysDepartment); |
| | | } |
| | | |
| | | /** |
| | | * 下载私有云服务器License文件 |
| | | * |
| | | * @param departmentId 科室ID |
| | | * @param response HttpServletResponse |
| | | * @return void |
| | | */ |
| | | @PostMapping("/downloadLicense") |
| | | public void downloadLicense(@RequestParam Long departmentId, HttpServletResponse response) { |
| | | |
| | | SysDepartment department = sysDepartmentService.getById(departmentId); |
| | | String serverLicense = ""; |
| | | |
| | | OutputStream out = null; |
| | | InputStream fileInputStream = null; |
| | | try { |
| | | if (department != null) { |
| | | if (department.getIsPrivate() == 1) { |
| | | if ((department.getPrivateServerGuuid() != null) && (!department.getPrivateServerGuuid().isEmpty())) { |
| | | serverLicense = AesUtils.encrypt(department.getPrivateServerGuuid()); |
| | | |
| | | } else { |
| | | serverLicense = String.format("此科室【%s】未设置服务器GUUID,不能下载私有云服务器License", departmentId); |
| | | log.error(serverLicense); |
| | | } |
| | | } else { |
| | | serverLicense = String.format("此科室【%s】非私有云客户,不能下载私有云服务器License", departmentId); |
| | | log.error(serverLicense); |
| | | } |
| | | } else { |
| | | serverLicense = String.format("此科室【%s】不存在,不能下载私有云服务器License", departmentId); |
| | | log.error(serverLicense); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | byte[] arr = serverLicense.getBytes(); |
| | | |
| | | // 设置输出的格式 |
| | | response.reset(); |
| | | response.setContentType("application/x-msdownload"); |
| | | response.addHeader("Content-Length", "" + arr.length); |
| | | response.addHeader("Content-Disposition", "attachment; filename=\"" + department.getDepartmentName() + "License.txt\""); |
| | | |
| | | |
| | | out = response.getOutputStream(); |
| | | fileInputStream = new ByteArrayInputStream(arr); |
| | | byte[] buffer = new byte[1024 * 10]; |
| | | int len = 0; |
| | | while ((len = fileInputStream.read(buffer)) > 0) { |
| | | out.write(buffer, 0, len); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | //log.error("私有云服务器Guuid加密出错"); |
| | | } finally { |
| | | |
| | | if (fileInputStream != null) { |
| | | try { |
| | | fileInputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载私有云本地数据库初始化数据 |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @param response |
| | | * @return void |
| | | */ |
| | | @PostMapping("/downloadData") |
| | | public void downloadPrivateData(@RequestParam("hospitalId") Long hospitalId,@RequestParam("departmentId") Long departmentId, HttpServletResponse response){ |
| | | String dataSql = ""; |
| | | |
| | | dataSql = sysDepartmentService.initPrivateData(hospitalId,departmentId); |
| | | |
| | | OutputStream out = null; |
| | | InputStream fileInputStream = null; |
| | | try { |
| | | byte[] arr = dataSql.getBytes(); |
| | | |
| | | // 设置输出的格式 |
| | | response.reset(); |
| | | response.setContentType("application/x-msdownload"); |
| | | response.addHeader("Content-Length", "" + arr.length); |
| | | response.addHeader("Content-Disposition", "attachment; filename=\"" + departmentId.toString() + ".sql\""); |
| | | |
| | | |
| | | out = response.getOutputStream(); |
| | | fileInputStream = new ByteArrayInputStream(arr); |
| | | byte[] buffer = new byte[1024 * 10]; |
| | | int len = 0; |
| | | while ((len = fileInputStream.read(buffer)) > 0) { |
| | | out.write(buffer, 0, len); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | |
| | | } finally { |
| | | |
| | | if (fileInputStream != null) { |
| | | try { |
| | | fileInputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |