自动化立体仓库 - WMS系统
#
zjj
2024-09-23 539d9ffc477d28a23a923b41fdeabc8c37c99ce6
src/main/java/com/zy/asrs/controller/LocOwnerController.java
@@ -1,22 +1,34 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSONArray;
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.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.zy.asrs.entity.LocOwner;
import com.zy.asrs.service.LocOwnerService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
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 java.util.*;
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;
import java.util.Map;
@RestController
public class LocOwnerController extends BaseController {
@@ -112,13 +124,16 @@
    @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<String, Object> map = new HashMap<>();
            map.put("id", locOwner.getId());
            map.put("value", locOwner.getId());
            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);
@@ -134,4 +149,34 @@
        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物料数据");
    }
}