Browse Source

增加添加机器功能

liujiankang 7 years ago
parent
commit
a7e882327e

+ 9 - 0
watero-rst-core/src/main/java/com.iamberry.rst.core/pts/PtsMachine.java

@@ -25,6 +25,7 @@ public class PtsMachine implements Serializable{
     private String machineNfcId;//nfcId(卡片ID)
     private Date machineCreateTime;//创建时间
     private Date machineUpdateTime;//修改时间
+    private Integer machineProduceId;//产品ID
 
     public Integer getMachineId() {
         return machineId;
@@ -161,4 +162,12 @@ public class PtsMachine implements Serializable{
     public void setMachineNfcId(String machineNfcId) {
         this.machineNfcId = machineNfcId;
     }
+
+    public Integer getMachineProduceId() {
+        return machineProduceId;
+    }
+
+    public void setMachineProduceId(Integer machineProduceId) {
+        this.machineProduceId = machineProduceId;
+    }
 }

+ 10 - 7
watero-rst-service/src/main/java/com/iamberry/rst/service/pts/mapper/machineMapper.xml

@@ -5,11 +5,11 @@
         INSERT INTO tb_rst_pts_machine
         (machine_qrcode,machine_barcode,machine_sales_state,
         machine_status,machine_produced_time,machine_is_print,
-        machine_compound_img,machine_process_state,machine_create_time,machine_produce_type,machine_nfcId)
+        machine_compound_img,machine_process_state,machine_create_time,machine_produce_type,machine_nfcId,machine_produce_id)
         VALUES
         (#{machineQrcode},#{machineBarcode},2,#{machineStatus},
         #{machineProducedTime},#{machineIsPrint},#{machineCompoundImg},#{machineProcessState},
-        #{machineCreateTime},#{machineProduceType},#{machineNfcId})
+        #{machineCreateTime},#{machineProduceType},#{machineNfcId},#{machineProduceId})
     </insert>
 
     <update id="updateMachine" parameterType="PtsMachine" >
@@ -70,7 +70,8 @@
          machine_hardware_version machineHardwareVersion,
          machine_create_time machineCreateTime,
          machine_update_time machineUpdateTime,
-         machine_produce_type machineProduceType
+         machine_produce_type machineProduceType,
+         machine_produce_id machineProduceId
          FROM  tb_rst_pts_machine
         <where>
             <if test="machineBarcode != null and machineBarcode != ''">
@@ -103,7 +104,8 @@
          machine_hardware_version machineHardwareVersion,
          machine_create_time machineCreateTime,
          machine_update_time machineUpdateTime,
-         machine_produce_type machineProduceType
+         machine_produce_type machineProduceType,
+         machine_produce_id machineProduceId
          from tb_rst_pts_machine where machine_id > #{machineId}
          order by machine_create_time desc
     </select>
@@ -148,7 +150,8 @@
          machine_hardware_version machineHardwareVersion,
          machine_create_time machineCreateTime,
          machine_update_time machineUpdateTime,
-         machine_produce_type machineProduceType
+         machine_produce_type machineProduceType,
+         machine_produce_id machineProduceId
         from tb_rst_pts_machine WHERE  machine_id = #{machineId}
         order by machine_create_time desc
     </select>
@@ -313,12 +316,12 @@
     <insert id="addMahineBatch" useGeneratedKeys="true" parameterType="java.util.List">
         insert into tb_rst_pts_machine (machine_qrcode,machine_barcode,machine_sales_state,
         machine_status,machine_produced_time,machine_is_print,
-        machine_compound_img,machine_process_state,machine_create_time,machine_produce_type,machine_nfcId)
+        machine_compound_img,machine_process_state,machine_create_time,machine_produce_type,machine_nfcId,machine_produce_id)
         values
         <foreach collection="list" item="item" index="index" separator="," >
             (#{item.machineQrcode},#{item.machineBarcode},2,#{item.machineStatus},
             #{item.machineProducedTime},#{item.machineIsPrint},#{item.machineCompoundImg},#{item.machineProcessState},
-            #{item.machineCreateTime},#{item.machineProduceType},#{item.machineNfcId})
+            #{item.machineCreateTime},#{item.machineProduceType},#{item.machineNfcId},#{item.machineProduceId})
         </foreach>
     </insert>
 </mapper>

+ 53 - 10
watero-rst-web/src/main/java/com/iamberry/rst/controllers/pts/AdminMachineController.java

@@ -391,40 +391,63 @@ public class AdminMachineController {
     @RequestMapping("/_add_machine_batch")
     public ResponseJson addMachineBatch(HttpServletRequest request) {
         ResponseJson rj = new ResponseJson();
-        String machineType = request.getParameter("machineType");
+        String produceId = request.getParameter("produceId");//产品ID
         String machineSoftwareVersion = request.getParameter("machineSoftwareVersion");
         String number = request.getParameter("number");
-        if (machineType == null || machineType.equals("") ||
+        if (produceId == null || produceId.equals("") ||
                 machineSoftwareVersion == null || machineSoftwareVersion.equals("") ||
                 number == null || number.equals("")) {
             rj.setReturnCode(500);
             return rj;
         }
-
         Produce produce = new Produce();
-        produce.setProduceId(Integer.valueOf(machineType));
+        produce.setProduceId(Integer.valueOf(produceId));
         produce = produceService.getProduce(produce);    //根据产品获取产品信息
 
         ArrayList<PtsMachine> ptsList = new ArrayList<PtsMachine>();
-        PtsMachine ptsMachine = new PtsMachine();
-        MachineController machineController = new MachineController();
+        //生成条形码前缀
+        String berQrcode = generationBarCode(produce);
+        //获取当前月机器总数
+        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM");
+        java.util.Date currTime = new java.util.Date();
+        String curTime = formatter.format(currTime);
+        Integer machineNumber = machineService.selectMonthCount(curTime);
+        String num = null;
         for (int i = 0; i < Integer.valueOf(number); i++) {
-            //生成条形码,二维码
-            String berQrcode = machineController.generationBarCode(produce);
+            machineNumber = machineNumber + i;
+            switch(String.valueOf(machineNumber+1).length()){
+                case 0:
+                    num = "0001";
+                    break;
+                case 1:
+                    num = "000"+String.valueOf(machineNumber);
+                    break;
+                case 2:
+                    num = "00"+String.valueOf(machineNumber);
+                    break;
+                case 3:
+                    num = "0"+String.valueOf(machineNumber);
+                    break;
+                case 4:
+                    num = String.valueOf(machineNumber);
+                    break;
+            }
             String json = String.format(NameUtils.QR_LIMIT_STR_SCENE, ResultInfo.barCodePrefix + berQrcode);
             QRCJson qrc = WeixinUtil.createQrcode(json);
+            PtsMachine ptsMachine = new PtsMachine();
             ptsMachine.setMachineQrcode(qrc.getUrl());//二维码
-            ptsMachine.setMachineBarcode(berQrcode);//条形码
+            ptsMachine.setMachineBarcode(berQrcode+num);//条形码
             ptsMachine.setMachineStatus(1);//机器状态
             ptsMachine.setMachineProducedTime(new Date());//生产时间
             ptsMachine.setMachineIsPrint(1);//是否打印1:未打印2:已打印
             ptsMachine.setMachineCompoundImg("合成的图片url");
             ptsMachine.setMachineProcessState(1);//生成流程状态1.正常2.异常
             ptsMachine.setMachineCreateTime(new Date());//创建时间
-            ptsMachine.setMachineProduceType(Integer.valueOf(machineType));//产品类型
+            ptsMachine.setMachineProduceType(produce.getProduceType());//产品类型
             ptsMachine.setMachineNfcId(productNfcId);
             ptsMachine.setMachineHardwareVersion(machineSoftwareVersion);
             ptsMachine.setMachineSoftwareVersion(machineSoftwareVersion);
+            ptsMachine.setMachineProduceId(Integer.valueOf(produceId));
             ptsList.add(ptsMachine);
         }
         Integer msg = machineService.addMahineBatch(ptsList);
@@ -436,5 +459,25 @@ public class AdminMachineController {
         return rj;
     }
 
+
+    private String productModel = "1X";//产品型号
+    private String productFeatures = "A";//产品特性
+    private String softwareVersion = "30";//软件版本
+    //生成条形码
+    public String generationBarCode(Produce produce){
+        Calendar cal = Calendar.getInstance();
+        int year = cal.get(Calendar.YEAR);
+        int month = cal.get(Calendar.MONTH) + 1;
+
+        String months = String.valueOf(month);
+        if(month < 10){
+            months = "0"+months;
+        }
+        productModel = produce.getProduceModel();
+        productFeatures = produce.getProduceFeature();
+        //拼接
+        String barcode = productModel+productFeatures+softwareVersion+String.valueOf(year).substring(2,4)+months;
+        return barcode;
+    }
 }
 

+ 32 - 29
watero-rst-web/src/main/webapp/WEB-INF/views/pts/machine/batchAddMachine.ftl

@@ -7,41 +7,44 @@
 <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
 <meta http-equiv="Cache-Control" content="no-siteapp" />
 <title>添加机器</title>
+    <style>
+        .my-title{font-weight: 500;padding-left: 15px;position: relative;}
+        .my-title:after{content: '';position: absolute;left: 0;top:12%;width: 3px;height: 80%;background: #32a3d8;}
+        .my-input{padding: 8px 10px;width: 80%;border:1px solid rgba(0,0,0,.1);}
+        .my-input-date{padding: 8px 10px;border:1px solid rgba(0,0,0,.1);width: 80%;background: url(http://s.iamberry.com/images/rili-1.png) 98.5% center no-repeat; background-size:auto 50%;}
+        .input-box{margin: 18px 0;}
+        .input-dic{float: left;margin:5px 10px 0 0;font-size: 12px;}
+        .add-list{list-style-type: none;padding: 10px;background-color: #f5f5f5;width: 60%;float: left;margin: 0;}
+        .add-list>li{margin: 10px 0;}
+        .my-textarea{padding: 5px 10px;width: 80%;border:1px solid rgba(0,0,0,.1);}
+        .my-btn-reset{padding: 10px 20px;width: 150px; background-color: #fff;color: #32a3d8;border: 1px solid #32a3d8;cursor:pointer;margin: 10px 10px 0 10px;}
+        .my-btn-submit{padding: 10px 20px;width: 150px; background-color: #32a3d8;color: #fff;border: 1px solid #32a3d8;cursor:pointer;margin: 10px 10px 0 10px;}
+        .my-select{border: 1px solid rgba(0,0,0,.1);padding:6px 50px 6px 15px;width: 60%; height: 34px; -webkit-appearance:none;appearance:none;background: url(http://s.iamberry.com/images/select-1.png) right center no-repeat #fff;background-size:auto 100%;}
+        input[type=radio]{-webkit-appearance:none;appearance:none;background: url(/rst/common/images/pts/radio-1.png) center center no-repeat;background-size:auto 100%;width: 20px;height: 20px;margin-right: 10px;}
+        input[type=radio]:checked{-webkit-appearance:none;appearance:none;background: url(/rst/common/images/pts/radio-2.png) center center no-repeat;background-size:auto 100%;width: 20px;height: 20px;margin-right: 10px;}
+    	.spanhidth{width: 48px;}
+	</style>
 <#include "/base/add_base.ftl">
 </head>
 <body>
 <div class="pd-20">
 	<form   class="form form-horizontal" id="form-admin-add">	
-		<div class="row cl">
-			<label class="form-label col-3"><span class="c-red">*</span>产品:</label>
-			<div class="formControls col-5">
-                <select class="my-select" name="machineType">
-                    <#if (produceList ?size > 0)>
-                        <#list produceList as list>
-                            <option value ="${list.produceId}">${list.produceName}</option>
-                        </#list>
-                    <#else >
-                        <option value ="">暂无产品,请到生产产品列表添加产品</option>
-                    </#if>
-                </select>
-			</div>
-			<div class="col-4"> </div>
-		</div>
-		<div class="row cl">
-			<label class="form-label col-3"><span class="c-red">*</span>软件版本:</label>
-			<div class="formControls col-5">
-				<input id="machineSoftwareVersion" type="text" name="machineSoftwareVersion"  value="" class="input-text" datatype="*6-20" nullmsg="描述不能为空,可以为:xx月二次生成">
-			</div>
-			<div class="col-4"> </div>
-		</div>
-		<div class="row cl">
-			<label class="form-label col-3"><span class="c-red">*</span>数量:</label>
-			<div class="formControls col-5">
-				<input id="number" type="text" name="number"  value="" class="input-text" datatype="*6-20" nullmsg="每次最少生成一个机器">
-			</div>
-			<div class="col-4"> </div>
-		</div>
 
+            <div class="input-box">
+                <span class="input-dic spanhidth">产品</span>
+				<select class="my-select" name="produceId">
+						<#if (produceList ?size > 0)>
+							<#list produceList as list>
+								<option value ="${list.produceId}">${list.produceName}</option>
+							</#list>
+						<#else >
+							<option value ="">暂无产品,请到生产产品列表添加产品</option>
+						</#if>
+				</select>
+            </div>
+        <div class="input-box"><span class="input-dic spanhidth">软件版本</span><input class="my-input" type="text"  name="machineSoftwareVersion" id="machineSoftwareVersion" placeholder="软件版本"/> </div>
+
+        <div class="input-box"><span class="input-dic spanhidth">数量</span><input class="my-input" type="text"  name="number" id="number" placeholder="每次最少生成一个机器"/> </div>
 		<div class="row cl">
 			<div class="col-9 col-offset-3">
 				<input id="sumbit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="admin_add()">