package com.storlead.sales.controller.customer;

import com.storlead.framework.common.util.generate.CodeGenerate;
import com.storlead.framework.common.result.Result;
import com.storlead.sales.enums.ResourceTypeEnum;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-09-03 17:56
 */
@RestController
@RequestMapping("/common")
@Api(tags = "销售: 业务公共API")
public class CommonApiController {

    /**
     * 生成对应的业务编码
     */
    @RequestMapping("/generateBizCode")
    public Result<?> generateBizCode(String bizTypeCode) {
        ResourceTypeEnum resourceTypeEnum =  ResourceTypeEnum.getTypeEnumByCode(bizTypeCode);
        if (Objects.isNull(resourceTypeEnum)) {
            return Result.error("参数错误,未获取到code");
        }
        String code = CodeGenerate.generate12Code(resourceTypeEnum.codePrefix);
        return Result.result(code);
    }
}
