mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2025-07-18 07:49:25 +00:00
Merge branch 'feature/#3_Développement_code_métier_serveur' into develop
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package com.pqt.core.entities.members;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -10,22 +9,14 @@ import java.util.Objects;
|
||||
public class Client extends PqtMember{
|
||||
|
||||
private String address;
|
||||
private Date lastUpdate;
|
||||
|
||||
public Client() {
|
||||
super(-1, PqtMemberType.CLIENT);
|
||||
}
|
||||
|
||||
public Client(int id, String address) {
|
||||
public Client(long id, String address) {
|
||||
super(id, PqtMemberType.CLIENT);
|
||||
this.address = address;
|
||||
this.lastUpdate = new Date();
|
||||
}
|
||||
|
||||
public Client(int id, String address, Date lastUpdate) {
|
||||
super(id, PqtMemberType.CLIENT);
|
||||
this.address = address;
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
@ -36,12 +27,19 @@ public class Client extends PqtMember{
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Date getLastUpdate() {
|
||||
return lastUpdate;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Client client = (Client) o;
|
||||
|
||||
return address.equals(client.address) && id==client.id && type.equals(client.type);
|
||||
}
|
||||
|
||||
public void setLastUpdate(Date lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return address.hashCode() + type.hashCode() + Integer.class.cast(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,11 @@
|
||||
package com.pqt.core.entities.members;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DataServer extends PqtMember{
|
||||
|
||||
private String address;
|
||||
private Date lastUpdate;
|
||||
|
||||
public DataServer() {
|
||||
super(-1, PqtMemberType.DATA_SERVER);
|
||||
@ -16,15 +14,8 @@ public class DataServer extends PqtMember{
|
||||
public DataServer(long id, String address) {
|
||||
super(id, PqtMemberType.DATA_SERVER);
|
||||
this.address = address;
|
||||
this.lastUpdate = new Date();
|
||||
}
|
||||
|
||||
public DataServer(long id, String address, Date lastUpdate) {
|
||||
super(id, PqtMemberType.DATA_SERVER);
|
||||
this.address = address;
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
@ -33,14 +24,6 @@ public class DataServer extends PqtMember{
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Date getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
public void setLastUpdate(Date lastUpdate) {
|
||||
this.lastUpdate = lastUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), address);
|
||||
|
@ -7,8 +7,8 @@ import java.util.Objects;
|
||||
|
||||
public class PqtMember implements ILoggable, Serializable {
|
||||
|
||||
private long id;
|
||||
private PqtMemberType type;
|
||||
protected long id;
|
||||
protected PqtMemberType type;
|
||||
|
||||
public PqtMember() {
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.pqt.core.entities.messages;
|
||||
|
||||
import com.pqt.core.entities.members.PqtMember;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -9,15 +10,19 @@ public class Message {
|
||||
private Map<String, String> fields;
|
||||
private MessageType type;
|
||||
private PqtMember emitter, receiver;
|
||||
private Account user;
|
||||
private Message replyTo;
|
||||
|
||||
public Message(MessageType type, PqtMember emitter, PqtMember receiver) {
|
||||
this(type, emitter, receiver, null);
|
||||
public Message(MessageType type, PqtMember emitter, PqtMember receiver, Account user, Message replyTo) {
|
||||
this(type, emitter, receiver, user, replyTo, null);
|
||||
}
|
||||
|
||||
public Message(MessageType type, PqtMember emitter, PqtMember receiver, Map<String, String> fields) {
|
||||
public Message(MessageType type, PqtMember emitter, PqtMember receiver, Account user, Message replyTo, Map<String, String> fields) {
|
||||
this.emitter = emitter;
|
||||
this.receiver = receiver;
|
||||
this.type = type;
|
||||
this.user = user;
|
||||
this.replyTo = replyTo;
|
||||
this.fields = new HashMap<>();
|
||||
if(fields!=null)
|
||||
for(String key : fields.keySet()){
|
||||
@ -56,10 +61,10 @@ public class Message {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj)
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if(!this.getClass().isInstance(obj))
|
||||
if (!this.getClass().isInstance(obj))
|
||||
return false;
|
||||
|
||||
Message other = Message.class.cast(obj);
|
||||
@ -68,4 +73,12 @@ public class Message {
|
||||
&& Objects.equals(this.receiver, other.receiver)
|
||||
&& Objects.equals(this.type, other.type);
|
||||
}
|
||||
|
||||
public Account getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Message getReplyTo() {
|
||||
return replyTo;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,36 @@
|
||||
package com.pqt.core.entities.messages;
|
||||
|
||||
public enum MessageType {
|
||||
QUERY_CONNECT,
|
||||
ACK_CONNECT,
|
||||
ERR_CONNECT,
|
||||
REF_CONNECT,
|
||||
ERROR_QUERY,
|
||||
REFUSED_QUERY,
|
||||
|
||||
QUERY_SALE,
|
||||
ACK_SALE,
|
||||
ERR_SALE,
|
||||
REF_SALE,
|
||||
|
||||
QUERY_REVERT_SALE,
|
||||
ACK_REVERT_SALE,
|
||||
ERR_REVERT_SALE,
|
||||
REF_REVERT_SALE,
|
||||
|
||||
QUERY_LAST_SALES_LIST,
|
||||
MSG_LAST_SALES_LIST,
|
||||
|
||||
QUERY_STAT,
|
||||
MSG_STAT,
|
||||
ERR_STAT,
|
||||
REF_STAT,
|
||||
|
||||
QUERY_STOCK,
|
||||
MSG_STOCK,
|
||||
ERR_STOCK,
|
||||
REF_STOCK,
|
||||
|
||||
QUERY_LOGIN,
|
||||
ACK_LOGIN,
|
||||
ERR_LOGIN,
|
||||
REF_LOGIN,
|
||||
QUERY_ACCOUNT_LIST,
|
||||
MSG_ACCOUNT_LIST,
|
||||
|
||||
QUERY_CONNECT_ACCOUNT,
|
||||
ACK_CONNECT_ACCOUNT,
|
||||
|
||||
QUERY_UPDATE,
|
||||
ACK_UPDATE,
|
||||
ERR_UPDATE,
|
||||
REF_UPDATE
|
||||
|
||||
QUERY_PING,
|
||||
ACK_PING,
|
||||
|
||||
QUERY_CONFIG_LIST,
|
||||
MSG_CONFIG_LIST
|
||||
}
|
||||
|
@ -34,10 +34,14 @@ public class Product implements ILoggable, Serializable{
|
||||
this.category = category;
|
||||
this.components = new ArrayList<>();
|
||||
if(components!=null){
|
||||
this.components.addAll(components);
|
||||
components.stream().forEach(p->this.components.add(new Product(p)));
|
||||
}
|
||||
}
|
||||
|
||||
public Product(Product p) {
|
||||
this(p.id, p.name, p.amountRemaining, p.amountSold, p.sellable, p.price, p.components, p.category);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package com.pqt.core.entities.query;
|
||||
|
||||
public class ConnectQuery extends SimpleQuery {
|
||||
|
||||
private String serverAddress;
|
||||
|
||||
public ConnectQuery(String serverAddress) {
|
||||
super(QueryType.CONNECT);
|
||||
this.serverAddress = serverAddress;
|
||||
}
|
||||
|
||||
public String getServerAddress() {
|
||||
return serverAddress;
|
||||
}
|
||||
|
||||
public void setServerAddress(String serverAddress) {
|
||||
this.serverAddress = serverAddress;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.pqt.core.entities.query;
|
||||
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
|
||||
public class LogQuery extends SimpleQuery {
|
||||
|
||||
private Account account;
|
||||
|
||||
private boolean newDesiredState;
|
||||
|
||||
public LogQuery(Account account, boolean newDesiredState) {
|
||||
super(QueryType.LOG);
|
||||
this.account = account;
|
||||
this.newDesiredState = newDesiredState;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public boolean isNewDesiredState() {
|
||||
return newDesiredState;
|
||||
}
|
||||
|
||||
public void setNewDesiredState(boolean newDesiredState) {
|
||||
this.newDesiredState = newDesiredState;
|
||||
}
|
||||
}
|
@ -109,10 +109,10 @@ public class Sale implements ILoggable, Serializable{
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(this == obj)
|
||||
if (this == obj)
|
||||
return true;
|
||||
|
||||
if(!this.getClass().isInstance(obj))
|
||||
if (!this.getClass().isInstance(obj))
|
||||
return false;
|
||||
|
||||
Sale other = Sale.class.cast(obj);
|
||||
@ -123,4 +123,18 @@ public class Sale implements ILoggable, Serializable{
|
||||
&& Objects.equals(this.orderedWith, other.orderedWith)
|
||||
&& Objects.equals(this.type, other.type);
|
||||
}
|
||||
|
||||
public double getTotalPrice() {
|
||||
if(type.getPriceMultiplier()==0)
|
||||
return 0;
|
||||
return getTotalWorth()*type.getPriceMultiplier();
|
||||
}
|
||||
|
||||
public double getTotalWorth(){
|
||||
double totalWorth = 0;
|
||||
for(Product product : this.products.keySet()){
|
||||
totalWorth+=product.getPrice()*(double)this.products.get(product);
|
||||
}
|
||||
return totalWorth;
|
||||
}
|
||||
}
|
||||
|
@ -4,5 +4,15 @@ package com.pqt.core.entities.sale;
|
||||
* Created by Notmoo on 18/07/2017.
|
||||
*/
|
||||
public enum SaleType {
|
||||
CASH, BANK_CHECK, STUDENT_ASSOCIATION_ACCOUNT, OFFERED_GUEST, OFFERED_STAFF_MEMBER
|
||||
CASH(1), BANK_CHECK(1), STUDENT_ASSOCIATION_ACCOUNT(1), OFFERED_GUEST(0), OFFERED_STAFF_MEMBER(0);
|
||||
|
||||
private double priceMultiplier;
|
||||
|
||||
SaleType(double priceMultiplier) {
|
||||
this.priceMultiplier = priceMultiplier;
|
||||
}
|
||||
|
||||
public double getPriceMultiplier() {
|
||||
return priceMultiplier;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.pqt.core.entities.server_config;
|
||||
|
||||
public enum ConfigFields {
|
||||
ALLOW_SALE_COMMIT,
|
||||
ALLOW_SALE_REVERT,
|
||||
|
||||
ALLOW_STOCK_VIEW,
|
||||
ALLOW_STOCK_UPDATE,
|
||||
|
||||
ALLOW_ACCOUNT_CONNECT,
|
||||
ALLOW_ACCOUNT_MODIFICATION
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.pqt.core.entities.server_config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServerConfig {
|
||||
|
||||
private Map<ConfigFields, Boolean> fields;
|
||||
|
||||
public ServerConfig() {
|
||||
}
|
||||
|
||||
public ServerConfig(Map<ConfigFields, Boolean> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public ServerConfig(ConfigFields... configFields) {
|
||||
fields = new HashMap<>();
|
||||
Arrays.stream(configFields).forEach(field->fields.put(field, true));
|
||||
|
||||
EnumSet.allOf(ConfigFields.class).stream().filter(field->!fields.containsKey(field)).forEach(field->fields.put(field, false));
|
||||
}
|
||||
|
||||
public Map<ConfigFields, Boolean> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(Map<ConfigFields, Boolean> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public boolean isSupported(ConfigFields field){
|
||||
return fields.containsKey(field) && fields.get(field);
|
||||
}
|
||||
|
||||
public void switchFieldValue(ConfigFields field){
|
||||
if(fields.containsKey(field)){
|
||||
fields.replace(field, !fields.get(field));
|
||||
}else{
|
||||
fields.put(field, true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean add(ConfigFields field, boolean value){
|
||||
if(!fields.containsKey(field)){
|
||||
fields.put(field, value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -10,31 +10,19 @@ import java.util.Objects;
|
||||
* Created by Notmoo on 18/07/2017.
|
||||
*/
|
||||
public class Account implements ILoggable, Serializable {
|
||||
private int id;
|
||||
private String username;
|
||||
private String passwordHash;
|
||||
private Date creationDate;
|
||||
private String password;
|
||||
private AccountLevel permissionLevel;
|
||||
|
||||
public Account() {
|
||||
}
|
||||
|
||||
public Account(int id, String username, String passwordHash, Date creationDate, AccountLevel permissionLevel) {
|
||||
this.id = id;
|
||||
public Account(String username, String password, AccountLevel permissionLevel) {
|
||||
this.username = username;
|
||||
this.passwordHash = passwordHash;
|
||||
this.creationDate = creationDate;
|
||||
this.password = password;
|
||||
this.permissionLevel = permissionLevel;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
@ -43,20 +31,12 @@ public class Account implements ILoggable, Serializable {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPasswordHash(String passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(Date creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public AccountLevel getPermissionLevel() {
|
||||
|
@ -1,8 +1,21 @@
|
||||
package com.pqt.core.entities.user_account;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by Notmoo on 18/07/2017.
|
||||
*/
|
||||
public enum AccountLevel {
|
||||
GUEST, STAFF, WAITER, MASTER
|
||||
LOWEST, GUEST, STAFF, WAITER, MASTER;
|
||||
|
||||
public static AccountLevel getLowest(){
|
||||
return Arrays.stream(AccountLevel.values()).sorted(Comparator.naturalOrder()).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static AccountLevel getHighest(){
|
||||
return Arrays.stream(AccountLevel.values()).sorted(Comparator.reverseOrder()).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user