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

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.nutrition.common.dto.HealthInfoFullDto;
import com.bonus.canteen.core.nutrition.common.service.HealthInfoService;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.i18n.I18n;
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 = {"mobile-健康档案"}
)
@RequestMapping({"/health/mobile/info"})
public class HealthMobileInfoController {
   private static final Logger log = LoggerFactory.getLogger(HealthMobileInfoController.class);
   @Resource
   private HealthInfoService healthInfoService;

   @ApiOperation("获取人员档案详情")
   @PostMapping({"/detail-health-info"})
   public AjaxResult detailHealthInfo(@RequestBody HealthInfoFullDto dto) {
      if (ObjectUtil.isNull(dto.getCustId())) {
         throw new ServiceException(I18n.getMessage("nutrition.healthInfo.custId.nonNull", new Object[0]));
      } else {
         return success(this.healthInfoService.detailHealthInfo(dto.getCustId()));
      }
   }

   @ApiOperation("编辑人员健康档案")
   @PostMapping({"/edit-health-info"})
   public void editHealthInfo(@RequestBody HealthInfoFullDto healthInfoFullDto) {
      if (ObjectUtil.isNull(healthInfoFullDto.getCustId())) {
         throw new ServiceException(I18n.getMessage("nutrition.healthInfo.custId.nonNull", new Object[0]));
      } else {
         this.healthInfoService.editHealthInfo(healthInfoFullDto);
      }
   }
}
