package cn.jbit.pet.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import cn.jbit.pet.dao.Accountbao;
import cn.jbit.pet.dao.Petbao;
import cn.jbit.pet.dao.Petownerbao;
import cn.jbit.pet.dao.Petstorebao;
import cn.jbit.pet.dao.impl.AccountbaoImpl;
import cn.jbit.pet.dao.impl.PetbaoImpl;
import cn.jbit.pet.dao.impl.PetownerbaoImpl;
import cn.jbit.pet.dao.impl.PetstorebaoImpl;
import cn.jbit.pet.entity.Account;
import cn.jbit.pet.entity.Pet;
import cn.jbit.pet.entity.Petowner;
import cn.jbit.pet.entity.Petstore;
public class Test {
static Scanner input=new Scanner(System.in);
static Petbao petbao=new PetbaoImpl(); //宠物
static Petownerbao petownerbao=new PetownerbaoImpl();//宠物主人
static Petstorebao petstorebao=new PetstorebaoImpl();//宠物商店
static Accountbao accountbao=new AccountbaoImpl();//账目
static int count;
/**
* 启动
* @param args
*/
public static void main(String[] args) {
System.out.println("宠物商店启动");
System.out.println("Wonderland醒来,所有宠物从MySQL中醒来");
petbao.petShow();//查询宠物
System.out.println("\n所有宠物主人从MySQL中醒来");
petownerbao.PetownerShow();//查询主人
System.out.println("\n所有宠物商店从MySQL中醒来");
System.out.println("**********************************");
petstorebao.petstoreShow();//查询宠物商店
System.out.println("**********************************");
do {
System.out.println("\n请选择输入登录模式,输入1为宠物主人登录,输入2为宠物商店登录:");
String num=input.next();
if("1".equals(num)){
Master();//宠物主人登录
}else if("2".equals(num)){
Store();//宠物商店登录
}else{
System.out.println("没有该登录模式!");
}
System.out.println("是否继续登录?(继续操作输入y,不继续操作输入其他字符)");
String yn=input.next();
if(yn.toLowerCase().equals("y")){
}else {
System.out.println("您已退出宠物系统!");
break;
}
} while (true);
}
/**
* 宠物商店登录
*/
static Petstore petstore=new Petstore();
private static void Store() {
System.out.println("请先登录,请输入宠物商店的名字:");
String name=input.next();
System.out.println("请输入宠物商店的密码:");
String password=input.next();
petstore.setName(name);
petstore.setPassword(password);
if (petstorebao.petstore(petstore) != null) {
System.out.println("--------恭喜成功登录--------");
System.out.println("--------宠物商店的基本信息--------");
System.out.println("名字:"+petstore.getName());
System.out.println("元宝数:"+petstore.getDalance());
System.out.println("登录成功后,可以进行如下操作:");
do {
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.开宠物商店");
String num=input.next();
if("1".equals(num)){
storepurchase();//购买
}else if("2".equals(num)){
storeaverage();//卖出
}else if("3".equals(num)){
storefoster();//培育
}else if("4".equals(num)){
storewait();//查询宠物
}else if("5".equals(num)){
storebalance();//查询商店结余
}else if("6".equals(num)){
storeaccounts();//查看商店账目
}else if("7".equals(num)){
storeopen();//开店
}else {
System.out.println("没有该操作!");
}
System.out.println("是否继续操作?(继续操作输入y,不继续操作输入其他字符)");
String yn=input.next();
if(yn.toLowerCase().equals("y")){
}else {
System.out.println("你已返回上一级选项!\n");
break;
}
} while (true);
}
}
/**
* 开店
*/
private static void storeopen() {
System.out.println("请输入您要开的宠物商店的名称:");
String name=input.next();
System.out.println("请输入该宠物商店的密码:");
String password=input.next();
System.out.println("请输入该宠物商店的起始资金:");
double balance=input.nextDouble();
petstore.setName(name);
petstore.setPassword(password);
petstore.setDalance(balance);
petstorebao.petstoreInsert(petstore);
}
/**
* 查询账目
*/
private static void storeaccounts() {
System.out.println("--------当前宠物商店的账务--------");
System.out.println("类型\t宠物名称\t商店名称\t宠物主人\t交易金额\t交易时间");
List<Account> list=new ArrayList<Account>();
list=accountbao.storeaccounts(petstore.getId());
for (int i = 0; i < list.size(); i++) {
if (list.get(i)!=null) {
if (list.get(i).getDeal_type().equals("1")) {
list.get(i).setDeal_type("卖出");
}else {
list.get(i).setDeal_type("购入");
}
System.out.println(list.get(i).getDeal_type()+"\t"+list.get(i).getPet_id()+"\t"+list.get(i).getSeller_id()+"\t"+list.get(i).getBuyer_id()+"\t"+list.get(i).getPrice()+"\t"+list.get(i).getDeal_time());
}
}
list=accountbao.storeaccounts2(petstore.getId());
for (int i = 0; i < list.size(); i++) {
if (list.get(i)!=null) {
if (list.get(i).getDeal_type().equals("1")) {
list.get(i).setDeal_type("卖出");
}else {
list.get(i).setDeal_type("购入");
}
System.out.println(list.get(i).getDeal_type()+"\t"+list.get(i).getPet_id()+"\t"+list.get(i).getSeller_id()+"\t"+list.get(i).getBuyer_id()+"\t"+list.get(i).getPrice()+"\t"+list.get(i).getDeal_time());
}
}
}
private static void storebalance() {
System.out.println("当前宠物商店的资金结余为:"+petstore.getDalance());
}
/**
* 查询待售
*/
private static void storewait() {
System.out.println("--------当前宠物商店有如下代售宠物--------");
System.out.println("序号\t宠物名称\t类型\t价格");
Map<Integer, Pet> map=new HashMap<Integer, Pet>();
int count=0;
List<Pet> list=new ArrayList<Pet>();
list=petbao.storeSelect(petstore.getId());
for (int i = 0; i < list.size(); i++) {
if (list.get(i)!=null) {
count++;
System.out.println(count+"\t"+list.get(i).getName()+"\t"+list.get(i).getTypename()+"\t"+list.get(i).getPrice());
map.put(count, list.get(i));
}
}
}
/**
* 培育
*/
private static void storefoster() {
System.out.println("请输入您要培育的宠物的名称:");
String name=input.next();
System.out.println("请输入该宠物的宠物类型:");
String type=input.next();
System.out.println("请输入该宠物的售出价格:");
double price=input.nextDouble();
petbao.storefoster(name,type,price,petstore.getId());
}
/**
* 宠物商店卖出
*/
private static void storeaverage() {
System.out.println("--------当前宠物商店有如下代售宠物--------");
System.out.println("序号\t宠物名称\t类型\t价格");
Map<Integer, Pet> map=new HashMap<Integer, Pet>();
int count=0;
List<Pet> list=new ArrayList<Pet>();
list=petbao.storeSelect(petstore.getId());
for (int i = 0; i < list.size(); i++) {
if (list.get(i)!=null) {
count++;
System.out.println(count+"\t"+list.get(i).getName()+"\t"+list.get(i).getTypename()+"\t"+list.get(i).getPrice());
map.put(count, list.get(i));
}
}
System.out.println("请输入您要卖出的宠物的编号:");
int pet_id=input.nextInt();
Pet pet=map.get(pet_id);
System.out.println("请输入要卖给的宠物主人的编号:");
int owner_id=input.nextInt();
int panduan1=petownerbao.update(owner_id,pet.getPrice());
int panduan2=petstorebao.update(petstore.getId(), pet.getPrice());
int ownerid=petbao.purchase(pet,owner_id);
int panduan3=accountbao.insert(1, pet.getId(), petstore.getId(), owner_id, pet.getPrice());
if (panduan1!=0 && panduan2!=0 && panduan3!=0 && ownerid!=0) {
System.out.println("台账正确插入一条信息!");
}
}
/**
* 卖出
*/
private static void storepurchase() {
System.out.println("请输入宠物主人的编号:");
int owner_id=input.nextInt();
System.out.println("--------该宠物主人有�
评论0