package com.hotent.portal.controller.openController;

import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.annotation.OpenApi;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.model.CommonResult;
import com.hotent.sys.persistence.manager.SysIdentityManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/** <pre>
* 描述：流水号 控制器类
* @author dengyg
* @company 广州宏天软件股份有限公司
* @email dengyg@jee-soft.cn
* @date 2018-06-06 14:20
* </pre>
*/
@RestController
@RequestMapping("/${openApi.prefix}/sys/identity/v1/")
@Api(tags="流水号（对外接口）")
@ApiGroup(group= {ApiGroupConsts.GROUP_PORTAL})
@OpenApi(moduleName = "portal模块",function = "流水号")
public class SysIdentityOpenController {

    @Resource
    SysIdentityManager identityManager;

    @RequestMapping(value="getNextIdByAlias",method= RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    @ApiOperation(value = "获取下一个流水号", httpMethod = "GET", notes = "获取下一个流水号")
    @OpenApi(description = "获取下一个流水号")
    public CommonResult<String> getNextIdByAlias(@ApiParam(name="alias",value="流水号别名", required = true) @RequestParam String alias) throws Exception{
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("id", null);
        params.put("alias", alias);
        if(identityManager.isAliasExisted(params)){
            String nextId = identityManager.nextId(alias);
            return new CommonResult<String>(true, "获取流水号成功！", nextId);
        }
        return new CommonResult<String>(false, "获取流水号失败！");
    }
}