-CORRECCIÓN DE HORAS EN LOS NEW DATE() PARA LOS REGISTROS EN EL WS

This commit is contained in:
Brayan.Gonzalez 2025-03-04 09:31:47 -07:00
parent 78d9e09391
commit 25fde10e97
6 changed files with 1117 additions and 1043 deletions

View File

@ -113,7 +113,7 @@ public class ExchangeEnebledUsersController implements Serializable {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, -7);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
parameters.add(new ModelParameter(TransferCfg.FIELD_LAST_UPDATED_ON, date));
parameters.add(new ModelParameter(TransferCfg.FIELD_ID, transerId));

View File

@ -284,6 +284,12 @@ public class LoanController implements Serializable {
String comments = "Se pago " + precio + texto;
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
LoanDetails details = new LoanDetails(
UUID.randomUUID().toString(),
new Loan(feesToPayByLoanRequestJaxb.getIdLoan()),
@ -294,7 +300,7 @@ public class LoanController implements Serializable {
LoanDetailsType.PAYMENT,
comments,
feesToPayByLoanRequestJaxb.getIdUser(),
new Date());
date);
parameters.add(new ModelParameter(LoanDetailsCfg.FIELD_ID, ids));
@ -408,9 +414,6 @@ public class LoanController implements Serializable {
throw new Exception(user_unavailable);
}
//DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();//dateFormat.parse(jaxb.getStrDate());
LoanByUser loanByUser = new LoanByUser(
new LoanByUserId(null, jaxb.getUserId()),
LoanStatus.PENDING,
@ -420,6 +423,12 @@ public class LoanController implements Serializable {
LoanType loanType = loanTypeRepository.findLoanType(jaxb.getLoanTypeId());
RouteCtlg routeCtlg = new RouteCtlg(jaxb.getRouteId());
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
Loan loan = new Loan(
new LoanType(loanType.getId()),
null,
@ -548,7 +557,13 @@ public class LoanController implements Serializable {
LoanFeeNotification notification = null;
try {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
List<ModelParameter> parameters = new ArrayList<>();
Loan loan = loanRepository.findLoanById(transfer.getLoanId());
@ -712,7 +727,12 @@ public class LoanController implements Serializable {
PersonJaxb endorsement) throws Exception {
logger.debug("renovation");
try {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
Loan currentLoan = loanRepository.findLoanById(loan);
LoanType newCredit = loanTypeRepository.findLoanType(credit);
@ -844,7 +864,12 @@ public class LoanController implements Serializable {
PersonJaxb endorsement) throws Exception {
logger.debug("renovationHasPaymentToday");
try {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
Loan currentLoan = loanRepository.findLoanById(loan);
LoanType newCredit = loanTypeRepository.findLoanType(credit);
@ -972,6 +997,12 @@ public class LoanController implements Serializable {
totalAmountPaid = loan.getAmountPaid().add(discount);
newLastReferenceNumber = loan.getLastReferenceNumber() + 1;
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loanDetails = new LoanDetails(
new Loan(loanByRenovation.getLoanOld().getId()),
new User(user),
@ -980,7 +1011,7 @@ public class LoanController implements Serializable {
newLastReferenceNumber,
LoanDetailsType.RENOVATION_PAYMENT,
user,
new Date(),
date,
"Retención de " + discount + " el la entrega del crédito renovado");
}
@ -1055,6 +1086,12 @@ public class LoanController implements Serializable {
totalAmountPaid = loan.getAmountPaid().add(discount);
newLastReferenceNumber = loan.getLastReferenceNumber() + 1;
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loanDetails = new LoanDetails(
new Loan(loanByRenovation.getLoanOld().getId()),
new User(user),
@ -1063,7 +1100,7 @@ public class LoanController implements Serializable {
newLastReferenceNumber,
LoanDetailsType.RENOVATION_PAYMENT,
user,
new Date(),
date,
"Retención de " + discount + " el la entrega del crédito renovado");
}
@ -1269,11 +1306,17 @@ public class LoanController implements Serializable {
loans.add(new Loan(row.getIdLoan()));
});
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loanParams.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, loanStatus));
loanParams.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, new BigDecimal(0)));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, 0));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, updateLoanToDeliveryStatusList.getIdUpdateUser()));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, new Date()));
loanParams.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, date));
loanParams.add(new ModelParameter(LoanCfg.FIELD_ID, ids));
loanByUserParams.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, loanStatus));
@ -1300,7 +1343,12 @@ public class LoanController implements Serializable {
logger.debug("updateLoanByIdFromCertifiedView");
try {
List<ModelParameter> parameters = new ArrayList<>();
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
parameters.add(
new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED)

View File

@ -23,6 +23,7 @@ import com.arrebol.apc.model.loan.LoanDetails;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.logging.log4j.LogManager;
@ -35,185 +36,197 @@ import org.hibernate.query.Query;
*/
public class LoanByRenovationRepository extends GenericRepository implements Serializable {
private static final long serialVersionUID = 1357519239619447184L;
final Logger logger = LogManager.getLogger(LoanByRenovationRepository.class);
private static final long serialVersionUID = 1357519239619447184L;
final Logger logger = LogManager.getLogger(LoanByRenovationRepository.class);
/**
*
* @param newLoanId
* @return
* @throws Exception
*/
public LoanByRenovation findLoanRenovationByNewLoanId(String newLoanId) throws Exception {
logger.debug("findLoanRenovationByNewLoanId");
try {
List<ModelParameter> parameters = new ArrayList<>();
/**
*
* @param newLoanId
* @return
* @throws Exception
*/
public LoanByRenovation findLoanRenovationByNewLoanId(String newLoanId) throws Exception {
logger.debug("findLoanRenovationByNewLoanId");
try {
List<ModelParameter> parameters = new ArrayList<>();
parameters.add(
new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_NEW, new Loan(newLoanId))
);
parameters.add(
new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_NEW, new Loan(newLoanId))
);
return (LoanByRenovation) createNamedQueryUniqueResult(
LoanByRenovation.class,
LoanByRenovationCfg.QUERY_FIND_LOAN_RENOVATION_BY_NEW_LOAN_ID,
parameters);
} catch (Exception e) {
logger.error("findLoanRenovationByNewLoanId", e);
throw e;
}
}
return (LoanByRenovation) createNamedQueryUniqueResult(
LoanByRenovation.class,
LoanByRenovationCfg.QUERY_FIND_LOAN_RENOVATION_BY_NEW_LOAN_ID,
parameters);
} catch (Exception e) {
logger.error("findLoanRenovationByNewLoanId", e);
throw e;
}
}
/**
*
* @param loanByRenovation
* @param userId
* @param comments
* @param action
* @param amount
* @param discount
* @param loanDetails
* @param totalAmountPaid
* @param newLastReferenceNumber
* @param comission
* @return
* @throws Exception
*/
public boolean updateLoanRenovationFromCerfierView(
LoanByRenovation loanByRenovation,
String userId,
String comments,
boolean action,
BigDecimal amount,
BigDecimal discount,
LoanDetails loanDetails,
BigDecimal totalAmountPaid,
Integer newLastReferenceNumber,
ComissionType comission) throws Exception {
logger.debug("updateLoanRenovationFromCerfierView");
boolean success = false;
try {
openConnection();
/**
*
* @param loanByRenovation
* @param userId
* @param comments
* @param action
* @param amount
* @param discount
* @param loanDetails
* @param totalAmountPaid
* @param newLastReferenceNumber
* @param comission
* @return
* @throws Exception
*/
public boolean updateLoanRenovationFromCerfierView(
LoanByRenovation loanByRenovation,
String userId,
String comments,
boolean action,
BigDecimal amount,
BigDecimal discount,
LoanDetails loanDetails,
BigDecimal totalAmountPaid,
Integer newLastReferenceNumber,
ComissionType comission) throws Exception {
logger.debug("updateLoanRenovationFromCerfierView");
boolean success = false;
try {
openConnection();
Date lastUpdatedOn = new Date();
List<ModelParameter> parameters = new ArrayList<>();
Date date2 = new Date();
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(date2);
calendar2.add(Calendar.HOUR_OF_DAY, -7);
date2 = calendar2.getTime();
// Update loanByRenovation details in Renovation table
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_RENOVATION_STATUS, action ? LoanRenovationStatus.APPROVED : LoanRenovationStatus.REJECTED));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_ID, loanByRenovation.getId()));
Date lastUpdatedOn = date2;
List<ModelParameter> parameters = new ArrayList<>();
if (0 < executeQuery(LoanByRenovationCfg.QUERY_UPDATE_LOAN_RENOVATION, parameters)) {
// Update loanByRenovation details in Renovation table
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LOAN_RENOVATION_STATUS, action ? LoanRenovationStatus.APPROVED : LoanRenovationStatus.REJECTED));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanByRenovationCfg.FIELD_ID, loanByRenovation.getId()));
parameters.clear();
if (0 < executeQuery(LoanByRenovationCfg.QUERY_UPDATE_LOAN_RENOVATION, parameters)) {
// Update NEW loan details in Loan table
parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanCfg.FIELD_CREATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanNew().getId()));
parameters.clear();
if (0 < executeQuery(LoanCfg.QUERY_UPDATE_LOAN_WITH_CREATED_ON_BY_ID_FROM_CERTIFIER_VIEW, parameters)) {
parameters.clear();
// Update NEW loan details in Loan table
parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, comments));
parameters.add(new ModelParameter(LoanCfg.FIELD_CREATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanNew().getId()));
// Update OLD loan details in Loan table
String commentsOldLoan = action ? "Crédito renovado" : "El certificador rechazo la renovación de este crédito";
String strQuery = LoanCfg.QUERY_UPDATE_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
if (0 < executeQuery(LoanCfg.QUERY_UPDATE_LOAN_WITH_CREATED_ON_BY_ID_FROM_CERTIFIER_VIEW, parameters)) {
parameters.clear();
if (action && null != loanDetails && null != totalAmountPaid && null != newLastReferenceNumber) {
parameters.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, totalAmountPaid));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, newLastReferenceNumber));
// Update OLD loan details in Loan table
String commentsOldLoan = action ? "Crédito renovado" : "El certificador rechazo la renovación de este crédito";
String strQuery = LoanCfg.QUERY_UPDATE_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
strQuery = LoanCfg.QUERY_UPDATE_DISCOUNT_AND_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
}
if (action && null != loanDetails && null != totalAmountPaid && null != newLastReferenceNumber) {
parameters.add(new ModelParameter(LoanCfg.FIELD_AMOUNT_PAID, totalAmountPaid));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_REFERENCE_NUMBER, newLastReferenceNumber));
parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, commentsOldLoan));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanOld().getId()));
strQuery = LoanCfg.QUERY_UPDATE_DISCOUNT_AND_LOAN_BY_ID_FROM_CERTIFIER_VIEW;
}
if (0 < executeQuery(strQuery, parameters)) {
parameters.add(new ModelParameter(LoanCfg.FIELD_LOAN_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED));
parameters.add(new ModelParameter(LoanCfg.FIELD_COMMENTS, commentsOldLoan));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_BY, userId));
parameters.add(new ModelParameter(LoanCfg.FIELD_LAST_UPDATED_ON, lastUpdatedOn));
parameters.add(new ModelParameter(LoanCfg.FIELD_ID, loanByRenovation.getLoanOld().getId()));
// Update OLD loanByUser details in Loan By User Table
List<ModelParameter> params = new ArrayList<>();
if (0 < executeQuery(strQuery, parameters)) {
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanOld().getId())));
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED));
// Update OLD loanByUser details in Loan By User Table
List<ModelParameter> params = new ArrayList<>();
Query query1 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID);
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanOld().getId())));
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.FINISH : LoanStatus.APPROVED));
params.forEach((param) -> {
query1.setParameter(param.getParameter(), param.getValue());
});
Query query1 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID);
query1.executeUpdate();
params.forEach((param) -> {
query1.setParameter(param.getParameter(), param.getValue());
});
// Update NEW loanByUser details in Loan By User Table
params.clear();
query1.executeUpdate();
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanNew().getId())));
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
// Update NEW loanByUser details in Loan By User Table
params.clear();
Query query2 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID);
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN, new Loan(loanByRenovation.getLoanNew().getId())));
params.add(new ModelParameter(LoanByUserCfg.FIELD_LOAN_BY_USER_STATUS, action ? LoanStatus.APPROVED : LoanStatus.REJECTED));
params.forEach((param) -> {
query2.setParameter(param.getParameter(), param.getValue());
});
Query query2 = getSession().createNamedQuery(LoanByUserCfg.QUERY_UPDATE_LOAN_BY_USER_BY_LOAND_ID);
query2.executeUpdate();
params.forEach((param) -> {
query2.setParameter(param.getParameter(), param.getValue());
});
if (action) {
// Insert new loanDetails (discount) in Loan Details table
if (null != loanDetails) {
getSession().save(loanDetails);
}
query2.executeUpdate();
// Insert delivery details (To know cash that certifier deliveried) in Delivery Table
Delivery delivery = new Delivery(
new User(userId),
new Loan(loanByRenovation.getLoanNew().getId()),
amount,
userId,
new Date(),
comission
);
if (action) {
// Insert new loanDetails (discount) in Loan Details table
if (null != loanDetails) {
getSession().save(loanDetails);
}
getSession().save(delivery);
}
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
flushAndClear();
closeConnection();
// Insert delivery details (To know cash that certifier deliveried) in Delivery Table
Delivery delivery = new Delivery(
new User(userId),
new Loan(loanByRenovation.getLoanNew().getId()),
amount,
userId,
date,
comission
);
logger.info("Certifier delivery the loan details: " + loanByRenovation);
success = true;
} else {
rollback();
}
} else {
rollback();
}
getSession().save(delivery);
}
flushAndClear();
closeConnection();
logger.info("Certifier delivery the loan details: " + loanByRenovation);
success = true;
} else {
rollback();
}
} else {
rollback();
rollback();
}
return success;
} catch (Exception e) {
} else {
rollback();
logger.error("updateLoanRenovationFromCerfierView", e);
throw e;
}
}
}
return success;
} catch (Exception e) {
rollback();
logger.error("updateLoanRenovationFromCerfierView", e);
throw e;
}
}
private int executeQuery(String xmlQuery, List<ModelParameter> parameters) {
Query query = getSession().createNamedQuery(xmlQuery);
private int executeQuery(String xmlQuery, List<ModelParameter> parameters) {
Query query = getSession().createNamedQuery(xmlQuery);
parameters.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
});
parameters.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
});
return query.executeUpdate();
}
return query.executeUpdate();
}
}

View File

@ -16,6 +16,7 @@ import com.arrebol.apc.model.loan.LoanDetails;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Tuple;
@ -31,169 +32,175 @@ import org.hibernate.query.Query;
*/
public class LoanDetailsRepository extends GenericRepository implements Serializable {
/**
*
* @param details
* @return
* @throws Exception
*/
public boolean saveLoanDetails(LoanDetails details) throws Exception {
logger.debug("saveLoanDetails");
try {
return save(details);
} catch (Exception e) {
logger.error("saveLoanDetails", e);
throw e;
}
}
/**
*
* @param details
* @return
* @throws Exception
*/
public boolean saveLoanDetails(LoanDetails details) throws Exception {
logger.debug("saveLoanDetails");
try {
return save(details);
} catch (Exception e) {
logger.error("saveLoanDetails", e);
throw e;
}
}
public List<LoanDetails> findFeesToPayByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findFeesToPayByLoanId");
public List<LoanDetails> findFeesToPayByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findFeesToPayByLoanId");
List<LoanDetails> results = new ArrayList<>();
try {
List<Tuple> tuples = xmlQueryTuple(xmlQuery, parameters);
List<LoanDetails> results = new ArrayList<>();
try {
List<Tuple> tuples = xmlQueryTuple(xmlQuery, parameters);
tuples.forEach((tuple) -> {
results.add(new LoanDetails(tuple.get("id", String.class), tuple.get("createdOn", Date.class), tuple.get("feeStatus", FeeStatus.class)));
tuples.forEach((tuple) -> {
results.add(new LoanDetails(tuple.get("id", String.class), tuple.get("createdOn", Date.class), tuple.get("feeStatus", FeeStatus.class)));
});
} catch (Exception e) {
logger.error("findFeesToPayByLoanId", e);
throw e;
}
return results;
}
/**
*
* @param xmlQuery
* @param parameters
* @return
* @throws Exception
*/
public List<LoanDetails> findLoanDetailsByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findLoanDetailsByLoanId");
List<LoanDetails> results = new ArrayList<>();
try {
results = createNamedQueryResultList(LoanDetails.class, xmlQuery, parameters);
} catch (Exception e) {
logger.error("findLoanDetailsByLoanId", e);
throw e;
}
return results;
}
/**
*
* @param xmlQuery
* @param parameters
* @param loanDetails
* @return
* @throws Exception
*/
public boolean updatePaidFeesStatusInLoanDetailIds(String xmlQuery, List<ModelParameter> parameters, LoanDetails loanDetails) throws Exception {
boolean success = false;
Session sssn = null;
Transaction trnsctn = null;
try {
sssn = HibernateUtil.getSessionFactory().getCurrentSession();
trnsctn = sssn.beginTransaction();
Loan loan = sssn.get(Loan.class, loanDetails.getLoan().getId());
if (null != parameters && !parameters.isEmpty()) {
Query query = sssn.createNamedQuery(xmlQuery);
parameters.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
});
} catch (Exception e) {
logger.error("findFeesToPayByLoanId", e);
throw e;
}
query.executeUpdate();
logger.debug("Query update executed");
}
BigDecimal totalFees = loan.getAmountPaid().add(loanDetails.getPaymentAmount());
return results;
}
loanDetails.setReferenceNumber(loan.getLastReferenceNumber() + 1);
/**
*
* @param xmlQuery
* @param parameters
* @return
* @throws Exception
*/
public List<LoanDetails> findLoanDetailsByLoanId(String xmlQuery, List<ModelParameter> parameters) throws Exception {
logger.debug("findLoanDetailsByLoanId");
sssn.save(loanDetails);
List<LoanDetails> results = new ArrayList<>();
try {
results = createNamedQueryResultList(LoanDetails.class, xmlQuery, parameters);
} catch (Exception e) {
logger.error("findLoanDetailsByLoanId", e);
throw e;
}
loan.setAmountPaid(totalFees);
loan.setLastReferenceNumber(loan.getLastReferenceNumber() + 1);
loan.setLastUpdatedBy(loanDetails.getCreatedBy());
return results;
}
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
loan.setLastUpdatedOn(date);
/**
*
* @param xmlQuery
* @param parameters
* @param loanDetails
* @return
* @throws Exception
*/
public boolean updatePaidFeesStatusInLoanDetailIds(String xmlQuery, List<ModelParameter> parameters, LoanDetails loanDetails) throws Exception {
boolean success = false;
sssn.update(loan);
Session sssn = null;
Transaction trnsctn = null;
try {
sssn = HibernateUtil.getSessionFactory().getCurrentSession();
trnsctn = sssn.beginTransaction();
trnsctn.commit();
Loan loan = sssn.get(Loan.class, loanDetails.getLoan().getId());
if (null != parameters && !parameters.isEmpty()) {
Query query = sssn.createNamedQuery(xmlQuery);
parameters.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
});
query.executeUpdate();
logger.debug("Query update executed");
}
BigDecimal totalFees = loan.getAmountPaid().add(loanDetails.getPaymentAmount());
loanDetails.setReferenceNumber(loan.getLastReferenceNumber() + 1);
sssn.save(loanDetails);
loan.setAmountPaid(totalFees);
loan.setLastReferenceNumber(loan.getLastReferenceNumber() + 1);
loan.setLastUpdatedBy(loanDetails.getCreatedBy());
loan.setLastUpdatedOn(new Date());
sssn.update(loan);
trnsctn.commit();
logger.info("Entity updated");
success = true;
} catch (Exception e) {
logger.error("Method updatePaidFeesStatusInLoanDetailIds() ", e);
if (null != trnsctn) {
trnsctn.rollback();
}
throw e;
}
/* finally {
logger.info("Entity updated");
success = true;
} catch (Exception e) {
logger.error("Method updatePaidFeesStatusInLoanDetailIds() ", e);
if (null != trnsctn) {
trnsctn.rollback();
}
throw e;
}
/* finally {
if (null != sssn) {
sssn.close();
}
}*/
return success;
}
return success;
}
/**
*
* @param hbmQuery
* @param params
* @return
*/
public Long countLoandDetails(String hbmQuery, List<ModelParameter> params) {
Long count;
Transaction transaction = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.beginTransaction();
/**
*
* @param hbmQuery
* @param params
* @return
*/
public Long countLoandDetails(String hbmQuery, List<ModelParameter> params) {
Long count;
Transaction transaction = null;
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
transaction = session.beginTransaction();
Query query = session.createNamedQuery(hbmQuery);
Query query = session.createNamedQuery(hbmQuery);
params.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
});
params.forEach((param) -> {
query.setParameter(param.getParameter(), param.getValue());
});
count = (Long) query.getSingleResult();
count = (Long) query.getSingleResult();
transaction.commit();
transaction.commit();
return count;
} catch (Exception e) {
logger.error("countLoandDetails", e);
if (null != transaction) {
transaction.rollback();
}
throw e;
}
}
return count;
} catch (Exception e) {
logger.error("countLoandDetails", e);
if (null != transaction) {
transaction.rollback();
}
throw e;
}
}
/**
*
* @param hbmQuery
* @param parameters
* @return
* @throws Exception
*/
public boolean updateLoanDetails(String hbmQuery, List<ModelParameter> parameters) throws Exception {
try {
return updateCreateNamedQuery(hbmQuery, parameters);
} catch (Exception e) {
logger.error("Method updateLoanDetails", e);
throw e;
}
}
/**
*
* @param hbmQuery
* @param parameters
* @return
* @throws Exception
*/
public boolean updateLoanDetails(String hbmQuery, List<ModelParameter> parameters) throws Exception {
try {
return updateCreateNamedQuery(hbmQuery, parameters);
} catch (Exception e) {
logger.error("Method updateLoanDetails", e);
throw e;
}
}
private static final long serialVersionUID = -6088464996350747643L;
final Logger logger = LogManager.getLogger(LoanDetailsRepository.class);
private static final long serialVersionUID = -6088464996350747643L;
final Logger logger = LogManager.getLogger(LoanDetailsRepository.class);
}

View File

@ -14,6 +14,7 @@ import com.arrebol.apc.model.core.User;
import com.arrebol.apc.model.enums.GenericStatus;
import com.arrebol.apc.model.gasoline.Gasoline;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
import javax.ws.rs.FormParam;
@ -32,45 +33,51 @@ import org.apache.logging.log4j.Logger;
@Path("gasoline")
public class GasolineWS implements Serializable {
@PUT
@Path("save-new-gasoline-payment")
@Produces(MediaType.APPLICATION_JSON)
public Response saveNewGasolinePayment(@FormParam("idUser") String idUser,
@FormParam("idOffice") String idOffice,
@FormParam("idRoute") String idRoute,
@FormParam("total") Double total,
@FormParam("km") Double km,
@FormParam("quantity") Double quantity,
@FormParam("description") String description) {
Response response;
try {
GasolineController controller = new GasolineController();
@PUT
@Path("save-new-gasoline-payment")
@Produces(MediaType.APPLICATION_JSON)
public Response saveNewGasolinePayment(@FormParam("idUser") String idUser,
@FormParam("idOffice") String idOffice,
@FormParam("idRoute") String idRoute,
@FormParam("total") Double total,
@FormParam("km") Double km,
@FormParam("quantity") Double quantity,
@FormParam("description") String description) {
Response response;
try {
GasolineController controller = new GasolineController();
Gasoline gasoline = new Gasoline(
UUID.randomUUID().toString(),
new User(idUser),
new Office(idOffice),
new RouteCtlg(idRoute),
quantity,
km,
total,
GenericStatus.ENABLED,
description,
idUser,
new Date());
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, -7);
date = calendar.getTime();
if (controller.saveNewGasolinePayment(gasoline)) {
response = Response.ok().build();
} else {
response = Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
} catch (Exception e) {
logger.error("saveNewGasolineEntry");
Gasoline gasoline = new Gasoline(
UUID.randomUUID().toString(),
new User(idUser),
new Office(idOffice),
new RouteCtlg(idRoute),
quantity,
km,
total,
GenericStatus.ENABLED,
description,
idUser,
date);
if (controller.saveNewGasolinePayment(gasoline)) {
response = Response.ok().build();
} else {
response = Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
return response;
}
}
} catch (Exception e) {
logger.error("saveNewGasolineEntry");
response = Response.status(Response.Status.NOT_ACCEPTABLE).build();
}
return response;
}
private static final long serialVersionUID = -5280895557294295916L;
final Logger logger = LogManager.getLogger(getClass());
private static final long serialVersionUID = -5280895557294295916L;
final Logger logger = LogManager.getLogger(getClass());
}

File diff suppressed because it is too large Load Diff