Explorar o código

1.通知公告后台列表修改,一个公告一条记录。
2.导出测试记录性能优化:将1对多查询,改为1对1查询。
3.连接是否中断,改在inactive中判断。
4.导出改为分页导出,并增加客户端进度提示。

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

+ 1 - 2
common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java

@@ -17,7 +17,6 @@ public interface DeviceInfoService {
 	DeviceInfo getByDeviceNo(String deviceNo);
 	List<DeviceInfo> findByCompanyId(String companyId);
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
-	void updateByDeviceNo(String deviceNo, String ip);
-
+	void updateByDeviceNo(String deviceNo, boolean online);
 	List<DeviceInfo> listOnline();
 }

+ 7 - 22
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java

@@ -89,29 +89,14 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 	}
 
 	@Override
-	public void updateByDeviceNo(String deviceNo, String ip) {
-		try{
-			DeviceInfo deviceInfo= deviceInfoDAO.findByDeviceNo(deviceNo);
-			String oldIp = deviceInfo.getIpAddress();
-
-			if (deviceInfo != null){
-				deviceInfo.setIsOnline(true);
-				deviceInfo.setHeartbeatUpdateTime(new Date());
-				deviceInfo.setAbnormalReason("");
-				deviceInfoDAO.update(deviceInfo);
-			}
-
-
-			if (deviceInfo.getIsAutoUpdate()!=null &&
-			deviceInfo.getIsAutoUpdate() && !deviceInfo.getIpAddress().equals(ip)){
-				deviceInfo.setIpAddress(ip);
-				deviceInfoDAO.update(deviceInfo);
-				log.warn(deviceNo+"的ip由原来的:"+oldIp+"自动更新为:"+ip);
-			}
-		}catch (Exception e){
-			log.error("ip:"+ip+",deviceNo:"+deviceNo +":" +e.getMessage());
-		}
+	public void updateByDeviceNo(String deviceNo, boolean online) {
+		DeviceInfo deviceInfo= deviceInfoDAO.findByDeviceNo(deviceNo);
 
+		if (deviceInfo != null){
+			deviceInfo.setIsOnline(online);
+			deviceInfo.setHeartbeatUpdateTime(new Date());
+			deviceInfoDAO.update(deviceInfo);
+		}
 	}
 
 	@Override

+ 23 - 1
common/src/main/java/com/jpsoft/smart/modules/common/utils/TimeZonesUtil.java

@@ -7,7 +7,6 @@ import java.math.BigDecimal;
  * @date 2020-4-1 13:14
  */
 public class TimeZonesUtil {
-
     public static String getUpperTimeZone(String timeZones){
         String timeZoneStr = timeZones.substring(0,timeZones.lastIndexOf("-")+1);
         String minStr = timeZones.substring(timeZones.lastIndexOf("-")+1,timeZones.length());
@@ -70,4 +69,27 @@ public class TimeZonesUtil {
 
         return h+"时"+m+"分"+s+"秒";
     }
+
+    public static String friendlyTimeFormat(long time){
+        long sec = 1000;
+        long min = 60*sec;
+
+        StringBuilder sb = new StringBuilder();
+
+        if (time>min) {
+            sb.append(String.format("%d分",time/min));
+        }
+
+        long remainder = time % min;
+
+        if (remainder>sec){
+            sb.append(String.format("%d秒",remainder/sec));
+        }
+
+        remainder = remainder % sec;
+
+        sb.append(String.format("%d毫秒",remainder));
+
+        return sb.toString();
+    }
 }

+ 6 - 3
common/src/main/resources/mapper/base/MessageNotice.xml

@@ -92,8 +92,8 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="MessageNoticeMap">
 		<![CDATA[
-			select * from base_message_notice a
-			LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			select a.id_,a.title_,a.status_,a.create_time,a.update_time
+			from base_message_notice a
 		]]>
 		<where>
 			and a.del_flag = false
@@ -101,9 +101,12 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 				and a.title_ like #{searchParams.title}
 			</if>
 			<if test="searchParams.companyIds != null">
-				<foreach collection="searchParams.companyIds" item="companyId" open=" and b.company_id in("  close=")" separator=",">
+				a.id_ in (
+				select b.notice_id from base_message_notice_company b where b.company_id in (
+				<foreach collection="searchParams.companyIds" item="companyId" separator=",">
 					#{companyId}
 				</foreach>
+				)
 			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">

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

@@ -49,9 +49,22 @@
     </resultMap>
     <resultMap id="PersonDeviceLogMap" extends="SimpleMap" type="com.jpsoft.smart.modules.base.entity.PersonDeviceLog">
         <association property="device" column="device_no"
-                     select="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO.getByDeviceNo"></association>
+                     select="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO.getByDeviceNo">
+        </association>
         <association property="person" column="person_id"
-                     select="com.jpsoft.smart.modules.base.dao.PersonInfoDAO.get"></association>
+                     select="com.jpsoft.smart.modules.base.dao.PersonInfoDAO.get">
+        </association>
+    </resultMap>
+    <resultMap id="PersonDeviceLogListMap" extends="SimpleMap" type="com.jpsoft.smart.modules.base.entity.PersonDeviceLog">
+        <association property="device"
+            resultMap="com.jpsoft.smart.modules.base.dao.DeviceInfoDAO.DeviceInfoMap"
+            columnPrefix="device_"
+        />
+        <association
+                property="person"
+                resultMap="com.jpsoft.smart.modules.base.dao.PersonInfoDAO.PersonInfoMap"
+                columnPrefix="person_"
+        />
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.PersonDeviceLog">
         <!--
@@ -112,11 +125,23 @@
         order by record_time asc
 	</select>
 
-    <select id="search" parameterType="hashmap" resultMap="PersonDeviceLogMap">
+    <select id="search" parameterType="hashmap" resultMap="PersonDeviceLogListMap">
         <![CDATA[
-			select a.*,c.del_flag as person_flag  from base_person_device_log a left join base_device_info b
-			on  a.device_no = b.device_no left join base_person_info c
-			on a.person_id = c.id_
+			select a.*,
+	        b.alias_name as device_alias_name,
+			c.name_ as person_name_,
+			c.phone_ as person_phone_,
+			c.id_card as person_id_card,
+			c.open_id as person_open_id,
+			c.position1_ as person_position1_,
+			c.position2_ as person_position2_,
+	        c.position3_ as person_position3_,
+	        c.position4_ as person_position4_,
+	        c.position5_ as person_position5_,
+	        c.face_image_url as person_face_image_url
+			from base_person_device_log a
+			left join base_device_info b on a.device_no = b.device_no
+			left join base_person_info c on a.person_id = c.id_
 		]]>
         <where>
             and a.del_flag = false
@@ -169,8 +194,15 @@
                   and a.temperature_ <= #{searchParams.maxTemperature}
                 ]]>
             </if>
-            <if test="searchParams.matchMsg != null">
-                and a.match_msg like #{searchParams.matchMsg}
+            <if test='searchParams.matchMsg == "1"'>
+                <![CDATA[
+                    and a.person_id<>0
+                ]]>
+            </if>
+            <if test='searchParams.matchMsg == "0"'>
+                <![CDATA[
+                    and a.person_id=0
+                ]]>
             </if>
             <if test="searchParams.distinct">
                 and a.rownum_ in (

+ 27 - 2
lapi/src/main/java/com/jpsoft/smart/lapi/handler/HeartReportHandler.java

@@ -10,6 +10,7 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.SimpleChannelInboundHandler;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.joda.time.DateTime;
 import org.joda.time.Minutes;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -66,7 +67,7 @@ public class HeartReportHandler extends SimpleChannelInboundHandler<HeartReportI
                 sysLog.setPointcut(deviceNo);
                 sysLog.setUrl("/LAPI/V1.0/PACS/Controller/HeartReportInfo");
                 sysLog.setData(heartReportInfo.toString());
-                sysLog.setRemark("收到设备心跳");
+                sysLog.setRemark("设备心跳信号");
                 SocketAddress remoteAddress = ctx.channel().remoteAddress();
                 sysLog.setRemoteIp(remoteAddress.toString());
                 sysLog.setCreateTime(new Date());
@@ -74,7 +75,7 @@ public class HeartReportHandler extends SimpleChannelInboundHandler<HeartReportI
             }).start();
         }
 
-        deviceInfoService.updateByDeviceNo(deviceNo,ip);
+        deviceInfoService.updateByDeviceNo(deviceNo,true);
 
         //新连接,则设置连接对应设备号
         if(ctx.channel().attr(LapiAttrKeys.DEVICE_NO).get()==null){
@@ -92,4 +93,28 @@ public class HeartReportHandler extends SimpleChannelInboundHandler<HeartReportI
             activeLapiChannelMap.put(deviceNo, lapiChannel);
         }
     }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+        super.channelInactive(ctx);
+
+        String deviceNo = ctx.channel().attr(LapiAttrKeys.DEVICE_NO).get();
+
+        if(StringUtils.isNotEmpty(deviceNo)){
+            log.warn(deviceNo + "已离线");
+
+            new Thread(()->{
+                SysLog sysLog = new SysLog();
+                sysLog.setPointcut(deviceNo);
+                sysLog.setUrl("/LAPI/V1.0/PACS/Controller/HeartReportInfo");
+                sysLog.setRemark("设备离线");
+                SocketAddress remoteAddress = ctx.channel().remoteAddress();
+                sysLog.setRemoteIp(remoteAddress.toString());
+                sysLog.setCreateTime(new Date());
+                sysLogService.insert(sysLog);
+
+                deviceInfoService.updateByDeviceNo(deviceNo,false);
+            }).start();
+        }
+    }
 }

+ 4 - 9
web/src/main/java/com/jpsoft/smart/modules/base/controller/MessageNoticeController.java

@@ -1,6 +1,7 @@
 package com.jpsoft.smart.modules.base.controller;
 
 import com.github.pagehelper.Page;
+import com.google.common.collect.Lists;
 import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.MessageNoticeCompany;
 import com.jpsoft.smart.modules.base.entity.PersonCompany;
@@ -256,8 +257,6 @@ public class MessageNoticeController {
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
             String title,
-            String companyId,
-            String companyCode,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             @RequestAttribute String subject){
@@ -284,13 +283,9 @@ public class MessageNoticeController {
             searchParams.put("title","%" + title + "%");
         }
 
-        if (StringUtils.isEmpty(companyCode)){
-            if (!userService.hasRole(subject,"SYSADMIN")) {
-                searchParams.put("companyIds", companyInfo.getCode().split(","));
-            }
-        }
-        else{
-            searchParams.put("companyIds", companyInfo.getCode().split(","));
+        if (!userService.hasRole(subject,"SYSADMIN")) {
+            String[] arr = companyInfo.getCode().split(",");
+            searchParams.put("companyIds",  Arrays.asList(arr,"-1"));
         }
 
         Page<MessageNotice> page = messageNoticeService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);

+ 172 - 90
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceLogController.java

@@ -14,6 +14,7 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
+import com.jpsoft.smart.modules.common.utils.TimeZonesUtil;
 import com.jpsoft.smart.modules.sys.entity.Role;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.RoleService;
@@ -27,18 +28,32 @@ import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+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.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.joda.time.DateTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.web.bind.annotation.*;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 @RestController
 @RequestMapping("/personDeviceLog")
@@ -63,6 +78,10 @@ public class PersonDeviceLogController {
     @Autowired
     private CompanyPositionService companyPositionService;
 
+    @Autowired
+    private ValueOperations<String,Object> valueOperations;
+
+    private final String exportPrefix = "exportDeviceLog_";
 
     @ApiOperation(value = "列表")
     @RequestMapping(value = "pageList", method = RequestMethod.POST)
@@ -144,7 +163,7 @@ public class PersonDeviceLogController {
         }
 
         if (StringUtil.isNotEmpty(matchMsg)) {
-            searchParams.put("matchMsg", "%" + matchMsg + "%");
+            searchParams.put("matchMsg", matchMsg);
         }
 
         if (StringUtil.isNotEmpty(timeRanges)) {
@@ -192,10 +211,28 @@ public class PersonDeviceLogController {
         return msgResult;
     }
 
+    @GetMapping("exportProgress")
+    public MessageResult<String> exportProgress(String timestamp){
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        String exportProgress = (String)valueOperations.get(exportPrefix + timestamp);
+
+        if(StringUtils.isNotEmpty(exportProgress)){
+            msgResult.setMessage(exportProgress);
+            msgResult.setResult(true);
+        }
+
+        return msgResult;
+    }
+
+    public void setExportProgress(String timestamp,String msg){
+        valueOperations.set(exportPrefix + timestamp , msg,5, TimeUnit.MINUTES);
+    }
 
     @ApiOperation(value = "导出日志台账")
     @PostMapping("exportXls")
     @ApiImplicitParams({
+            @ApiImplicitParam(name = "timestamp", value = "时间戳", paramType = "query"),
             @ApiImplicitParam(name = "companyId", value = "所属单位编号", paramType = "query"),
             @ApiImplicitParam(name = "subordinate", value = "是否查询下级单位", required = false, paramType = "query", dataType = "String"),
             @ApiImplicitParam(name = "deviceNo", value = "设备编号", paramType = "query"),
@@ -207,6 +244,7 @@ public class PersonDeviceLogController {
             @ApiImplicitParam(name = "distinct", value = "是否去重", paramType = "query")
     })
     public MessageResult<String> exportXls(
+            String timestamp,
             String companyId,
             @RequestParam(value = "subordinate", defaultValue = "false") Boolean subordinate,
             String deviceNo, String aliasName, String personName,
@@ -214,31 +252,33 @@ public class PersonDeviceLogController {
             @RequestParam(value = "distinct", defaultValue = "false") Boolean distinct,
             @RequestAttribute String subject) {
         MessageResult<String> msgResult = new MessageResult<>();
+
         try {
+            long start = System.currentTimeMillis();
+
             User user = userService.get(subject);
             String userCompanyId = user.getCompanyId();
 
-            HSSFWorkbook workbook = new HSSFWorkbook();
-            HSSFSheet sheet = workbook.createSheet();
+            Workbook workbook = new HSSFWorkbook();
+            Sheet sheet = workbook.createSheet();
 
             //表头
-            HSSFRow rowTitle = sheet.createRow(0);
-            HSSFCell cellTitle1 = rowTitle.createCell(0);
+            Row rowTitle = sheet.createRow(0);
+            Cell cellTitle1 = rowTitle.createCell(0);
             cellTitle1.setCellValue("序号");
-            HSSFCell cellTitle2 = rowTitle.createCell(1);
+            Cell cellTitle2 = rowTitle.createCell(1);
             cellTitle2.setCellValue("检测时间");
-            HSSFCell cellTitle3 = rowTitle.createCell(2);
+            Cell cellTitle3 = rowTitle.createCell(2);
             cellTitle3.setCellValue("人员姓名");
-            HSSFCell cellTitle4 = rowTitle.createCell(3);
+            Cell cellTitle4 = rowTitle.createCell(3);
             cellTitle4.setCellValue("测温度数");
-            HSSFCell cellTitle5 = rowTitle.createCell(4);
+            Cell cellTitle5 = rowTitle.createCell(4);
             cellTitle5.setCellValue("设备编号");
-            HSSFCell cellTitle6 = rowTitle.createCell(5);
+            Cell cellTitle6 = rowTitle.createCell(5);
             cellTitle6.setCellValue("设备别称");
-            HSSFCell cellTitle7 = rowTitle.createCell(6);
+            Cell cellTitle7 = rowTitle.createCell(6);
             cellTitle7.setCellValue("拍照图片");
 
-
             //获取公司
             //五级位置
             //CompanyInfo companyInfo = companyInfoService.get(companyId);
@@ -246,15 +286,15 @@ public class PersonDeviceLogController {
             CompanyPosition companyPosition = null;
             if (companyPositionList.size() > 0) {
                 companyPosition = companyPositionList.get(0);
-                HSSFCell cellTitle8 = rowTitle.createCell(7);
+                Cell cellTitle8 = rowTitle.createCell(7);
                 cellTitle8.setCellValue(companyPosition.getPosition1Name());
-                HSSFCell cellTitle9 = rowTitle.createCell(8);
+                Cell cellTitle9 = rowTitle.createCell(8);
                 cellTitle9.setCellValue(companyPosition.getPosition2Name());
-                HSSFCell cellTitle10 = rowTitle.createCell(9);
+                Cell cellTitle10 = rowTitle.createCell(9);
                 cellTitle10.setCellValue(companyPosition.getPosition3Name());
-                HSSFCell cellTitle11 = rowTitle.createCell(10);
+                Cell cellTitle11 = rowTitle.createCell(10);
                 cellTitle11.setCellValue(companyPosition.getPosition4Name());
-                HSSFCell cellTitle12 = rowTitle.createCell(11);
+                Cell cellTitle12 = rowTitle.createCell(11);
                 cellTitle12.setCellValue(companyPosition.getPosition5Name());
             }
 
@@ -262,7 +302,7 @@ public class PersonDeviceLogController {
             Map<String, Object> searchParams = new HashMap<>();
 
             List<Sort> sortList = new ArrayList<>();
-            sortList.add(new Sort("a.record_time", "desc"));
+            sortList.add(new Sort("a.record_time", "asc"));
 
             //为公司管理员
             boolean isSysAdmin = userService.hasRole(subject, "SYSADMIN");
@@ -307,6 +347,10 @@ public class PersonDeviceLogController {
                 searchParams.put("distinct", distinct);
             }
 
+            if (StringUtil.isNotEmpty(matchMsg)) {
+                searchParams.put("matchMsg", matchMsg);
+            }
+
             if (StringUtil.isNotEmpty(timeRanges)) {
                 String[] timeRangeArray = timeRanges.split(",");
                 String beginTime = "";
@@ -338,103 +382,141 @@ public class PersonDeviceLogController {
                 searchParams.put("maxTemperature", maxTemperature);
             }
 
-            //Page<PersonDeviceLog> page = personDeviceLogService.pageSearch(searchParams, 1, 10000, false, sortList);
-            List<PersonDeviceLog> page = personDeviceLogService.pageList(searchParams,sortList);
+            int pageNum = 1;
+            boolean needCount = true;
+            int totalPages = 1;
+            int pageSize = 500;
+            long total = 0;
+            long exportNum = 0;
 
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
-            for (int i = 0; i < page.size(); i++) {
+            while(pageNum<=totalPages){
+                Page<PersonDeviceLog> page = personDeviceLogService.pageSearch(searchParams, pageNum, pageSize, needCount, sortList);
 
-                PersonDeviceLog personDeviceLog = page.get(i);
+                if(needCount){
+                    totalPages = page.getPages();
+                    total = page.getTotal();
+                    setExportProgress(timestamp , "导出进度:0/" +  page.getTotal() + "...");
+                }
 
-                HSSFRow rowContent = sheet.createRow(i + 1);
+                for (int i = 0; i < page.size(); i++) {
+                    PersonDeviceLog personDeviceLog = page.get(i);
 
-                HSSFCell cellContent1 = rowContent.createCell(0);
-                cellContent1.setCellValue(i + 1);
+                    Row rowContent = sheet.createRow( (pageNum-1)*pageSize + i + 1);
 
-                String recordTime = "";
-                if (personDeviceLog.getRecordTime() != null) {
-                    recordTime = sdf.format(personDeviceLog.getRecordTime());
-                }
+                    Cell cellContent1 = rowContent.createCell(0);
+                    cellContent1.setCellValue(i + 1);
 
-                HSSFCell cellContent2 = rowContent.createCell(1);
-                cellContent2.setCellValue(recordTime);
+                    String recordTime = "";
+                    if (personDeviceLog.getRecordTime() != null) {
+                        recordTime = sdf.format(personDeviceLog.getRecordTime());
+                    }
 
-                String name = "";
-                if (personDeviceLog.getPerson() != null) {
-                    name = personDeviceLog.getPerson().getName();
-                } else {
-                    name = "匿名用户";
-                }
-                HSSFCell cellContent3 = rowContent.createCell(2);
-                cellContent3.setCellValue(name);
-                HSSFCell cellContent4 = rowContent.createCell(3);
-                cellContent4.setCellValue(personDeviceLog.getTemperature().toString());
-                HSSFCell cellContent5 = rowContent.createCell(4);
-                cellContent5.setCellValue(personDeviceLog.getDeviceNo());
-                HSSFCell cellContent6 = rowContent.createCell(5);
-                if(personDeviceLog.getDevice() != null) {
-                    cellContent6.setCellValue(personDeviceLog.getDevice().getAliasName());
-                }
-                HSSFCell cellContent7 = rowContent.createCell(6);
-                cellContent7.setCellValue(personDeviceLog.getFaceImage());
-
-                //五级位置
-                //判断 如果公司没有五级位置 就不做展示
-                if (companyPositionList.size() > 0) {
-                    PersonInfo person = personDeviceLog.getPerson();
-                    if (person != null) {
-                        HSSFCell cellContent8 = rowContent.createCell(7);
-                        if (person.getPosition1() != null) {
-                            cellContent8.setCellValue(person.getPosition1());
-                        }
-                        HSSFCell cellContent9 = rowContent.createCell(8);
-                        if (person.getPosition1() != null) {
-                            cellContent9.setCellValue(person.getPosition2());
-                        }
-                        HSSFCell cellContent10 = rowContent.createCell(9);
-                        if (person.getPosition1() != null) {
-                            cellContent10.setCellValue(person.getPosition3());
-                        }
-                        HSSFCell cellContent11 = rowContent.createCell(10);
-                        if (person.getPosition1() != null) {
-                            cellContent11.setCellValue(person.getPosition4());
-                        }
-                        HSSFCell cellContent12 = rowContent.createCell(11);
-                        if (person.getPosition1() != null) {
-                            cellContent12.setCellValue(person.getPosition5());
+                    Cell cellContent2 = rowContent.createCell(1);
+                    cellContent2.setCellValue(recordTime);
+
+                    String name = "";
+                    if (personDeviceLog.getPerson() != null) {
+                        name = personDeviceLog.getPerson().getName();
+                    } else {
+                        name = "匿名用户";
+                    }
+                    Cell cellContent3 = rowContent.createCell(2);
+                    cellContent3.setCellValue(name);
+                    Cell cellContent4 = rowContent.createCell(3);
+                    cellContent4.setCellValue(personDeviceLog.getTemperature().toString());
+                    Cell cellContent5 = rowContent.createCell(4);
+                    cellContent5.setCellValue(personDeviceLog.getDeviceNo());
+                    Cell cellContent6 = rowContent.createCell(5);
+                    if(personDeviceLog.getDevice() != null) {
+                        cellContent6.setCellValue(personDeviceLog.getDevice().getAliasName());
+                    }
+                    Cell cellContent7 = rowContent.createCell(6);
+                    cellContent7.setCellValue(personDeviceLog.getFaceImage());
+
+                    //五级位置
+                    //判断 如果公司没有五级位置 就不做展示
+                    if (companyPositionList.size() > 0) {
+                        PersonInfo person = personDeviceLog.getPerson();
+                        if (person != null) {
+                            Cell cellContent8 = rowContent.createCell(7);
+                            if (person.getPosition1() != null) {
+                                cellContent8.setCellValue(person.getPosition1());
+                            }
+                            Cell cellContent9 = rowContent.createCell(8);
+                            if (person.getPosition1() != null) {
+                                cellContent9.setCellValue(person.getPosition2());
+                            }
+                            Cell cellContent10 = rowContent.createCell(9);
+                            if (person.getPosition1() != null) {
+                                cellContent10.setCellValue(person.getPosition3());
+                            }
+                            Cell cellContent11 = rowContent.createCell(10);
+                            if (person.getPosition1() != null) {
+                                cellContent11.setCellValue(person.getPosition4());
+                            }
+                            Cell cellContent12 = rowContent.createCell(11);
+                            if (person.getPosition1() != null) {
+                                cellContent12.setCellValue(person.getPosition5());
+                            }
                         }
                     }
+
+                    sheet.autoSizeColumn(i);
                 }
 
+                pageNum++;
+                needCount = false; //第二页就不用查总数
+                exportNum += page.size();
 
-                sheet.autoSizeColumn(i);
+                setExportProgress(timestamp ,String.format("导出进度:%s/%s...", exportNum, total));
             }
 
             //todo 将wb保存到oss
             ByteArrayOutputStream output = new ByteArrayOutputStream();
             workbook.write(output);
-
             byte[] buffer = output.toByteArray();
-            ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+            output.close();
+
+            logger.warn("原文件大小:" + buffer.length);
+
+            String fileName = DateTime.now().toString("yyyyMMddHHmmss") + ".xls";
 
-            String downloadUrl = OSSUtil.upload(ossConfig, "import", "error.xls", input);
+            InputStream input = new ByteArrayInputStream(buffer);
+
+            //todo 如果超过2M则压缩
+            if(buffer.length>2*1024*1024){
+                setExportProgress(timestamp ,"导出数据完毕,正在压缩...");
+
+                ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
+
+                ZipOutputStream zos = new ZipOutputStream(zipOut);
+                ZipEntry zipEntry = new ZipEntry(fileName);
+                zos.putNextEntry(zipEntry);
+                zos.write(buffer, 0, buffer.length);
+                zos.close();
+
+                byte[] zipBuffer = zipOut.toByteArray();
+                logger.warn("压缩后文件大小:" + zipBuffer.length);
+
+                input = new ByteArrayInputStream(zipBuffer);
+            }
+
+            long end = System.currentTimeMillis();
+
+            setExportProgress(timestamp ,"导出数据完毕,正在保存...");
+            String downloadUrl = OSSUtil.upload(ossConfig, "export", fileName, input);
 
-            //todo 返回导入失败报表下载链接
             msgResult.setData(downloadUrl);
-            msgResult.setResult(true);
 
-            //将exal输出到哪个文件夹中
-//            ByteArrayOutputStream out = new ByteArrayOutputStream();
-//            workbook.write(out);
-//            workbook.close();
-//
-//            String fileName = new String("导出数据".getBytes("UTF-8"), "iso-8859-1");
-//            response.setContentType("application/x-msdownload");
-//            response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls");
-//            response.getOutputStream().write(out.toByteArray());
-//            response.getOutputStream().flush();
+            long elapse = end - start;
 
+            msgResult.setMessage(String.format(
+                    "导出完毕,请点击下载链接保存!耗时: %s",
+                    TimeZonesUtil.friendlyTimeFormat(elapse)));
+
+            msgResult.setResult(true);
         } catch (Exception ex) {
             logger.error(ex.getMessage(), ex);
 

+ 62 - 0
web/src/main/java/com/jpsoft/smart/modules/common/controller/TinymceController.java

@@ -0,0 +1,62 @@
+package com.jpsoft.smart.modules.common.controller;
+
+import com.jpsoft.smart.config.OSSConfig;
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
+import org.apache.commons.lang3.StringUtils;
+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.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+@Controller
+@RequestMapping("/tinymce")
+public class TinymceController {
+    @Autowired
+    private OSSConfig ossConfig;
+
+    @RequestMapping(value = "/upload", method = RequestMethod.POST)  
+    @ResponseBody  
+    public Map<String, String> upload(HttpServletRequest request,HttpServletResponse response,@RequestParam MultipartFile upfile) throws IOException {
+	    Map<String, String> result = new HashMap<>();
+
+	    if (request.getMethod().equals("OPTIONS")){
+            response.setStatus(202);
+            return result;
+        }
+
+    	String retImgUrl = "";
+		String subFolder ="/editor";
+
+		try {
+            retImgUrl = OSSUtil.upload(ossConfig,subFolder,upfile.getOriginalFilename(),upfile.getInputStream());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+    	String oldFileName= upfile.getOriginalFilename();
+
+    	//返回类型
+        if(StringUtils.isNotEmpty(retImgUrl)){
+	    	result.put("url", retImgUrl);
+	        result.put("size", String.valueOf(upfile.getSize()));  
+	        result.put("type", oldFileName.substring(oldFileName.lastIndexOf(".")));
+	        result.put("title", oldFileName.substring(0,oldFileName.lastIndexOf(".")));
+	        result.put("original", oldFileName.substring(0,oldFileName.lastIndexOf(".")));//文件名称
+	        result.put("state", STATE_SUCESS);
+        }
+
+        return result;  
+    }
+
+    private final static String STATE_SUCESS = "SUCCESS";
+}

+ 3 - 3
web/src/main/java/com/jpsoft/smart/schduled/CleanVisitorRecordTask.java

@@ -55,13 +55,13 @@ public class CleanVisitorRecordTask {
             removeRawCount += personDeviceLogService.delete(personDeviceLog.getId());
         }
 
-        //删除过滤记录
-        removeFilterCount = personDeviceFilterLogService.deleteExpiredVisitorRecord(100);
+        //删除过滤记录->过滤表中都是保存person_id!=0记录
+//      removeFilterCount = personDeviceFilterLogService.deleteExpiredVisitorRecord(100);
 
         //增加系统日志
         SysLog sysLog = new SysLog();
         sysLog.setPointcut("清除过期访问者测温记录");
-        sysLog.setRemark(String.format("删除图片数量:%s,删除原始测温记录:%s,删除过滤后测温记录:%s",
+        sysLog.setRemark(String.format("删除图片数量:%s,删除原始测温记录:%s",
                 removeImageCount,removeRawCount,removeFilterCount));
         sysLog.setCreateTime(new Date());
 

+ 2 - 2
web/src/main/java/com/jpsoft/smart/schduled/HeartbeatDetectionTask.java

@@ -25,8 +25,8 @@ public class HeartbeatDetectionTask {
     @Autowired
     private ILapiService lapiService;
 
-    //每2分钟执行一次
-    @Scheduled(cron = "0 0/2 * * * ?")
+    //每2分钟执行一次->改在unactive方法中执行
+//    @Scheduled(cron = "0 0/2 * * * ?")
     public void run() {
         log.warn("设备在线定时任务启动");
         List<DeviceInfo> deviceInfoList = deviceInfoService.listOnline();