package com.bcxin.ins.service.user.impl;

import com.bcxin.ins.dao.user.ClientCompanyDao;
import com.bcxin.ins.rest.UserSupportUtil;
import com.bcxin.ins.service.user.ClientCompanyService;
import com.bcxin.ins.entity.user.SysClientCompany;
import com.bcxin.ins.vo.ClientUserVo;
import com.bcxin.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service
public class ClientCompanyServiceImpl extends ServiceImpl<ClientCompanyDao,SysClientCompany> implements ClientCompanyService {


    @Override
    public boolean saveCompany(SysClientCompany company, ClientUserVo vo) {
        SysClientCompany companyVo= this.selectById(vo.getCid());
        //完善资料
        companyVo.setIs_certification(company.getIs_certification());
        companyVo.setLink_name(company.getLink_name());
        companyVo.setLink_duty(company.getLink_duty());
        companyVo.setLink_phone(company.getLink_phone());
        companyVo.setLink_email(company.getLink_email());
        companyVo.setLink_card_type(company.getLink_card_type());
        companyVo.setLink_card(company.getLink_card());
        companyVo.setLegal_authorization_img(company.getLegal_authorization_img());
        companyVo.setOrganization_code_img(company.getOrganization_code_img());
        companyVo.setBusiness_address_img(company.getBusiness_address_img());
        companyVo.setTax_registration_img(company.getTax_registration_img());
        companyVo.setDistrict(company.getDistrict());
        companyVo.setCity(company.getCity());
        companyVo.setProvince(company.getProvince());
        companyVo.setEnterprise_type(company.getEnterprise_type());
        companyVo.setEnterprise_type_two(company.getEnterprise_type_two());
        companyVo.setRegistered_address(company.getRegistered_address());
        companyVo.setOrganization_code(company.getOrganization_code());
        companyVo.setOrganization_code_type(company.getOrganization_code_type());
        companyVo.setCompany_name(company.getCompany_name());
        this.updateById(companyVo);
        //更新UserVo
        vo=setUserVo(vo,companyVo);
        UserSupportUtil.setSessionUser(vo);
        Map<String,Object> map= UserSupportUtil.getCompany(companyVo);

        return true;
    }

    private ClientUserVo setUserVo(ClientUserVo vo, SysClientCompany company) {
        vo.setLink_name(company.getLink_name());
        vo.setLink_duty(company.getLink_duty());
        vo.setLink_phone(company.getLink_phone());
        vo.setLink_email(company.getLink_email());
        vo.setLink_card_type(company.getLink_card_type());
        vo.setLink_card(company.getLink_card());
        vo.setLegal_authorization_img(company.getLegal_authorization_img());
        vo.setOrganization_code_img(company.getOrganization_code_img());
        vo.setBusiness_address_img(company.getBusiness_address_img());
        vo.setTax_registration_img(company.getTax_registration_img());
        vo.setDistrict(company.getDistrict());
        vo.setCity(company.getCity());
        vo.setProvince(company.getProvince());
        vo.setEnterprise_type(company.getEnterprise_type());
        vo.setRegistered_address(company.getRegistered_address());
        vo.setOrganization_code(company.getOrganization_code());
        vo.setCompany_name(company.getCompany_name());
        vo.setOrganization_code_type(company.getOrganization_code_type());
        vo.setC_is_certification(company.getIs_certification());
        vo.setEnterprise_type_two(company.getEnterprise_type_two());
        return vo;
    }
}
