一.入库:本质就是保存入库文件中cat code instock inDate 到code表并及时更新库存表stock中cat对应的总量quantity!
code表: id code cat inStock inDate outDate stock表: id cat quantity
0.
<div id="drop-zone">拖放<br/>S1001-xxx.csv<br/>文件到此处</div> <div id="fileInfo"></div> <table data-bind="foreach: racks" class="sortable"> <tbody data-bind="foreach: plates"> <tr data-bind="foreach: $data"> <td> <span class="plate-label" data-bind="text: label"></span> <div class="plate-code" data-bind="text: code, css: {‘plate-no-tube‘: ‘No Tube‘ == code, ‘plate-no-read‘: ‘No Read‘ == code}"></div> <div class="plate-cat" data-bind="text: cat"></div> </td> </tr> </tbody> </table> <div> <button id="inStockButton" type="button" disabled data-bind="click: inStock">入库</button> </div> //通过ajax传递了cat 和codes Model.prototype.inStock = function() { var codes, i, j, len, len1, plate, plateRow, racks, ref; codes = []; racks = ko.mapping.toJS(this.racks); if (racks.length) { ref = racks[0].plates; for (i = 0, len = ref.length; i < len; i++) { plateRow = ref[i]; for (j = 0, len1 = plateRow.length; j < len1; j++) { plate = plateRow[j]; if (plate.code.match(/^\d+$/)) { codes.push(plate.code); } } } return $.postJSON(‘doInStock.jhtml‘, { cat: this.cat, codes: codes }).done((function(_this) { return function(json) { if (json.error) { return alert(json.error); } else { return alert(‘上传成功‘); } }; })(this)); } };
1.action.xml
<action name="in-stock" class="codeLibAction" method="inStock"> <result name="success">/WEB-INF/jsp/backoffice/codelib/in-stock.jsp</result> <interceptor-ref name="defaultStack" /> <interceptor-ref name="permission" /> </action> <action name="doInStock" class="codeLibAction" method="doInStock"/>
2. action
public String inStock() { return SUCCESS; } @SuppressWarnings("unchecked") public String doInStock() { Map<String, Object> result = new HashMap<>(); try { Map<String, Object> map = readJSON(); String cat = (String) map.get("cat"); List<String> codes = (List<String>) map.get("codes"); codeLibService.saveNewStockCodes(cat, codes); } catch (Exception e) { e.printStackTrace(); result.put("error", e.getMessage()); } writeJSON(result); return null; }
3.daoImpl
private void updateStockQuantity() { dao.flush();//把前面CRUD等操作刷入到数据库中,否则后面查询不到数据,因为事务的原因。 dao.executeSql("insert selleck_cl_stock(cat) select distinct c.cat from selleck_cl_stock_code c where not exists(select * from selleck_cl_stock s where s.cat=c.cat)"); dao.executeSql("update selleck_cl_stock s set quantity = (select count(*) from selleck_cl_stock_code c where c.cat=s.cat and instock=1)"); } @Override public void saveNewStockCodes(String cat, List<String> codes) throws Exception { List<CodeLibStockCodeDTO> stockCodeList = new ArrayList<>(codes.size()); Date today = new Date(); codes.forEach(code -> { CodeLibStockCodeDTO codeLibStockCode = new CodeLibStockCodeDTO(); codeLibStockCode.setCat(cat); codeLibStockCode.setCode(code); codeLibStockCode.setInstock(1); codeLibStockCode.setInDate(today); stockCodeList.add(codeLibStockCode); }); dao.save(stockCodeList); updateStockQuantity(); }
二: 保存订单(一种是新建订单的保存,一种是编辑后的保存), 读取excel中表格的某些字段保存到codeliborder订单表和plate药品孔位表,效果图
当点击Create按钮新建一个订单:新建订单必须先要求订单号no在大合同selleck_ordr中存在!
codeliborder表: id no memo boardFile plate表: id codelibOrderId rack plate row col cat code 其中rack orderno cat可以通过文件名解析获得,是前台传过来的
//1.保存并上传文件到指定的目录用于下次下载用。
public String orderSave() { if (StringUtils.isBlank(order.getMemo())) { throw new RuntimeException("请填写备注"); } String root = ServletActionContext.getServletContext().getRealPath("/"); codeLibService.save(order, excel, excelFileName, root, forceUpdate == 1); return SUCCESS; }
//第一种情况是编辑后保存. 先编辑后保存,通过点击order所在的列的id去数据库查询有没有记录,如果有记录再去看订单的状态是否为null,如果是null设置成working
public String orderEdit() { order = codeLibService.findCodeLibOrderById(order.getId()).orElseGet(CodeLibOrderDTO::new); if (order.getStatus() == null) { order.setStatus("working"); } return SUCCESS; }
//serviceImpl 保存的业务逻辑,此时只会执行前三行的代码,后面的代码不会执行!
@Override public void save(CodeLibOrderDTO order, File file, String filename, String uploadRoot, boolean resetStock) { dao.save(order); if (resetStock) { resetStockOutData(order); } if (file != null) { String savePath = uploadRoot + "newpath/downloads/codelib/"; char[] chars = filename.trim().toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (c < ‘-‘ || c > ‘z‘) { chars[i] = ‘-‘; } } filename = new String(chars); order.setBoardFile(filename); dao.save(order); try { Files.createDirectories(new File(savePath).toPath()); } catch (Exception e) { throw new RuntimeException(e); } savePath += order.getId().toString() + "-" + filename; try (OutputStream out = new FileOutputStream(savePath); InputStream in = new FileInputStream(file)) { IOUtils.copy(in, out); } catch (Exception e) { throw new RuntimeException(e); } List<CodeLibOrderPlateDTO> platesFromExcel = getOrderPlatesFromExcel(file, order); List<CodeLibOrderPlateDTO> plates = getPlates(order); if ( ! isPlatesMatch(platesFromExcel, plates)) { if ( ! plates.isEmpty() && ! resetStock) { throw new RuntimeException("新分子库表格与当前数据不匹配,请选择【清空已出库数据】"); } dao.delete(plates); dao.save(platesFromExcel); } } }
时间: 2024-10-12 18:52:22