瀏覽代碼

更新导入

liu 9 月之前
父節點
當前提交
701f5f460e

+ 3 - 1
src/main/java/com/sqx/modules/address/controller/AdminInsideAddressController.java

@@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Valid;
+import java.io.IOException;
+import java.text.ParseException;
 import java.util.List;
 
 
@@ -84,7 +86,7 @@ public class AdminInsideAddressController {
 
     @PostMapping("import")
     @ApiOperation("导入内部地址列表")
-    public void importData(@RequestParam("file") MultipartFile file) {
+    public void importData(@RequestParam("file") MultipartFile file) throws IOException, ParseException {
         if (file.isEmpty()) {
             throw new SqxException("请选择需要上传的文件");
         }

+ 3 - 1
src/main/java/com/sqx/modules/address/service/InsideAddressService.java

@@ -10,6 +10,8 @@ import com.sqx.modules.address.vo.InsideAddressShortVO;
 import com.sqx.modules.address.vo.InsideAddressVO;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.text.ParseException;
 import java.util.List;
 
 /**
@@ -61,6 +63,6 @@ public interface InsideAddressService extends IService<InsideAddress> {
      * 导入内部地址列表
      * @param file 导入文件
      */
-    void importData(MultipartFile file);
+    void importData(MultipartFile file)throws IOException, ParseException;
 
 }

+ 186 - 19
src/main/java/com/sqx/modules/address/service/impl/InsideAddressServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.sqx.common.exception.SqxException;
@@ -17,12 +18,28 @@ import com.sqx.modules.address.entity.InsideAddress;
 import com.sqx.modules.address.query.InsideAddressQuery;
 import com.sqx.modules.address.service.InsideAddressService;
 import com.sqx.modules.address.vo.InsideAddressVO;
+import com.sqx.modules.riderStation.entity.RiderStation;
+import com.sqx.modules.riderStation.service.RiderStationService;
 import com.sqx.modules.utils.excel.EasyExcelUtil;
 import com.sqx.modules.utils.excel.ExcelFinishCallBack;
+import com.sqx.modules.utils.excel.ExcelUtils;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.checkerframework.checker.units.qual.A;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -34,6 +51,9 @@ import java.util.stream.Collectors;
 @Service
 public class InsideAddressServiceImpl extends ServiceImpl<InsideAddressDao, InsideAddress> implements InsideAddressService {
 
+    @Autowired
+    RiderStationService riderStationService;
+
     @Override
     public PageUtils pages(InsideAddressQuery query) {
         Page<InsideAddress> page = new Page<>(query.getPage(), query.getLimit());
@@ -111,31 +131,178 @@ public class InsideAddressServiceImpl extends ServiceImpl<InsideAddressDao, Insi
     }
 
     @Override
-    public void importData(MultipartFile file) {
-        EasyExcelUtil.readAnalysis(file, InsideAddressDTO.class, new ExcelFinishCallBack<InsideAddressDTO>() {
-            @Override
-            public void doAfterAllAnalysed(List<InsideAddressDTO> result) {
-                if (CollUtil.isNotEmpty(result)) {
-                    saveBatch(result);
+    public void importData(MultipartFile file) throws IOException, ParseException {
+        InputStream inputStream = file.getInputStream();
+        XSSFWorkbook sheets = new XSSFWorkbook(inputStream);
+        //读取第一张sheet
+        XSSFSheet sheetAt = sheets.getSheetAt(0);
+        DataFormatter dataFormatter = new DataFormatter();
+        ArrayList<InsideAddress> insideAddresses = new ArrayList<>();
+        for (int rowNum = 0; rowNum < sheetAt.getLastRowNum() + 1; rowNum++) {
+            XSSFRow row = sheetAt.getRow(rowNum);
+            if (row != null) {
+                if (rowNum == 0) {
+                    String stationName = dataFormatter.formatCellValue(row.getCell(0));//骑手站点
+                    if (!stationName.equals("骑手站点")) {
+                        throw new SqxException("导入数据第一列为骑手站点");
+                    }
+                    String province = dataFormatter.formatCellValue(row.getCell(1));//省
+                    if (!province.equals("省")) {
+                        throw new SqxException("导入数据第二列为省");
+                    }
+                    String city = dataFormatter.formatCellValue(row.getCell(2));//市
+                    if (!city.equals("市")) {
+                        throw new SqxException("导入数据第三列为市");
+                    }
+                    String district = dataFormatter.formatCellValue(row.getCell(3));//区/县
+                    if (!district.equals("区/县")) {
+                        throw new SqxException("导入数据第四列为区/县");
+                    }
+                    String addressDetail = dataFormatter.formatCellValue(row.getCell(4));//地址名
+                    if (!addressDetail.equals("地址名")) {
+                        throw new SqxException("导入数据第五列为地址名");
+                    }
+                    String lng = dataFormatter.formatCellValue(row.getCell(5));//经度
+                    if (!lng.equals("经度")) {
+                        throw new SqxException("导入数据第六列为经度");
+                    }
+                    String lat = dataFormatter.formatCellValue(row.getCell(6));//纬度
+                    if (!lat.equals("纬度")) {
+                        throw new SqxException("导入数据第列七为纬度");
+                    }
+                    String deliveryFee = dataFormatter.formatCellValue(row.getCell(7));//地址配送费
+                    if (!deliveryFee.equals("地址配送费")) {
+                        throw new SqxException("导入数据第列七为地址配送费");
+                    }
+                    String sort = dataFormatter.formatCellValue(row.getCell(8));//排序
+                    if (!sort.equals("排序")) {
+                        throw new SqxException("导入数据第列七为排序");
+                    }
+                    String status = dataFormatter.formatCellValue(row.getCell(9));//是否启用
+                    if (!status.equals("是否启用")) {
+                        throw new SqxException("导入数据第列七为是否启用");
+                    }
+
+                }else {
+                    InsideAddress insideAddress = new InsideAddress();
+                    String stationName = dataFormatter.formatCellValue(row.getCell(0));//骑手站点
+                    if (ObjectUtils.isNotEmpty(stationName)) {
+                        RiderStation riderStation=riderStationService.getName(stationName);
+                        if (ObjectUtils.isNotEmpty(riderStation)) {
+                            insideAddress.setStationId(riderStation.getId());
+                        }else {
+                            int h = rowNum + 1;
+                            throw new SqxException("第" + h + "行,骑手站点不存在");
+                        }
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,骑手站点为空");
+                    }
+                    String province = dataFormatter.formatCellValue(row.getCell(1));//省
+                    if (ObjectUtils.isNotEmpty(province)) {
+                        insideAddress.setProvince(province);
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,省为空");
+                    }
+
+                    String city = dataFormatter.formatCellValue(row.getCell(2));//市
+                    if (ObjectUtils.isNotEmpty(city)) {
+                        insideAddress.setCity(city);
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,市为空");
+                    }
+
+                    String district = dataFormatter.formatCellValue(row.getCell(3));//区/县
+                    if (ObjectUtils.isNotEmpty(district)) {
+                        insideAddress.setDistrict(district);
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,市为空");
+                    }
+
+                    String addressDetail = dataFormatter.formatCellValue(row.getCell(4));//地址名
+                    if (ObjectUtils.isNotEmpty(addressDetail)) {
+//                        判断地址是否重复
+                        long count = baseMapper.selectCount(new LambdaQueryWrapper<InsideAddress>()
+                                .eq(InsideAddress::getAddressDetail, addressDetail));
+                        if (count > 0) {
+                            throw new SqxException("地址详情不能重复");
+                        }
+                        insideAddress.setAddressDetail(addressDetail);
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,地址名为空");
+                    }
+
+                    String lng = dataFormatter.formatCellValue(row.getCell(5));//经度
+                    if (ObjectUtils.isNotEmpty(lng)) {
+                        insideAddress.setLng(Double.valueOf(lng));
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,经度为空");
+                    }
+
+                    String lat = dataFormatter.formatCellValue(row.getCell(6));//纬度
+                    if (ObjectUtils.isNotEmpty(lat)) {
+                        insideAddress.setLat(Double.valueOf(lat));
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,纬度为空");
+                    }
+
+                    String deliveryFee = dataFormatter.formatCellValue(row.getCell(7));//地址配送费
+                    if (ObjectUtils.isNotEmpty(deliveryFee)) {
+                        insideAddress.setDelFlag(deliveryFee);
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,地址配送费为空");
+                    }
+
+                    String sort = dataFormatter.formatCellValue(row.getCell(8));//排序
+                    if (ObjectUtils.isNotEmpty(sort)) {
+                        insideAddress.setSort(Integer.valueOf(sort));
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,排序为空");
+                    }
+
+                    String status = dataFormatter.formatCellValue(row.getCell(9));//是否启用
+                    if (ObjectUtils.isNotEmpty(status)) {
+                        if (status.equals("启用")) {
+                            insideAddress.setStatus("1");
+                        }else {
+                            insideAddress.setStatus("0");
+                        }
+                    }else {
+                        int h = rowNum + 1;
+                        throw new SqxException("第" + h + "行,是否启用为空");
+                    }
+
+                    insideAddress.setDelFlag(Constant.NO);
+                    insideAddress.setCreateTime(new Date());
+                    insideAddress.setUpdateTime(new Date());
+
+                    insideAddresses.add(insideAddress);
                 }
             }
 
-            @Override
-            public void doSaveBatch(List<InsideAddressDTO> result) {
-                saveBatch(result);
+        }
+//        去掉导入表的重复数据,并且重复地址只取第一条
+        ArrayList<InsideAddress> list = new ArrayList<>();
+        ArrayList<String> addressDetailList = new ArrayList<>();
+        for (int i = 0; i < insideAddresses.size(); i++) {
+            InsideAddress insideAddress = insideAddresses.get(i);
+            String addressDetail = insideAddress.getAddressDetail();
+            if (!list.contains(insideAddress)&&!addressDetailList.contains(addressDetail)) {
+                list.add(insideAddress);
+                addressDetailList.add(addressDetail);
             }
+        }
 
-            private void saveBatch(List<InsideAddressDTO> dtoList) {
-                List<InsideAddress> list = dtoList.stream().map(item -> {
-                    ValidatorUtils.validateEntity(item);
-                    InsideAddress address = new InsideAddress();
-                    BeanUtil.copyProperties(item, address);
-                    return address;
-                }).collect(Collectors.toList());
+        this.saveBatch(list);
 
-                saveOrUpdateBatch(list);
-            }
-        });
     }
 
     private void checkAddressUnique(InsideAddressDTO insideAddressDTO) {

+ 2 - 0
src/main/java/com/sqx/modules/riderStation/service/RiderStationService.java

@@ -21,4 +21,6 @@ public interface RiderStationService extends IService<RiderStation> {
     Result updateStation(RiderStation riderStation);
 
     Result removeStation(Integer id);
+
+    RiderStation getName(String stationName);
 }

+ 8 - 0
src/main/java/com/sqx/modules/riderStation/service/impl/RiderStationServiceImpl.java

@@ -101,4 +101,12 @@ public class RiderStationServiceImpl extends ServiceImpl<RiderStationDao, RiderS
         return Result.success();
     }
 
+    @Override
+    public RiderStation getName(String stationName) {
+        LambdaQueryWrapper<RiderStation> wrapper=new LambdaQueryWrapper<>();
+        wrapper.eq(RiderStation::getStationName,stationName);
+        RiderStation station = this.getOne(wrapper);
+        return station;
+    }
+
 }

+ 1 - 1
src/main/java/com/sqx/scheduler/export/ExportScheduler.java

@@ -435,5 +435,5 @@ public class ExportScheduler {
         PlatformBillDto query = getPlatformBillDto(exportJob);
         return platformBillService.excelPlatformBillList(query);
     }
-    
+
 }

+ 0 - 1
src/main/resources/application-dev.yml

@@ -96,7 +96,6 @@ secure-api:
             - /app/wxPay/notify
             - /app/wxPay/notifyJsApi
             - /app/wxPay/notifyShop
-            - 、
             - /app/wxPay/notifyJsApiShop
             - /app/wxPay/notifyMpShop
             - /pay/open/notify

+ 2 - 2
src/main/resources/application.yml

@@ -79,8 +79,8 @@ mybatis-plus:
     cache-enabled: false
     call-setters-on-nulls: true
     jdbc-type-for-null: 'null'
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-#    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl