liujiankang 7 лет назад
Родитель
Сommit
7c80e7fb87

+ 3 - 3
watero-rst-core/src/main/java/com.iamberry.rst.core/pts/PtsComponents.java

@@ -23,7 +23,7 @@ public class PtsComponents implements Serializable {
 
     private Integer componentsCost;//零件成本(分)
 
-    private Integer componentsWeight;//零件重量(g)
+    private double componentsWeight;//零件重量(g)
 
     private String componentsMaterial;//材料
 
@@ -99,11 +99,11 @@ public class PtsComponents implements Serializable {
         this.componentsCost = componentsCost;
     }
 
-    public Integer getComponentsWeight() {
+    public double getComponentsWeight() {
         return componentsWeight;
     }
 
-    public void setComponentsWeight(Integer componentsWeight) {
+    public void setComponentsWeight(double componentsWeight) {
         this.componentsWeight = componentsWeight;
     }
 

+ 3 - 0
watero-rst-service/src/main/java/com/iamberry/rst/service/pts/mapper/machinePartsMapper.xml

@@ -91,6 +91,9 @@
             <if test="componentsName !=null and componentsName !='' ">
                 AND t.components_name = #{componentsName}
             </if>
+            <if test="supplierId !=null and supplierId !='' ">
+                AND t.supplier_id = #{supplierId}
+            </if>
         </where>
     </select>
 

+ 50 - 0
watero-rst-web/src/main/java/com/iamberry/rst/controllers/pts/AdminMachinePartsController.java

@@ -11,15 +11,21 @@ import com.iamberry.rst.faces.pts.ProduceService;
 import com.iamberry.rst.faces.pts.PtsBomService;
 import com.iamberry.rst.utils.StitchAttrUtil;
 import com.iamberry.wechat.tools.ResponseJson;
+import com.iamberry.wechat.tools.ResultInfo;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.context.ContextLoader;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 import org.springframework.web.servlet.ModelAndView;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
+import java.io.*;
 import java.util.Date;
 import java.util.List;
 
@@ -104,6 +110,10 @@ public class AdminMachinePartsController {
         List<Produce> list = produceService.getProduceList();
         mv.addObject("produceList",list);
 
+        //获取供应商
+        List<PtsSupplier> listSupplier = machineSupplierService.listMachineSupplier();
+        mv.addObject("listSupplier", listSupplier);
+
         StitchAttrUtil.setModelAndView(ptsComponents, mv, "/admin/machineParts/_parts_list", pagedResult);
         return mv;
     }
@@ -170,4 +180,44 @@ public class AdminMachinePartsController {
         }
         return responseJson;
     }
+
+
+    /*
+     * 通过流的方式上传文件
+     * @RequestParam("file") 将name=file控件得到的文件封装成CommonsMultipartFile 对象
+     */
+    @ResponseBody
+    @RequestMapping("/fileUpload")
+    public ResponseJson  fileUpload(HttpServletRequest request,@RequestParam("file") CommonsMultipartFile file) throws IOException {
+        ResponseJson responseJson = new ResponseJson();
+        System.out.println("fileName:"+file.getOriginalFilename());
+        //获取项目根目录
+        WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
+        ServletContext servletContext = webApplicationContext.getServletContext();
+        String realPath = servletContext.getRealPath(ResultInfo.PARTS_IMAGE);
+        String imgUrl = new Date().getTime()+file.getOriginalFilename();
+        try {
+            //获取输出流
+            OutputStream os=new FileOutputStream(realPath+imgUrl);
+
+            //获取输入流 CommonsMultipartFile 中可以直接得到文件的流
+            InputStream is=file.getInputStream();
+            byte[] bts = new byte[1024];
+            //一个一个字节的读取并写入
+            while(is.read(bts)!=-1)
+            {
+                os.write(bts);
+            }
+            os.flush();
+            os.close();
+            is.close();
+
+        } catch (FileNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        responseJson.setReturnCode(200);
+        responseJson.addResponseKeyValue("imgUrl",imgUrl);
+        return responseJson;
+    }
 }

+ 2 - 2
watero-rst-web/src/main/java/com/iamberry/rst/controllers/pts/AdminMachineVersionController.java

@@ -96,7 +96,7 @@ public class AdminMachineVersionController {
     }
 
     /**
-     * 进入修改机器零件页面
+     * 进入修改机器版本页面
      * **/
     @RequiresPermissions("machineVersion:update:machineVersion")
     @RequestMapping("/_to_update_machineVersion")
@@ -113,7 +113,7 @@ public class AdminMachineVersionController {
     }
 
     /**
-     * 修改机器零件
+     * 修改机器版本
      * **/
     @ResponseBody
     @RequiresPermissions("machineVersion:update:machineVersion")

+ 1 - 0
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machine/addRenovationMachine.ftl

@@ -129,6 +129,7 @@
 
 /*机器-添加*/
 function admin_add(){
+    layer.msg('加载中', {icon: 16});
    		  var msg = dataCharm();
    		  if(msg){
               $.ajax({

+ 27 - 5
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machinePtras/parts_list.ftl

@@ -32,6 +32,27 @@
     <div class="text-c">
         <form action="${path}/admin/machineParts/_parts_list" method="post">
             <button type="button" style="cursor:pointer; float: left;" class="my-btn-search" onclick="toAddParts();">添加机器零件</button>
+
+            <select class="my-select" name="supplierId" id="supplierId" style="height: 36px;width: 150px">
+                <option value ="">所有供应商</option>
+                <#if (listSupplier ?size > 0)>
+                    <#list listSupplier as list>
+                        <option value ="${list.supplierId}" <#if supplierId??><#if supplierId ==list.supplierId >selected="selected"</#if></#if> >${list.supplierName}</option>
+                    </#list>
+                <#else >
+                <option value ="">暂无供应商,请到供应商列表添加供应商</option>
+            </#if>
+            </select>
+
+            <select class="my-select" name="produceId" style="height: 36px;width: 150px">
+                <option value ="">所有产品</option>
+            <#if produceList?? &&  (produceList?size > 0) >
+                <#list produceList as produce>
+                    <option value ="${produce.produceId!}" <#if produceId??><#if produceId ==produce.produceId >selected="selected"</#if></#if>>${produce.produceName!}</option>
+                </#list>
+            </#if>
+            </select>
+
             <select class="my-select" name="produceId" style="height: 36px;width: 150px">
                 <option value ="">所有产品</option>
                 <#if produceList?? &&  (produceList?size > 0) >
@@ -55,8 +76,8 @@
             <th width="100">零件名称</th>
             <th width="80">图片</th>
             <th width="80">状态</th>
-            <th width="100">成本</th>
-            <th width="80">重量</th>
+            <th width="100">成本(元)</th>
+            <th width="80">重量(g)</th>
             <th width="80">材料</th>
             <th width="80">材料类型</th>
             <th width="80">MBSC</th>
@@ -73,9 +94,10 @@
                             <td>${parts.supplierName!''}</td>
                             <td>${parts.componentsName!''}</td>
                             <td><img style="width: 50px;height: 50px;" src="${parts.componentsImg!''}"></td>
-                            <td>${parts.componentsStatus!''}</td>
-                            <td>${parts.componentsCost!''}</td>
-                            <td>${parts.componentsWeight/100!''}</td>
+                            <td><#if parts.componentsStatus == 0 >停止使用</#if>
+                                <#if parts.componentsStatus == 1 >正常使用</#if></td>
+                            <td>${parts.componentsCost/100!''}</td>
+                            <td>${parts.componentsWeight!''}</td>
                             <td>${parts.componentsMaterial!''}</td>
                             <td><#if parts.componentsType == 1>塑胶件</#if>
                                 <#if parts.componentsType == 2>五金件</#if>

+ 52 - 9
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machinePtras/ptras_add.ftl

@@ -59,25 +59,45 @@
 				</select>
 				</span> </div>
         </div>
-        <div class="row cl">
+        <#--<div class="row cl">
             <label class="form-label col-xs-4 col-sm-3">零件图片:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <img alt="介绍图" src="/common/images/pts/addparts.jpg" id="partsImg" width="90" height="80">
                 <input type="hidden" id="componentsImg" name="componentsImg" value=""/>
 			</div>
+        </div>-->
+
+        <div class="row cl">
+            <label class="form-label col-xs-4 col-sm-3">零件图片:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <input type="file" name="file" id="fileid">
+                <img alt="介绍图" src="/common/images/pts/addparts.jpg" id="partsImg" width="90" height="80">
+                <input type="hidden" id="componentsImg" name="componentsImg" value=""/>
+                <button type="button" class="btn" style="background: #32a3d8;color: #fff;-webkit-transform:translateY(-5%);" id="uploadSubmit"><i class="Hui-iconfont">&#xe665;</i> 上传</button>
+            </div>
         </div>
+        <#--<div class="row cl">
+            <label class="form-label col-xs-4 col-sm-2">缩略图:</label>
+            <div class="formControls col-xs-8 col-sm-9">
+                <div class="uploader-thum-container">
+                    <div id="fileList" class="uploader-list"></div>
+                    <div id="filePicker">选择图片</div>
+                    <button id="btn-star" class="btn btn-default btn-uploadstar radius ml-10">开始上传</button>
+                </div>
+            </div>
+        </div>-->
 
 		<div class="row cl">
 			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>零件状态:</label>
 			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
+                <div class="radio-box">
+                    <input type="radio" id="sex-2" value="1" name="componentsStatus" checked>
+                    <label for="sex-2">正常使用</label>
+                </div>
 				<div class="radio-box">
-					<input name="componentsStatus" type="radio" value="0" id="sex-1" checked>
+					<input name="componentsStatus" type="radio" value="0" id="sex-1" >
 					<label for="sex-1">停止使用</label>
 				</div>
-				<div class="radio-box">
-					<input type="radio" id="sex-2" value="1" name="componentsStatus">
-					<label for="sex-2">正常使用</label>
-				</div>
 			</div>
 		</div>
 
@@ -116,7 +136,7 @@
             </div>
         </div>
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>规格:</label>
+            <label class="form-label col-xs-4 col-sm-3">规格:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <input type="text" class="input-text" value="" id="componentsSpecification" name="componentsSpecification" placeholder="请输入材料规格(允许为空)">
             </div>
@@ -139,11 +159,15 @@
 		</div>
 	</form>
 </article>
+
 <script type="text/javascript" src="${path}/common/kingedit/kindeditor.js"></script>
 <script type="text/javascript" src="${path}/common/kingedit/lang/zh_CN.js"></script>
+
+<script type="text/javascript" src="${path}/common/lib/webuploader/0.1.5/webuploader.min.js"></script>
+<script type="text/javascript" src="${path}/common/lib/jquery/1.9.1/ajaxfileupload.js"></script>
 <script type="text/javascript">
 
-    KindEditor.ready(function(K) {
+    /*KindEditor.ready(function(K) {
         var editor = K.editor({
             fileManagerJson : '${path}/common/kingedit/jsp/file_manager_json.jsp',
             uploadJson : '${path}/common/kingedit/jsp/upload_json.jsp',
@@ -164,7 +188,7 @@
                 });
             });
         });
-    });
+    });*/
 
         $(function(){
 	$('.skin-minimal input').iCheck({
@@ -254,6 +278,25 @@
 		}
 	});
 });
+
+
+    $('#uploadSubmit').click(function() {
+        $.ajaxFileUpload({
+            url:"${path}/admin/machineParts/fileUpload",//需要链接到服务器地址
+            secureuri:false,
+            fileElementId:"fileid",//文件选择框的id属性
+            dataType: 'json',   //json
+            success: function (data) {
+                if(data.returnCode == 200){
+                    alert(${path});
+                    $('#componentsImg').val(data.returnMsg.imgUrl);
+                    $('#partsImg').attr("src",${path}+"/"+data.returnMsg.imgUrl);
+                }else{
+                    alert('上传失败!');
+                }
+            }
+        });
+    });
 </script> 
 <!--/请在上方写此页面业务相关的脚本-->
 </body>

+ 7 - 7
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machinePtras/ptras_update.ftl

@@ -71,14 +71,14 @@
 		<div class="row cl">
 			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>零件状态:</label>
 			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
-				<div class="radio-box">
+                <div class="radio-box">
+                    <input type="radio" id="sex-2" value="1" name="componentsStatus" <#if ptsComponents.componentsStatus == 1>checked</#if>>
+                    <label for="sex-2">正常使用</label>
+                </div>
+                <div class="radio-box">
 					<input name="componentsStatus" type="radio" value="0" id="sex-1" <#if ptsComponents.componentsStatus == 0>checked</#if>>
 					<label for="sex-1">停止使用</label>
 				</div>
-				<div class="radio-box">
-					<input type="radio" id="sex-2" value="1" name="componentsStatus" <#if ptsComponents.componentsStatus == 1>checked</#if>>
-					<label for="sex-2">正常使用</label>
-				</div>
 			</div>
             <input type="hidden" value="${ptsComponents.componentsStatus!''}" name="oldComponentsStatus" id="oldComponentsStatus">
 		</div>
@@ -118,7 +118,7 @@
             </div>
         </div>
         <div class="row cl">
-            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>规格:</label>
+            <label class="form-label col-xs-4 col-sm-3">规格:</label>
             <div class="formControls col-xs-8 col-sm-9">
                 <input type="text" class="input-text" value="${ptsComponents.componentsSpecification!''}" id="componentsSpecification" name="componentsSpecification" placeholder="请输入材料规格(允许为空)">
             </div>
@@ -235,7 +235,7 @@
            var componentsStatus=$('input:radio[name="componentsStatus"]:checked').val();
            var oldComponentsStatus =   $("#oldComponentsStatus").val();
            if(produceId != oldProduceId || componentsStatus != oldComponentsStatus){
-               layer.confirm('修改产品或零件状态后会影响到以往的BOM清单,是否修改?',function(index){
+               layer.confirm('修改的零件,会影响已经生产好的机器。如果修改零件的供应商、材料等信息,建议添加一次Bom,并做对应软硬件版本升级。,是否修改?',function(index){
                    $.ajax({
                        cache: true,
                        type: "POST",

+ 1 - 0
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machineVersion/version_add.ftl

@@ -108,6 +108,7 @@
                 success: function(data){
                     if (data.returnCode == 200) {
                         layer.msg('添加成功!', {icon: 1, time: 2000});
+                        window.location.href = document.referrer;
                     }else{
                         layer.msg('添加失败!', {icon: 2, time: 2000});
                     }

+ 237 - 0
watero-rst-web/src/main/webapp/common/lib/jquery/1.9.1/ajaxfileupload.js

@@ -0,0 +1,237 @@
+
+jQuery.extend({
+
+
+    createUploadIframe: function(id, uri)
+    {
+        //create frame
+        var frameId = 'jUploadFrame' + id;
+
+        if(window.ActiveXObject) {
+            var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
+            if(typeof uri== 'boolean'){
+                io.src = 'javascript:false';
+            }
+            else if(typeof uri== 'string'){
+                io.src = uri;
+            }
+        }
+        else {
+            var io = document.createElement('iframe');
+            io.id = frameId;
+            io.name = frameId;
+        }
+        io.style.position = 'absolute';
+        io.style.top = '-1000px';
+        io.style.left = '-1000px';
+
+        document.body.appendChild(io);
+
+        return io
+    },
+    createUploadForm: function(id, fileElementId)
+    {
+        //create form
+        var formId = 'jUploadForm' + id;
+        var fileId = 'jUploadFile' + id;
+        var form = $('<form  action="" method="POST" name="' + formId + '" id="' + formId + '" enctype="multipart/form-data"></form>');
+        var oldElement = $('#' + fileElementId);
+        var newElement = $(oldElement).clone();
+        $(oldElement).attr('id', fileId);
+        $(oldElement).before(newElement);
+        $(oldElement).appendTo(form);
+        //set attributes
+        $(form).css('position', 'absolute');
+        $(form).css('top', '-1200px');
+        $(form).css('left', '-1200px');
+        $(form).appendTo('body');
+        return form;
+    },
+    addOtherRequestsToForm: function(form,data)
+    {
+        // add extra parameter
+        var originalElement = $('<input type="hidden" name="" value="">');
+        for (var key in data) {
+            name = key;
+            value = data[key];
+            var cloneElement = originalElement.clone();
+            cloneElement.attr({'name':name,'value':value});
+            $(cloneElement).appendTo(form);
+        }
+        return form;
+    },
+
+    ajaxFileUpload: function(s) {
+        // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
+        s = jQuery.extend({}, jQuery.ajaxSettings, s);
+        var id = new Date().getTime()
+        var form = jQuery.createUploadForm(id, s.fileElementId);
+        if ( s.data ) form = jQuery.addOtherRequestsToForm(form,s.data);
+        var io = jQuery.createUploadIframe(id, s.secureuri);
+        var frameId = 'jUploadFrame' + id;
+        var formId = 'jUploadForm' + id;
+        // Watch for a new set of requests
+        if ( s.global && ! jQuery.active++ )
+        {
+            jQuery.event.trigger( "ajaxStart" );
+        }
+        var requestDone = false;
+        // Create the request object
+        var xml = {}
+        if ( s.global )
+            jQuery.event.trigger("ajaxSend", [xml, s]);
+        // Wait for a response to come back
+        var uploadCallback = function(isTimeout)
+        {
+            var io = document.getElementById(frameId);
+            try
+            {
+                if(io.contentWindow)
+                {
+                    xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
+                    xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
+
+                }else if(io.contentDocument)
+                {
+                    xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
+                    xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
+                }
+            }catch(e)
+            {
+                jQuery.handleError(s, xml, null, e);
+            }
+            if ( xml || isTimeout == "timeout")
+            {
+                requestDone = true;
+                var status;
+                try {
+                    status = isTimeout != "timeout" ? "success" : "error";
+                    // Make sure that the request was successful or notmodified
+                    if ( status != "error" )
+                    {
+                        // process the data (runs the xml through httpData regardless of callback)
+                        var data = jQuery.uploadHttpData( xml, s.dataType );
+                        // If a local callback was specified, fire it and pass it the data
+                        if ( s.success )
+                            s.success( data, status );
+
+                        // Fire the global callback
+                        if( s.global )
+                            jQuery.event.trigger( "ajaxSuccess", [xml, s] );
+                    } else
+                        jQuery.handleError(s, xml, status);
+                } catch(e)
+                {
+                    status = "error";
+                    jQuery.handleError(s, xml, status, e);
+                }
+
+                // The request was completed
+                if( s.global )
+                    jQuery.event.trigger( "ajaxComplete", [xml, s] );
+
+                // Handle the global AJAX counter
+                if ( s.global && ! --jQuery.active )
+                    jQuery.event.trigger( "ajaxStop" );
+
+                // Process result
+                if ( s.complete )
+                    s.complete(xml, status);
+
+                jQuery(io).unbind()
+
+                setTimeout(function()
+                {	try
+                    {
+                        $(io).remove();
+                        $(form).remove();
+
+                    } catch(e)
+                    {
+                        jQuery.handleError(s, xml, null, e);
+                    }
+
+                }, 100)
+
+                xml = null
+
+            }
+        }
+        // Timeout checker
+        if ( s.timeout > 0 )
+        {
+            setTimeout(function(){
+                // Check to see if the request is still happening
+                if( !requestDone ) uploadCallback( "timeout" );
+            }, s.timeout);
+        }
+        try
+        {
+            // var io = $('#' + frameId);
+            var form = $('#' + formId);
+            $(form).attr('action', s.url);
+            $(form).attr('method', 'POST');
+            $(form).attr('target', frameId);
+            if(form.encoding)
+            {
+                form.encoding = 'multipart/form-data';
+            }
+            else
+            {
+                form.enctype = 'multipart/form-data';
+            }
+            $(form).submit();
+
+        } catch(e)
+        {
+            jQuery.handleError(s, xml, null, e);
+        }
+        if(window.attachEvent){
+            document.getElementById(frameId).attachEvent('onload', uploadCallback);
+        }
+        else{
+            document.getElementById(frameId).addEventListener('load', uploadCallback, false);
+        }
+        return {abort: function () {}};
+
+    },
+
+    uploadHttpData: function( r, type ) {
+        var data = !type;
+        data = type == "xml" || data ? r.responseXML : r.responseText;
+        // If the type is "script", eval it in global context
+        if ( type == "script" )
+            jQuery.globalEval( data );
+        // Get the JavaScript object, if JSON is used.
+        if ( type == "json" )
+        {
+            // If you add mimetype in your response,
+            // you have to delete the '<pre></pre>' tag.
+            // The pre tag in Chrome has attribute, so have to use regex to remove
+            var data = r.responseText;
+            var rx = new RegExp("<pre.*?>(.*?)</pre>","i");
+            var am = rx.exec(data);
+            //this is the desired data extracted
+            var data = (am) ? am[1] : "";    //the only submatch or empty
+            eval( "data = " + data );
+        }
+        // evaluate scripts within html
+        if ( type == "html" )
+            jQuery("<div>").html(data).evalScripts();
+        //alert($('param', data).each(function(){alert($(this).attr('value'));}));
+        return data;
+    },
+    handleError: function( s, xhr, status, e )      {
+        // If a local callback was specified, fire it
+        if ( s.error ) {
+            s.error.call( s.context || s, xhr, status, e );
+        }
+
+        // Fire the global callback
+        if ( s.global ) {
+            (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
+        }
+    }
+
+})
+