manager.supplier.service.SupplierFileService.java Source code

Java tutorial

Introduction

Here is the source code for manager.supplier.service.SupplierFileService.java

Source

package manager.supplier.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import manager.basicdata.area.model.Area;
import manager.basicdata.companyClass.model.CompanyClass;
import manager.basicdata.companyClass.service.CompanyClassService;
import manager.basicdata.currency.model.Currency;
import manager.basicdata.currency.service.CurrencyService;
import manager.basicdata.materialClass.model.MaterialClass;
import manager.basicdata.tradeClass.model.TradeClass;
import manager.basicdata.tradeClass.service.TradeClassService;
import common.model.TreeModel;
import common.user.data.RegAccoutCompanyInfoMapper;
import common.user.data.RegAccoutMapper;
import common.user.model.RegAccout;
import common.user.model.RegAccoutCompanyInfo;
import common.user.model.RegSalt;
import manager.supplier.data.BankAccountMapper;
import manager.supplier.data.CompetitorMapper;
import manager.supplier.data.DevicelistMapper;
import manager.supplier.data.GoodsMapper;
import manager.supplier.data.InvoiceTitleMapper;
import manager.supplier.data.MainCustomerMapper;
import manager.supplier.data.MetarialMapper;
import manager.supplier.data.SupplierFileMapper;
import manager.supplier.model.AuthUpdateAttched;
import manager.supplier.model.AuthcationUpdate;
import manager.supplier.model.BankAccount;
import manager.supplier.model.CompanyAuthAttachedHistory;
import manager.supplier.model.CompanyAuthcationHistory;
import manager.supplier.model.Competitor;
import manager.supplier.model.Devicelist;
import manager.supplier.model.Goods;
import manager.supplier.model.InvoiceTitle;
import manager.supplier.model.MainCustomer;
import manager.supplier.model.Metarial;
import manager.supplier.model.SupplierFile;

import org.activiti.engine.impl.util.json.JSONObject;
import org.apache.commons.beanutils.PropertyUtilsBean;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import platform.company.model.PfCompanySimpleInfo;
import platform.company.service.CompanyForPlateFormService;

import usercenter.saleManage.data.AccessApplicationCategoryMapper;
import usercenter.saleManage.data.AccessApplicationCompetitorMapper;
import usercenter.saleManage.data.AccessApplicationCustomerMapper;
import usercenter.saleManage.data.AccessApplicationDevicelistMapper;
import usercenter.saleManage.data.AccessApplicationGoodsMapper;
import usercenter.saleManage.data.AccessApplicationMetarialMapper;
import usercenter.saleManage.data.AccessInvoiceTitleMapper;
import usercenter.saleManage.data.AccessTempletElementMapper;
import usercenter.saleManage.model.AccessTempletElement;
import usercenter.saleManage.service.AccessAccountService;
import usercenter.saleManage.service.AccessApplicationInfoService;
import usercenter.supplierFiles.data.SupplierFilesMapper;
import usercenter.supplierFiles.data.SupplierOwnerInfoMapper;
import usercenter.supplierFiles.data.SupplierRegaccountInfoMapper;
import usercenter.supplierFiles.model.SupplierOwnerInfo;
import usercenter.supplierFiles.model.SupplierRegaccountInfo;
import usercenter.supplierFiles.service.SupplierFilesService;
import util.BeanUtil;
import util.Const;
import util.CryptoUtils;
import util.IpAddressUtils;
import util.MD5Util;
import util.SessionUtil;
import manager.supplier.service.CompanyAuthcationHistoryService;
import manager.supplier.service.CompanyAuthAttachedHistoryService;
import manager.supplier.service.AuthUpdateAttchedService;
import manager.supplier.service.AuthcationUpdateService;
import manager.supplier.model.Attched;
import manager.supplier.service.AttchedService;

@Service
public class SupplierFileService {
    @Autowired
    private SupplierFileMapper mapper;

    @Autowired
    private CompanyAuthcationHistoryService companyAuthcationHistoryService;
    @Autowired
    private CompanyAuthAttachedHistoryService companyAuthAttachedHistoryService;
    @Autowired
    private AttchedService attchedService;

    @Autowired
    private AuthcationUpdateService authcationUpdateService;
    @Autowired
    private AuthUpdateAttchedService authUpdateAttchedService;
    @Autowired
    private SupplierFilesService supplierFilesService;
    @Autowired
    private CompanyForPlateFormService companyForPlateFormService;
    @Autowired
    private TradeClassService tradeClassService;
    @Autowired
    private CompanyClassService companyClassService;
    @Autowired
    private CurrencyService currencyService;
    @Autowired
    private RegAccoutMapper regMapper;
    @Autowired
    private SupplierFilesMapper supplierMapper;
    @Autowired
    private SupplierOwnerInfoMapper soiMapper;
    @Autowired
    private SupplierRegaccountInfoMapper sriMapper;
    @Autowired
    private AccessApplicationInfoService aaiService;
    @Autowired
    private AccessTempletElementMapper ateMapper;
    @Autowired
    private BankAccountMapper baMapper;
    @Autowired
    private AccessAccountService aaService;
    @Autowired
    private RegAccoutCompanyInfoMapper rciMapper;
    @Autowired
    private InvoiceTitleMapper itMapper;
    @Autowired
    private AccessInvoiceTitleMapper aitMapper;
    @Autowired
    private DevicelistMapper dlMapper;
    @Autowired
    private AccessApplicationDevicelistMapper adlMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private AccessApplicationGoodsMapper aagMapper;
    @Autowired
    private CompetitorMapper competitorMapper;
    @Autowired
    private AccessApplicationCompetitorMapper aacMapper;
    @Autowired
    private MetarialMapper metarialMapper;
    @Autowired
    private AccessApplicationMetarialMapper aamMapper;
    @Autowired
    private MainCustomerMapper customerMapper;
    @Autowired
    private AccessApplicationCustomerMapper aacuMapper;
    @Autowired
    private AccessApplicationCategoryMapper aacaMapper;

    public List<SupplierFile> getSupplierFileList(Map<String, Object> params) {

        return mapper.getSupplierFileList(params);
    }

    /**
     * @Description:?
     * SupplierFileService
     * getSupplierFileInfoList
     * @param params
     * @return List<SupplierFile>
     * @author yukai
     * 2016-10-10 ?2:44:37
     */
    public List<SupplierFile> getSupplierFileInfoList(Map<String, Object> params) {
        return mapper.getSupplierFileInfoList(params);
    }

    public List<SupplierFile> getSupplierFileByID(Map<String, Object> params) {
        return mapper.getSupplierFileByID(params);
    }

    @Transactional
    public void addSupplierFile(SupplierFile[] arr) {
        Object clientip = SessionUtil.getAttribute(Const.SESSION_IP);
        for (SupplierFile obj : arr) {
            if (clientip != null && !"".equals(clientip)) {
                String ip_addr = clientip.toString();
                obj.setIp_addr(ip_addr);
                obj.setCreate_dt(new Date());
            }
            mapper.addSupplierFile(obj);
        }
    }

    @Transactional
    public void updateSupplierFile(SupplierFile[] arr) {
        for (SupplierFile obj : arr) {
            mapper.updateSupplierFile(obj);
        }
    }

    @Transactional
    public void deleteSupplierFile(SupplierFile[] arr) {
        for (SupplierFile obj : arr) {
            mapper.deleteSupplierFile(obj);
        }
    }

    /**
    * @Description: ??
    * @param apply_sts
     company_id
    * @return 0 ?1
    * @author xufeng
    * @date 2015-11-17 
    */
    public String checkStatusSame(Map<String, Object> params) {
        JSONObject json = new JSONObject();
        int count = mapper.checkStatusSame(params);
        json.put("result", count);
        json.put("success", true);
        return json.toString();
    }

    public List<CompanyClass> getCompanyClassList(Map<String, Object> params) {
        return mapper.getCompanyClassList(params);
    }

    public Integer getCountByIdAndName(Map<String, Object> params) {
        return mapper.getCountByIdAndName(params);
    }

    public Integer getCountByName(Map<String, Object> params) {
        return mapper.getCountByName(params);
    }

    public Integer checkSupplierExistInReg(Map<String, Object> params) {
        return supplierFilesService.checkSupplierExistInReg(params);
    }

    public List<Area> getAreaList(Map<String, Object> params) {
        return mapper.getAreaList(params);
    }

    public List<MaterialClass> getMaterialClassList(Map<String, Object> params) {
        return mapper.getMaterialClassList(params);
    }

    /**
    * @Description: ?  
    * @param  node ()
    * Request supplier/supplierFile.srm?method=getMaterialClassTree
    * Response {data:[{List<TreeModel>}]} <br/><br/>
    * @author xufeng
    * @date 2015-11-03
    */
    public List<TreeModel> getMaterialClassTree(Map<String, Object> params) {
        List<TreeModel> stlist = new ArrayList<TreeModel>();
        List<MaterialClass> list = getMaterialClassList(params);

        for (MaterialClass sa : list) {
            TreeModel st = new TreeModel();
            st.setId(sa.getMc_id());
            st.setParentId(sa.getF_id());
            st.setText(sa.getMc_name());
            st.setLeaf(sa.getLeaf());
            st.setExpanded("false");

            st.setType("MaterialClass");
            stlist.add(st);

        }

        return stlist;
    }

    /*
     * getSuppliersByMultiSearch
     * ????
     * */
    public List<SupplierFile> getSuppliersByMultiSearch(Map<String, Object> params) {
        return mapper.getSuppliersByMultiSearch(params);
    }

    /**
     * ?????id ??
     * @param params
     * @return company_id, cpyname_en,cpyname_cn
     * @author chenlong
     * @2016-04-08
     */
    public List<SupplierFile> getSuppliersByCpnameSearch(Map<String, Object> params) {

        return mapper.getSuppliersByCpnameSearch(params);
    }

    /**
     * ?ID?
    * @Description:
    * SupplierFileService
    * getCompanyForReg
    * @param params
    * @return List<SupplierFile>
    * @author chenlong
    * 2016-10-12 ?4:40:54
     */
    public List<SupplierFile> getCompanyForReg(Map<String, Object> params) {
        return mapper.getCompanyForReg(params);
    }

    /**
     * ???????
     * @param company_id?
     * @author yangliping
     * @date 2016-7-28 14:52:36
     */
    public void saveCompanyAuthHistory(Map<String, Object> params) {
        String idArrayString = params.get("companyid_array").toString();
        String[] idArray = idArrayString.split(",");
        //System.out.println("11111111111111111111:"+idArrayString);
        for (int j = 0; j < idArray.length; j++) {

            Map<String, Object> companyPara = new HashMap<String, Object>();
            companyPara.put("company_id", idArray[j]);
            //System.out.println("company_id:"+idArray[j]);
            List<SupplierFile> companys = mapper.getSupplierFileByID(companyPara);
            if (companys.size() > 0) {
                SupplierFile company = companys.get(0);
                CompanyAuthcationHistory history = new CompanyAuthcationHistory();
                history.setCompany_id(company.getCompany_id());
                history.setClass_id(company.getClass_id());
                history.setNature_id(company.getNature_id());
                history.setKey_remark(company.getKey_remark());
                history.setCpyname_cn(company.getCpyname_cn());
                history.setIndustry_id(company.getIndustry_id());
                history.setCorporation(company.getCorporation());
                history.setReg_fund(company.getReg_fund());
                history.setCurrency_id(company.getCurrency_id());
                history.setEstablish_dt(company.getEstablish_dt());
                history.setCreated_dt(new Date());
                //??????????,?
                companyAuthcationHistoryService.addCompanyAuthcationHistory(history);
                int auth_history_id = history.getAuth_history_id();
                //System.out.println("auth_history_id:"+auth_history_id);

                //

                Map<String, Object> attachPara = new HashMap<String, Object>();
                attachPara.put("company_id", company.getCompany_id());
                attachPara.put("is_license", true);
                //???
                List<Attched> Attcheds = attchedService.getAttchedList(attachPara);
                for (int i = 0; i < Attcheds.size(); i++) {
                    CompanyAuthAttachedHistory attHistory = new CompanyAuthAttachedHistory();
                    attHistory.setAuth_history_id(auth_history_id);
                    attHistory.setFile_type_id(Attcheds.get(i).getFile_type_id());
                    attHistory.setFile_name(Attcheds.get(i).getFile_name());
                    attHistory.setCompany_id(Attcheds.get(i).getCompany_id());
                    attHistory.setObject_id(Attcheds.get(i).getMogodb_id());
                    attHistory.setCreate_dt(new Date());
                    //?????
                    companyAuthAttachedHistoryService.addCompanyAuthAttachedHistory(attHistory);
                }
            }
        }
    }

    /**
     * @Description:?????????
     * AuthcationUpdateService
     * saveCompanyUpdateAuthToHistory
     * @param params void
     * @author yangliping
     * 2016-7-29 ?12:06:
     * 21
     */
    public void saveCompanyUpdateAuthToHistory(Map<String, Object> params) {
        //?
        String idArrayString = params.get("authUpdateIdArray").toString();
        String[] idArray = idArrayString.split(",");
        for (int j = 0; j < idArray.length; j++) {
            Map<String, Object> updatePara = new HashMap<String, Object>();
            updatePara.put("auth_update_id", idArray[j]);
            List<AuthcationUpdate> updateItems = authcationUpdateService.getAuthcationUpdateList(updatePara);
            if (updateItems.size() > 0) {

                AuthcationUpdate upcompany = updateItems.get(0);
                //??
                Map<String, Object> companyPara = new HashMap<String, Object>();
                companyPara.put("company_id", upcompany.getCompany_id());

                List<SupplierFile> companys = mapper.getSupplierFileByID(companyPara);
                if (companys.size() > 0) {
                    SupplierFile company = companys.get(0);

                    company.setCompany_id(upcompany.getCompany_id());
                    company.setClass_id(upcompany.getClass_id());
                    company.setNature_id(upcompany.getNature_id());
                    company.setKey_remark(upcompany.getKey_remark());
                    company.setCpyname_cn(upcompany.getCpyname_cn());
                    company.setIndustry_id(upcompany.getIndustry_id());
                    company.setCorporation(upcompany.getCorporation());
                    company.setReg_fund(upcompany.getReg_fund());
                    company.setCurrency_id(upcompany.getCurrency_id());
                    company.setEstablish_dt(upcompany.getEstablish_dt());
                    mapper.updateSupplierFile(company);
                }

                //??
                CompanyAuthcationHistory history = new CompanyAuthcationHistory();
                history.setCompany_id(upcompany.getCompany_id());
                history.setClass_id(upcompany.getClass_id());
                history.setNature_id(upcompany.getNature_id());
                history.setKey_remark(upcompany.getKey_remark());
                history.setCpyname_cn(upcompany.getCpyname_cn());
                history.setIndustry_id(upcompany.getIndustry_id());
                history.setCorporation(upcompany.getCorporation());
                history.setReg_fund(upcompany.getReg_fund());
                history.setCurrency_id(upcompany.getCurrency_id());
                history.setEstablish_dt(upcompany.getEstablish_dt());
                history.setCreated_dt(new Date());
                companyAuthcationHistoryService.addCompanyAuthcationHistory(history);
                int auth_history_id = history.getAuth_history_id();
                //System.out.println("auth_history_id:"+auth_history_id);
                //
                //?
                Map<String, Object> attachUPara = new HashMap<String, Object>();
                attachUPara.put("auth_update_id", upcompany.getAuth_update_id());
                List<AuthUpdateAttched> AuthUpdateAttcheds = authUpdateAttchedService
                        .getAuthUpdateAttchedList(attachUPara);
                //?
                Map<String, Object> attachPara = new HashMap<String, Object>();
                attachPara.put("company_id", upcompany.getCompany_id());
                attachPara.put("is_license", true);
                //???

                List<Attched> Attcheds = attchedService.getAttchedList(attachPara);
                for (int k = 0; k < AuthUpdateAttcheds.size(); k++) {
                    boolean isUpdate = false;
                    Attched attched = new Attched();
                    AuthUpdateAttched currUpdateAttched = AuthUpdateAttcheds.get(k);
                    for (int i = 0; i < Attcheds.size(); i++) {
                        Attched currAttched = Attcheds.get(i);
                        if (currUpdateAttched.getCompany_id() == currAttched.getCompany_id()
                                && currUpdateAttched.getFile_type_id() == currAttched.getFile_type_id()) {
                            isUpdate = true;
                            attched = currAttched;
                            attched.setMogodb_id(currUpdateAttched.getObject_id());
                        }
                    }
                    if (isUpdate) {
                        //?????
                        attchedService.updateAttched(new Attched[] { attched });
                    } else {
                        //???
                        attched.setCompany_id(currUpdateAttched.getCompany_id());
                        attched.setFile_name(currUpdateAttched.getFile_name());
                        attched.setFile_type_id(currUpdateAttched.getFile_type_id());
                        attched.setMogodb_id(currUpdateAttched.getObject_id());
                        attchedService.addAttched(new Attched[] { attched });
                    }
                }
                Attcheds = attchedService.getAttchedList(attachPara);
                for (Attched attched : Attcheds) {
                    CompanyAuthAttachedHistory attHistory = new CompanyAuthAttachedHistory();
                    attHistory.setAuth_history_id(auth_history_id);
                    attHistory.setFile_type_id(attched.getFile_type_id());
                    attHistory.setFile_name(attched.getFile_name());
                    attHistory.setCompany_id(attched.getCompany_id());
                    attHistory.setObject_id(attched.getMogodb_id());
                    attHistory.setCreate_dt(new Date());
                    //?????
                    companyAuthAttachedHistoryService.addCompanyAuthAttachedHistory(attHistory);
                }
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("company_id", upcompany.getCompany_id());
                supplierFilesService.updateAuthStsByCompanyId(map);
            }
        }
    }

    /**
     * @Description:excel??????
     * SupplierFileService
     * addSupplierFileByExcel
     * @param finalFile
     * @param json
     * @param request
     * @throws Exception void
     * @author yukai
     * 2016-10-13 ?4:10:34
     */
    public void addSupplierFileByExcel(File finalFile, JSONObject json, HttpServletRequest request, int ownerId)
            throws Exception {
        Map<String, Object> params = new HashMap<String, Object>();
        Map<String, Object> supplierParams = new HashMap<String, Object>();
        Map<String, Object> accInfoParams = new HashMap<String, Object>();
        Map<String, Object> accountParams = new HashMap<String, Object>();
        Map<String, Object> invoiceParams = new HashMap<String, Object>();
        Map<String, Object> deviceParams = new HashMap<String, Object>();
        Map<String, Object> goodsParams = new HashMap<String, Object>();
        Map<String, Object> metarialParams = new HashMap<String, Object>();
        Map<String, Object> customerParams = new HashMap<String, Object>();
        Map<String, Object> competitorParams = new HashMap<String, Object>();
        String currentIp = IpAddressUtils.getCurrentIpAddress(request);//?IP?
        //excel?
        List<SupplierFile> supplierFilelist = getSupplierListFromExcel(finalFile, json, request);
        //excel??
        List<BankAccount> bankAccountlist = getAccountListFromExcel(finalFile, json, request);
        //excel??
        List<InvoiceTitle> invoiceTitlelist = getTitleListFromExcel(finalFile, json, request);
        //excel?
        List<Devicelist> devicelist = getDeviceListFromExcel(finalFile, json, request);
        //excel??
        List<Goods> goodslist = getGoodsListFromExcel(finalFile, json, request);
        //excel?
        List<Competitor> competitorlist = getCompetitorListFromExcel(finalFile, json, request);
        //excel???
        List<Metarial> metariallist = getMetarialListFromExcel(finalFile, json, request);
        //excel?
        List<MainCustomer> customerlist = getCustomerListFromExcel(finalFile, json, request);
        //??
        if (json.getBoolean("success") && supplierFilelist.size() > 0) {
            //?
            Date createDate = new Date();
            Pattern accPattern = Pattern.compile("^[a-zA-Z0-9_\u4e00-\u9fa5]+$");
            Pattern phonepattern = Pattern.compile("^1[3|4|5|8][0-9]{9}$");
            //?
            for (int i = 0; i < supplierFilelist.size(); i++) {
                SupplierFile item = supplierFilelist.get(i);
                item.setCreate_dt(createDate);
                item.setApply_sts(15);
                //???
                String supplierName = item.getCpyname_cn();
                params.put("company_id", ownerId);
                //List<RegAccoutCompanyInfo> rInfos=rciMapper.getRegAccoutCompanyInfoList(params);
                //int reg_id=rInfos.get(0).getReg_id();
                //params.put("reg_id", reg_id);
                params.put("supplierName", supplierName);
                int count = supplierFilesService.checkSupplierExistInReg(params);
                if (count > 0) {
                    json.put("success", false);
                    json.put("message", supplierName + "");
                    return;
                }
                //??
                String phone = item.getM_phone();
                if (phone != null && !phone.equals("")) {
                    Matcher m = phonepattern.matcher(phone);
                    if (!m.matches()) {
                        json.put("success", false);
                        json.put("message", phone + "??");
                        return;
                    }
                }
                //
                String className = item.getClass_name();
                params.put("class_name", className);
                List<TradeClass> tradeClasses = tradeClassService.getTradeClassList(params);
                if (tradeClasses.size() == 0) {
                    json.put("success", false);
                    json.put("message", className + "?");
                    return;
                } else {
                    item.setClass_id(tradeClasses.get(0).getClass_id() + "");
                }
                //?
                String natureName = item.getNature_name();
                params.put("nature_name", natureName);
                List<CompanyClass> companyClasses = companyClassService.getCompanyClassList(params);
                if (companyClasses.size() == 0) {
                    json.put("success", false);
                    json.put("message", natureName + "?");
                    return;
                } else {
                    item.setNature_id(companyClasses.get(0).getNature_id() + "");
                }
                //??
                String currencyName = item.getCurrency_name();
                params.put("currency_name", currencyName);
                List<Currency> currencies = currencyService.getCurrencyList(params);
                if (currencies.size() == 0) {
                    json.put("success", false);
                    json.put("message", currencyName + "?");
                    return;
                } else {
                    item.setCurrency_id(currencies.get(0).getCurrency_id());
                }
                //???
                String account = item.getReg_account();
                String password = MD5Util.encode2hex(item.getPassword());
                String email = item.getReg_email();
                if (account != null && !account.equals("")) {
                    Matcher m = accPattern.matcher(account);
                    if (!m.matches()) {
                        json.put("success", false);
                        json.put("message", account + "??");
                        return;
                    } else {
                        int length = getWordCount(account);
                        if (length < 5 || length > 15) {
                            json.put("success", false);
                            json.put("message", account + "???");
                            return;
                        } else {
                            params.put("userName", account);
                            int count1 = regMapper.getUserNameCount(params);
                            if (count1 > 0) {
                                json.put("success", false);
                                json.put("message", account + "");
                                return;
                            } else {
                                if (password == null || password == "") {
                                    json.put("success", false);
                                    json.put("message", account + "??");
                                    return;
                                } else {
                                    if (email == null || email == "") {
                                        json.put("success", false);
                                        json.put("message", account + "?");
                                        return;
                                    } else {
                                        params.put("email", email);
                                        int count2 = regMapper.getUserEmailCount(params);
                                        if (count2 > 0) {
                                            json.put("success", false);
                                            json.put("message", email + "");
                                            return;
                                        } else {
                                            String salt = CryptoUtils.getSalt();//???
                                            item.setPassword(CryptoUtils.getHash(password, salt));
                                            item.setSalt(salt);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //???
            for (int i = 0; i < supplierFilelist.size(); i++) {
                SupplierFile item = supplierFilelist.get(i);
                int company_id = 0;
                boolean flag = true;//???
                String companyName = item.getCpyname_cn();
                params.put("companyName", companyName);
                List<PfCompanySimpleInfo> companys = companyForPlateFormService.getCompanyByName(params);
                if (companys.size() > 0) {
                    company_id = companys.get(0).getCompany_id();
                    flag = true;
                } else {
                    mapper.addSupplierFile(item);//???
                    company_id = item.getCompany_id();
                    flag = false;
                }
                if (item.getReg_account() != null && !item.getReg_account().equals("")) {
                    Byte emailValid = 0;//?
                    RegAccout regAccout = new RegAccout();
                    regAccout.setAcc_name(item.getReg_account());
                    regAccout.setPassword(item.getPassword());
                    regAccout.setReg_date(createDate);
                    regAccout.setRole_id(1);
                    regAccout.setReg_email(item.getReg_email());
                    regAccout.setEmail_valid(emailValid);
                    regAccout.setLast_login_ip(currentIp);
                    regMapper.addRegAccout(regAccout);//??
                    RegSalt rs = new RegSalt();
                    rs.setAcc_name(item.getReg_account());
                    rs.setSalt(item.getSalt());
                    regMapper.addSalt(rs);//??
                    RegAccoutCompanyInfo rci = new RegAccoutCompanyInfo();
                    rci.setReg_id(regAccout.getReg_id());
                    rci.setCompany_id(item.getCompany_id());
                    rciMapper.addRegAccoutCompanyInfo(rci);
                }
                supplierParams.put("company_id", company_id);
                supplierParams.put("supplier_cpyname", item.getCpyname_cn());
                supplierParams.put("source_type", 2);
                supplierParams.put("file_status", 0);
                supplierMapper.addSupplierFiles(supplierParams);//?

                params.put("companyId", ownerId);
                String ownerName = companyForPlateFormService.getCompanyNameByCompanyId(params);
                SupplierOwnerInfo soi = new SupplierOwnerInfo();
                soi.setCompany_id(ownerId);
                soi.setOwner_cpyname(ownerName);
                soi.setSupplier_id(Integer.parseInt(supplierParams.get("supplier_id").toString()));
                soiMapper.addSupplierOwnerInfo(soi);//?

                params.put("company_id", ownerId);
                List<RegAccoutCompanyInfo> rInfos = rciMapper.getRegAccoutCompanyInfoList(params);
                int reg_id = rInfos.get(0).getReg_id();
                SupplierRegaccountInfo sri = new SupplierRegaccountInfo();
                sri.setReg_id(reg_id);
                sri.setSupplier_id(Integer.parseInt(supplierParams.get("supplier_id").toString()));
                sriMapper.addSupplierRegaccountInfo(sri);//??

                //???
                List<AccessTempletElement> elements = ateMapper.getAccessTempletElementList(params);
                Map<String, Object> map = BeanUtil.beanToMap(item);//javamap
                for (AccessTempletElement accessTempletElement : elements) {
                    if ("companyIntroduction".equals(accessTempletElement.getRelated_basis())) {//???
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get("company_introduction"));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    } else if ("exportNum".equals(accessTempletElement.getRelated_basis())) {
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get("export_num"));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    } else if ("importNum".equals(accessTempletElement.getRelated_basis())) {
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get("import_num"));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    } else if ("companyArea".equals(accessTempletElement.getRelated_basis())) {
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get("company_area"));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    } else if ("factoryArea".equals(accessTempletElement.getRelated_basis())) {
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get("factory_area"));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    } else if ("schoolCoop".equals(accessTempletElement.getRelated_basis())) {
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get("school_coop"));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    } else {//??
                        accInfoParams.put("supplier_id",
                                Integer.parseInt(supplierParams.get("supplier_id").toString()));
                        accInfoParams.put("e_id", accessTempletElement.getE_id());
                        accInfoParams.put("content", map.get(accessTempletElement.getRelated_basis()));
                        aaiService.addAccessApplicationInfo(accInfoParams);
                    }
                }
                //???
                if (bankAccountlist.size() > 0) {
                    //???
                    for (int j = 0; j < bankAccountlist.size(); j++) {
                        BankAccount account = bankAccountlist.get(j);
                        if (account.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                account.setCompany_id(company_id);
                                account.setDefault_id(false);
                                baMapper.addBankAccount(account);//???
                            }
                            accountParams.put("account_name", account.getAccount_name());
                            accountParams.put("account_code", account.getAccount_code());
                            accountParams.put("default_id", 0);
                            accountParams.put("account_sts", 0);
                            accountParams.put("app_account_id", account.getAccount_id());
                            accountParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            aaService.addAccessAccount(accountParams);
                        }
                    }
                }
                //???
                if (invoiceTitlelist.size() > 0) {
                    //???
                    for (int j = 0; j < invoiceTitlelist.size(); j++) {
                        InvoiceTitle invoiceTitle = invoiceTitlelist.get(j);
                        if (invoiceTitle.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                invoiceTitle.setCompany_id(company_id);
                                invoiceTitle.setDefault_id(false);
                                itMapper.addInvoiceTitle(invoiceTitle);//???
                            }
                            invoiceParams.put("invoice_title_name", invoiceTitle.getInvoice_title_name());
                            invoiceParams.put("default_id", 0);
                            invoiceParams.put("invoice_title_sts", 0);
                            invoiceParams.put("app_invoice_title_id", invoiceTitle.getInvoice_title_id());
                            invoiceParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            aitMapper.addAccessInvoiceTitle(invoiceParams);
                        }
                    }
                }

                //???
                if (devicelist.size() > 0) {
                    //???
                    for (int j = 0; j < devicelist.size(); j++) {
                        Devicelist device = devicelist.get(j);
                        if (device.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                device.setCompany_id(company_id);
                                dlMapper.addDevicelist(device);//???
                            }
                            deviceParams.put("deviceName", device.getDevice_name());
                            deviceParams.put("specifications", device.getSpecifications());
                            deviceParams.put("place", device.getPlace());
                            deviceParams.put("price", device.getPrice());
                            deviceParams.put("buyDay", device.getBuy_day());
                            deviceParams.put("advanced", device.getAdvanced());
                            deviceParams.put("deviceNum", device.getDevice_num());
                            deviceParams.put("AppDeviceId", device.getDevice_id());
                            deviceParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            adlMapper.addAccessApplicationDevicelist(deviceParams);
                        }
                    }
                }
                //???
                if (competitorlist.size() > 0) {
                    //???
                    for (int j = 0; j < competitorlist.size(); j++) {
                        Competitor competitor = competitorlist.get(j);
                        if (competitor.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                competitor.setCompany_id(company_id);
                                competitorMapper.addCompetitor(competitor);
                            }
                            competitorParams.put("competitorName", competitor.getCompetitor_name());
                            competitorParams.put("AppCompetitorId", competitor.getCompetitor_id());
                            competitorParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            aacMapper.addAccessApplicationCompetitor(competitorParams);
                        }
                    }
                }
                //???
                if (goodslist.size() > 0) {
                    //???
                    for (int j = 0; j < goodslist.size(); j++) {
                        Goods goods = goodslist.get(j);
                        if (goods.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                goods.setCompany_id(company_id);
                                goodsMapper.addGoods(goods);
                            }
                            goodsParams.put("goodsName", goods.getGoods_name());
                            goodsParams.put("goodsBrand", goods.getGoods_brand());
                            goodsParams.put("AppGoodsId", goods.getGoods_id());
                            goodsParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            aagMapper.addAccessApplicationGoods(goodsParams);
                        }
                    }
                }
                //???
                if (metariallist.size() > 0) {
                    //???
                    for (int j = 0; j < metariallist.size(); j++) {
                        Metarial metarial = metariallist.get(j);
                        if (metarial.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                metarial.setCompany_id(company_id);
                                metarialMapper.addMetarial(metarial);
                            }
                            metarialParams.put("materialName", metarial.getMaterial_name());
                            metarialParams.put("materialBrand", metarial.getMaterial_brand());
                            metarialParams.put("AppMaterialId", metarial.getMaterial_id());
                            metarialParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            aamMapper.addAccessApplicationMetarial(metarialParams);
                        }
                    }
                }
                //???
                if (customerlist.size() > 0) {
                    //???
                    for (int j = 0; j < customerlist.size(); j++) {
                        MainCustomer customer = customerlist.get(j);
                        if (customer.getCompany_name().equals(item.getCpyname_cn())) {
                            if (!flag) {
                                customer.setCompany_id(company_id);
                                customerMapper.addMainCustomer(customer);
                            }
                            customerParams.put("customerName", customer.getCustomer_name());
                            customerParams.put("AppCustomerId", customer.getCustomer_id());
                            customerParams.put("supplier_id",
                                    Integer.parseInt(supplierParams.get("supplier_id").toString()));
                            aacuMapper.addAccessApplicationCustomer(customerParams);
                        }
                    }
                }
            }
            json.put("message", "??");
        }
    }

    private List<MainCustomer> getCustomerListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<MainCustomer> items = new ArrayList<MainCustomer>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(6);// ?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                MainCustomer item = new MainCustomer();
                if (row.getCell(0) == null || row.getCell(1) == null) {
                    json.put("success", false);
                    json.put("message", "?7" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                item.setCustomer_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setCompany_name((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"?".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    private List<Metarial> getMetarialListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<Metarial> items = new ArrayList<Metarial>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(5); //?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                Metarial item = new Metarial();
                if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null) {
                    json.put("success", false);
                    json.put("message", "?6" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
                item.setMaterial_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setMaterial_brand((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                item.setCompany_name((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"???".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    private List<Competitor> getCompetitorListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<Competitor> items = new ArrayList<Competitor>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(7); //?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                Competitor item = new Competitor();
                if (row.getCell(0) == null || row.getCell(1) == null) {
                    json.put("success", false);
                    json.put("message", "?8" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                item.setCompetitor_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setCompany_name((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"?".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    private List<Goods> getGoodsListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<Goods> items = new ArrayList<Goods>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(4); //?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                Goods item = new Goods();
                if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null) {
                    json.put("success", false);
                    json.put("message", "?5" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
                item.setGoods_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setGoods_brand((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                item.setCompany_name((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"??".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    private List<Devicelist> getDeviceListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<Devicelist> items = new ArrayList<Devicelist>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(3); //?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                Devicelist item = new Devicelist();
                if (row.getCell(0) == null || row.getCell(5) == null || row.getCell(7) == null) {
                    json.put("success", false);
                    json.put("message", "?4" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                if (row.getCell(1) != null) {
                    row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                }
                if (row.getCell(2) != null) {
                    row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
                }
                if (row.getCell(6) != null) {
                    row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
                }
                row.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
                item.setDevice_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setSpecifications((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                item.setPlace((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
                item.setPrice((row.getCell(3) == null) ? 0 : row.getCell(3).getNumericCellValue());
                item.setBuy_day((row.getCell(4) == null) ? null : row.getCell(4).getDateCellValue());
                item.setDevice_num((int) ((row.getCell(5) == null) ? 0 : row.getCell(5).getNumericCellValue()));
                item.setAdvanced((row.getCell(6) == null) ? "" : row.getCell(6).getStringCellValue());
                item.setCompany_name((row.getCell(7) == null) ? "" : row.getCell(7).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    private List<InvoiceTitle> getTitleListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<InvoiceTitle> items = new ArrayList<InvoiceTitle>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(2); //?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                InvoiceTitle item = new InvoiceTitle();
                if (row.getCell(0) == null || row.getCell(1) == null) {
                    json.put("success", false);
                    json.put("message", "?3" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                item.setInvoice_title_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setCompany_name((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"?".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    private List<BankAccount> getAccountListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<BankAccount> items = new ArrayList<BankAccount>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(1); //?  
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                BankAccount item = new BankAccount();
                if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null) {
                    json.put("success", false);
                    json.put("message", "?2" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
                item.setAccount_name((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setAccount_code((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                item.setCompany_name((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"?".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    /**
     * @Description:?EXCEL
     * SupplierFileService
     * getListFromExcel
     * @param finalFile
     * @param json
     * @param request
     * @return
     * @throws Exception List<SupplierFile>
     * @author yukai
     * 2016-10-13 ?4:11:14
     */
    private List<SupplierFile> getSupplierListFromExcel(File finalFile, JSONObject json, HttpServletRequest request)
            throws Exception {
        List<SupplierFile> items = new ArrayList<SupplierFile>();
        String fileName = finalFile.getName();

        boolean isE2007 = false; //?excel2007?  
        if (fileName.endsWith("xlsx")) {
            isE2007 = true;
        }
        InputStream input = new FileInputStream(finalFile);
        Workbook wb = null;
        //??(20032007)??  
        if (isE2007) {
            wb = new XSSFWorkbook(input);
        } else {
            wb = new HSSFWorkbook(input);
        }
        Sheet sheet = wb.getSheetAt(0); //?  
        if (!sheet.iterator().hasNext()) {
            json.put("success", false);
            json.put("message", "excel");
            return items;
        }
        int trLength = sheet.getLastRowNum();
        if (trLength <= 2) {
            json.put("success", false);
            json.put("message", "?");
        }
        for (Row row : sheet) { //?
            //
            if (row.getRowNum() > 2) {
                SupplierFile item = new SupplierFile();
                if ((row.getCell(0) == null || row.getCell(0).toString().equals(""))
                        && (row.getCell(1) == null || row.getCell(1).toString().equals(""))
                        && (row.getCell(2) == null || row.getCell(2).toString().equals(""))
                        && (row.getCell(3) == null || row.getCell(3).toString().equals(""))
                        && (row.getCell(4) == null || row.getCell(4).toString().equals(""))
                        && (row.getCell(5) == null || row.getCell(5).toString().equals(""))
                        && (row.getCell(6) == null || row.getCell(6).toString().equals(""))
                        && (row.getCell(7) == null || row.getCell(7).toString().equals(""))
                        && (row.getCell(8) == null || row.getCell(8).toString().equals(""))
                        && (row.getCell(9) == null || row.getCell(9).toString().equals(""))
                        && (row.getCell(10) == null || row.getCell(10).toString().equals(""))
                        && (row.getCell(11) == null || row.getCell(11).toString().equals(""))) {
                    if (row.getRowNum() == 3) {
                        json.put("success", false);
                        json.put("message", "?");
                    }
                    break;//?
                }
                if (row.getCell(0) == null || row.getCell(1) == null || row.getCell(2) == null
                        || row.getCell(3) == null || row.getCell(4) == null || row.getCell(5) == null
                        || row.getCell(6) == null || row.getCell(7) == null || row.getCell(8) == null
                        || row.getCell(9) == null || row.getCell(10) == null) {
                    json.put("success", false);
                    json.put("message", "" + (row.getRowNum() + 1) + "??");
                    break;
                }
                row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(4).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(5).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
                row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
                //if(row.getCell(9)!=null){
                row.getCell(9).setCellType(Cell.CELL_TYPE_STRING);
                //    }
                //if(row.getCell(10)!=null){
                row.getCell(10).setCellType(Cell.CELL_TYPE_STRING);
                //   }
                if (row.getCell(11) != null) {
                    row.getCell(11).setCellType(Cell.CELL_TYPE_STRING);
                }
                item.setCpyname_cn((row.getCell(0) == null) ? "" : row.getCell(0).getStringCellValue());
                item.setCorporation((row.getCell(1) == null) ? "" : row.getCell(1).getStringCellValue());
                item.setContact_addr((row.getCell(2) == null) ? "" : row.getCell(2).getStringCellValue());
                item.setContacts((row.getCell(3) == null) ? "" : row.getCell(3).getStringCellValue());
                item.setM_phone((row.getCell(4) == null) ? "" : row.getCell(4).getStringCellValue());
                item.setClass_name((row.getCell(5) == null) ? "" : row.getCell(5).getStringCellValue());
                item.setNature_name((row.getCell(6) == null) ? "" : row.getCell(6).getStringCellValue());
                item.setReg_fund((row.getCell(7) == null) ? 0 : row.getCell(7).getNumericCellValue());
                item.setCurrency_name((row.getCell(8) == null) ? "" : row.getCell(8).getStringCellValue());
                item.setReg_account((row.getCell(9) == null) ? "" : row.getCell(9).getStringCellValue());
                item.setPassword((row.getCell(10) == null) ? "" : row.getCell(10).getStringCellValue());
                item.setReg_email((row.getCell(11) == null) ? "" : row.getCell(11).getStringCellValue());
                items.add(item);
            } else if (row.getRowNum() == 1) {//
                String name = (row.getCell(0) == null) ? "" : row.getCell(0).toString().trim();
                if (!"".equals(name)) {
                    json.put("success", false);
                    json.put("message", "?");
                    break;
                }
            }
        }
        input.close();
        return items;
    }

    /**
     * @Description:?2
     * SupplierFileService
     * getWordCount
     * @param s
     * @return int
     * @author yukai
     * 2016-10-13 ?4:11:30
     */
    public int getWordCount(String s) {
        s = s.replaceAll("[^\\x00-\\xff]", "**");
        int length = s.length();
        return length;
    }

    /**
     * @Description:
     * SupplierFileService
     * addSupplierFileInfo
     * @param params void
     * @author yukai
     * 2016-10-18 ?3:23:10
     * @throws InvocationTargetException 
     * @throws InstantiationException 
     * @throws IllegalAccessException 
     * @throws Exception 
     */
    public void addSupplierFileInfo(Map<String, Object> params) throws Exception {
        Map<String, Object> companyParams = new HashMap<String, Object>();
        Map<String, Object> supplierParams = new HashMap<String, Object>();
        Map<String, Object> accInfoParams = new HashMap<String, Object>();
        Map<String, Object> categoryParams = new HashMap<String, Object>();
        int owner_id = Integer.parseInt(params.get("owner_id").toString());
        int reg_id = Integer.parseInt(params.get("reg_id").toString());
        //SupplierFile item=(SupplierFile)BeanUtil.mapToObject(params,SupplierFile.class);
        int company_id = 0;
        String companyName = params.get("cpyname_cn").toString();
        companyParams.put("companyName", companyName);
        List<PfCompanySimpleInfo> companys = companyForPlateFormService.getCompanyByName(companyParams);
        if (companys.size() > 0) {
            company_id = companys.get(0).getCompany_id();
            params.put("isSync", false);
        } else {
            params.put("apply_sts", 15);
            mapper.addSupplierFile1(params);//???
            company_id = Integer.parseInt(params.get("company_id").toString());
            RegAccoutCompanyInfo rci = new RegAccoutCompanyInfo();
            rci.setCompany_id(company_id);
            rci.setReg_id(reg_id);
            rciMapper.addRegAccoutCompanyInfo(rci);
            params.put("isSync", true);
        }
        supplierParams.put("company_id", company_id);
        supplierParams.put("supplier_cpyname", companyName);
        supplierParams.put("source_type", 2);
        supplierParams.put("file_status", 0);
        supplierMapper.addSupplierFiles(supplierParams);//?

        companyParams.put("companyId", owner_id);
        String ownerName = companyForPlateFormService.getCompanyNameByCompanyId(companyParams);
        SupplierOwnerInfo soi = new SupplierOwnerInfo();
        soi.setCompany_id(owner_id);
        soi.setOwner_cpyname(ownerName);
        soi.setSupplier_id(Integer.parseInt(supplierParams.get("supplier_id").toString()));
        soiMapper.addSupplierOwnerInfo(soi);//?

        companyParams.put("company_id", owner_id);
        List<RegAccoutCompanyInfo> rInfos = rciMapper.getRegAccoutCompanyInfoList(companyParams);
        int reg_id1 = rInfos.get(0).getReg_id();
        SupplierRegaccountInfo sri = new SupplierRegaccountInfo();
        sri.setReg_id(reg_id1);
        sri.setSupplier_id(Integer.parseInt(supplierParams.get("supplier_id").toString()));
        sriMapper.addSupplierRegaccountInfo(sri);//??
        //???
        List<AccessTempletElement> elements = ateMapper.getAccessTempletElementList(params);
        for (AccessTempletElement accessTempletElement : elements) {
            if ("companyIntroduction".equals(accessTempletElement.getRelated_basis())) {//???
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("company_introduction"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("exportNum".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("export_num"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("importNum".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("import_num"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("companyArea".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("company_area"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("factoryArea".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("factory_area"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("schoolCoop".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("school_coop"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("use_begintime".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content",
                        params.get("use_begintime") != null
                                ? params.get("use_begintime").toString().substring(0, 10)
                                : null);
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("use_endtime".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content",
                        params.get("use_endtime") != null ? params.get("use_endtime").toString().substring(0, 10)
                                : null);
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else if ("reg_addr_code".equals(accessTempletElement.getRelated_basis())) {
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get("contact_addr_code"));
                aaiService.addAccessApplicationInfo(accInfoParams);
            } else {//??
                accInfoParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
                accInfoParams.put("e_id", accessTempletElement.getE_id());
                accInfoParams.put("content", params.get(accessTempletElement.getRelated_basis()));
                aaiService.addAccessApplicationInfo(accInfoParams);
            }
        }
        ArrayList<Integer> arr1 = (ArrayList<Integer>) params.get("category_id_1");
        ArrayList<Integer> arr2 = (ArrayList<Integer>) params.get("category_id_2");
        ArrayList<Integer> arr3 = (ArrayList<Integer>) params.get("category_id_3");
        categoryParams.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
        for (int i = 0; i < arr1.size(); i++) {
            categoryParams.put("category_id", arr1.get(i));
            aacaMapper.addAccessApplicationCategory(categoryParams);
        }
        for (int j = 0; j < arr2.size(); j++) {
            categoryParams.put("category_id", arr2.get(j));
            aacaMapper.addAccessApplicationCategory(categoryParams);
        }
        for (int k = 0; k < arr3.size(); k++) {
            categoryParams.put("category_id", arr3.get(k));
            aacaMapper.addAccessApplicationCategory(categoryParams);
        }
        params.put("company_id", company_id);
        params.put("supplier_id", Integer.parseInt(supplierParams.get("supplier_id").toString()));
    }

    /**
     * @Description: SupplierFileService updateSupplierFileInfo
     * @param params
     *            void
     * @author yukai 2016-10-18 ?3:23:14
     */
    public void updateSupplierFileInfo(Map<String, Object> params) throws Exception {
        Map<String, Object> categoryParams = new HashMap<String, Object>();
        //SupplierFile item=(SupplierFile)BeanUtil.mapToObject(params,SupplierFile.class);
        if (params.containsKey("isSync")) {
            if (Boolean.parseBoolean(params.get("isSync").toString())) {
                params.put("apply_sts", 15);
                mapper.updateSupplierFile1(params);
            }

            int supplier_id = Integer.valueOf(params.get("supplier_id").toString());
            ArrayList<Integer> arr1 = (ArrayList<Integer>) params.get("category_id_1");
            ArrayList<Integer> arr2 = (ArrayList<Integer>) params.get("category_id_2");
            ArrayList<Integer> arr3 = (ArrayList<Integer>) params.get("category_id_3");
            categoryParams.put("supplier_id", supplier_id);
            aacaMapper.deleteAccessApplicationCategoryBySupplierId(categoryParams);
            for (int i = 0; i < arr1.size(); i++) {
                categoryParams.put("category_id", arr1.get(i));
                aacaMapper.addAccessApplicationCategory(categoryParams);
            }
            for (int j = 0; j < arr2.size(); j++) {
                categoryParams.put("category_id", arr2.get(j));
                aacaMapper.addAccessApplicationCategory(categoryParams);
            }
            for (int k = 0; k < arr3.size(); k++) {
                categoryParams.put("category_id", arr3.get(k));
                aacaMapper.addAccessApplicationCategory(categoryParams);
            }
            // ?
            String factory_area = params.get("factory_area").toString();
            params.put("factoryArea", factory_area);
            params.remove("factory_area");
            // ??
            String company_area = params.get("company_area").toString();
            params.put("companyArea", company_area);
            params.remove("company_area");
            //  ?
            if (params.get("use_begintime") != null) {
                String use_begintime = params.get("use_begintime").toString().substring(0, 10);
                params.put("use_begintime", use_begintime);
            }
            if (params.get("use_endtime") != null) {
                String use_endtime = params.get("use_endtime").toString().substring(0, 10);
                params.put("use_endtime", use_endtime);
            }
            AppInfoUtil(supplier_id, params);
        }
    }

    /**
     * @Description:?
     * SupplierFileService
     * AppInfoUtil
     * @param record_id
     * @param params void
     * @author yukai
     * 2016-10-18 ?4:33:57
     */
    public void AppInfoUtil(int supplier_id, Map<String, Object> params) {
        Map<String, Object> para = new HashMap<String, Object>();
        params.remove("reg_addr_code");
        Iterator<Map.Entry<String, Object>> it = params.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Object> entry = it.next();
            para.put("related_basis", entry.getKey());
            para.put("supplier_id", supplier_id);
            if ("cpyname_cn".equals(entry.getKey())) {
                para.put("related_basis", "cpyname_cn1");
            }
            //po?????code?
            if ("contact_addr_code".equals(entry.getKey())) {
                para.put("related_basis", "reg_addr_code");
            }
            //?e_id
            Integer e_ids = aaiService.getEID(para);
            if (e_ids != null) {
                int e_id = e_ids.intValue();
                para.put("e_id", e_id);
                if (entry.getValue() != null) {
                    para.put("content", entry.getValue().toString());
                    aaiService.updateAccessApplicationInfoBySupplierId(para);
                }
            }
        }
    }

    public List<SupplierFile> getOwnerCompanyList(Map<String, Object> params) {
        return mapper.getOwnerCompanyList(params);
    }

}