| | |
| | | package com.kidgrow.usercenter.controller; |
| | | |
| | | import java.util.Map; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.controller.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.ObjectError; |
| | | import org.springframework.web.bind.annotation.*; |
| | | 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.usercenter.model.SysDepartment; |
| | | import com.kidgrow.usercenter.service.ISysDepartmentService; |
| | | import com.kidgrow.usercenter.service.ISysOrganizationService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import com.kidgrow.usercenter.model.SysDepartment; |
| | | import com.kidgrow.usercenter.service.ISysDepartmentService; |
| | | import com.kidgrow.common.model.*; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.validation.ObjectError; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: 科室表 |
| | | * @Project: 用户中心 |
| | | * @CreateDate: Created in 2020-04-02 18:32:36 <br> |
| | |
| | | @RestController |
| | | @RequestMapping("/sysdepartment") |
| | | @Api(tags = "科室表") |
| | | public class SysDepartmentController extends BaseController{ |
| | | public class SysDepartmentController extends BaseController { |
| | | @Autowired |
| | | private ISysDepartmentService sysDepartmentService; |
| | | @Autowired |
| | | private ISysOrganizationService sysOrganizationService; |
| | | |
| | | /** |
| | | * 列表 |
| | |
| | | }) |
| | | @GetMapping |
| | | public ResultBody<PageResult> list(@RequestParam Map<String, Object> params) { |
| | | if(params.size()==0){ |
| | | params.put("page",1); |
| | | params.put("limit",10); |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return ResultBody.ok().data(sysDepartmentService.findList(params)); |
| | | } |
| | |
| | | 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); |
| | | return ResultBody.ok().data(isPays).msg("操作成功"); |
| | | } |
| | | /** |
| | | * 查询 |
| | | */ |
| | | @ApiOperation(value = "查看支付功能的开通状态") |
| | | @GetMapping("/getPayMes") |
| | | public ResultBody getPayMes(Long departmentId) { |
| | | 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)) { |
| | | 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); |
| | | return StringUtils.isNotBlank(departName); |
| | | } |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody SysDepartment sysDepartment, BindingResult bindingResult) { |
| | | List<String> errMsg= new ArrayList<>(); |
| | | @PostMapping("/{hosId}") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | 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()) { |
| | | errMsg.add(error.getDefaultMessage()); |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | boolean v= sysDepartmentService.saveOrUpdate(sysDepartment); |
| | | if(v) { |
| | | return ResultBody.ok().data(sysDepartment).msg("保存成功"); |
| | | //先检查该医院该科室是否已经存在 |
| | | if (sysDepartment.getId() == null) { |
| | | |
| | | if (departMentNameIsUsed(hosId,sysDepartment.getDepartmentName())) { |
| | | return ResultBody.failed().msg(String.format("该医院下已经存在科室 %s", sysDepartment.getDepartmentName())); |
| | | } |
| | | } |
| | | else { |
| | | //先检查是否存在组织信息 |
| | | SysOrganization sysOrganization = new SysOrganization(); |
| | | if (sysDepartment.getOrgId() != null) { |
| | | sysOrganization.setId(sysDepartment.getOrgId()); |
| | | } else { |
| | | sysOrganization.setOrgName(sysDepartment.getDepartmentName()); |
| | | //临时暂用其它字段承载数据 |
| | | sysOrganization.setOrgParentId(sysDepartment.getUpdateUserId()); |
| | | } |
| | | sysOrganization = sysOrganizationService.findByObject(sysOrganization); |
| | | if (sysOrganization == null) { |
| | | //创建一个组织 |
| | | sysOrganization = new SysOrganization(); |
| | | sysOrganization.setOrgName(sysDepartment.getDepartmentName()); |
| | | sysOrganization.setOrgAttr(2); |
| | | sysOrganization.setOrgLevel(2); |
| | | //临时暂用其它字段承载数据 |
| | | sysOrganization.setOrgParentId(sysDepartment.getUpdateUserId()); |
| | | if(!sysUser.getOrganizations().isEmpty()){ |
| | | sysOrganization.setCreateUserOrgCode(sysUser.getOrganizations().get(1).getOrgCode()); |
| | | } |
| | | } else { |
| | | sysOrganization.setOrgName(sysDepartment.getDepartmentName()); |
| | | } |
| | | boolean org = sysOrganizationService.saveOrUpdateSer(sysOrganization); |
| | | sysDepartment.setOrgId(sysOrganization.getId()); |
| | | boolean v = sysDepartmentService.saveOrUpdate(sysDepartment); |
| | | if (v) { |
| | | return ResultBody.ok().data(sysDepartment).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | | } |
| | | } |
| | |
| | | @ApiOperation(value = "删除") |
| | | @DeleteMapping("/{id}") |
| | | public ResultBody delete(@PathVariable Long id) { |
| | | boolean v= sysDepartmentService.removeById(id); |
| | | if(v) { |
| | | boolean v = sysDepartmentService.removeById(id); |
| | | if (v) { |
| | | return ResultBody.ok().msg("删除成功"); |
| | | } |
| | | else { |
| | | } else { |
| | | return ResultBody.failed().msg("删除失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据医院获取 组织,通过组织,获取科室; |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @GetMapping("findListByHospitalId") |
| | | public ResultBody findListByHospitalId(@RequestParam Map<String, Object> params) { |
| | | return sysDepartmentService.findListByHospitalId(params); |
| | | } |
| | | @PostMapping |
| | | public ResultBody update(@RequestBody SysDepartment sysDepartment){ |
| | | if(sysDepartment.getId()==null){ |
| | | return ResultBody.failed("请输入id"); |
| | | } |
| | | QueryWrapper queryWrapper =new QueryWrapper(); |
| | | queryWrapper.eq("id",sysDepartment.getId()); |
| | | boolean update = sysDepartmentService.update(sysDepartment, queryWrapper); |
| | | if(update){ |
| | | return ResultBody.ok(); |
| | | }else { |
| | | return ResultBody.failed("更新数据失败"); |
| | | } |
| | | } |
| | | /** |
| | | *运动处方调用 是否开通服务 |
| | | */ |
| | | |
| | | @PostMapping("getHealth") |
| | | public ResultBody getHealth(@RequestBody SysDepartment sysDepartment){ |
| | | if(sysDepartment.getId()==null){ |
| | | return ResultBody.failed("请输入id"); |
| | | } |
| | | return sysDepartmentService.getHealth(sysDepartment); |
| | | } |
| | | |
| | | } |