基于javaweb+mysql的ssm+mavenit设备固定资产管理系统(java+ssm+thymeleaf+html+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM+Mavenit设备固定资产管理系统(java+ssm+thymeleaf+html+mysql+maven)
一、项目简述
功能包括: 用户登录,设备管理,设备指派,贝附信息,信息公告, 信息维护,系统管理,图表统计等等功能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
int typeIndex = text.indexOf("设备类型:");
int dateIndex = text.indexOf("购买日期:");
int brandIndex = text.indexOf("设备品牌:");
int erpCodeIndex = text.indexOf("ERP编码:");
int modelIndex = text.indexOf("设备型号:");
/* 开始截取 */
String id = text.substring(idIndex, typeIndex).substring(5).trim();
String type = text.substring(typeIndex, dateIndex).substring(5).trim();
String purchaseTime = text.substring(dateIndex, brandIndex).substring(5).trim();
purchaseTime = sdf.format(sdf2.parse(purchaseTime));
String brand = text.substring(brandIndex, erpCodeIndex).substring(5).trim();
String erpcode = text.substring(erpCodeIndex, modelIndex).substring(6).trim();
String model=text.substring(modelIndex).substring(5).trim();
Map resMap = new HashMap();
resMap.put("id",id);
resMap.put("type",type);
resMap.put("purchaseTime",purchaseTime);
resMap.put("brand",brand);
resMap.put("erpCode",erpcode);
resMap.put("devModel",model);
is.close();
return resMap;
}
public Map findMap(List<HashMap<String, Object>> list){
//组装结果
List<String> keyList = new ArrayList<>();
List<Long> valueList = new ArrayList<>();
Map<String, Object> res = new HashMap<>();
String key;
long value;
for (HashMap<String, Object> stringStringMap : list) {
for (Map.Entry<String, Object> entry : stringStringMap.entrySet()) {
if ("key".equals(entry.getKey())) {
key = (String) entry.getValue();
keyList.add(key);
} else {
value = (long) entry.getValue();
valueList.add(value);
}
}
}
res.put("keyArr", keyList.toArray());
res.put("valueArr", valueList.toArray());
return res;
}
@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());
/**
* 修改设备信息
* @param example
* @return
*/
int updateDevice(Device example);
/**
* 根据Id删除设备
* @param devId
* @return
*/
int deleteDeviceById(String devId);
/**
* 修改设备状态
* @param devId
* @param status
* @return
*/
int updateStatusByid(String devId, int status);
/**
* 更新设备持有者
* @param devId
* @param groups
* @return
*/
int updateDevOwnersByDevId(String devId,String[] groups);
/**
* 更新设备部门
* @param devId
* @param fri_org
* @param sec_org
* @param orgid_addr
* @return
*/
int updateDevOrgsByDevId(String devId,String fri_org,String sec_org,String orgid_addr );
/**
* 根据条件动态查询设备
* @param example
* @return
*/
List<DeviceDTO> listDeviceDTOByexample(DeviceDTO example);
/**
}
//将两组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);
}
/**
* 根据条件动态查询设备
* @throws ParseException
*/
@PostMapping
public String addDevice(HttpServletRequest request) throws ParseException {
Device device = new Device();
device.setDevId(request.getParameter("devId"));
device.setTypeId(request.getParameter("typeId"));
device.setBrandId(request.getParameter("brandId"));
device.setDevModel(request.getParameter("devModel"));
device.setErpCode(request.getParameter("erpCode"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
device.setPurchaseTime(sdf.parse(request.getParameter("purchaseTime")));
device.setLastUpate(new Date());
//新增设备基本信息时,触发器会自动新增设备使用信息和运行信息
deviceService.addDevice(device);
return "deviceManage";
}
/**
* 检查设备id是否重复
* @param devId
* @return
*/
@GetMapping("/checkDevId")
@ResponseBody
public int checkDevId(String devId){
DeviceDTO deviceDTO = deviceService.getDeviceDtoById(devId);
if (deviceDTO != null )
return 0;
else
return 1;
}
/**
* 修改设备基础信息
* @param request
* @return
* @throws ParseException
*/
@PutMapping("/baseInfo")
public String updateDevicveBaseInfo(HttpServletRequest request) throws ParseException {
Device device = new Device();
device.setDevId(request.getParameter("devId"));
device.setTypeId(request.getParameter("typeId"));
device.setBrandId(request.getParameter("brandId"));
device.setDevModel(request.getParameter("devModel"));
device.setErpCode(request.getParameter("erpCode"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
device.setPurchaseTime(sdf.parse(request.getParameter("purchaseTime")));
public void deviceList(HttpServletRequest request,ModelMap map){
String user = (String) SecurityUtils.getSubject().getPrincipal();
request.getSession().setAttribute("loginUser",user);
List<DeviceType> typeList = baseInfoService.listDeviceType();
List<DeviceBrand> deviceBrandList = baseInfoService.listDeviceBrand();
Organization example = new Organization();
example.setOrgLevel(1);
List<Organization> organizationList = organizationService.listOrganizationByExample(example);
map.put("parentOrg",organizationList);
map.put("deviceBrandList",deviceBrandList);
map.put("deviceTypeList",typeList);
}
//信息公告
@GetMapping("/notice")
public void noticeList(){}
//设备类型
@GetMapping("/deviceTypes")
public void deviceTypes(){}
//设备品牌
@GetMapping("/deviceBrands")
public void deviceBrands(){}
//一级部门
@GetMapping("/friDepartments")
public void friDepartments(){}
//二级部门
@GetMapping("/secDepartments")
public void secDepartments(ModelMap map){
Organization example = new Organization();
example.setOrgLevel(1);
List<Organization> organizationList = organizationService.listOrganizationByExample(example);
map.put("parentOrg",organizationList);
}
//物理地址
@GetMapping("/macAddress")
public void macAddress(ModelMap map){
Organization example = new Organization();
example.setOrgLevel(1);
List<Organization> organizationList = organizationService.listOrganizationByExample(example);
map.put("parentOrg",organizationList);
}
//组织结构
@GetMapping("/Organizations")
public void Organizations(){}
//新增设备
@GetMapping("/addDevice")
public void addDevice(ModelMap map){
List<DeviceBrand> deviceBrandList = baseInfoService.listDeviceBrand();
map.put("deviceBrandList",deviceBrandList);
List<DeviceType> deviceTypeList = baseInfoService.listDeviceType();
map.put("deviceTypeList",deviceTypeList);
*/
private void printOptLog() {
Gson gson = new Gson();
String optTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startTimeMillis);
String data1 = "管理员:" + userNo + "\r\n"
+ "请求地址:" + requestPath + "\r\n"
+ "请求IP:" + remoteAddr + "\r\n"
+ "方法描述:" + discription + "\r\n"
+ "开始时间:" + optTime + "\r\n"
+ "调用方法时间:" + (endTimeMillis - startTimeMillis) + "ms;" + "\r\n"
+"参数:"+gson.toJson(inputParamMap)+"\r\n"
+"返回参数:"+gson.toJson(outputParamMap)+"\r\n";
System.out.println(data1);
SystemLog systemLog = new SystemLog();
systemLog.setUserNo(userNo);
systemLog.setRequestPath(requestPath);
systemLog.setRemoteAddr(remoteAddr);
systemLog.setDiscription(discription);
systemLog.setStartTime(new Date(startTimeMillis));
systemLog.setExecutionTimeMillis(endTimeMillis - startTimeMillis);
systemLog.setInputParam(gson.toJson(inputParamMap));
systemLog.setOutputParam(gson.toJson(outputParamMap));
systemLogDao.insertLog(systemLog);
}
}
@Controller
@RequestMapping("/account")
public class AccountController {
//自动注入服务类
@Autowired
private AccountService accountService;
/**
* 管理员账户信息
}
/**
* 按用户名筛选设备
* @param dataList
* @param userName
* @return
*/
public List<DeviceDTO> selectDeviceDTObyUserName(List<DeviceDTO> dataList,String userName) {
if (dataList != null) {
Iterator iterator = dataList.iterator();
while (iterator.hasNext()) {
DeviceDTO deviceDTO = (DeviceDTO) iterator.next();
String userNameList = deviceDTO.getUserNameList();
if (!userNameList.contains(userName)) {
iterator.remove();
}
}
}
return dataList;
}
/**
* 根据类型统计设备数量
* @param monthStr
* @return
*/
@Override
public Map staDeviceByType(String monthStr) {
List<HashMap<String, Object>> list = deviceDao.staDeviceByType(monthStr);
return findMap(list);
}
/**
* 根据品牌统计设备数量
* @param monthStr
* @return
*/
@Override
public Map staDeviceByBrand(String monthStr) {
List<HashMap<String, Object>> list = deviceDao.staDeviceByBrand(monthStr);
return findMap(list);
}
/**
* 根据部门统计设备数量
* @param monthStr
* @return
*/
@Override
}
//账户信息
@GetMapping("/account")
public void account(){}
//设备台账
@GetMapping("/deviceList")
public void deviceList(HttpServletRequest request,ModelMap map){
String user = (String) SecurityUtils.getSubject().getPrincipal();
request.getSession().setAttribute("loginUser",user);
List<DeviceType> typeList = baseInfoService.listDeviceType();
List<DeviceBrand> deviceBrandList = baseInfoService.listDeviceBrand();
Organization example = new Organization();
example.setOrgLevel(1);
List<Organization> organizationList = organizationService.listOrganizationByExample(example);
map.put("parentOrg",organizationList);
map.put("deviceBrandList",deviceBrandList);
map.put("deviceTypeList",typeList);
}
//信息公告
@GetMapping("/notice")
public void noticeList(){}
//设备类型
@GetMapping("/deviceTypes")
public void deviceTypes(){}
//设备品牌
@GetMapping("/deviceBrands")
public void deviceBrands(){}
//一级部门
@GetMapping("/friDepartments")
public void friDepartments(){}
//二级部门
@GetMapping("/secDepartments")
public void secDepartments(ModelMap map){
Organization example = new Organization();
example.setOrgLevel(1);
List<Organization> organizationList = organizationService.listOrganizationByExample(example);
map.put("parentOrg",organizationList);
}
//物理地址
@GetMapping("/macAddress")
public void macAddress(ModelMap map){
Organization example = new Organization();
example.setOrgLevel(1);
List<Organization> organizationList = organizationService.listOrganizationByExample(example);
map.put("parentOrg",organizationList);
}
@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
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
ExcelExportUtil.exportExcelFile(response, workbook,file);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 在响应中返回文件流
* @param response 请求响应
* @param workbook excel文件
*/
public static void exportExcelFile(HttpServletResponse response, XSSFWorkbook workbook,String fileName) {
response.setContentType("application/octet-stream;charset=UTF-8");
fileName+= System.currentTimeMillis();
fileName+=".xlsx";
try {
response.addHeader("Content-Disposition", "attachment;filename="
+ new String(fileName.getBytes("GB2312"), "iso8859-1"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
arr.add(deviceDTO.getDepFri());
arr.add(deviceDTO.getDepSec());
arr.add(deviceDTO.getAddress());
arr.add(deviceDTO.getUserNameList());
arr.add(deviceDTO.getNetwork()==1?"内网":"外网");
arr.add(deviceDTO.getMacAddress());
arr.add(sdf2.format(deviceDTO.getLastUpate()));
String[] arrStr = arr.toArray(new String[0]);
dataList.add(arrStr);
};break;
}
ExcelExportUtil.downloadExcelFile(response,sheetName,headers,dataList,fileName);
}
/**
* 按用户名筛选设备
* @param dataList
* @param userName
* @return
*/
public List<DeviceDTO> selectDeviceDTObyUserName(List<DeviceDTO> dataList,String userName) {
if (dataList != null) {
Iterator iterator = dataList.iterator();
while (iterator.hasNext()) {
DeviceDTO deviceDTO = (DeviceDTO) iterator.next();
String userNameList = deviceDTO.getUserNameList();
if (!userNameList.contains(userName)) {
iterator.remove();
}
}
}
return dataList;
}
/**
* 根据类型统计设备数量
* @param monthStr
* @return
*/
@Override
}
@Aspect
@Component
public class ControllerAspect {
@Autowired
SystemLogDao systemLogDao;
private final static org.slf4j.Logger logger = LoggerFactory.getLogger(ControllerAspect.class);
//切入点表达式
// @Pointcut("execution(public int cn.cqu.service.impl.*.*(..))")
@Pointcut("@annotation(cn.cqu.util.MyLog)")
public void pointCut() {
}
private String requestPath = null ; // 请求地址
private String userNo = null ; // 用户名
private Map<?,?> inputParamMap = null ; // 传入参数
private Map<String, Object> outputParamMap = null; // 存放输出结果
private long startTimeMillis = 0; // 开始时间
private long endTimeMillis = 0; // 结束时间
private String remoteAddr; //请求IP
private String discription; //方法描述
/**
* 记录开始时间
* @param joinPoint
/**
* 修改设备状态
*
* @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
*/
@GetMapping("/ownerList")
public String getOwnerList(ModelMap map, String devId){
Map resMap = accountService.listOwenrByDevId(devId);
map.put("ownerMap", resMap);
return "allotDevice::list-refresh";
}
/**
* 添加账户
* @param account
* @return
*/
@PostMapping
@ResponseBody
public int addAccount(Account account){
return accountService.addAccount(account);
}
/**
* 根据uuid删除账户
* @param uuid
* @return
*/
@DeleteMapping("/{uuid}")
@ResponseBody
public int deleteAccount(@PathVariable("uuid")String uuid){
return accountService.deleteAccountById(uuid);
}
/**
* 修改账户密码
* @param uuid
* @param password
* @return
*/
@PutMapping("/password")
@ResponseBody
public int updatePassword(String uuid, String password){
return accountService.updatePasswordByid(uuid,password);
}
/**
* 修改账户状态
* @param uuid
* @param status
* @return
*/
@PutMapping("/status")
@ResponseBody
systemLogDao.insertLog(systemLog);
}
}
@Controller
@RequestMapping("/account")
public class AccountController {
//自动注入服务类
@Autowired
private AccountService accountService;
/**
* 管理员账户信息
* @return
*/
@GetMapping("/admins")
public String listAdmins(ModelMap map){
List<AccountDTO> adminList = accountService.listAccountByLevel(2);
List<AccountDTO> superAdminList = accountService.listAccountByLevel(1);
adminList.addAll(superAdminList);
map.put("adminsList", adminList);
return "system::table-refresh";
}
private LogService logService;
/**
* 获取所有设备类型信息
* @param map
* @return
*/
@RequestMapping("/type/list")
public String listDeviceType(ModelMap map){
List<DeviceType> typeList = baseInfoService.listDeviceType();
map.put("typeList",typeList);
return "deviceTypes::table-refresh";
}
/**
* 添加设备类型
* @param deviceType
* @return
*/
@PostMapping("/type")
@ResponseBody
public int addtDeviceType(DeviceType deviceType){
return baseInfoService.addtDeviceType(deviceType);
}
/**
* 删除设备类型
* @param typeId
* @return
*/
@DeleteMapping("/type/{typeId}")
@ResponseBody
public int delteDeviceTypByid(@PathVariable("typeId") String typeId){
return baseInfoService.deleteDeviceTypeById(typeId);
}
/**
* 修改设备类型
* @param deviceType
* @return
*/
@PutMapping("/type")
@ResponseBody
public int updateDeviceType(DeviceType deviceType){
return baseInfoService.updateDeviceType(deviceType);