瀏覽代碼

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

yeshijie 3 年之前
父節點
當前提交
1156c989c9

+ 4 - 0
common/common-entity/sql记录

@ -1346,3 +1346,7 @@ CREATE TABLE `base_hvdevice_sos_log` (
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='烟感气感设备报警日志记录表';
-- 2021-08-23 已执行
ALTER table `base`.`wlyy_devices` add column `device_type` tinyint(2) DEFAULT NULL COMMENT '设备种类 0健康设备 1安防设备'

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/DeviceDetail.java

@ -43,6 +43,7 @@ public class DeviceDetail extends IdEntity {
    private Integer isBinding;//是否绑定(0否 1 绑定单端口 2 绑定双端口)
    private String bindingCount;//绑定次数({"1":"0", "2":"0"})
    private Date grantTime;//发放时间
    private Integer deviceType;
    //1.5.0版本新增字段
    private String grantDoctor;//发放医生code
@ -314,4 +315,13 @@ public class DeviceDetail extends IdEntity {
    public void setGrantDoctorName(String grantDoctorName) {
        this.grantDoctorName = grantDoctorName;
    }
    @Column(name = "device_type")
    public Integer getDeviceType() {
        return deviceType;
    }
    public void setDeviceType(Integer deviceType) {
        this.deviceType = deviceType;
    }
}

+ 50 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/DetectionPlatformService.java

@ -2,12 +2,14 @@ package com.yihu.jw.care.service.statistics;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.restmodel.web.PageEnvelop;
import io.swagger.models.auth.In;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
@ -50,21 +52,66 @@ public class DetectionPlatformService  {
    public JSONObject getDeviceComapny(){
        JSONObject object = new JSONObject();
        String deviceTypeSum = "SELECT COUNT(1) deviceTypeSum FROM dm_device where del = 1 GROUP BY brands";
        String deviceTypeSum = "SELECT * FROM wlyy_devices WHERE device_name IS NOT NULL AND device_name != '' GROUP BY device_name";
        List<Map<String , Object>> deviceList = jdbcTemplate.queryForList(deviceTypeSum);
        if (deviceList.size() > 0) {
            object.put("deviceTypeCount",deviceList.size()); //设备品牌数量
        } else {
            object.put("deviceTypeCount",0);
        }
        String manufacturerSql = "";
        String manufacturerSql = "SELECT * FROM wlyy_devices WHERE manufacturer IS NOT NULL AND manufacturer != '' GROUP BY manufacturer ;";
        List<Map<String , Object>> manufacturerList = jdbcTemplate.queryForList(manufacturerSql);
        if (manufacturerList.size() > 0) {
            object.put("manufacturerCount",manufacturerList.size());
            object.put("manufacturerCount",manufacturerList.size()); //入驻厂商数量
        } else {
            object.put("manufacturerCount",0);
        }
        String securitySql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" +
                "(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 1) allCount,\n" +
                "(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 1 AND is_binding = 1) isUse";
        List<Map<String , Object>> securityList = jdbcTemplate.queryForList(securitySql);
        if (securityList.size() > 0) {
            object.put("securityAllCount",securityList.get(0).get("allCount")); //安防设备总量
            object.put("securityIsUseCount",securityList.get(0).get("isUse"));//安防设备使用中数量
            object.put("securityInventoryCount",securityList.get(0).get("inventory"));//安防设备库存量
        } else {
            object.put("securityAllCount",0); //安防设备总量
            object.put("securityIsUseCount",0);//安防设备使用中数量
            object.put("securityInventoryCount",0);//安防设备库存量
        }
        String healthSql = "SELECT allCount,isUse,(allCount - isUse) inventory FROM \n" +
                "(SELECT COUNT(1) allCount FROM wlyy_devices WHERE device_type = 0) allCount,\n" +
                "(SELECT COUNT(1) isUse FROM wlyy_devices WHERE device_type = 0 AND is_binding = 1) isUse";
        List<Map<String , Object>> healthList = jdbcTemplate.queryForList(healthSql);
        if (healthList.size() > 0) {
            object.put("healthAllCount",securityList.get(0).get("allCount"));//健康设备总量
            object.put("healthIsUseCount",securityList.get(0).get("isUse"));//健康设备使用中数量
            object.put("healthInventoryCount",securityList.get(0).get("inventory"));//健康设备库存量
        } else {
            object.put("healthAllCount",0);//健康设备总量
            object.put("healthIsUseCount",0);//健康设备使用中数量
            object.put("healthInventoryCount",0);//健康设备库存量
        }
        //物联率
        object.put("lawOfIOT",getRange( ((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")),( (Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount") ) ));
        object.put("isUseAllIot",((Integer)securityList.get(0).get("isUse") + (Integer) healthList.get(0).get("isUser")));//已发放设备
        object.put("allIot",(Integer) securityList.get(0).get("allCount") + (Integer) healthList.get(0).get("allCount"));//总设备
        return object;
    }
    public String getRange(int first, int second) {
        if (second == 0 && first > 0) {
            //如果分母为0 分子不为0 返回100%
            return "100%";
        } else if (second == 0 && first == 0) {
            //如果分母为0 分子为0 返回0%
            return "0%";
        }
        float size = (float) (first * 100) / second;
        DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0
        String filesize = df.format(size);
        return filesize + "%";
    }
}

+ 3 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/DeviceDetailDao.java

@ -20,4 +20,7 @@ public interface DeviceDetailDao extends PagingAndSortingRepository<DeviceDetail
    @Query("select a from DeviceDetail a where a.deviceCode = ?1 and a.manufacturerCode = ?2")
    DeviceDetail findByDeviceCodeAndManufacturerCode(String deviceCode,String manufacturerCode);
    @Query("select a from DeviceDetail a where a.sim = ?2")
    List<DeviceDetail> findBySim(String sim);
}

+ 125 - 2
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java

@ -1,19 +1,27 @@
package com.yihu.jw.care.endpoint;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.service.DeviceService;
import com.yihu.jw.entity.care.device.DeviceDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created with IntelliJ IDEA.
@ -31,6 +39,121 @@ public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    @RequestMapping(value = "/importDeviceFromExcel", produces = "application/json;charset=UTF-8",method = RequestMethod.POST)
    @ResponseBody
    public String importFromExcel(HttpServletRequest request,@ApiParam(value = "文件", required = true)
    @RequestParam(value = "file", required = true) MultipartFile file) {
        List errorLs = new ArrayList<>();
        List correctLs = new ArrayList<>();
        Map<String, String> errorMsgMap = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<String> deviceCodes = new ArrayList<>();
        try {
            request.setCharacterEncoding("UTF-8");
            InputStream inputStream = file.getInputStream();
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet[] sheets = rwb.getSheets();
            int rows;
            int row;
            String manufacturer=null;//厂商名称
            String deviceName; //设备名称
            String deviceModel; //设备型号
            String deviceCode;  //设备SN
            String sim;  //sim卡号
            String bindingCount; //单人{"1":"0"}  多人{"1":"0", "2":"0"}
            String deviceType; //设备种类  0健康设备 1安防设备
            Sheet sheet = sheets[0];    //第一张表
            rows = sheet.getRows();
            for (int j = 1; j < rows; j++) {
                if (sheet.getRow(j).length == 0) {
                    continue;
                }
                DeviceDetail deviceDetail = new DeviceDetail();
                row = j;
                manufacturer = sheet.getCell(0, row).getContents().trim();    //0 厂商名称
                deviceName = sheet.getCell(1, row).getContents().trim();  //1 设备名称
                deviceModel = sheet.getCell(2, row).getContents().trim();   //2 设备型号
                deviceCode = sheet.getCell(3, row).getContents().trim(); //3 设备SN
                sim = sheet.getCell(4, row).getContents().trim();  //4 sim卡号
                bindingCount = sheet.getCell(5, row).getContents().trim(); //5
                deviceType = sheet.getCell(6, row).getContents().trim(); //6 设备种类
                if (StringUtils.isBlank(deviceCode)){
                    continue;
                }
                if (deviceCodes.contains(deviceCode)){
                    errorMsgMap.put(deviceCode,"设备SN码重复");
                    continue;
                }
                deviceCodes.add(deviceCode);
                if (StringUtils.isBlank(manufacturer)){
                    errorMsgMap.put(deviceCode,"厂商名称不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceName)){
                    errorMsgMap.put(deviceCode,"设备名称不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceModel)){
                    errorMsgMap.put(deviceCode,"设备型号不能为空");
                    continue;
                }
                if (StringUtils.isBlank(bindingCount)){
                    errorMsgMap.put(deviceCode,"设备类型不能为空");
                    continue;
                }
                if (StringUtils.isBlank(deviceType)){
                    errorMsgMap.put(deviceCode,"设备种类不能为空");
                    continue;
                }else {
                    if ("健康设备".equals(deviceType)){
                        deviceType = "1";
                    }
                    else if ("安防设备".equals(deviceType)){
                        deviceType= "0";
                    }
                    else {
                        errorMsgMap.put(deviceCode,"不支持该设备种类");
                        continue;
                    }
                }
                if (deviceDetailDao.findByDeviceCode(deviceCode).size()>0){
                    errorMsgMap.put(deviceCode,"该设备SN码已存在");
                    continue;
                }
                if (StringUtils.isNotBlank(sim) && deviceDetailDao.findBySim(sim).size()>0){
                    errorMsgMap.put(deviceCode,"该sim卡号已存在");
                    continue;
                }
                deviceDetail.setApplyDate(sdf.format(new Date()));
                deviceDetail.setManufacturer(manufacturer);
                deviceDetail.setDeviceName(deviceName);
                deviceDetail.setDeviceModel(deviceModel);
                deviceDetail.setDeviceCode(deviceCode);
                deviceDetail.setSim(sim);
                deviceDetail.setBindingCount("");
                deviceDetail.setDeviceType(Integer.parseInt(deviceType));
                correctLs.add(deviceDetail);
            }
            deviceDetailDao.save(correctLs);
            //包装导入结果(导入成功数量、错误对象集合)
            Map<String, Object> map = new HashMap<>();
            map.put("successNum", correctLs.size());
            map.put("failedNum", rows-1 - correctLs.size() );
            map.put("errorData", JSON.toJSONString(errorMsgMap, SerializerFeature.WriteMapNullValue));
            System.out.println(map);
            return success();
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "操作失败!");
        }
    }
    @GetMapping("test")
    public String test(){