package com.alpha.test;
import com.alpha.dao.UserDao;
import com.alpha.dao.impl.UserDaoImpl;
import com.alpha.pojo.Staff;
import com.alpha.service.impl.staffServiceImpl;
import com.alpha.service.staffService;
import com.sun.org.apache.xpath.internal.operations.Equals;
import com.sun.org.apache.xpath.internal.operations.Number;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
UserDaoImpl userDao = new UserDaoImpl();
staffService staffService = new staffServiceImpl();
StringUtils utils = new StringUtils();
while (true){
System.out.println("欢迎来到alpha员工管理系统,请根据功能输入相应的编号");
System.out.println("1,添加功能");
System.out.println("2,查询功能");
System.out.println("3,显示功能");
System.out.println("4,编辑功能");
System.out.println("5,删除功能");
System.out.println("6,统计功能");
System.out.println("7,退出程序");
System.out.print("请输入序号执行功能:");
Scanner scanner = new Scanner(System.in);
int index = scanner.nextInt();
if( index == 1){
while (true){
System.out.println("根据职工号添加工作量和记录");
System.out.print("请输入相应职工号:");
int pid = scanner.nextInt();
if(userDao.selByPid(pid) != null){
System.out.print("请输入相应工作量(以数字表示):");
int task = scanner.nextInt();
System.out.print("请输入相应记录:");
String recording = scanner.next();
// System.out.println(pid+"task:"+task+"recording"+recording);
staffService.ChangeTaskByPidService(pid,task,recording);
}else {
System.out.println("查无此人");
}
System.out.println("返回主菜单,请输入exit,重新查询请回车");
//清除缓存
scanner.nextLine();
String exit = scanner.nextLine();
if(exit.equals("exit")){
break;
}
}
}else if(index == 2){
while (true){
System.out.println("1.根据职工号或姓名查询员工记录");
System.out.println("2.根据职工号查询工作量");
System.out.print("请输入序号:");
int ind = scanner.nextInt();
if(ind == 1){
System.out.print("请输入职工号或姓名:");
String PAN = scanner.next();
// System.out.println();
String str = userDao.selRecordByPidAndName(PAN,(utils.isNumeric(PAN)));
System.out.println("查询结果:"+str);
}else if(ind == 2){
System.out.print("请输入职工号:");
int pid = scanner.nextInt();
int task = userDao.selTaskByPid(pid);
System.out.println("查询结果:Task = "+task);
}else {
System.out.println("输入无效");
}
System.out.println("返回主菜单,请输入exit,重新查询请回车");
//清除缓存
scanner.nextLine();
String exit = scanner.nextLine();
if(exit.equals("exit")){
break;
}
}
}else if(index == 3){
while (true){
System.out.println("显示所有员工信息");
List<Staff> list = userDao.selAll();
for (Staff staff : list){
System.out.println("员工信息:"+staff);
}
System.out.println("返回主菜单,请输入exit,重新查询请回车");
//清除缓存
scanner.nextLine();
String exit = scanner.nextLine();
if(exit.equals("exit")){
break;
}
}
}else if(index == 4){
while (true){
Staff staff = new Staff();
Staff sta;
System.out.println("请输入要修改的信息的职工号:");
int pid = scanner.nextInt();
sta = userDao.selByPid(pid);
if(sta == null){
System.out.println("查无此人");
}else {
System.out.println("原有信息:"+sta);
System.out.println("说明:如果不想修改某一项的值,可回车跳过");
System.out.print("1,姓名(username):");
scanner.nextLine();
String username = scanner.nextLine();
System.out.print("2,性别(six):");
String six = scanner.nextLine();
System.out.print("3,年龄(age):");
String age = scanner.nextLine();
System.out.print("4,所属部门(unit):");
String unit = scanner.nextLine();
System.out.print("5,电话(phone):");
String phone = scanner.nextLine();
System.out.print("6,任务量(task):");
String task = scanner.nextLine();
System.out.print("6,员工记录(recording):");
String recording = scanner.nextLine();
staff.setRecording(recording);
System.out.println(task);
if(task.equals("")){
staff.setTask(sta.getTask());
}else{
staff.setTask(Integer.valueOf(task));
}
if(phone.equals("")){
staff.setPhone(sta.getPhone());
}else {
staff.setPhone(Integer.valueOf(phone));
}
if(age.equals("")){
staff.setAge(sta.getAge());
}else {
staff.setAge(Integer.valueOf(age));
}
staff.setPid(pid);
staff.setUnit(unit);
staff.setSix(six);
staff.setUsername(username);
System.out.println(staff.toString());
int ind = userDao.updByStaff(staff);
if(ind > 0){
System.out.println("修改成功");
}else {
System.out.println("修改失败");
}
}
System.out.println("返回主菜单,请输入exit,重新查询请回车");
//清除缓存
String exit = scanner.nextLine();
if(exit.equals("exit")){
break;