| | |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.MatCode; |
| | | import com.zy.asrs.entity.MatCodePrint; |
| | | import com.zy.asrs.service.MatCodeService; |
| | | import com.zy.common.CodeRes; |
| | | 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.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.*; |
| | |
| | | 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))); |
| | | } |
| | | |
| | | @RequestMapping(value = "/matCode/list/auth") |
| | | @ManagerAuth |
| | | public R list(@RequestParam(defaultValue = "1")Integer curr, |
| | | @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); |
| | | } |
| | | } |
| | | } |
| | |
| | | excel.setBarcode(matCode.getBarcode()); |
| | | excel.setMatName(matCode.getMatName()); |
| | | excel.setStr1(matCode.getStr1()); |
| | | excel.setStr2(matCode.getStr2()); |
| | | excels.add(excel); |
| | | if (rowCount != null && excels.size() >= rowCount){ |
| | | break; |
| | |
| | | @RequestMapping(value = "/matCode/import/auth") |
| | | @ManagerAuth(memo = "物料编码数据导入") |
| | | public R matCodeImport(MultipartFile file) throws IOException, InterruptedException { |
| | | Thread.sleep(2000); |
| | | EasyExcel.read(file.getInputStream(), MatCodeExcel.class, new MatCodeExcelListener()).sheet().doRead(); |
| | | 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 = "物料编码打印") |
| | | public R matCodePrint(@RequestParam(value = "param[]") String[] param) { |
| | | if(Cools.isEmpty(param)) { |
| | | return R.parse(CodeRes.EMPTY); |
| | | } |
| | | List<MatCodePrint> res = new ArrayList<>(); |
| | | for (String matNo : param){ |
| | | MatCode matCode = matCodeService.selectById(matNo); |
| | | // 打印数据注入 |
| | | MatCodePrint print = new MatCodePrint(); |
| | | print.setMatNo(matCode.getMatNo()); |
| | | print.setBarcode(matCode.getBarcode()); |
| | | print.setMatName(matCode.getMatName()); |
| | | print.setStr1(matCode.getStr1()); |
| | | print.setStr2(matCode.getStr2()); |
| | | res.add(print); |
| | | } |
| | | return R.ok().add(res); |
| | | } |
| | | |
| | | @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 { |
| | | 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(); |
| | | } |
| | | |