• selleck--codelib


    一.入库:本质就是保存入库文件中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);
                }
            }
        }
    

     //3.当forceUpdate==1 时

        private void resetStockOutData(CodeLibOrderDTO order) {
            Map<String, Object> params = new HashMap<>();
            params.put("orderId", order.getId());
            dao.flush();
            dao.executeSql("update selleck_cl_stock_code set instock=1, outDate=null where code in (select code from selleck_cl_order_plate where codeLibOrderId=:orderId)", params);
            dao.executeSql("update selleck_cl_order_plate set code=null where codeLibOrderId=:orderId", params);
            updateStockQuantity();
        }
    

     第二种情况是: 点击Create 保存 ,跑到了order-edit---执行的是orderEdit方法

                <s:if test="user.hasPermission(1134)">
                    <li>
                        <input type="button" name="edit" onClick='location="/codelib/order-edit.jhtml?order.id="' value="Create" class="input_btn" />
                    </li>
                </s:if>
    

     1.此刻通过id去查DB,肯定没有数据,因为新建的order,那里会有id,执行的是orElseGet(CodeLibOrderDTO::new),设置了状态为working

        public String orderEdit() {
            order = codeLibService.findCodeLibOrderById(order.getId()).orElseGet(CodeLibOrderDTO::new);
            if (order.getStatus() == null) {
                order.setStatus("working");
            }
            return SUCCESS;
        }
    

     2.成功跳转到order-edit.jsp页面

    
    
            <action name="order-edit" class="codeLibAction" method="orderEdit">
                <interceptor-ref name="defaultStack" />
                <interceptor-ref name="permission" />
                <result name="success">/WEB-INF/jsp/backoffice/codelib/order-edit.jsp</result>
            </action>
    
    
    

     3.点击submit按钮提交到 order-save这个action,执行orderSave方法

    <s:form theme="simple" method="post" action="order-save" id="sbform" target="_self" enctype="multipart/form-data">
        <input type="hidden" name="order.id" value="<s:property value="order.id"/>">
        <input type="hidden" name="order.boardFile" value="<s:property value="order.boardFile"/>">
        <table width="100%" cellpadding="0" cellspacing="0" border="0" id="table" class="sortable">
    

     当forceUpdate的值等于1的时候,清空数据,而现实是100%被清空了,因为在orderSave方法中人为的写死了forceUpdate == 1,所以不管前台选择什么都会被清空数据。

                <tr bgColor="white">
                    <td align="center">清空已出库数据</td>
                    <td>
                        <select name="forceUpdate">
                            <option value="0"></option>
                            <option value="1">清空数据</option>
                        </select>
                    </td>
                </tr>
    
     
    
    
    
     
  • 相关阅读:
    Windows Phone本地数据库(SQLCE):3、[table]attribute(翻译) (转)
    深入理解 Node.js 中 EventEmitter源码分析(3.0.0版本)
    深入理解 Getter和Setter 对对象的属性监听
    深入理解Proxy 及 使用Proxy实现vue数据双向绑定
    深入理解 ES6中的 Reflect
    深入理解 Object.defineProperty 及实现数据双向绑定
    Egg入门学习(三)---理解中间件作用
    学习使用PM2管理nodejs进程
    Egg入门学习(二)---理解service作用
    Egg入门学习(一)
  • 原文地址:https://www.cnblogs.com/bravolove/p/5856798.html
Copyright © 2020-2023  润新知