瀏覽代碼

Merge remote-tracking branch 'origin/V1' into V1

jz.kai 5 年之前
父節點
當前提交
e355a1948c

+ 52 - 0
common/src/main/java/com/jpsoft/smart/modules/common/utils/POIUtils.java

@@ -1,5 +1,6 @@
 package com.jpsoft.smart.modules.common.utils;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.converter.ExcelToHtmlConverter;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.*;
@@ -122,6 +123,10 @@ public class POIUtils {
         }
     }
 
+    public POIUtils() {
+        wb = new HSSFWorkbook();
+    }
+
     public Sheet getSheetAt(int sheetIndex){
         return wb.getSheetAt(sheetIndex);
     }
@@ -372,4 +377,51 @@ public class POIUtils {
             System.out.println(result);
         }
     }
+
+    public Workbook exportErrorXls(int sheetIndex,int validateColIndex, int rowNum) {
+        Workbook destBook = new HSSFWorkbook();
+        Sheet destSheet = destBook.createSheet();
+
+        //复制列头
+        Sheet srcSheet = wb.getSheetAt(sheetIndex);
+        Row srcHeaderRow = wb.getSheetAt(sheetIndex).getRow(0);
+        Row destHeaderRow = destSheet.createRow(0);
+
+        for (int i=0;i<srcHeaderRow.getLastCellNum();i++){
+            if (srcHeaderRow.getCell(i)!=null) {
+                destHeaderRow.createCell(i).setCellValue(srcHeaderRow.getCell(i).getStringCellValue());
+            }
+            else{
+                break;
+            }
+        }
+
+        int srcRowIndex = 1;
+        int destRowIndex = 1;
+
+        while(srcRowIndex<= rowNum){
+            Row dataRow1 = srcSheet.getRow(srcRowIndex);
+
+            Cell cell = dataRow1.getCell(validateColIndex);
+
+            if (cell!=null && StringUtils.isNotEmpty(cell.getStringCellValue())){
+                Row dataRow2 = destSheet.createRow(destRowIndex);
+
+                for (int i=0;i<dataRow1.getLastCellNum();i++){
+                    if (dataRow1.getCell(i)!=null) {
+                        dataRow2.createCell(i).setCellValue((String)getCellValue(0,srcRowIndex,i));
+                    }
+                    else{
+                        break;
+                    }
+                }
+
+                destRowIndex++;
+            }
+
+            srcRowIndex++;
+        }
+
+        return destBook;
+    }
 }

+ 22 - 19
common/src/main/resources/mapper/base/PersonDeviceLog.xml

@@ -3,7 +3,7 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!-- namespace必须指向DAO接口 -->
 <mapper namespace="com.jpsoft.smart.modules.base.dao.PersonDeviceLogDAO">
-    <resultMap id="PersonDeviceLogMap" type="PersonDeviceLog">
+    <resultMap id="PersonDeviceLogMap" type="com.jpsoft.smart.modules.base.entity.PersonDeviceLog">
         <id property="id" column="id_" />
         <result property="createBy" column="create_by" />
         <result property="createTime" column="create_time" />
@@ -24,7 +24,7 @@
         <association property="person" column="person_id"
                      select="com.jpsoft.smart.modules.base.dao.PersonInfoDAO.get"></association>
     </resultMap>
-    <insert id="insert" parameterType="PersonDeviceLog">
+    <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.PersonDeviceLog">
         <!--
         <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
             select sys_guid() from dual
@@ -35,21 +35,21 @@
 	    (id_,create_by,create_time,update_by,update_time,is_effective,del_flag,device_no,person_id,temperature_,match_status,match_msg,match_face_id,face_image,record_time)
 		values
 		(
-#{id,jdbcType=VARCHAR}
-,#{createBy,jdbcType=VARCHAR}
-,#{createTime,jdbcType= TIMESTAMP }
-,#{updateBy,jdbcType=VARCHAR}
-,#{updateTime,jdbcType= TIMESTAMP }
-,#{isEffective,jdbcType= NUMERIC }
-,#{delFlag,jdbcType= NUMERIC }
-,#{deviceNo,jdbcType=VARCHAR}
-,#{personId,jdbcType=VARCHAR}
-,#{temperature,jdbcType=NUMERIC}
-,#{matchStatus,jdbcType=INTEGER}
-,#{matchMsg,jdbcType=VARCHAR}
-,#{matchFaceId,jdbcType= INTEGER}
-,#{faceImage,jdbcType=VARCHAR}
-,#{recordTime,jdbcType=TIMESTAMP}
+        #{id,jdbcType=VARCHAR}
+        ,#{createBy,jdbcType=VARCHAR}
+        ,#{createTime,jdbcType= TIMESTAMP }
+        ,#{updateBy,jdbcType=VARCHAR}
+        ,#{updateTime,jdbcType= TIMESTAMP }
+        ,#{isEffective,jdbcType= NUMERIC }
+        ,#{delFlag,jdbcType= NUMERIC }
+        ,#{deviceNo,jdbcType=VARCHAR}
+        ,#{personId,jdbcType=VARCHAR}
+        ,#{temperature,jdbcType=NUMERIC}
+        ,#{matchStatus,jdbcType=INTEGER}
+        ,#{matchMsg,jdbcType=VARCHAR}
+        ,#{matchFaceId,jdbcType= INTEGER}
+        ,#{faceImage,jdbcType=VARCHAR}
+        ,#{recordTime,jdbcType=TIMESTAMP}
 		)
 	]]>
     </insert>
@@ -61,8 +61,11 @@
 		]]>
         <where>
             and a.del_flag = false and b.del_flag=false
-            <if test="searchParams.deviceIds != null">
-                and b.id_ in #{searchParams.deviceIds}
+            <if test="searchParams.deviceIdList != null">
+                and b.id_ in
+                <foreach item="item" collection="searchParams.deviceIdList"  open="(" separator="," close=")">
+                    #{item}
+                </foreach>
             </if>
             <if test="searchParams.deviceNo != null">
                 and a.device_no like #{searchParams.deviceNo}

+ 25 - 11
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceLogController.java

@@ -83,20 +83,24 @@ public class PersonDeviceLogController {
         sortList.add(new Sort("a.record_time","desc"));
 
         //为公司管理员
-        boolean is_admin = userService.hasRole(subject,"ADMIN");
-        if(is_admin){
+        boolean isSysAdmin = userService.hasRole(subject,"SYSADMIN");
+
+        if(!isSysAdmin){
             User user = userService.get(subject);
             String companyId = user.getCompanyId();
 
             List<DeviceInfo> deviceInfoList = deviceInfoService.findByCompanyId(companyId);
-            String deviceIds ="";
+            List<String> deviceIdList = new ArrayList<String>();
+
             for (DeviceInfo deviceInfo:deviceInfoList) {
-                deviceIds += deviceInfo.getId()+",";
+                deviceIdList.add(deviceInfo.getId());
             }
-            if(StringUtil.isNotEmpty(deviceIds)){
-                deviceIds = deviceIds.substring(0,deviceIds.lastIndexOf(","));
-                searchParams.put("deviceIds","("+deviceIds+")");
+
+            if (deviceIdList.size()==0) {
+                deviceIdList.add("-1");
             }
+
+            searchParams.put("deviceIdList", deviceIdList);
         }
         if(StringUtil.isNotEmpty(deviceNo)){
             searchParams.put("deviceNo","%"+deviceNo+"%");
@@ -159,7 +163,6 @@ public class PersonDeviceLogController {
     @ApiOperation(value="导出日志台账")
     @PostMapping("exportXls")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "companyId",value = "企业ID", paramType = "query"),
             @ApiImplicitParam(name = "deviceNo",value = "设备编号", paramType = "query"),
             @ApiImplicitParam(name = "aliasName",value = "设备别名", paramType = "query"),
             @ApiImplicitParam(name = "personName",value = "人员姓名", paramType = "query"),
@@ -167,7 +170,6 @@ public class PersonDeviceLogController {
             @ApiImplicitParam(name = "temperatureRanges",value = "温度范围", paramType = "query")
     })
     public MessageResult<String> exportXls(
-                                String companyId,
                                 String deviceNo,String aliasName,String personName,
                                 String timeRanges,String temperatureRanges,
                                 @RequestAttribute String subject) {
@@ -201,9 +203,21 @@ public class PersonDeviceLogController {
             List<Sort> sortList = new ArrayList<>();
             sortList.add(new Sort("a.record_time","desc"));
 
-            if(StringUtil.isNotEmpty(companyId)){
-                searchParams.put("companyId",companyId);
+            //为公司管理员
+            boolean is_admin = userService.hasRole(subject,"ADMIN");
+            if(is_admin){
+                User user = userService.get(subject);
+                String companyId = user.getCompanyId();
+
+                List<DeviceInfo> deviceInfoList = deviceInfoService.findByCompanyId(companyId);
+                List<String> deviceIdList = new ArrayList<String>();
+                for (DeviceInfo deviceInfo:deviceInfoList) {
+                    deviceIdList.add(deviceInfo.getId());
+                }
+
+                searchParams.put("deviceIdList",deviceIdList);
             }
+
             if(StringUtil.isNotEmpty(deviceNo)){
                 searchParams.put("deviceNo","%"+deviceNo+"%");
             }

+ 8 - 21
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -20,8 +20,8 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -363,12 +363,14 @@ public class PersonInfoController {
         if (StringUtils.isNotEmpty(phone)) {
             searchParams.put("phone","%" + phone + "%");
         }
-        if(userService.hasRole(subject,"ADMIN")){
-            searchParams.put("companyId",user.getCompanyId());
-        }
+
         if (userService.hasRole(subject,"SYSADMIN") && StringUtils.isNotEmpty(companyId)) {
             searchParams.put("companyId",companyId);
         }
+        else{
+            searchParams.put("companyId",user.getCompanyId());
+        }
+
         if (StringUtils.isNotEmpty(position1)) {
             searchParams.put("position1",position1);
         }
@@ -723,26 +725,11 @@ public class PersonInfoController {
                 msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
 
                 //todo 只保留错误数据的sheet
-                int rowIndex = 1;
-
-                while(rowIndex<= sheet1.getLastRowNum()){
-                    Cell cell = sheet1.getRow(rowIndex).getCell(validateColIndex);
-
-                    if (cell==null || StringUtils.isEmpty(cell.getStringCellValue())){
-                        sheet1.removeRow(sheet1.getRow(rowIndex));
-
-                        if (rowIndex<sheet1.getLastRowNum()) {
-                            sheet1.shiftRows(rowIndex + 1, sheet1.getLastRowNum(), -1); //删除后下面行上移,则不需要移动rowIndex
-                        }
-                    }
-                    else {
-                        rowIndex++;
-                    }
-                }
+                Workbook wb = poiUtils.exportErrorXls(sheetIndex,validateColIndex,1 + affectCount + failCount);
 
                 //todo 将wb保存到oss
                 ByteArrayOutputStream output = new ByteArrayOutputStream();
-                poiUtils.getWorkbook().write(output);
+                wb.write(output);
 
                 byte[] buffer = output.toByteArray();
                 ByteArrayInputStream input = new ByteArrayInputStream(buffer);