package pvc

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/astaxie/beego"
	"k8s-console/dto"
	"k8s-console/dto/pvc"
	"k8s-console/utils"
	"k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/kubernetes/scheme"
	"sigs.k8s.io/yaml"
	"strings"
)

var (
	infoLogger  = utils.InfoLogger
	errorLogger = utils.ErrorLogger
)

// PersistentVolumeClaimsController operations for harborImage
type PersistentVolumeClaimsController struct {
	beego.Controller
}

// URLMapping ...
func (c *PersistentVolumeClaimsController) URLMapping() {
	c.Mapping("getPvcList", c.GetPvcList)
	c.Mapping("createPvc", c.CreatePvc)
	c.Mapping("removePvc", c.RemovePvc)
}

// Post ...
// @Title GetPvcList
// @Description get PvcList
// @Param	lang		query 	string	true	"api result language type"
// @Param	body		body 	pvc.GetPvcListRequestDto	true	""
// @Success 200
// @Failure 300 {object} dto.BaseResponseDto
// @router /getPvcList [post]
func (c *PersistentVolumeClaimsController) GetPvcList() {
	lang := c.GetString("lang")
	infoLogger.Println("语言: ", lang)
	var requestDto pvc.GetPvcListRequestDto
	var errorResponseDto = dto.BaseResponseDto{300, utils.GetI18nLang(lang, "sysError")}
	var successResponseDto = dto.GetPageListBaseResponseDto{}
	successResponseDto.Status = 200
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &requestDto); err != nil {
		errorLogger.Println(err.Error())
		errorResponseDto.Message = utils.GetI18nLang(lang, "requestParamIncorrectFormat")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}
	infoLogger.Println("存储卷声明列表查询接口请求参数: ", requestDto)

	pageIndex := requestDto.PageIndex
	pageSize := requestDto.PageSize
	if pageIndex < 0 {
		errorResponseDto.Message = utils.GetI18nLang(lang, "pageIndexRange")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}
	if pageSize <= 0 {
		errorResponseDto.Message = utils.GetI18nLang(lang, "pageSizeRange")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}
	nameSpace := requestDto.NameSpace

	// 获取k8s客户端
	k8sClient := utils.GetK8sClient()
	if k8sClient == nil {
		errorResponseDto.Message = utils.GetI18nLang(lang, "createK8sConFail")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}
	//查询集群所有命名空间信息
	nameSpaceList, err := k8sClient.CoreV1().Namespaces().List(metav1.ListOptions{})
	if err != nil {
		errorLogger.Printf("查询集群所有命名空间失败: %s", err.Error())
		errorResponseDto.Message = utils.GetI18nLang(lang, "getClusterAllNamespacesFail")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}
	allNameSpaceList := []string{}
	for _, item := range nameSpaceList.Items {
		infoLogger.Println(item.Name)
		allNameSpaceList = append(allNameSpaceList, item.Name)
	}

	if len(allNameSpaceList) > 0 && !utils.IsContains(allNameSpaceList, nameSpace) {
		errorLogger.Println("集群不存在此命名空间")
		errorResponseDto.Message = utils.GetI18nLang(lang, "theNameSpaceNotExistInCluster")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}

	//查询命名空间下所有pvc信息
	pvcList, err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).List(metav1.ListOptions{})
	if err != nil {
		errorLogger.Printf("查询集群%s空间所有pvc失败: %s", nameSpace, err.Error())
		errorResponseDto.Message = utils.GetI18nLang(lang, "getPvcListByNameSpaceFail")
		c.Data["json"] = errorResponseDto
		c.ServeJSON()
		return
	}

	itemList := pvcList.Items

	totalRecords := len(itemList)
	totalPages := 0

	result := []pvc.GetPvcListResultDataResponseDto{}
	for _, item := range pvcList.Items {
		creationTimestamp, err := utils.ParseDateToString(lang, item.CreationTimestamp.Time)
		if err != nil {
			errorLogger.Printf("时间格式转换失败: %s", err.Error())
		}

		accessModes := []string{}
		for _, v := range item.Status.AccessModes {
			accessModes = append(accessModes, string(v))
		}

		volumeName := item.Spec.VolumeName
		if len([]rune(volumeName)) == 0 { // 没有存储卷就显示为<none>
			volumeName = "<none>"
		}

		storageClassName := "<none>"
		// 存储类先取item.Spec.StorageClassName的值
		if item.Spec.StorageClassName != nil { // 没有存储类就显示为<none>
			storageClassName = *item.Spec.StorageClassName
		}
		// item.Spec.StorageClassName如果为nil，就再取item.ObjectMeta.Annotations中key为volume.beta.kubernetes.io/storage-class的值
		storageClassKey := "volume.beta.kubernetes.io/storage-class"
		annotationsMap := item.ObjectMeta.Annotations
		if storageClass, ok := annotationsMap[storageClassKey]; ok {
			storageClassName = storageClass
		}

		capacityMap := item.Status.Capacity
		capacityStorage := ""
		if v, ok := capacityMap["storage"]; ok {
			capacityStorage = v.String()
		}
		pvcDto := pvc.GetPvcListResultDataResponseDto{
			PvcName:      item.Name,
			Status:       string(item.Status.Phase),
			Volume:       volumeName,
			Capacity:     capacityStorage,
			AccessModes:  accessModes,
			StorageClass: storageClassName,
			CreatedTime:  creationTimestamp,
		}
		infoLogger.Println(pvcDto)
		result = append(result, pvcDto)
	}

	resultList := []pvc.GetPvcListResultDataResponseDto{}
	if totalRecords > 0 {
		totalPages = totalRecords/pageSize + 1
		if totalRecords%pageSize == 0 {
			totalPages = totalRecords / pageSize
		}
		if totalRecords <= pageIndex*pageSize {
			errorResponseDto.Message = utils.GetI18nLang(lang, "pageIndexOutRange")
			c.Data["json"] = errorResponseDto
			c.ServeJSON()
			return
		}
		resultList = result[pageIndex*pageSize:]
		if len(result)-pageIndex*pageSize >= pageSize {
			resultList = result[pageIndex*pageSize : (pageIndex+1)*pageSize]
		}
	} else {
		if totalRecords < pageIndex*pageSize {
			errorResponseDto.Message = utils.GetI18nLang(lang, "pageIndexOutRange")
			c.Data["json"] = errorResponseDto
			c.ServeJSON()
			return
		}
	}

	successResponseDto.Result = resultList
	successResponseDto.PageInfo = dto.PageInfoBaseResponseDto{
		TotalRecords: totalRecords,
		TotalPages:   totalPages,
	}
	c.Data["json"] = successResponseDto
	c.ServeJSON()
}

// Post ...
// @Title CreatePvc
// @Description create pvc
// @Param	lang		query 	string	true	"api result language type"
// @Param	body		body 	pvc.PvcCreateRequestDto	true	""
// @Success 200 {object} dto.BaseResponseDto
// @Failure 300 {object} dto.BaseResponseDto
// @router /createPvc [post]
func (c *PersistentVolumeClaimsController) CreatePvc() {
	lang := c.GetString("lang")
	infoLogger.Println("语言: ", lang)
	var requestDto pvc.PvcCreateRequestDto
	var responseDto = dto.BaseResponseDto{300, utils.GetI18nLang(lang, "sysError")}
	infoLogger.Println("存储卷声明新建接口转换前的请求参数: ", string(c.Ctx.Input.RequestBody))
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &requestDto); err != nil {
		errorLogger.Println(err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "requestParamIncorrectFormat")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}
	infoLogger.Println("存储卷声明新建接口转换后的请求参数: ", requestDto)

	nameSpace := requestDto.NameSpace
	pvcOptions := v1.PersistentVolumeClaim{}
	// 复制字段
	utils.StructCopy(&pvcOptions, &requestDto)

	pvcName := pvcOptions.ObjectMeta.Name

	// 获取k8s客户端
	k8sClient := utils.GetK8sClient()
	if k8sClient == nil {
		responseDto.Message = utils.GetI18nLang(lang, "createK8sConFail")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	// 校验请求参数
	if err := createPvcValid(lang, nameSpace, pvcOptions, k8sClient); err != nil {
		errorLogger.Printf("存储卷声明新建校验失败: %s", err.Error())
		responseDto.Message = err.Error()
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	//查询pvc是否存在
	if _, err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).Get(pvcName, metav1.GetOptions{}); err != nil {
		errStr := err.Error()
		errorLogger.Printf("查询获取集群%s空间%s的pvc详情失败: %s", nameSpace, pvcName, errStr)
		if !strings.Contains(errStr, "not found") {
			responseDto.Message = utils.GetI18nLang(lang, "getThePvcInfoFail")
			c.Data["json"] = responseDto
			c.ServeJSON()
			return
		}

		//不存在则创建pvc
		_, err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).Create(&pvcOptions)
		if err != nil {
			errorLogger.Printf("创建集群%s空间%s的pvc失败: %s", nameSpace, pvcName, err.Error())
			responseDto.Message = strings.Join([]string{utils.GetI18nLang(lang, "createPvcFail"), err.Error()}, ": ")
			c.Data["json"] = responseDto
			c.ServeJSON()
			return
		}
		infoLogger.Printf("创建集群%s空间%s的pvc成功", nameSpace, pvcName)

	} else {
		//存在则提示
		errorLogger.Printf("%s空间名为%s的pvc已存在，无法创建", nameSpace, pvcName)
		responseDto.Message = strings.Join([]string{utils.GetI18nLang(lang, "createPvcFail"), err.Error()}, ": ")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	responseDto.Status = 200
	responseDto.Message = utils.GetI18nLang(lang, "success")
	c.Data["json"] = responseDto
	c.ServeJSON()

}

// Post ...
// @Title RemovePvc
// @Description remove pvc
// @Param	lang		query 	string	true	"api result language type"
// @Param	body		body 	pvc.PvcRemoveRequestDto	 true	""
// @Success 200 {object} dto.BaseResponseDto
// @Failure 300 {object} dto.BaseResponseDto
// @router /removePvc [post]
func (c *PersistentVolumeClaimsController) RemovePvc() {
	lang := c.GetString("lang")
	infoLogger.Println("语言: ", lang)
	var requestDto pvc.PvcRemoveRequestDto
	var responseDto = dto.BaseResponseDto{300, utils.GetI18nLang(lang, "sysError")}
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &requestDto); err != nil {
		errorLogger.Println(err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "requestParamIncorrectFormat")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}
	infoLogger.Println("删除存储卷声明接口请求参数: ", requestDto)

	nameSpace := requestDto.NameSpace
	pvcName := requestDto.PvcName
	if strings.TrimSpace(nameSpace) == "" {
		errorLogger.Println("命名空间不能为空")
		responseDto.Message = utils.GetI18nLang(lang, "requestParamIncorrectFormat")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}
	if strings.TrimSpace(pvcName) == "" {
		errorLogger.Println("pvc名称不能为空")
		responseDto.Message = utils.GetI18nLang(lang, "requestParamIncorrectFormat")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}
	//查询集群所有命名空间信息
	allNameSpaceList, err := utils.GetClusterAllNameSpaces(lang)
	infoLogger.Println(allNameSpaceList)
	if err != nil {
		errorLogger.Printf("查询集群所有命名空间失败: %s", err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "getClusterAllNamespacesFail")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}
	if len(allNameSpaceList) > 0 && !utils.IsContains(allNameSpaceList, nameSpace) {
		errorLogger.Println("集群不存在此命名空间")
		responseDto.Message = utils.GetI18nLang(lang, "theNameSpaceNotExistInCluster")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	// 获取k8s客户端
	k8sClient := utils.GetK8sClient()
	if k8sClient == nil {
		responseDto.Message = utils.GetI18nLang(lang, "createK8sConFail")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	//查询pvc是否存在
	pvc, err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).Get(pvcName, metav1.GetOptions{})
	if err != nil {
		errorLogger.Printf("查询获取集群%s空间%s的pvc详情失败: %s", nameSpace, pvcName, err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "getThePvcInfoFail")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	//查询命名空间下所有pod信息
	podList, err := k8sClient.CoreV1().Pods(nameSpace).List(metav1.ListOptions{})
	if err != nil {
		errorLogger.Printf("查询集群%s空间所有pod失败: %s", nameSpace, err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "getPodList_getTheNameSpacePodsFail")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	// 循环当前命名空间下所有pod中是否有挂载了该pvc的
	podHasPvc := false
	for _, item := range podList.Items {
		for _, volume := range item.Spec.Volumes {
			if !utils.IsNil(volume.PersistentVolumeClaim) {
				claimName := volume.PersistentVolumeClaim.ClaimName
				if claimName == pvcName {
					infoLogger.Printf("集群%s空间中%s的pod绑定了对应的pvc: %s", nameSpace, item.Name, claimName)
					podHasPvc = true
					break
				}
			}
		}
	}

	// 校验状态为Bound，并且绑定了对应的PV时不允许删除
	pvcStatus := string(pvc.Status.Phase)
	pvcVolumeName := pvc.Spec.VolumeName
	if pvcStatus == "Bound" && len([]rune(pvcVolumeName)) != 0 && podHasPvc {
		infoLogger.Printf("集群%s空间存储卷声明%s的状态为: %s，并且绑定了对应的pv: %s，不允许删除", nameSpace, pvcName, pvcStatus, pvcVolumeName)
		responseDto.Message = utils.GetI18nLang(lang, "removePvcFailByBoundStatus")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	if err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).Delete(pvcName, &metav1.DeleteOptions{}); err != nil {
		errorLogger.Printf("移除%s空间存储卷声明: %s失败，错误信息: %s", nameSpace, pvcName, err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "removePvcFail")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	responseDto.Status = 200
	responseDto.Message = utils.GetI18nLang(lang, "success")
	c.Data["json"] = responseDto
	c.ServeJSON()
}

func createPvcValid(lang string, nameSpace string, pvcOptions v1.PersistentVolumeClaim, k8sClient *kubernetes.Clientset) error {

	if strings.TrimSpace(nameSpace) == "" {
		errorLogger.Println("命名空间不能为空")
		return errors.New(utils.GetI18nLang(lang, "requestParamIncorrectFormat"))
	}
	//查询集群所有命名空间信息
	allNameSpaceList, err := utils.GetClusterAllNameSpaces(lang)
	infoLogger.Println(allNameSpaceList)
	if err != nil {
		errorLogger.Printf("查询集群所有命名空间失败: %s", err.Error())
		return errors.New(utils.GetI18nLang(lang, "getClusterAllNamespacesFail"))
	}
	if len(allNameSpaceList) > 0 && !utils.IsContains(allNameSpaceList, nameSpace) {
		errorLogger.Println("集群不存在此命名空间")
		return errors.New(utils.GetI18nLang(lang, "theNameSpaceNotExistInCluster"))
	}

	pvcNameSpace := pvcOptions.ObjectMeta.Namespace
	if pvcNameSpace != nameSpace {
		errorLogger.Println("命名空间必须与当前命名空间一致")
		return fmt.Errorf("%v", "命名空间必须与当前命名空间一致")
	}

	if strings.TrimSpace(pvcOptions.TypeMeta.APIVersion) != "v1" {
		errorLogger.Println("ApiVersion值有误")
		return fmt.Errorf("%v", "ApiVersion值有误")
	}

	if strings.TrimSpace(pvcOptions.TypeMeta.Kind) == "" || strings.TrimSpace(pvcOptions.TypeMeta.Kind) != "PersistentVolumeClaim" {
		errorLogger.Println("Kind值有误")
		return fmt.Errorf("%v", "Kind值有误")
	}

	// 转换yaml格式
	yamlBytes, err := yaml.Marshal(pvcOptions)
	if err != nil {
		errorLogger.Printf("转换yaml失败: %s", err.Error())
		return errors.New(utils.GetI18nLang(lang, "invalidPvcFormat"))
	}
	infoLogger.Println("\n" + string(yamlBytes))

	decode := scheme.Codecs.UniversalDeserializer()
	_, _, err = decode.Decode(yamlBytes, nil, nil)
	if err != nil {
		errorLogger.Printf("转换yaml文件失败: %s", err.Error())
		return errors.New(utils.GetI18nLang(lang, "invalidPvcFormat"))
	}

	// 存储资源的可用存储卷声明数量校验
	var allPVCNumber, availablePVCNumber int32
	pvcList, err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).List(metav1.ListOptions{})
	if err != nil {
		errorLogger.Printf("查询集群%s空间所有pvc失败: %s", nameSpace, err.Error())
		return errors.New(utils.GetI18nLang(lang, "getPvcListByNameSpaceFail"))
	}
	allPVCNumber = int32(len(pvcList.Items) + 1)
	if resourceQuotaResourceLimitData, err := utils.GetResourceQuotaResourceLimitData(nameSpace, lang); err == nil {
		availablePVCNumber = int32(resourceQuotaResourceLimitData.PVCNumber)
	}
	// default、paas空间不需要校验，availablePVCNumber数量为0，所以需要加上availablePVCNumber大于0的判断
	if availablePVCNumber > 0 && availablePVCNumber < allPVCNumber {
		errorLogger.Printf("%s空间存储资源的可用存储卷声明数量%s小于即将新增后的存储卷声明数量%s，无法新增创建存储卷声明", nameSpace, availablePVCNumber, allPVCNumber)
		return errors.New(utils.GetI18nLang(lang, "outOfPvcRange"))
	}

	return nil
}

func checkPvcContent(lang string, nameSpace string, pvcOptions v1.PersistentVolumeClaim) error {
	pvcName := pvcOptions.ObjectMeta.Name
	if strings.TrimSpace(pvcName) == "" {
		return fmt.Errorf("%v", "存储卷声明名称不能为空")
	}

	if strings.TrimSpace(nameSpace) == "" {
		return fmt.Errorf("%v", "命名空间不能为空")
	}
	//查询集群所有命名空间信息
	allNameSpaceList, err := utils.GetClusterAllNameSpaces(lang)
	infoLogger.Println(allNameSpaceList)
	if err != nil {
		errorLogger.Printf("查询集群所有命名空间失败: %s", err.Error())
		return errors.New(utils.GetI18nLang(lang, "getClusterAllNamespacesFail"))
	}
	if len(allNameSpaceList) > 0 && !utils.IsContains(allNameSpaceList, nameSpace) {
		errorLogger.Println("集群不存在此命名空间")
		return errors.New(utils.GetI18nLang(lang, "theNameSpaceNotExistInCluster"))
	}

	pvcNameSpace := pvcOptions.ObjectMeta.Namespace
	if pvcNameSpace != nameSpace {
		errorLogger.Println("命名空间必须与当前命名空间一致")
		return fmt.Errorf("%v", "命名空间必须与当前命名空间一致")
	}

	if strings.TrimSpace(pvcOptions.TypeMeta.APIVersion) != "v1" {
		errorLogger.Println("ApiVersion值有误")
		return fmt.Errorf("%v", "ApiVersion值有误")
	}

	if strings.TrimSpace(pvcOptions.TypeMeta.Kind) == "" || strings.TrimSpace(pvcOptions.TypeMeta.Kind) != "PersistentVolumeClaim" {
		errorLogger.Println("Kind值有误")
		return fmt.Errorf("%v", "Kind值有误")
	}

	// 转换yaml格式
	yamlBytes, err := yaml.Marshal(pvcOptions)
	if err != nil {
		errorLogger.Printf("转换yaml失败: %s", err.Error())
		return errors.New(utils.GetI18nLang(lang, "invalidPvcFormat"))
	}
	infoLogger.Println("\n" + string(yamlBytes))

	decode := scheme.Codecs.UniversalDeserializer()
	_, _, err = decode.Decode(yamlBytes, nil, nil)
	if err != nil {
		errorLogger.Printf("转换yaml文件失败: %s", err.Error())
		return errors.New(utils.GetI18nLang(lang, "invalidPvcFormat"))
	}

	// 获取k8s客户端
	k8sClient := utils.GetK8sClient()
	if k8sClient == nil {
		return errors.New(utils.GetI18nLang(lang, "createK8sConFail"))
	}

	// 存储资源的可用存储卷声明数量校验
	var allPVCNumber, availablePVCNumber int32
	pvcList, err := k8sClient.CoreV1().PersistentVolumeClaims(nameSpace).List(metav1.ListOptions{})
	if err != nil {
		errorLogger.Printf("查询集群%s空间所有pvc失败: %s", nameSpace, err.Error())
		return errors.New(utils.GetI18nLang(lang, "getPvcListByNameSpaceFail"))
	}
	allPVCNumber = int32(len(pvcList.Items) + 1)
	if resourceQuotaResourceLimitData, err := utils.GetResourceQuotaResourceLimitData(nameSpace, lang); err == nil {
		availablePVCNumber = int32(resourceQuotaResourceLimitData.PVCNumber)
	}
	// default、paas空间不需要校验，availablePVCNumber数量为0，所以需要加上availablePVCNumber大于0的判断
	if availablePVCNumber > 0 && availablePVCNumber < allPVCNumber {
		errorLogger.Printf("%s空间存储资源的可用存储卷声明数量%s小于即将新增后的存储卷声明数量%s，无法新增创建存储卷声明", nameSpace, availablePVCNumber, allPVCNumber)
		return errors.New(utils.GetI18nLang(lang, "outOfPvcRange"))
	}

	err = k8sClient.CoreV1().RESTClient().Post().
		SetHeader("Accept", "application/json; dry-run").
		SetHeader("Content-Type", "application/json; verify").
		Namespace(nameSpace).
		Resource("persistentvolumeclaims").
		Body(&pvcOptions).
		Param("dryRun", "All").
		Do().Error()

	if err != nil {
		errorLogger.Printf("存储卷声明校验运行失败: %s", err.Error())
		return fmt.Errorf("%v: %v", utils.GetI18nLang(lang, "checkPvcFailed"), err.Error())
	}

	return nil
}

// Post ...
// @Title CheckPvcContent
// @Description check pvc content
// @Param	lang		query 	string	true	"api result language type"
// @Param	body		body 	pvc.PvcCreateRequestDto	true	""
// @Success 200 {object} dto.BaseResponseDto
// @Failure 300 {object} dto.BaseResponseDto
// @router /checkPvcContent [post]
func (c *PersistentVolumeClaimsController) CheckPvcContent() {
	lang := c.GetString("lang")
	infoLogger.Println("语言: ", lang)
	var requestDto pvc.PvcCreateRequestDto
	var responseDto = dto.BaseResponseDto{300, utils.GetI18nLang(lang, "sysError")}
	infoLogger.Println("存储卷声明校验接口转换前的请求参数: ", string(c.Ctx.Input.RequestBody))
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &requestDto); err != nil {
		errorLogger.Println(err.Error())
		responseDto.Message = utils.GetI18nLang(lang, "requestParamIncorrectFormat")
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}
	infoLogger.Println("存储卷声明校验接口转换后的请求参数: ", requestDto)

	nameSpace := requestDto.NameSpace
	pvcOptions := v1.PersistentVolumeClaim{}
	// 复制字段
	utils.StructCopy(&pvcOptions, &requestDto)

	// 校验请求参数
	if err := checkPvcContent(lang, nameSpace, pvcOptions); err != nil {
		errorLogger.Printf("存储卷声明校验失败: %s", err.Error())
		responseDto.Message = err.Error()
		c.Data["json"] = responseDto
		c.ServeJSON()
		return
	}

	responseDto.Status = 200
	responseDto.Message = utils.GetI18nLang(lang, "success")
	c.Data["json"] = responseDto
	c.ServeJSON()

}
