Explorar o código

台账查询修改。

zhengqiang %!s(int64=5) %!d(string=hai) anos
pai
achega
c4c814b695

+ 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;
+    }
 }

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

@@ -63,8 +63,8 @@
             and a.del_flag = false and b.del_flag=false
             <if test="searchParams.deviceIdList != null">
                 and b.id_ in
-                <foreach item="item" collection="searchParams.deviceIdList"  open="('" separator="," close="')">
-                    ${item}
+                <foreach item="item" collection="searchParams.deviceIdList"  open="(" separator="," close=")">
+                    #{item}
                 </foreach>
             </if>
             <if test="searchParams.deviceNo != null">

+ 10 - 20
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -14,6 +14,7 @@ import com.jpsoft.smart.modules.lapi.service.ILapiService;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.UserService;
+import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -21,7 +22,9 @@ 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.Row;
 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 +366,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 +728,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);