|
@@ -452,6 +452,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private ResponseJson saveExcelData(String filePath, Integer authUserId, Integer createBy) {
|
|
|
//判断是否为excel类型文件
|
|
|
if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
|
|
@@ -460,6 +461,173 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 获取供应商品牌
|
|
|
List<String> shopBrands = shopService.getShopBrands(authUserId);
|
|
|
|
|
|
+ // 授权列表
|
|
|
+ List<CmBrandAuthPo> authImportList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileInputStream fis = new FileInputStream(filePath);
|
|
|
+ // 得到表格数据
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(fis);
|
|
|
+
|
|
|
+ //得到第一个工作表(机构表)
|
|
|
+ XSSFSheet authPartySheet = workbook.getSheetAt(0);
|
|
|
+ //获得表头
|
|
|
+ Row rowHead = authPartySheet.getRow(0);
|
|
|
+ //判断表头是否正确
|
|
|
+ if (7 != rowHead.getLastCellNum() || !"机构名称".equals(rowHead.getCell(0).getStringCellValue())) {
|
|
|
+ return ResponseJson.error("授权机构表格式错误");
|
|
|
+ }
|
|
|
+ // 获得数据的总行数
|
|
|
+ int authPartyRowNum = authPartySheet.getLastRowNum();
|
|
|
+
|
|
|
+ //获得所有数据
|
|
|
+ for (int i = 1; i <= authPartyRowNum; i++) {
|
|
|
+ //获得第i行对象
|
|
|
+ Row authPartyRow = authPartySheet.getRow(i);
|
|
|
+ // 校验机构名称
|
|
|
+ String authParty = authPartyRow.getCell(0).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(authParty)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行机构名称不能为空");
|
|
|
+ }
|
|
|
+ // 校验省市区
|
|
|
+ String area = authPartyRow.getCell(1).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(area)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行所在地区不能为空");
|
|
|
+ }
|
|
|
+ String[] areaSplit = area.split("/");
|
|
|
+ if (areaSplit.length < 2 || areaSplit.length > 3) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行所在地区格式错误");
|
|
|
+ }
|
|
|
+ // 省份
|
|
|
+ String provinceName = areaSplit[0];
|
|
|
+ if (StringUtils.isEmpty(provinceName)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行省份不能为空");
|
|
|
+ }
|
|
|
+ if (provinceName.length() > 2) {
|
|
|
+ provinceName = provinceName.substring(0, provinceName.length() - 1).trim();
|
|
|
+ }
|
|
|
+ Integer provinceId = authMapper.getProvinceId(provinceName);
|
|
|
+ // 市名
|
|
|
+ String cityName = areaSplit[1];
|
|
|
+ if (StringUtils.isEmpty(cityName)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行市名不能为空");
|
|
|
+ }
|
|
|
+ if (cityName.length() > 2) {
|
|
|
+ cityName = cityName.substring(0, cityName.length() - 1).trim();
|
|
|
+ }
|
|
|
+ Integer cityId = authMapper.getCityId(cityName);
|
|
|
+ // 区名
|
|
|
+ Integer townId = null;
|
|
|
+ if (areaSplit.length > 2) {
|
|
|
+ String townName = areaSplit[2];
|
|
|
+ if (StringUtils.isNotEmpty(townName) && townName.length() > 2) {
|
|
|
+ townName = townName.substring(0, townName.length() - 1).trim();
|
|
|
+ }
|
|
|
+ List<TownPo> townList = authMapper.getTownList(townName);
|
|
|
+ for (int j = 0; j < townList.size(); i++) {
|
|
|
+ TownPo town = townList.get(j);
|
|
|
+ if (null == townId) {
|
|
|
+ if (null != cityId) {
|
|
|
+ if (town.getCityId().equals(cityId)) {
|
|
|
+ townId = town.getTownId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Integer checkCityId = authMapper.getCityIdByTownId(town.getTownId());
|
|
|
+ if (null != provinceId && null != checkCityId) {
|
|
|
+ Integer checkProvinceId = authMapper.getProvinceIdByCityId(cityId);
|
|
|
+ if (provinceId.equals(checkProvinceId)) {
|
|
|
+ cityId = checkCityId;
|
|
|
+ townId = town.getTownId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验详细地址
|
|
|
+ String address = authPartyRow.getCell(2).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(address)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行所在地区不能为空");
|
|
|
+ }
|
|
|
+ // 校验经纬度
|
|
|
+ String lngAndLat = authPartyRow.getCell(3).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(lngAndLat)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行经纬度不能为空");
|
|
|
+ }
|
|
|
+ String[] split = lngAndLat.split(",");
|
|
|
+ if (2 != split.length) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行经纬度格式错误");
|
|
|
+ }
|
|
|
+ BigDecimal lng = new BigDecimal(split[0]);
|
|
|
+ BigDecimal lat = new BigDecimal(split[1]);
|
|
|
+ // 校验联系电话
|
|
|
+ String mobile = authPartyRow.getCell(4).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(mobile)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行联系电话不能为空");
|
|
|
+ }
|
|
|
+ // 校验员工人数
|
|
|
+ Integer empNum = null;
|
|
|
+ String empNumStr = authPartyRow.getCell(5).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(empNumStr)) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行员工人数不能为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ empNum = Integer.parseInt(empNumStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return ResponseJson.error("第" + i + 1 + "行员工人数格式错误");
|
|
|
+ }
|
|
|
+ // 校验店铺备注
|
|
|
+ String remarks = authPartyRow.getCell(6).getStringCellValue();
|
|
|
+ Integer customFlag = 0;
|
|
|
+ if (StringUtils.isNotEmpty(remarks)) {
|
|
|
+ customFlag = 1;
|
|
|
+ }
|
|
|
+ CmBrandAuthPo authPo = new CmBrandAuthPo();
|
|
|
+ authPo.setAuthParty(authParty);
|
|
|
+ authPo.setProvinceId(provinceId);
|
|
|
+ authPo.setCityId(cityId);
|
|
|
+ authPo.setTownId(townId);
|
|
|
+ authPo.setAddress(address);
|
|
|
+ authPo.setLng(lng);
|
|
|
+ authPo.setLat(lat);
|
|
|
+ authPo.setMobile(mobile);
|
|
|
+ authPo.setEmpNum(empNum);
|
|
|
+ authPo.setCustomFlag(customFlag);
|
|
|
+ authPo.setRemarks(remarks);
|
|
|
+ authImportList.add(authPo);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseJson.error("导入失败,请检查表格数据");
|
|
|
+ } finally {
|
|
|
+ // 删除临时数据
|
|
|
+ File tempFile = new File(filePath);
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时表格:" + delete);
|
|
|
+ }
|
|
|
+ // 保存授权数据
|
|
|
+ authImportList.forEach(authPo -> {
|
|
|
+ // 保存授权机构
|
|
|
+ CmBrandAuthPo auth = new CmBrandAuthPo();
|
|
|
+ auth.setAuthUserId(authUserId);
|
|
|
+ auth.setCreateBy(createBy);
|
|
|
+ // 导入数据
|
|
|
+ ResponseJson responseJson = saveAuth(auth, null, true, 1);
|
|
|
+ });
|
|
|
+ return ResponseJson.success("导入成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 已停用
|
|
|
+ */
|
|
|
+ private ResponseJson saveExcelDataBak(String filePath, Integer authUserId, Integer createBy) {
|
|
|
+ //判断是否为excel类型文件
|
|
|
+ if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
|
|
|
+ System.out.println("文件不是excel类型");
|
|
|
+ }
|
|
|
+ // 获取供应商品牌
|
|
|
+ List<String> shopBrands = shopService.getShopBrands(authUserId);
|
|
|
+
|
|
|
// 授权列表
|
|
|
List<AuthImportPo> authImportList = new ArrayList<>();
|
|
|
|