@Override @Scheduled(cron = "0 37 0 * * *") public void saveAllCompanyFromKm() throws Exception { logger.info("开始同步所有K米商家信息"); long startTime = System.currentTimeMillis(); Dto param = new BaseDto(); param.put(TOKEN_NAME, getKmAccessToken()); KRespResParam resp = HttpClientUtils.post(getUrl(getAllCompany_path), param, KRespResParam.class); List<BaseDto> resList = resp.getRes(); if (resList != null) { // 初步过滤非法数据 fiterIllegalData(resList); List<Company> companyList = new ArrayList<>(); for (BaseDto dto : resList) { int companyid = dto.getAsInteger("companyid"); Company company = new Company(); company.setCompanyID(companyid); company.setCompanyCode(dto.getAsString("companycode")); company.setCompanyPsw(dto.getAsString("pass")); company.setCompanyType(dto.getAsString("companytype")); company.setCompanyName(dto.getAsString("companyname")); company.setRegionCode(dto.getAsString("regioncode")); company.setCompanyAddress(dto.getAsString("companyaddress")); company.setCompanyMemo(dto.getAsString("companymemo")); company.setCompanyURL(dto.getAsString("companyurl")); company.setCompanyStatus(dto.getAsInteger("status").byteValue()); company.setMapPositionX(dto.getAsString("mappositionx")); company.setMapPositionY(dto.getAsString("mappositiony")); companyList.add(company); } companyRepository.save(companyList); } long endtime = System.currentTimeMillis(); logger.info("结束同步所有K米商家信息,花费时间是{} S", (endtime - startTime) / 1000); }
/** * 获取商户 * * @param companyid */ private void getCompany(int companyid, Model model) { Company company = companyRepository.findOne(companyid); // 商家不能为空 AppUtils.assertCompanyNotNull(company); model.addAttribute(COMPANY, company); }