| | |
| | | package com.zy.asrs.controller; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.*; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.Mat; |
| | | import com.zy.asrs.entity.MatPrint; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.entity.result.KeyValueVo; |
| | | import com.zy.asrs.mapper.TagMapper; |
| | | import com.zy.asrs.service.ManPakOutService; |
| | | import com.zy.asrs.service.MatService; |
| | | import com.zy.asrs.service.OrderDetlService; |
| | | import com.zy.asrs.utils.MatExcelListener; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.config.AdminInterceptor; |
| | |
| | | import com.zy.common.utils.BarcodeUtils; |
| | | import com.zy.common.utils.QrCode; |
| | | import com.zy.common.web.BaseController; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | public class MatController extends BaseController { |
| | | |
| | | @Autowired |
| | | private MatService matService; |
| | | @Autowired |
| | | private OrderDetlService orderDetlService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private ManPakOutService manPakOutService; |
| | | |
| | | @RequestMapping(value = "/mat/auto/matnr/auth") |
| | | public R autoMatnr(){ |
| | |
| | | return R.ok().add(mats); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/mat/search/pda/auth") |
| | | @ManagerAuth |
| | | public R pdaSearch(@RequestParam(required = false)String condition){ |
| | |
| | | List<Mat> mats = matService.selectList(wrapper); |
| | | return R.ok().add(mats); |
| | | } |
| | | @RequestMapping(value = "/mat/list/pda/page/auth") |
| | | @ManagerAuth |
| | | public R pdaPageList(@RequestParam(required = true)Long tagId, |
| | | @RequestParam(defaultValue = "1")Integer curr, |
| | | @RequestParam(defaultValue = "10")Integer limit){ |
| | | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("tag_id", tagId); |
| | | wrapper.orderBy("create_time", false); |
| | | return R.ok().add(matService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/mat/{id}/auth") |
| | | @ManagerAuth |
| | |
| | | return R.ok(matService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/matCode/auth0") |
| | | @RequestMapping(value = "/mat/auth") |
| | | @ManagerAuth |
| | | public R find(@RequestParam("matnr") String matnr) { |
| | | return R.ok(matService.selectOne(new EntityWrapper<Mat>().eq("matnr", matnr))); |
| | |
| | | return R.ok(matService.getPage(new Page<>(curr, limit) |
| | | , String.valueOf(tagId) |
| | | , param.get("matnr") |
| | | , param.get("maktx")) |
| | | , param.get("maktx") |
| | | , param.get("batch")) |
| | | ); |
| | | |
| | | } |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @Resource |
| | | private TagMapper tagMapper; |
| | | |
| | | @RequestMapping(value = "/mat/export/auth") |
| | | @ManagerAuth |
| | | public R export(@RequestBody JSONObject param){ |
| | | EntityWrapper<Mat> wrapper = new EntityWrapper<>(); |
| | | List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); |
| | | Map<String, Object> map = excludeTrash(param.getJSONObject("mat")); |
| | | convert(map, wrapper); |
| | | List<Mat> list = matService.selectList(wrapper); |
| | | return R.ok(exportSupport(list, fields)); |
| | | public void export(@RequestBody JSONObject param, HttpServletResponse response) throws IOException { |
| | | //文件名 |
| | | String fileName =String.valueOf(System.currentTimeMillis()); |
| | | |
| | | OutputStream outputStream =null; |
| | | try { |
| | | //记录总数:实际中需要根据查询条件进行统计即可:一共多少条 |
| | | int totalCount=matService.selectCount(null); |
| | | //每一个Sheet存放100w条数据 |
| | | Integer sheetDataRows = 400000; |
| | | //每次写入的数据量20w,每页查询20W |
| | | Integer writeDataRows = 200000; |
| | | //计算需要的Sheet数量 |
| | | Integer sheetNum = totalCount % sheetDataRows == 0 ? (totalCount / sheetDataRows) : (totalCount / sheetDataRows + 1); |
| | | //计算一般情况下每一个Sheet需要写入的次数(一般情况不包含最后一个sheet,因为最后一个sheet不确定会写入多少条数据) |
| | | Integer oneSheetWriteCount = sheetDataRows / writeDataRows; |
| | | //计算最后一个sheet需要写入的次数 |
| | | Integer lastSheetWriteCount = totalCount % sheetDataRows == 0 ? oneSheetWriteCount : (totalCount % sheetDataRows % writeDataRows == 0 ? (totalCount / sheetDataRows / writeDataRows) : ((totalCount % sheetDataRows) / writeDataRows + 1)); |
| | | outputStream = response.getOutputStream(); |
| | | //必须放到循环外,否则会刷新流 |
| | | ExcelWriter excelWriter = EasyExcel.write(outputStream).build(); |
| | | //开始分批查询分次写入 |
| | | for (int i = 0; i < sheetNum; i++) { |
| | | //创建Sheet |
| | | WriteSheet sheet = new WriteSheet(); |
| | | sheet.setSheetName("Sheet"+i); |
| | | sheet.setSheetNo(i); |
| | | //循环写入次数: j的自增条件是当不是最后一个Sheet的时候写入次数为正常的每个Sheet写入的次数,如果是最后一个就需要使用计算的次数lastSheetWriteCount |
| | | for (int j = 0; j < (i != sheetNum - 1 ? oneSheetWriteCount : lastSheetWriteCount); j++) { |
| | | //分页查询一次20w |
| | | Page page1 = new Page(j + 1 + oneSheetWriteCount * i, writeDataRows); |
| | | //查询分页列表---按照自己的业务查列表,分页这个一定要使用这个:page1.getPageNum(),page1.getPageSize()!!! |
| | | List<Mat> list = matService.selectPage(new Page<>(page1.getCurrent(), page1.getLimit())).getRecords(); |
| | | List<Tag> tags = tagMapper.selectList(null); |
| | | // 所有类别 |
| | | Map<Long, String> tagMaps = tags.stream().collect(Collectors.toMap(Tag::getId,Tag::getName,(v1,v2) -> v1)); |
| | | // 归类id寻找归类名称 |
| | | list = list.stream().peek(mat -> mat.setUuid(tagMaps.get(mat.getTagId()))).collect(Collectors.toList()); |
| | | //写入到excel: |
| | | /**************z只需要选择一种方式即可*****************/ |
| | | //这里可以通过设置includeColumnFiledNames、excludeColumnFiledNames导出什么字段,可以动态配置,前端传过来那些列,就导出那些列 |
| | | //方式3、不做设置,全部导出 |
| | | WriteSheet writeSheet = EasyExcel.writerSheet(i, "Sheet" + (i + 1)).head(Mat.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build(); |
| | | excelWriter.write(list, writeSheet); |
| | | } |
| | | } |
| | | // 下载EXCEL,返回给前段stream流 |
| | | response.setContentType("application/octet-stream"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | excelWriter.finish(); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if (outputStream != null) { |
| | | outputStream.close(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @RequestMapping(value = "/matQuery/auth") |
| | |
| | | return R.ok(); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(orderDetl); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setAnfme(0.0D); |
| | | return R.ok().add(orderDetl); |
| | | } |
| | |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | @RequestMapping(value = "/order/print/auth") |
| | | @ManagerAuth(memo = "订单编码打印") |
| | | public R orderPrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<OrderDetl> res = new ArrayList<>(); |
| | | for (String orderNo : param){ |
| | | res = orderDetlService.selectList(new EntityWrapper<OrderDetl>().eq("order_no", orderNo)); |
| | | } |
| | | for (OrderDetl orderDetl: |
| | | res) { |
| | | orderDetl.setAnfme(orderDetl.getAnfme()-orderDetl.getWorkQty()); |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | @RequestMapping(value = "/pakOut/print/auth") |
| | | @ManagerAuth(memo = "拣货单编码打印") |
| | | public R pakOutPrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<ManPakOut> res = new ArrayList<>(); |
| | | for (String docNum : param){ |
| | | ManPakOut manPakOut = manPakOutService.selectOne(new EntityWrapper<ManPakOut>().eq("doc_num", docNum)); |
| | | res.add(manPakOut); |
| | | break; |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | @RequestMapping(value = "/pakOut/show") |
| | | public R showQR(){ |
| | | List<ManPakOut> manPakOuts = manPakOutService.selectList(null); |
| | | return R.ok(manPakOuts); |
| | | } |
| | | |
| | | |
| | | |
| | | /*************************************** 数据相关 ***********************************************/ |
| | | |
| | |
| | | /*************************************** xm-select ***********************************************/ |
| | | |
| | | // xm-select 搜索商品列表 |
| | | @RequestMapping("/mat/all/get/kv0") // todo:luxiaotao |
| | | @RequestMapping("/mat/all/get/kv") |
| | | @ManagerAuth |
| | | public R getMatDataKV(@RequestParam(required = false) String condition) { |
| | | Wrapper<Mat> wrapper = new EntityWrapper<Mat>() |
| | |
| | | for (Mat mat : mats) { |
| | | KeyValueVo vo = new KeyValueVo(); |
| | | vo.setName(mat.getMatnr() + " - " + mat.getMaktx()); |
| | | vo.setValue(mat.getId()); |
| | | vo.setValue(mat.getMatnr()); |
| | | valueVos.add(vo); |
| | | } |
| | | return R.ok().add(valueVos); |