package cn.hnthyy.thmz.controller;

import cn.hnthyy.thmz.comment.UserLoginToken;
import cn.hnthyy.thmz.entity.his.MzyZdChargeType;
import cn.hnthyy.thmz.service.his.MzyZdChargeTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;

@Slf4j
@RestController
public class MzyZdChargeTypeController {
    @Autowired
    private MzyZdChargeTypeService mzyZdChargeTypeService;
    /**
     * 查询所有使用中的号别
     *
     * @return
     */
    @UserLoginToken
    @RequestMapping(value = "/getAllMzChargeType", method = {RequestMethod.GET})
    public Map<String, Object> getAllMzChargeType() {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            resultMap.put("code", 0);
            resultMap.put("message", "查询所有使用中的号别成功");
            resultMap.put("data", mzyZdChargeTypeService.queryAllMzyZdChargeType());
            return resultMap;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("查询所有使用中的号别失败，错误信息{}", e.getMessage());
            resultMap.put("code", -1);
            resultMap.put("message", "查询所有使用中的号别失败");
            return resultMap;
        }
    }


    /**
     * 根据号别编号查询号别
     *
     * @return
     */
    @UserLoginToken
    @RequestMapping(value = "/getMzChargeTypeByCode", method = {RequestMethod.GET})
    public Map<String, Object> getMzChargeTypeByCode(@RequestParam("code") String code) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            if (StringUtils.isBlank(code)) {
                resultMap.put("code", -1);
                resultMap.put("message", "号别编号不能为空");
                return resultMap;
            }
            MzyZdChargeType mzyZdChargeType=mzyZdChargeTypeService.queryByCode(code);
           if(mzyZdChargeType==null){
               resultMap.put("code", -1);
               resultMap.put("message", "根据号别编号查询号别失败,没有对应的号别信息");
               return resultMap;
           }
            resultMap.put("code", 0);
            resultMap.put("message", "根据号别编号查询号别成功");
            resultMap.put("data", mzyZdChargeType);
            return resultMap;
        } catch (Exception e) {
            e.printStackTrace();
            log.error("根据号别编号查询号别失败，错误信息{}", e.getMessage());
            resultMap.put("code", -1);
            resultMap.put("message", "根据号别编号查询号别失败");
            return resultMap;
        }
    }
}
