package org.jeecg.modules.api.carrentController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.CompanyBean;
import org.jeecg.modules.apiService.CompanyService;
import org.jeecg.modules.carrentCompany.entity.CarrentCompany;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags="企业信息相关接口")
@RestController
@RequestMapping("/api/company")
@Slf4j
public class CompanyController {

    //企业信息
    @Resource
    private CompanyService companyService;
    /****************************************************************************************************/

    @ApiOperation(value="企业信息-企业注册", notes="企业信息-企业注册")
    @RequestMapping(value = "/addCompany", method = {RequestMethod.POST})
    public Result<?> addCompany(@RequestHeader("X-Access-Token") String token, CompanyBean companyBean){

        //将注册信息注入实体bean中
        CarrentCompany carrentCompany = new CarrentCompany();
        carrentCompany.setUserName(companyBean.getUserName());
        carrentCompany.setCompanyName(companyBean.getCompanyName());
        carrentCompany.setAddress(companyBean.getAddress());
        carrentCompany.setPhone(companyBean.getPhone());
        carrentCompany.setBusinessLicense(companyBean.getBusinessLicense());

        String message = "";
        //注册信息验证
        if(StringUtils.isEmpty(carrentCompany.getCompanyName())){
            message = "公司名称未填写，请填写公司名称!";
        }else if(StringUtils.isEmpty(carrentCompany.getUserName())){
            message = "联系人未填写，请填写联系人!";
        }else if(StringUtils.isEmpty(carrentCompany.getPhone())){
            message = "联系电话未填写，请填写联系电话!";
        }else if(StringUtils.isEmpty(carrentCompany.getAddress())){
            message = "公司地址未填写，请填写公司地址!";
        }else if(StringUtils.isEmpty(carrentCompany.getBusinessLicense())){
            message = "营业执照未填写，请上传营业执照!";
        }else {
            //注册信息无误，进入业务流程处理
            return companyService.addCompany(token, carrentCompany);
        }

        //注册信息有误，返回错误信息
        return Result.error(message);
    }
}
