package cn.cqu.service.impl;
import cn.cqu.dao.AccountDao;
import cn.cqu.dao.DeviceDao;
import cn.cqu.pojo.Account;
import cn.cqu.pojo.Device;
import cn.cqu.pojo.DeviceUseage;
import cn.cqu.pojo.dto.DeviceDTO;
import cn.cqu.service.DeviceService;
import cn.cqu.util.ExcelExportUtil;
import cn.cqu.util.MyLog;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class DeviceServiceImpl implements DeviceService {
@Autowired
private DeviceDao deviceDao;
@Autowired
private AccountDao accountDao;
/**
* 查询所有设备DTO
*
* @return
*/
@Override
public List<DeviceDTO> listDeviceDto() {
List<DeviceDTO> resList = new ArrayList<>();
//获取所有设备基础信息
List<Device> deviceList = deviceDao.listDevice();
for (Device device:deviceList
) {
DeviceDTO deviceDTO = getDeviceDtoById(device.getDevId());
resList.add(deviceDTO);
}
return resList;
}
/**
* 根据id查询设备DTO
*
* @param deviceId
* @return
*/
@Override
public DeviceDTO getDeviceDtoById(String deviceId) {
DeviceDTO example = new DeviceDTO();
example.setDevId(deviceId);
List<DeviceDTO> deviceDTOList = deviceDao.listDeviceDtoByExample(example);
if(deviceDTOList.size()>0){
DeviceDTO deviceDTO = deviceDTOList.get(0);
deviceDTO.setUserList(accountDao.listUserByDeviceId(deviceId));
return deviceDTO;
}
else return null;
}
/**
* 新增设备
*
* @param example
* @return
*/
@Override
@MyLog(actionName = "新增设备")
public int addDevice(Device example) {
return deviceDao.insertDevice(example);
}
/**
* 修改设备信息
*
* @param example
* @return
*/
@Override
@MyLog(actionName = "修改设备信息")
public int updateDevice(Device example) {
example.setLastUpate(new Date());
return deviceDao.updateDevice(example);
}
/**
* 根据Id删除设备
*
* @param devId
* @return
*/
@Override
@MyLog(actionName = "根据Id删除设备")
public int deleteDeviceById(String devId) {
return deviceDao.deleteDeviceById(devId);
}
/**
* 修改设备状态
*
* @param devId
* @param status
* @return
*/
@Override
@MyLog(actionName = "修改设备状态")
public int updateStatusByid(String devId, int status) {
DeviceUseage deviceUseage = new DeviceUseage();
deviceUseage.setDevId(devId);
deviceUseage.setDevStatus(status);
return deviceDao.updateDeviceUseage(deviceUseage);
}
/**
* 更新设备持有者
*
* @param devId
* @param groups
* @return
*/
@Override
@MyLog(actionName = "更新设备持有者")
public int updateDevOwnersByDevId(String devId, String[] groups) {
//新数组转换为list方便接下来比较
List<String> addAccountId;
if(!StringUtils.isEmpty(groups[0])) //非空判断
addAccountId = new ArrayList<>(Arrays.asList(groups));
else
addAccountId = new ArrayList<>();
//获取旧的设备使用者id集合 oldAccountId
List<Account> oldAccount = accountDao.listUserByDeviceId(devId);
List<String> deleteAccountId = new ArrayList<>();
List<String> deleteAccountId_coppy = new ArrayList<>();
for (Account account:oldAccount
) {
deleteAccountId.add(account.getUuid());
deleteAccountId_coppy.add(account.getUuid());
}
//将两组id数组对比
deleteAccountId.removeAll(addAccountId);//存在于旧的而不存在于新的,视为需要删除
addAccountId.removeAll(deleteAccountId_coppy);//存在于新的而不存在于旧的,视为需要添加
try {
for (String uuid:deleteAccountId
) {
deviceDao.deleteDeviceUserById(devId,uuid);
}
for (String uuid:addAccountId
) {
deviceDao.insertDeviceUser(devId,uuid);
}
return 1;
}catch (Exception e){
e.printStackTrace();
return 0;
}
}
/**
* 更新设备部门
*
* @param devId
* @param fri_org
* @param sec_org
* @param orgid_addr
* @return
*/
@Override
@MyLog(actionName = "更新设备部门")
public int updateDevOrgsByDevId(String devId, String fri_org, String sec_org, String orgid_addr) {
DeviceUseage example = new DeviceUseage();
example.setDevId(devId);
example.setDepFri(fri_org);
example.setDepSec(sec_org);
example.setAddress(orgid_addr);
return deviceDao.updateDeviceUseage(example);
}
/**
* 根据条件动态查询设备
*
* @param example
* @return
*/
@Override
public List<DeviceDTO> listDeviceDTOByexample(DeviceDTO example) {
List<DeviceDTO> deviceDTOList = deviceDao.listDeviceDtoByExample(example);
for (DeviceDTO deviceDTO: deviceDTOList
) {
deviceDTO.setUserList(accountDao.listUserByDeviceId(deviceDTO.getDevId()));
}
return deviceDTOList;
}
/**
* 导出Excel
*
* @param response
* @param pageName
*/
@Override
@MyLog(actionName = "导出Excel")
public void exportExcel(HttpServletResponse response, String pageName,String[] headers) {
String sheetName = "工作表1";
String fileName="" ;
List<DeviceDTO> deviceList = listDeviceDto();
List<String[]> dataList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//根据pageName不同 填充不同的数据
switch (pageName){
case "deviceManage":
fileName = "设备管理报表";
for (DeviceDTO deviceDTO:deviceList
) {
List<String> arr = new ArrayList();
arr.add(deviceDTO.getDevId());
arr.add(deviceDTO.getType());
arr.add(deviceDTO.getBrand());
arr.add(deviceDTO.getDevModel());
arr.add(sdf.format(deviceDTO.getPurchaseTime()));
arr.add(deviceDTO.getErpCode());
arr.add(deviceDTO.getDevStatus()==1?"停用":"启用");
arr.add(deviceDTO.getDomainStatus()==1?"未加域":"已加域");
String[] arrStr = arr.toArray(new String[0]);
dataList.add(arrStr);
};break;
case "deviceList":
fileName = "设备台账报表";
for (DeviceDTO deviceDTO:deviceList
) {
List<String> arr = new ArrayList();
arr.add(deviceDTO.getDevId());
arr.add(deviceDTO.getType());
arr.add(deviceDTO.getBrand());
arr.add(deviceDTO.getDevModel());
arr.add(sdf.format(deviceDTO.getPurchaseTime()));
arr.add(deviceDTO.getDepFri());
arr.add(deviceDTO.getDepSec());
arr.add(deviceDTO.getAddress());
arr.add(deviceDTO.getUserNameLis
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java精品项目源码第69期IT设备固定资产管理系统.zip (257个子文件)
DeviceServiceImpl.class 13KB
DeviceController.class 11KB
ControllerAspect.class 6KB
DeviceDTO.class 6KB
indexController.class 6KB
OrganizationServiceImpl.class 5KB
ExcelExportUtil.class 5KB
AccountServiceImpl.class 4KB
AccountController.class 4KB
BaseInfoController.class 4KB
OrgController.class 4KB
DeviceDao.class 3KB
BaseInfoServiceImpl.class 2KB
UserRealm.class 2KB
NoticeController.class 2KB
SystemLog.class 2KB
AccountDao.class 2KB
DeviceUseage.class 2KB
BaseInfoDao.class 2KB
Device.class 2KB
DeviceRunning.class 2KB
OrganizationDTO.class 2KB
Account.class 2KB
LoginController.class 1KB
NoticeServiceImpl.class 1KB
Notice.class 1KB
DeviceService.class 1KB
OrganizationDao.class 1KB
Organization.class 1KB
SystemLogDao.class 1KB
DeviceMaintain.class 1KB
OrganizationService.class 935B
LoginFormAuthenticationFilter.class 928B
LogServiceImpl.class 920B
AccountService.class 915B
NoticeDao.class 914B
DeviceBrand.class 754B
DeviceType.class 745B
BaseInfoService.class 575B
AccountDTO.class 552B
MyLog.class 419B
NoticeService.class 388B
LogService.class 300B
.classpath 1KB
org.eclipse.wst.common.component 736B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 516KB
materialdesignicons.min.css 120KB
bootstrap-datetimepicker.css 13KB
toastr.min.css 7KB
bootstrap-select.min.css 6KB
bootstrap-switch.min.css 6KB
dataTables.bootstrap4.css 5KB
vendor.bundle.base.css 3KB
d3tree.css 412B
zcgl数据库1.1.doc 405KB
项目设计.docx 17KB
template.docx 15KB
materialdesignicons-webfont.eot 407KB
Roboto-Medium.eot 177KB
Roboto-Regular.eot 177KB
Roboto-Black.eot 177KB
Roboto-Bold.eot 176KB
Roboto-Light.eot 176KB
allotDevice.html 24KB
deviceList.html 21KB
system.html 15KB
account.html 13KB
macAddress.html 13KB
home.html 12KB
charts.html 11KB
secDepartments.html 10KB
deviceManage.html 10KB
addDevice.html 9KB
friDepartments.html 9KB
deviceTypes.html 9KB
editDevice.html 8KB
deviceBrands.html 8KB
index.html 7KB
Organizations.html 6KB
footer.html 6KB
notice.html 5KB
sidebar.html 4KB
login.html 3KB
noticeEdit.html 3KB
noticeContent.html 3KB
header.html 2KB
layout.html 902B
ZCGL.iml 8KB
DeviceServiceImpl.java 13KB
DeviceController.java 10KB
OrganizationServiceImpl.java 6KB
indexController.java 5KB
ControllerAspect.java 5KB
DeviceDTO.java 5KB
AccountServiceImpl.java 4KB
DeviceDao.java 4KB
AccountController.java 4KB
ExcelExportUtil.java 4KB
BaseInfoController.java 3KB
共 257 条
- 1
- 2
- 3
资源评论
- 一瓢源码甘甜水2022-02-07用户下载后在一定时间内未进行评价,系统默认好评。
- java毕业2022-09-05资源很不错,内容和描述一致,值得借鉴,赶紧学起来!
小辰爱喝汤
- 粉丝: 668
- 资源: 132
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功