基于javaweb+mysql的ssm+mavenit设备固定资产管理系统(java+ssm+thymeleaf+html+mysql+maven)

基于javaweb+mysql的ssm+mavenit设备固定资产管理系统(java+ssm+thymeleaf+html+mysql+maven)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的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等等。

     * @return
     */
    @GetMapping("/list")
    public String listAccounts(ModelMap map){
       List<AccountDTO> accountList = accountService.listAccount();
        map.put("accountDTOList", accountList);
        return "account::table-refresh";
    }

    /**
     * 通过用户名称搜索用户
     * @param map
     * @param userName
     * @return
     */
    @GetMapping("/list/{userName}")
    public String listAccountsByUserName(ModelMap map,@PathVariable("userName")String userName){
       List<AccountDTO> accountList = accountService.listAccountByName(userName);
        map.put("accountDTOList", accountList);
        return "account::table-refresh";
    }
    /**
     * 添加管理员页面
     * @param map
     * @return
     */
    @GetMapping("/users")
    public String listUsers(ModelMap map){
        List<AccountDTO> accountList = accountService.listAccountByLevel(3);
        map.put("usersDTOList", accountList);
        return "system::list-refresh";
    }

    /**
     * 获取设备使用人信息
     * @param map
     * @param devId
     * @return
     */
    @GetMapping("/ownerList")
    public String getOwnerList(ModelMap map, String devId){
        Map resMap  = accountService.listOwenrByDevId(devId);
        map.put("ownerMap", resMap);
        return "allotDevice::list-refresh";
    }

        // 创建表头行
        XSSFRow row = sheet.createRow(rowNum);
        // 填充表头
        for (int m = 0; m < headers.length; m++) {
            XSSFCell cell = row.createCell(m);
            cell.setCellValue(headers[m]);
        }
        // 填充表格数据
        for (int n = 0; n < stringList.size(); n++) {
            XSSFRow dataRow = sheet.createRow(++rowNum);
            String[] data = stringList.get(n);
            for (int j = 0; j < data.length; j++) {
                dataRow.createCell(j).setCellValue(data[j]);
            }
        }
        return workbook;
    }

    /**
     * 下载模板
     * @param response 请求响应
     * @param file     文件
     */
    public static void downloadTemplate(HttpServletResponse response, String file) {
        try {
            ClassPathResource classPathResource = new ClassPathResource(file);
            InputStream inputStream = classPathResource.getInputStream();
            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) {
    }

    /**
     * 更新设备持有者
     *
     * @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;
        }

    }


    /**
     * 根据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
    public int updateStatus(String uuid,int status){
        return accountService.updateStatusByid(uuid,status);
    }

    /**
     * 更改管理员
     * @return
     */
    @PutMapping("/admins")
    @ResponseBody
    public int updateDevOwner(HttpServletRequest request){
        String[] groups = request.getParameter("groups").split(",");
     *
     * @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<>();
                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
    public Map staDeviceByType(String monthStr) {
        List<HashMap<String, Object>> list = deviceDao.staDeviceByType(monthStr);
        return findMap(list);
    }

    /**
     * 根据品牌统计设备数量
        response.setCharacterEncoding("UTF-8");
        //设置ContentType字段值
        response.setContentType("text/html;charset=utf-8");
        //获取所要下载的文件名称
        String filename = request.getParameter("filename");
        //下载文件所在目录

        String folder = request.getServletContext().getRealPath("/WEB-INF/statics/file/");
        //通知浏览器以下载的方式打开
        response.addHeader("Content-type", "appllication/octet-stream");
        response.addHeader("Content-Disposition", "attachment;filename="+filename);
        //通知文件流读取文件
//        InputStream in = request.getServletContext().getResourceAsStream(folder+filename);
        InputStream in = new FileInputStream(folder+filename);
        //获取response对象的输出流
        OutputStream out = response.getOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        //循环取出流中的数据
        while((len = in.read(buffer)) != -1){
            out.write(buffer,0,len);
        }
    }

    /**
     * 获取图表统计数据
     * @param request
     * @return
     * @throws ParseException
     */
    @GetMapping("/statistics")
    @ResponseBody
    public Map<String, Object> reloadChart(HttpServletRequest request) throws ParseException {
        String monthStr = request.getParameter("monthStr");
         monthStr = subMonth(monthStr);
        Map resultMap = new HashMap();
        //设备类型统计
         Map typeMap =  deviceService.staDeviceByType(monthStr);
         resultMap.put("typeMap",typeMap);
         //设备品牌统计
    @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
    @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){

@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;

    }

    /**
     * 新增设备
     *
            throws ServletException, IOException {

        response.setCharacterEncoding("UTF-8");
        //设置ContentType字段值
        response.setContentType("text/html;charset=utf-8");
        //获取所要下载的文件名称
        String filename = request.getParameter("filename");
        //下载文件所在目录

        String folder = request.getServletContext().getRealPath("/WEB-INF/statics/file/");
        //通知浏览器以下载的方式打开
        response.addHeader("Content-type", "appllication/octet-stream");
        response.addHeader("Content-Disposition", "attachment;filename="+filename);
        //通知文件流读取文件
//        InputStream in = request.getServletContext().getResourceAsStream(folder+filename);
        InputStream in = new FileInputStream(folder+filename);
        //获取response对象的输出流
        OutputStream out = response.getOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        //循环取出流中的数据
        while((len = in.read(buffer)) != -1){
            out.write(buffer,0,len);
        }
    }

    /**
     * 获取图表统计数据
     * @param request
     * @return
     * @throws ParseException
     */
    @GetMapping("/statistics")
    @ResponseBody
    public Map<String, Object> reloadChart(HttpServletRequest request) throws ParseException {
        String monthStr = request.getParameter("monthStr");
         monthStr = subMonth(monthStr);
        Map resultMap = new HashMap();
        //设备类型统计
         Map typeMap =  deviceService.staDeviceByType(monthStr);
         resultMap.put("typeMap",typeMap);
         //设备品牌统计
         Map brandMap = deviceService.staDeviceByBrand(monthStr);
         resultMap.put("brandMap",brandMap);
         //设备部门统计
         Map orgMap = deviceService.staDeviceByOrg(monthStr);
         resultMap.put("orgMap",orgMap);
     * 根据条件动态查询设备
     *
     * @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
        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")));
        device.setLastUpate(new Date());
        deviceService.updateDevice(device);
        return "deviceManage";
    }
    }
    /**
     * 添加管理员页面
     * @param map
     * @return
     */
    @GetMapping("/users")
    public String listUsers(ModelMap map){
        List<AccountDTO> accountList = accountService.listAccountByLevel(3);
        map.put("usersDTOList", accountList);
        return "system::list-refresh";
    }

    /**
     * 获取设备使用人信息
     * @param map
     * @param devId
     * @return
     */
    @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
     * 更改管理员
     * @return
     */
    @PutMapping("/admins")
    @ResponseBody
    public int updateDevOwner(HttpServletRequest request){
        String[] groups = request.getParameter("groups").split(",");
        int level = Integer.parseInt(request.getParameter("level"));
        return  accountService.updateAccountLevel(level,groups);
    };

}
package cn.cqu.util;

/**
 * 功能说明:文件工具类
 */
public class ExcelExportUtil {
    /**
     * 导出文件
     * @param response   请求响应
     * @param sheetName  Sheet名称
     * @param headers    表头
     * @param stringList 表数据
     */
    public static void downloadExcelFile(HttpServletResponse response, String sheetName, String[] headers,
                                         List<String[]> stringList,String fileName) {
        ExcelExportUtil.exportExcelFile(response, ExcelExportUtil.createExcelFile(sheetName, headers, stringList),fileName);
    }
    }
    /**
     * 添加管理员页面
     * @param map
     * @return
     */
    @GetMapping("/users")
    public String listUsers(ModelMap map){
        List<AccountDTO> accountList = accountService.listAccountByLevel(3);
        map.put("usersDTOList", accountList);
        return "system::list-refresh";
    }

    /**
     * 获取设备使用人信息
     * @param map
     * @param devId
     * @return
     */
    @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 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 = "更新设备持有者")
        String reStr = sdf.format(dt1);
        return reStr;
    }

    @PostMapping("/file")
    @ResponseBody
    public Map uploadFile(HttpServletRequest request) throws Exception {
        System.out.println("文件上传");
        //文件上传的位置
        String path =  request.getSession().getServletContext().getRealPath("/upload");
        File file = new File(path);
        if(!file.exists()){
            file.mkdirs();
        }
        //解析request对象,获取文件上传项
        DiskFileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload fileUpload = new ServletFileUpload(factory);
        //解析
        List<FileItem> list =  fileUpload.parseRequest(request);
        //遍历
        for (FileItem item:list
             ) {
            if(item.isFormField()){//普通表单项

          }   else{
                String fileName = item.getName()+UUID.randomUUID();
                //完成文件上传
                item.write(new File(path,fileName));
                //删除临时文件
                //item.delete();
                return   deviceService.fileRead(path+"/"+fileName);
            }
        }
        return null;
    }

}
package cn.cqu.controller;

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值