package com.xinelu.applet.controller.nurseappletpersoncenter;


import com.xinelu.applet.service.nurseappletpersoncenter.NurseAppletPersonCenterService;
import com.xinelu.common.annotation.MobileRequestAuthorization;
import com.xinelu.common.annotation.RepeatSubmit;
import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.manage.domain.nursestationperson.NurseStationPerson;
import com.xinelu.manage.dto.nursestationperson.NurseStationPersonCheckDTO;
import com.xinelu.manage.vo.nursestationpersonrevenue.RevenueTimeDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 护理员个人中心
 *
 * @author ljh
 * @version 1.0
 * Create by 2023/3/30 17:03
 */
@RestController
@RequestMapping("/nurseApplet/personCenter")
public class NurseAppletPersonCenterController extends BaseController {

    @Resource
    private NurseAppletPersonCenterService nurseAppletPersonCenterService;

    /**
     * 个人信息查询护理站人员的个人信息
     *
     * @param nursePersonId 个人信息
     * @return com.xinyilu.nurseapplet.domain.vo.nursepersonapplogin.NursePersonAppLoginsUserVO
     **/
    @MobileRequestAuthorization
    @GetMapping("/nurseAppletPersonCenter")
    public AjaxResult nurseAppletPersonCenter(Long nursePersonId) {
        if (Objects.isNull(nursePersonId)) {
            return AjaxResult.error("护理人员id不能为空！");
        }
        return AjaxResult.success(nurseAppletPersonCenterService.nurseAppletPersonCenter(nursePersonId));
    }

    /**
     * 个人中心-我的收益功能
     */
    @MobileRequestAuthorization
    @GetMapping("/personRevenue")
    public AjaxResult selectPersonRevenue(RevenueTimeDTO revenueTime) {
        if (Objects.isNull(revenueTime) || Objects.isNull(revenueTime.getNurseStationPersonId())) {
            return AjaxResult.error("护理员信息不能为空！");
        }
        return AjaxResult.success(nurseAppletPersonCenterService.selectPersonRevenue(revenueTime));
    }

    /**
     * 个人中心-我的收益功能明细
     *
     * @param revenueTime 用户信息及时间
     * @return AjaxResult
     */
    @GetMapping("/personRevenueDetails")
    public TableDataInfo selectPersonRevenueDetails(RevenueTimeDTO revenueTime) {
        return nurseAppletPersonCenterService.selectPersonRevenueDetails(revenueTime);
    }


    /**
     * 护理员App和小程序修改护理员信息以及上传证书
     *
     * @param nurseStationPersonCheckDTO 护理人员主表信息与证书信息
     * @return 上传结果
     */
    @RepeatSubmit
    @MobileRequestAuthorization
    @PostMapping("/updateNursePersonCheck")
    public AjaxResult updateNursePersonCheck(@RequestBody NurseStationPersonCheckDTO nurseStationPersonCheckDTO) {
        if (Objects.isNull(nurseStationPersonCheckDTO)) {
            return AjaxResult.error("信息不能为空！");
        }
        if (Objects.isNull(nurseStationPersonCheckDTO.getId())) {
            return AjaxResult.error("护理人员id信息不能为空！");
        }
        return nurseAppletPersonCenterService.updateNursePersonCheck(nurseStationPersonCheckDTO);
    }

    /**
     * 护理员App和小程序护理员修改状态
     *
     * @param nurseStationPerson 护理人员主表信息修改状态
     * @return 上传结果
     */
    @MobileRequestAuthorization
    @PostMapping("/updateNursePersonWorkStatus")
    public AjaxResult updateNursePersonWorkStatus(@RequestBody NurseStationPerson nurseStationPerson) {
        if (Objects.isNull(nurseStationPerson)) {
            return AjaxResult.error("护理员信息不存在，无法修改，请联系管理员！");
        }
        if (Objects.isNull(nurseStationPerson.getId())) {
            return AjaxResult.error("护理员信息不存在，无法修改，请联系管理员！");
        }
        if (Objects.isNull(nurseStationPerson.getWorkStatus())) {
            return AjaxResult.error("护理员状态信息不能为空！");
        }
        return nurseAppletPersonCenterService.updateNursePersonWorkStatus(nurseStationPerson);
    }

    /**
     * 护理员App和小程序护理员上传证书
     *
     * @param file          图片文件
     * @param nursePersonId 护理员id
     * @return 上传结果
     */
    @PostMapping("/uploadNurseStationPersonCertificateUrl")
    public AjaxResult uploadNurseStationPersonCertificateUrl(MultipartFile file, Long nursePersonId) throws Exception {
        if (Objects.isNull(nursePersonId)) {
            return AjaxResult.error("请选择要上传的人员id！");
        }
        if (Objects.isNull(file) || StringUtils.isBlank(file.getOriginalFilename())) {
            return AjaxResult.error("当前文件不存在，无法上传！");
        }
        if (file.getOriginalFilename().contains(Constants.EMPTY)) {
            return AjaxResult.error("当前文件名含有空格，请先去除空格在上传！");
        }
        return nurseAppletPersonCenterService.uploadNurseStationPersonCertificateUrl(file, nursePersonId);
    }
}
