| | |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.MatCode; |
| | | import com.zy.asrs.entity.MatCodePrint; |
| | | import com.zy.asrs.entity.OrderDetl; |
| | | import com.zy.asrs.service.MatCodeService; |
| | | import com.zy.asrs.utils.VersionUtils; |
| | | import com.zy.common.CodeRes; |
| | | import com.zy.common.config.AdminInterceptor; |
| | | import com.zy.common.model.KeyValueVo; |
| | | import com.zy.common.utils.BarcodeUtils; |
| | | import com.zy.common.utils.QrCode; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcel; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcelListener; |
| | | 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; |
| | | |
| | |
| | | @Autowired |
| | | private MatCodeService matCodeService; |
| | | |
| | | /*************************************** xm-select ***********************************************/ |
| | | |
| | | // xm-select 搜索商品列表 |
| | | @RequestMapping("/mat/all/get/kv") |
| | | @ManagerAuth |
| | | public R getMatDataKV(@RequestParam(required = false) String condition) { |
| | | Wrapper<MatCode> wrapper = new EntityWrapper<MatCode>() |
| | | .andNew().like("mat_no", condition).or().like("mat_name", condition) |
| | | .orderBy("appe_time", false); |
| | | List<MatCode> mats = matCodeService.selectPage(new Page<>(1, 30), wrapper).getRecords(); |
| | | List<KeyValueVo> valueVos = new ArrayList<>(); |
| | | for (MatCode mat : mats) { |
| | | KeyValueVo vo = new KeyValueVo(); |
| | | vo.setName(mat.getMatNo() + " - " + mat.getMatName()); |
| | | vo.setValue(mat.getMatNo()); |
| | | valueVos.add(vo); |
| | | } |
| | | return R.ok().add(valueVos); |
| | | } |
| | | |
| | | @RequestMapping(value = "/matCode/covert/{id}/auth") |
| | | @ManagerAuth |
| | | public R covert(@PathVariable("id") String id) { |
| | | MatCode matCode = matCodeService.selectById(String.valueOf(id)); |
| | | if (matCode == null) { |
| | | return R.ok(); |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | VersionUtils.setOrderDetl(orderDetl, matCode); |
| | | orderDetl.setAnfme(0.0D); |
| | | return R.ok().add(orderDetl); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/matCode/{id}/auth") |
| | | @ManagerAuth |
| | | public R get(@PathVariable("id") String id) { |
| | | return R.ok(matCodeService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/matCode/auth") |
| | | @ManagerAuth |
| | | public R find(@RequestParam("id") String id) { |
| | | return R.ok(matCodeService.selectById(String.valueOf(id))); |
| | | } |
| | | |
| | |
| | | @RequestParam(defaultValue = "10")Integer limit, |
| | | @RequestParam(required = false)String orderByField, |
| | | @RequestParam(required = false)String orderByType, |
| | | @RequestParam(required = false)String condition, |
| | | @RequestParam Map<String, Object> param){ |
| | | excludeTrash(param); |
| | | EntityWrapper<MatCode> wrapper = new EntityWrapper<>(); |
| | | convert(param, wrapper); |
| | | allLike(MatCode.class, param.keySet(), wrapper, condition); |
| | | if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} |
| | | else { |
| | | wrapper.orderBy("modi_time", false); |
| | | } |
| | | return R.ok(matCodeService.selectPage(new Page<>(curr, limit), wrapper)); |
| | | } |
| | | |
| | | private void convert(Map<String, Object> map, EntityWrapper wrapper){ |
| | | private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ |
| | | for (Map.Entry<String, Object> entry : map.entrySet()){ |
| | | if (entry.getKey().endsWith(">")) { |
| | | wrapper.ge(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); |
| | | } else if (entry.getKey().endsWith("<")) { |
| | | wrapper.le(Cools.deleteChar(entry.getKey()), DateUtils.convert(String.valueOf(entry.getValue()))); |
| | | String val = String.valueOf(entry.getValue()); |
| | | if (val.contains(RANGE_TIME_LINK)){ |
| | | String[] dates = val.split(RANGE_TIME_LINK); |
| | | wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); |
| | | wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); |
| | | } else { |
| | | wrapper.eq(entry.getKey(), String.valueOf(entry.getValue())); |
| | | wrapper.like(entry.getKey(), val); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | // 导出 |
| | | @RequestMapping(value = "/matCode/export/auth") |
| | | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "物料编码数据导出") |
| | | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "商品编号数据导出") |
| | | public void export(@RequestParam(required = false) String fileName, |
| | | @RequestParam(required = false) Integer rowCount, |
| | | HttpServletResponse response) throws Exception { |
| | | List<MatCode> list = matCodeService.selectList(new EntityWrapper<>()); |
| | | List<MatCodeExcel> excels = new ArrayList<>(); |
| | | for (MatCode matCode : list) { |
| | | MatCodeExcel excel = new MatCodeExcel(); |
| | | excel.setMatNo(matCode.getMatNo()); |
| | | excel.setBarcode(matCode.getBarcode()); |
| | | excel.setMatName(matCode.getMatName()); |
| | | excel.setStr1(matCode.getStr1()); |
| | | excel.setStr2(matCode.getStr2()); |
| | | MatCodeExcel excel = VersionUtils.getExcel(matCode); |
| | | excels.add(excel); |
| | | if (rowCount != null && excels.size() >= rowCount){ |
| | | break; |
| | |
| | | } |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | fileName = URLEncoder.encode(Cools.isEmpty(fileName)?"物料编码":fileName, "UTF-8"); |
| | | fileName = URLEncoder.encode(Cools.isEmpty(fileName)?"商品编号":fileName, "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), MatCodeExcel.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | |
| | | |
| | | // 导入 |
| | | @RequestMapping(value = "/matCode/import/auth") |
| | | @ManagerAuth(memo = "物料编码数据导入") |
| | | @ManagerAuth(memo = "商品编号数据导入") |
| | | @Transactional |
| | | public R matCodeImport(MultipartFile file) throws IOException, InterruptedException { |
| | | Thread.sleep(2000); |
| | | EasyExcel.read(file.getInputStream(), MatCodeExcel.class, new MatCodeExcelListener()).sheet().doRead(); |
| | | return R.ok(); |
| | | MatCodeExcelListener listener = new MatCodeExcelListener(getUserId()); |
| | | EasyExcel.read(file.getInputStream(), MatCodeExcel.class, listener).sheet().doRead(); |
| | | return R.ok("成功导入"+listener.getTotal()+"条物料信息"); |
| | | } |
| | | |
| | | // 打印 |
| | | @RequestMapping(value = "/macCode/print/auth") |
| | | @ManagerAuth(memo = "物料编码打印") |
| | | @RequestMapping(value = "/matCode/print/auth") |
| | | @ManagerAuth(memo = "商品编号打印") |
| | | public R matCodePrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | |
| | | // 打印数据注入 |
| | | MatCodePrint print = new MatCodePrint(); |
| | | print.setMatNo(matCode.getMatNo()); |
| | | print.setBarcodeUrl(matCode.getBarcode()); |
| | | print.setBarcode(matCode.getBarcode()); |
| | | print.setMatName(matCode.getMatName()); |
| | | print.setStr1(matCode.getStr1()); |
| | | print.setStr2(matCode.getStr2()); |
| | |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | // todo resource |
| | | @RequestMapping(value = "/macCode/barcode/auth") |
| | | // @ManagerAuth(memo = "物料编码条形码获取") |
| | | public R matCodeBarcode(@RequestParam String param, HttpServletResponse response) throws IOException { |
| | | @RequestMapping(value = "/macCode/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)){ |
| | | System.out.println(1); |
| | | return R.parse(BaseRes.EMPTY); |
| | | } |
| | | BufferedImage img = BarcodeUtils.encode(param); |
| | | 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"); |
| | | } |