package com.zy.acs.manager.manager.controller.utils; import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.google.common.collect.Lists; import com.zy.acs.common.utils.Utils; import com.zy.acs.manager.common.annotation.OperationLog; import com.zy.acs.manager.manager.entity.Code; import com.zy.acs.manager.manager.entity.Loc; import com.zy.acs.manager.manager.service.CodeGapService; import com.zy.acs.manager.manager.service.CodeService; import com.zy.acs.manager.manager.service.LocService; import com.zy.acs.manager.manager.service.RouteService; import com.zy.acs.manager.system.controller.BaseController; import io.swagger.annotations.Api; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.List; import java.util.Map; /** * Created by vincent on 2023/6/12 */ @Api(tags = "Utils Api") @RestController @RequestMapping("/api/file") public class UtilsController extends BaseController { @Autowired private RouteService routeService; @Autowired private LocService locService; @Autowired private CodeService codeService; @Autowired private CodeGapService codeGapService; /** * 文件上传 *
* 1. 创建excel对应的实体对象 参照{@link Map
* 2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link MapDataListener}
*
* 3. 直接读即可
*/
@RequestMapping("/excel/map/import")
@ResponseBody
@OperationLog("import map data")
public String upload(MultipartFile file) throws IOException {
EasyExcel.read(file.getInputStream(), new MapDataListener(routeService, codeService, codeGapService)).sheet().doRead();
return "success";
}
private List