package com.bonus.canteen.core.nutrition.controller;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.nutrition.common.dto.HealthInfoFullDto;
import com.bonus.canteen.core.nutrition.service.HealthInfoService;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static com.bonus.common.core.web.domain.AjaxResult.success;

@RestController
@Api(
   tags = {"健康档案"}
)
@RequestMapping({"/health/info"})
public class HealthInfoController {
   private static final Logger log = LoggerFactory.getLogger(HealthInfoController.class);
   @Resource
   private HealthInfoService healthInfoService;

   @ApiOperation("获取人员档案详情")
   @PostMapping({"/detail-health-info"})
   public AjaxResult detailHealthInfo(@RequestBody HealthInfoFullDto dto) {
      if (ObjectUtil.isNull(dto.getUserId())) {
         throw new ServiceException("用户id不能为空");
      } else {
         return success(this.healthInfoService.detailHealthInfo(dto.getUserId()));
      }
   }

   @ApiOperation("编辑人员健康档案")
   @PostMapping({"/edit-health-info"})
   public AjaxResult editHealthInfo(@RequestBody HealthInfoFullDto healthInfoFullDto) {
      if (ObjectUtil.isNull(healthInfoFullDto.getUserId())) {
         throw new ServiceException("用户id不能为空");
      } else {
         return success(this.healthInfoService.editHealthInfo(healthInfoFullDto));
      }
   }
}
