package thyyxxk.webserver.controller.lc.project;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.lc.company.LcCompany;
import thyyxxk.webserver.entity.lc.company.LcCompanyParam;
import thyyxxk.webserver.entity.lc.project.LcProjectAlias;
import thyyxxk.webserver.entity.lc.project.LcProjectType;
import thyyxxk.webserver.service.lc.project.LcProjectAliasService;
import thyyxxk.webserver.service.lc.project.LcProjectTypeService;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;

import java.util.List;


@RestController
@RequestMapping("/LcProjectAlias")
public class LcProjectAliasController {

    @Autowired
    private LcProjectAliasService lcProjectAliasService;

    /**
     * 通过id获取项目分类
     * @param id
     * @return
     */
    @PassToken
    @GetMapping("/getLcProjectAliasById")
    public ResultVo<LcProjectAlias> getLcProjectAliasById(@RequestParam("id") String id) {
        if (StringUtil.isBlank(id)) {
            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "id不能为空！");
        }
        return ResultVoUtil.success(lcProjectAliasService.getLcProjectAliasById(id));
    }

    /**
     * 查询项目别名列表
     * @param lcProjectAlias
     * @return
     */
    @PostMapping("/getLcProjectAliasList")
    public ResultVo<List<LcProjectAlias>> getLcProjectAliasList(@RequestBody LcProjectAlias lcProjectAlias) {
        return ResultVoUtil.success(lcProjectAliasService.getLcProjectAliasList(lcProjectAlias));
    }

    /**
     * 新增别名
     * @param lcProjectAlias
     * @return
     */
    @PostMapping("/insertLcProjectAlias")
    public ResultVo<String> insertLcProjectAlias(@RequestBody LcProjectAlias lcProjectAlias) {
        int i = lcProjectAliasService.insertLcProjectAlias(lcProjectAlias);
        if(i > 0) {
            return ResultVoUtil.success();
        } else {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "新增失败");
        }
    }
}
