ClientCustomerController.java 3.58 KB
package com.infoloop.tianting.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.stp.SaTokenInfo;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.ClientCustomerDto;
import com.infoloop.tianting.model.dto.ClientCustomerDbDTO.HospitalRecordDto;
import com.infoloop.tianting.model.dto.PermissionDTO.LoginDto;
import com.infoloop.tianting.model.dto.WxUserDto.WxUserOpenIdDto;
import com.infoloop.tianting.model.dto.WxUserDto.WxUserPhoneResponseDto;
import com.infoloop.tianting.service.ClientCustomerService;
import com.infoloop.tianting.service.LoginService;
import com.infoloop.tianting.service.WxMiniProgramService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "ClientCustomer")
@ApiSupport(order = -1)
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ClientCustomerController {
  private final ClientCustomerService clientCustomerService;
  private final WxMiniProgramService wxMiniProgramService;
  private final LoginService loginService;

  @ApiOperation(value = "根据hisCustomerId获取ClientCustomer")
  @GetMapping("/customers/his/{hisCustomerId}")
  @ResponseStatus(HttpStatus.OK)
  public ClientCustomerDto getClientCustomerByHISCustomerId(@PathVariable String hisCustomerId) {
    return  clientCustomerService.getClientCustomerByHISCustomerId(hisCustomerId);
  }

  @ApiOperation(value = "根据phone获取ClientCustomer")
  @GetMapping("/customers/phone/{phone}")
  @ResponseStatus(HttpStatus.OK)
  public ClientCustomerDto getClientCustomerByPhone(@PathVariable String phone) {
    return  clientCustomerService.getClientCustomerByPhone(phone);
  }

  @ApiOperation(value = "根据customerId获取住院记录")
  @GetMapping("/enterprise/{enterpriseId}/hospitalRecords/customers/{customerId}")
  @ResponseStatus(HttpStatus.OK)
  public List<HospitalRecordDto> getHospitalRecords(@PathVariable Integer enterpriseId,
      @PathVariable Integer customerId) {
    return  clientCustomerService.getClientCustomerHospitalRecordsByCustomerId(
        enterpriseId, customerId);
  }

  @ApiOperation(value = "小程序:根据code获取openId")
  @GetMapping("/wx/miniprogram/customers/openid/{code}")
  @ResponseStatus(HttpStatus.OK)
  public WxUserOpenIdDto getOpenIdByCode(@PathVariable String code) {
    return  wxMiniProgramService.getWxUserOpenIdByCode(code);
  }

  @ApiOperation(value = "小程序:根据code获取手机号")
  @GetMapping("/wx/miniprogram/customers/phone/{code}")
  @ResponseStatus(HttpStatus.OK)
  public WxUserPhoneResponseDto getPhoneByCode(@PathVariable String code) {
    return  wxMiniProgramService.getUserPhoneInfoByCode(code);
  }

  @SaIgnore
  @ApiOperation(value = "登陆")
  @PostMapping("/login")
  @ResponseStatus(HttpStatus.OK)
  public SaTokenInfo login(@Valid@RequestBody LoginDto loginDto) {
    return loginService.login(loginDto);
  }

}