packagecom.ts017.zjh;importjava.text.NumberFormat;importjava.util.Iterator;importjava.util.List;importjava.util.Map;importjava.util.Scanner;importcom.ts017.zjh.dao.IDeptDAO;importcom.ts017.zjh.dao.IEmpDAO;importcom.ts017.zjh.dao.factory.DAOFactory;importcom.ts017.zjh.vo.Department;importcom.ts017.zjh.vo.Employee;publicclassDepartmentOperate{privateIDeptDAOdao=null;Scannerscn=null;publicDepartmentOperate(){this.dao=DAOFactory.getIDemptDAOInstance();scn=newScanner(System.in);}publicvoidaddDepartment(){System.out.println();System.out.println(添加部门信息);System.out.println(=================================);System.out.print(请输入部门名称:);StringdeptName=scn.next();DepartmentrepeatDept=getDepartmentByName(deptName);if(repeatDept!=null){System.out.println(您输入的部门名已存在);return;}Departmentdept=newDepartment();dept.setDeptName(deptName);booleanflag=false;try{flag=this.dao.doCreate(dept);}catch(Exceptione){e.printStackTrace();}if(flag){System.out.println(添加部门成功);}else{System.out.println(添加部门失败);}}publicvoiddelDepartment(){System.out.println();System.out.print(请输入要删除的部门编号:);intdeptId=scn.nextInt();Departmentdept=getDepartmentById(deptId);if(dept==null){System.out.println(您输入的部门不存在);return;}IEmpDAOempDAO=DAOFactory.getIEmpDAOInstance();ListEmployeeemps=null;try{emps=empDAO.findByDeptId(deptId);}catch(Exceptione){e.printStackTrace();}if(emps!=null){this.showDepartment(dept);if(emps.size()0){System.out.println(该部门中有员工存在,若删除该部门,则相应的员工也会被删除,确定要删除吗(y/n)?);Stringopt=scn.next();if(opt.equalsIgnoreCase(y)){booleanflag=false;try{empDAO.doDeleteByDeptId(deptId);flag=this.dao.doDelete(deptId);}catch(Exceptione){e.printStackTrace();}if(flag){System.out.println(删除部门成功);}else{System.out.println(删除部门失败);}}}else{System.out.println(确定要删除该部门信息吗(y/n)?);Stringopt=scn.next();if(opt.equalsIgnoreCase(y)){booleanflag=false;try{flag=this.dao.doDelete(deptId);}catch(Exceptione){e.printStackTrace();}if(flag){System.out.println(删除部门成功);}else{System.out.println(删除部门失败);}}}}}publicvoidfindAll(){ListDepartmentdepts=null;try{depts=this.dao.findAll();}catch(Exceptione){e.printStackTrace();}if(depts!=null&&depts.size()!=0){this.showDepartment(depts);}else{System.out.println(没有部门信息);}}publicvoidfindDepartment(){intopt;do{this.showFindMenu();opt=scn.nextInt();switch(opt){case1:this.findByDeptId();break;case2:this.findByDeptname();break;case0:return;}}while(opt!=0);}publicvoidfindByDeptname(){System.out.println();System.out.print(请输入查找的部门名称:);StringdeptName=scn.next();Departmentdept=getDepartmentByName(deptName);if(dept!=null){this.showDepartment(dept);}else{System.out.println(相关信息不存在);}}publicvoidfindByDeptId(){System.out.println();System.out.print(请输入要查找的部门号:);intdeptId=scn.nextInt();Departmentdept=getDepartmentById(deptId);if(dept!=null){this.showDepartment(dept);}else{System.out.println(相关信息不存在);}}publicvoidupdateDepartment(){System.out.println();System.out.print(请输入要更新的部门编号:);intdeptId=scn.nextInt();Departmentdept=getDepartmentById(deptId);if(dept==null){System.out.println(您输入的部门不存在);return;}this.showDepartment(dept);System.out.println(更新部门信息);System.out.println(============================);System.out.print(请输入新的部门名称:);StringdeptName=scn.next();DepartmentrepeatDept=getDepartmentByName(deptName);while(repeatDept!=null){System.out.println(您输入的部门名称已存在,请重新输入);deptName=scn.next();repeatDept=getDepartmentByName(deptName);}DepartmentnewDept=newDepartment();newDept.setDeptId(deptId);newDept.setDeptName(deptName);booleanflag=false;try{flag=this.dao.doUpdate(newDept);}catch(Exceptione){e.printStackTrace();}if(flag){System.out.println(更新员工信息成功);}else{System.out.println(更新员工信息失败);}}publicvoidshowGroupAvgSalaryAboutDept(){MapInteger,DepartmentdeptMap=null;MapInteger,DoubleavgSalary=null;try{deptMap=this.dao.getDepartmentMap();avgSalary=this.dao.getAverageSalaryByGroup();}catch(Exceptione){e.printStackTrace();}System.out.println();System.out.println(\t部门平均薪水);System.out.println();System.out.println(\t部门编号\t部门名称\t平均薪水);System.out.println(===========================================);IteratorIntegerit=avgSalary.keySet().iterator();NumberFormatformat=NumberFormat.getInstance();format.setMaximumFractionDigits(1);while(it.hasNext()){Integerid=it.next();System.out.println(\t+id.intValue()+\t+deptMap.get(id).getDeptName()+\t+format.format(avgSalary.get(id)));}System.out.println();}publicvoidshowEmpCountAboutDept(){MapInteger,IntegerempCountMap=null;MapInteger,DepartmentdeptMap=null;try{empCountMap=this.dao.getEmpCountByGroup();deptMap=this.dao.getDepartmentMap();}catch(Exceptione){e.printStackTrace();}System.out.println();System.out.println(\t部门员工信息);System.out.println();System.out.println(\t编号\t名称\t人数);System.out.println(===========================================);IteratorIntegerit=empCountMap.keySet().iterator();while(it.hasNext()){Integerid=it.next();System.out.println(\t+id.intValue()+\t+deptMap.get(id).getDeptName()+\t+empCountMap.get(id));}System.out.println();}publicvoidshowTopAndLowSalaryAboutDept(){MapInteger,DoubletopSalaryMap=null;MapInteger,Doublel