package com.zy.asrs.wms.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zy.asrs.common.domain.CodeRes; import com.zy.asrs.common.domain.entity.LocInPrintMatExcel; import com.zy.asrs.common.domain.entity.MatExcel; import com.zy.asrs.common.domain.entity.MatPrint; import com.zy.asrs.common.domain.entity.OutLocOrderExcel; import com.zy.asrs.common.utils.*; import com.zy.asrs.common.wms.entity.LocInPrintMat; import com.zy.asrs.common.wms.entity.Mat; import com.zy.asrs.common.wms.entity.Tag; import com.zy.asrs.common.wms.service.LocInPrintMatService; import com.zy.asrs.common.wms.service.MatService; import com.zy.asrs.common.wms.service.TagService; import com.zy.asrs.framework.annotations.ManagerAuth; import com.zy.asrs.framework.common.BaseRes; import com.zy.asrs.framework.common.Cools; import com.zy.asrs.framework.common.R; import com.zy.asrs.framework.domain.KeyValueVo; import com.zy.asrs.framework.common.DateUtils; import com.zy.asrs.common.web.BaseController; import com.zy.asrs.wms.config.AdminInterceptor; 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.imageio.ImageIO; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URLEncoder; import java.util.*; @RestController public class TagController extends BaseController { @Autowired private TagService tagService; @Autowired private MatService matService; @Autowired private TreeUtils treeUtils; @Autowired private LocInPrintMatService locInPrintMatService; @RequestMapping(value = "/tag/list/pda/auth") @ManagerAuth public R pdaList(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam(required = false)Long parentId){ LambdaQueryWrapper tagLambdaQueryWrapper = new LambdaQueryWrapper<>(); if(!Cools.isEmpty(parentId)) { tagLambdaQueryWrapper.eq(Tag::getParentId, parentId == null ? getOriginTag().getId() : parentId); } List tags = tagService.list(tagLambdaQueryWrapper); return R.ok().add(tags); } @RequestMapping(value = "/tag/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(tagService.getById(String.valueOf(id))); } @RequestMapping(value = "/tag/page/auth") @ManagerAuth public R page(@RequestParam(defaultValue = "1")Integer curr, @RequestParam(defaultValue = "10")Integer limit, @RequestParam(required = false)String orderByField, @RequestParam(required = false)String orderByType, @RequestParam Map param) { Long hostId = getHostId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Tag::getHostId, hostId); excludeTrash(param); return R.parse("0-操作成功").add(tagService.list(wrapper)); } @RequestMapping(value = "/tag/add/auth") @ManagerAuth public R add(Tag tag) { tag.setHostId(getHostId()); tag.setStatus(1); tagService.save(tag); return R.ok(); } @RequestMapping(value = "/tag/update/auth") @ManagerAuth public R update(Tag tag){ if (Cools.isEmpty(tag) || null== tag.getId()){ return R.error(); } tagService.updateById(tag); return R.ok(); } @RequestMapping(value = "/tag/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ tagService.removeById(id); } return R.ok(); } @RequestMapping(value = "/tagQuery/auth") @ManagerAuth public R query(String condition) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.like(Tag::getId, condition); Page page = tagService.page(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (Tag tag : page.getRecords()){ Map map = new HashMap<>(); map.put("id", tag.getId()); map.put("value", tag.getId()); result.add(map); } return R.ok(result); } @RequestMapping("/tag/all/get/kv") @ManagerAuth public R getDataKV(@RequestParam(required = false) String condition) { List vos = new ArrayList<>(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (!Cools.isEmpty(condition)) { wrapper.like(Tag::getId, condition); } tagService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId()))); return R.ok().add(vos); } @PostMapping(value = "/tag/tree/auth") @ManagerAuth public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException { ArrayList tree = treeUtils.getTree(getOriginTag().getId(), getHostId()); // 深拷贝 List result = ListUtils.deepCopy(tree); if (!Cools.isEmpty(condition)) { treeUtils.remove(condition, result); treeUtils.remove(condition, result); } return R.ok(result); } /*************************************** 打印相关 ***********************************************/ @RequestMapping(value = "/mac/code/auth") // @ManagerAuth(memo = "物料编码条形码获取(type:1(条形码);2(二维码)") public R matCodeBarcode(@RequestParam(defaultValue = "1") Integer type , @RequestParam String param , HttpServletResponse response) throws Exception { AdminInterceptor.cors(response); if (Cools.isEmpty(param)){ return R.parse(BaseRes.EMPTY); } BufferedImage img; if (type == 1) { img = BarcodeUtils.encode(param); } else { img = QrCode.createImg(param); } if (!ImageIO.write(img, "jpg", response.getOutputStream())) { throw new IOException("Could not write an image of format jpg"); } response.getOutputStream().flush(); response.getOutputStream().close(); return R.ok(); } // 打印 @RequestMapping(value = "/mat/print/auth") @ManagerAuth(memo = "商品编码打印") public R matCodePrint(@RequestParam(value = "param[]") String[] param) { if(Cools.isEmpty(param)) { return R.parse(CodeRes.EMPTY); } List res = new ArrayList<>(); for (String matnr : param){ Mat mat = matService.getOne(new LambdaQueryWrapper().eq(Mat::getMatnr, matnr)); // 打印数据注入 MatPrint print = new MatPrint(); print.setMatnr(mat.getMatnr()); print.setBarcode(mat.getBarcode()); print.setMaktx(mat.getMaktx()); print.setSpecs(mat.getSpecs()); print.setUnit(mat.getUnit()); print.setMemo(mat.getMemo()); print.setMaterial(mat.getMaterial()); print.setDecrees(mat.getDecrees()); print.setImgNum(mat.getImgNum()); print.setWeight(String.valueOf(mat.getWeight())); print.setModel(mat.getModel()); print.setLength(String.valueOf(mat.getLength())); print.setWidth(mat.getWidth()); print.setHeight(mat.getHeight()); res.add(print); } return R.ok().add(res); } // 打印 @RequestMapping(value = "/loc/in/mat/print/auth") @ManagerAuth(memo = "商品编码打印") public R locInMatCodePrint(@RequestParam(value = "param[]") Long[] ids) { if(Cools.isEmpty(ids)) { return R.parse(CodeRes.EMPTY); } List res = new ArrayList<>(); for (Long id : ids){ LocInPrintMat locInPrintMat = locInPrintMatService.getById(id); Mat mat = matService.getOne(new LambdaQueryWrapper().eq(Mat::getMatnr, locInPrintMat.getMatnr())); if (Cools.isEmpty(mat)){ return R.error("品号:"+locInPrintMat.getMatnr()+"不存在,请先新增商品档案!!!").add("品号:"+locInPrintMat.getMatnr()+"不存在,请先新增商品档案!!!"); } int count=1; if(!Cools.isEmpty(locInPrintMat.getAnfme())){ count=locInPrintMat.getAnfme().intValue(); } for(int i=1;i<=count;i++){ // 打印数据注入 MatPrint print = new MatPrint(); print.setMatnr(mat.getMatnr()); print.setBarcode(mat.getBarcode()); print.setMaktx(mat.getMaktx()); print.setSpecs(mat.getSpecs()); print.setUnit(mat.getUnit()); print.setMemo(mat.getMemo()); print.setMaterial(mat.getMaterial()); print.setDecrees(locInPrintMat.getDecrees()); print.setImgNum(mat.getImgNum()); print.setWeight(String.valueOf(mat.getWeight())); print.setModel(mat.getModel()); print.setLength(String.valueOf(mat.getLength())); print.setWidth(mat.getWidth()); print.setHeight(mat.getHeight()); // // 打印数据注入 // MatPrint print = new MatPrint(); // print.setMatnr(locInPrintMat.getMatnr()); // print.setMaktx(locInPrintMat.getMaktx()); // print.setBatch(locInPrintMat.getBatch()); // print.setAnfme(locInPrintMat.getAnfme()); // print.setLocNo(locInPrintMat.getLocNo()); // print.setOwnerId(locInPrintMat.getOwnerId()); // print.setOwner(locInPrintMat.getOwner$()); print.setId(locInPrintMat.getId()); res.add(print); } locInPrintMat.setUpdateTime(new Date()); locInPrintMat.setUpdateBy(getUserId()); locInPrintMat.setStatus(2); locInPrintMatService.updateById(locInPrintMat); } return R.ok().add(res); } /*************************************** 数据相关 ***********************************************/ /** * excel导入模板下载 */ @RequestMapping(value = "/mat/excel/import/mould") public void matExcelImportMould(HttpServletResponse response) throws IOException { List excels = new ArrayList<>(); response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); String fileName = URLEncoder.encode("商品档案Excel导入模板", "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); EasyExcel.write(response.getOutputStream(), MatExcel.class) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .sheet("sheet1") .doWrite(excels); } // // excel导入-------判断是否有重复物料 // @PostMapping(value = "/mat/excel/import/check/auth") // @ManagerAuth(memo = "商品档案数据导入") // @Transactional // public R matExcelImportCheck(MultipartFile file) throws IOException { // MatExcelListener listener = new MatExcelListener(getUserId(), getHostId()); // EasyExcel.read(file.getInputStream(), MatExcel.class, listener).sheet().doRead(); // return R.ok("成功同步"+listener.getTotal()+"条商品数据"); // } // excel导入 @PostMapping(value = "/mat/excel/import/auth") @ManagerAuth(memo = "商品档案数据导入") @Transactional public R matExcelImport(MultipartFile file) throws IOException { MatExcelListener listener = new MatExcelListener(getUserId(), getHostId()); EasyExcel.read(file.getInputStream(), MatExcel.class, listener).sheet().doRead(); return R.ok("成功同步"+listener.getTotal()+"条商品数据"); } /** * excel导入模板下载 */ @RequestMapping(value = "/out/loc/box/excel/import/mould") public void outLocBoxExcelImportMould(HttpServletResponse response) throws IOException { List 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(), LocInPrintMatExcel.class) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .sheet("待打印物料模板") .doWrite(excels); } // excel导入 @PostMapping(value = "/out/loc/box/excel/import/auth") @ManagerAuth(memo = "导入待打印物料模板") @Transactional public R outLocBoxExcelImport(MultipartFile file) throws IOException { LocInPrintMatExcelListener listener = new LocInPrintMatExcelListener(getUserId(), getHostId()); EasyExcel.read(file.getInputStream(), LocInPrintMatExcel.class, listener).sheet().doRead(); return R.ok("成功导入"+listener.getTotal()[0]+"种待打印物料信息,共生成"+listener.getTotal()[1]+"条待打印条码!"); } /** * excel导入模板下载 */ @RequestMapping(value = "/out/loc/box/excel/import/out/mould") public void outLocBoxExcelImportOutMould(HttpServletResponse response) throws IOException { List 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(), OutLocOrderExcel.class) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) .sheet("出库模板") .doWrite(excels); } // excel导入 @PostMapping(value = "/out/loc/box/excel/import/out/auth") @ManagerAuth(memo = "导入订单信息出库") @Transactional public R outLocBoxExcelImportOut(MultipartFile file) throws IOException { OutLocOrderExcelListener listener = new OutLocOrderExcelListener(getUserId(), getHostId()); EasyExcel.read(file.getInputStream(), OutLocOrderExcel.class, listener).sheet().doRead(); return R.ok("成功导入"+listener.getTotal()[0]+"条订单明细!"); } }