|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.excel.EasyExcel; | 
|---|
|  |  |  | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.DateUtils; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocOwner; | 
|---|
|  |  |  | import com.zy.asrs.service.LocOwnerService; | 
|---|
|  |  |  | import com.zy.asrs.utils.LocOwnerExcelListener; | 
|---|
|  |  |  | import com.zy.common.entity.LocOwnerExcel; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R query(String condition) { | 
|---|
|  |  |  | EntityWrapper<LocOwner> wrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | wrapper.like("id", condition); | 
|---|
|  |  |  | wrapper.like("owner", condition); | 
|---|
|  |  |  | Page<LocOwner> page = locOwnerService.selectPage(new Page<>(0, 10), wrapper); | 
|---|
|  |  |  | List<Map<String, Object>> result = new ArrayList<>(); | 
|---|
|  |  |  | for (LocOwner locOwner : page.getRecords()){ | 
|---|
|  |  |  | 
|---|
|  |  |  | map.put("value", locOwner.getOwner()); | 
|---|
|  |  |  | map.put("phone", locOwner.getPhone()); | 
|---|
|  |  |  | map.put("addr", locOwner.getAddr()); | 
|---|
|  |  |  | map.put("type", "locOwner"); | 
|---|
|  |  |  | result.add(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(result); | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * excel导入模板下载 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RequestMapping(value = "/locOwner/excel/import/mould") | 
|---|
|  |  |  | public void plaExcelImportMould(HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | List<LocOwnerExcel> excels = new ArrayList<>(); | 
|---|
|  |  |  | response.setContentType("application/vnd.ms-excel"); | 
|---|
|  |  |  | response.setCharacterEncoding("utf-8"); | 
|---|
|  |  |  | String fileName = URLEncoder.encode("货主档案导入模板", "UTF-8"); | 
|---|
|  |  |  | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); | 
|---|
|  |  |  | EasyExcel.write(response.getOutputStream(), LocOwnerExcel.class) | 
|---|
|  |  |  | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) | 
|---|
|  |  |  | .sheet("sheet1") | 
|---|
|  |  |  | .doWrite(excels); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // excel导入 | 
|---|
|  |  |  | @PostMapping(value = "/locOwner/excel/import/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "货主档案数据导入") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R matExcelImport(MultipartFile file) throws IOException { | 
|---|
|  |  |  | LocOwnerExcelListener listener = new LocOwnerExcelListener(getUserId()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | EasyExcel.read(file.getInputStream(), LocOwnerExcel.class, listener).sheet().doRead(); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | throw new CoolException("导入的数据格式错误,原因:" + e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok("成功同步"+listener.getTotal()+"条pla物料数据"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|