fixed data issue for dashboard #25

Merged
usama.jameel merged 1 commits from qa-report into main 2025-05-23 09:46:54 +00:00
3 changed files with 36 additions and 24 deletions

View File

@ -34,7 +34,7 @@ public class FinishedItemDAO {
private final String SELECT_BY_STITCHED_ITEM_IDS = String.format("SELECT * FROM %s WHERE stitched_item_id IN (:stitched_item_ids)", TABLE_NAME);
private final String COUNT_TOTAL_FINISH_ITEM = String.format("SELECT COUNT(*) FROM %s WHERE job_card_id = :job_card_id AND is_segregated IS TRUE ", TABLE_NAME);
private final String SELECT_BY_JOB_CARD_AND_DATE = String.format("SELECT * FROM %s WHERE job_card_id = :job_card_id AND (:start_date IS NULL OR :end_date IS NULL OR created_at BETWEEN :start_date AND :end_date)", TABLE_NAME);
private final String SELECT_BY_DATE_QA_STATUS = String.format( "SELECT COUNT(*) FROM %s WHERE (:start_date IS NULL OR operation_date >= :start_date) AND operation_date <= :end_date AND qa_status = :qa_status AND id in (:ids) AND is_packed = FALSE", TABLE_NAME );
private final String SELECT_BY_DATE_QA_STATUS = String.format( "SELECT COUNT(*) FROM %s WHERE (:start_date IS NULL OR operation_date >= :start_date) AND operation_date <= :end_date AND qa_status = :qa_status AND id in (:ids) AND is_packed = FALSE AND is_qa = TRUE", TABLE_NAME );
public FinishedItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;

View File

@ -49,7 +49,8 @@ public class InventoryTransactionLegDAO {
private final String SELECT_FIRST_TRANSACTION_PARENT_TYPE_PARENT_ID = String.format("SELECT * FROM %s WHERE parent_document_id IN (:parent_document_id) AND parent_document_type = :parent_document_type ORDER BY transaction_leg_datetime ASC LIMIT 1", TABLE_NAME);
private final String SELECT_GROUP_By_TRANSACTION_PARENT_TYPE_PARENT_ID = String.format("SELECT * FROM %s WHERE parent_document_id IN (:parent_document_id) AND parent_document_type = :parent_document_type GROUP BY account_id", TABLE_NAME);
private final String SELECT_TRANSACTIONS_REMAINING = String.format("SELECT parent_document_id as parentIds FROM %s WHERE account_id = :account_id AND parent_document_type = :parent_document_type AND type = 'IN' AND parent_document_id NOT IN (SELECT parent_document_id FROM %s WHERE account_id = :account_id AND parent_document_type = :parent_document_type AND type = 'OUT')", TABLE_NAME, TABLE_NAME);
private final String SELECT_PARENT_ID_BY_TYPE_GROUP = String.format("SELECT parent_document_id as parentIds FROM %s WHERE account_id = :account_id AND parent_document_type = :parent_document_type AND type = 'IN' GROUP BY parent_document_id", TABLE_NAME);
private final String SELECT_IN_PARENT_ID_BY_TYPE_GROUP = String.format("SELECT parent_document_id as parentIds FROM %s WHERE account_id = :account_id AND parent_document_type = :parent_document_type AND type = 'IN' GROUP BY parent_document_id", TABLE_NAME);
private final String SELECT_OUT_PARENT_ID_BY_TYPE_GROUP = String.format("SELECT parent_document_id as parentIds FROM %s WHERE account_id = :account_id AND parent_document_type = :parent_document_type AND type = 'OUT' GROUP BY parent_document_id", TABLE_NAME);
private final String SELECT_JOB_CARD_DATES = String.format("SELECT * FROM %s WHERE job_card_id = :job_card_id AND (:start_date IS NULL OR :end_date IS NULL OR transaction_leg_datetime BETWEEN :start_date AND :end_date) AND type = :type ", TABLE_NAME);
private final String SELECT_JOB_CARD_And_Date_Type_Account_Id = String.format("SELECT * FROM %s WHERE job_card_id = :job_card_id AND (:start_date IS NULL OR :end_date IS NULL OR transaction_leg_datetime BETWEEN :start_date AND :end_date) AND type = :type AND account_id IN (:account_ids)", TABLE_NAME);
@ -228,10 +229,16 @@ public class InventoryTransactionLegDAO {
return namedParameterJdbcTemplate.queryForList( SELECT_TRANSACTIONS_REMAINING , params, Long.class );
}
public List<Long> getInParentIdIdByDate(String parentType, Integer accountId){
public List<Long> getInParentIdByDate(String parentType, Integer accountId){
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("account_id", accountId );
params.addValue("parent_document_type", parentType );
return namedParameterJdbcTemplate.queryForList( SELECT_PARENT_ID_BY_TYPE_GROUP , params, Long.class );
return namedParameterJdbcTemplate.queryForList( SELECT_IN_PARENT_ID_BY_TYPE_GROUP , params, Long.class );
}
public List<Long> getOutParentIdByDate(String parentType, Integer accountId){
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("account_id", accountId );
params.addValue("parent_document_type", parentType );
return namedParameterJdbcTemplate.queryForList( SELECT_OUT_PARENT_ID_BY_TYPE_GROUP , params, Long.class );
}
}

View File

@ -35,6 +35,7 @@ public class DashboardService {
public Map<String, Float> getPhasesProgressDayWise(String lineNo) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
HashMap<String, Float> progress = new HashMap<>();
String cuttingAccount = "CUTTING ACCOUNT " + lineNo;
String stitchingAccount = "STITCHING ACCOUNT " + lineNo;
@ -42,20 +43,13 @@ public class DashboardService {
String packagingAccount = "A GRADE ACCOUNT " + lineNo;
LocalDateTime today = LocalDateTime.now().withHour(0).withMinute(0).withSecond(1);
String startDate1 = today.format(formatter);
String endDate1 = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59).format(formatter);
String startDateWithHour = LocalDateTime.now().minusHours(1).format(formatter);
String endDateWithHour = LocalDateTime.now().format(formatter);
HashMap<String, Float> progress = new HashMap<>();
//set inventory accounts
List<InventoryAccount> inventoryAccounts = inventoryAccountDAO.findAll();
InventoryAccount inventoryAccount = inventoryAccounts.stream()
.filter(e -> cuttingAccount.equals(e.getTitle())).findFirst().orElse(new InventoryAccount());
Map<String, Integer> inventoryAccountMap = inventoryAccounts.stream()
.filter(e -> cuttingAccount.equals(e.getTitle()) ||
stitchingAccount.equals(e.getTitle()) ||
@ -63,49 +57,59 @@ public class DashboardService {
packagingAccount.equals(e.getTitle()))
.collect(Collectors.toMap(InventoryAccount::getTitle, e -> (int) e.getId()));
//get all in remaining transaction stitching
List<Long> stitchingItemIds = inventoryTransactionLegDAO.findRemainingByParentTypeAndAccountID("STITCHING_OFFLINE", inventoryAccountMap.get(stitchingAccount));
List<Long> finishing = inventoryTransactionLegDAO.getInParentIdIdByDate("FINISHED_ITEM", inventoryAccountMap.get(finishingAccount));
//get all out transaction stitching
List<Long> stitchingOutIds = inventoryTransactionLegDAO.getOutParentIdByDate("STITCHING_OFFLINE", inventoryAccountMap.get(stitchingAccount));
//get all in transaction finished
List<Long> finishing = inventoryTransactionLegDAO.getInParentIdByDate("FINISHED_ITEM", inventoryAccountMap.get(finishingAccount));
//get all in remaining transaction packaging
List<Long> packagingItemIDs = inventoryTransactionLegDAO.findRemainingByParentTypeAndAccountID("PACKAGING", inventoryAccountMap.get(packagingAccount));
//set stitching related details
Long approvedStitchingOfflineItems = 0L;
Long approvedStitchingOfflineItemsThenReject = 0L;
long qcReject = 0L;
if (stitchingItemIds != null && !stitchingItemIds.isEmpty()) {
approvedStitchingOfflineItems = stitchingOfflineItemDAO.findByQCOperationDateAndApproved(startDate1, endDate1, "APPROVED");
qcReject = stitchingOfflineItemDAO.findByQCOperationDateAndIds(null, endDate1, "REJECT", stitchingItemIds);
qcReject = stitchingOfflineItemDAO.findByQCOperationDateAndIds(startDate1, endDate1, "REJECT", stitchingItemIds);
approvedStitchingOfflineItemsThenReject = stitchingOfflineItemDAO.findByQCOperationDateAndIds(startDate1, endDate1, "REJECT",stitchingOutIds);
}
//set finishing related details
Long alterationPieceFinish = 0L;
Long rejectFinishedItem = 0L;
Long washFinishedItem = 0L;
Long approved = 0L;
Long operationNotPerformed = 0L;
if (finishing != null && !finishing.isEmpty()) {
approved = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(startDate1, endDate1, "APPROVED", finishing);
operationNotPerformed = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(null, endDate1, "-", finishing);
rejectFinishedItem = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(null, endDate1, "REJECT", finishing);
operationNotPerformed = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(startDate1, endDate1, "-", finishing);
rejectFinishedItem = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(startDate1, endDate1, "REJECT", finishing);
washFinishedItem = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(startDate1, endDate1, "WASHED", finishing);
alterationPieceFinish = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(null, endDate1, "ALTER", finishing);
alterationPieceFinish = finishedItemDAO.findByOperationDateAndIdsAndQaStatus(startDate1, endDate1, "ALTER", finishing);
}
//set packaging details
Long packagingItems = 0L;
if (packagingItemIDs != null && !packagingItemIDs.isEmpty()) {
packagingItems = packagingItemsDAO.findByDateAndIds(startDate1, endDate1, packagingItemIDs);
}
//set shift wise details and time
LocalDateTime statTime = LocalDateTime.now().withHour(9).withMinute(0).withSecond(0).withNano(0);
LocalDateTime endTime = statTime.plusMinutes(inventoryAccount.getShiftMinutes());
long minutesPassed = 0;
if (statTime.isBefore(LocalDateTime.now()) && LocalDateTime.now().isBefore(endTime)) {
minutesPassed = Duration.between(statTime, LocalDateTime.now()).toMinutes();
}
//set efficiency
long shiftTargetMinutesWise = getTargetShiftWiseOrHourlyWise(Math.max(0, minutesPassed), inventoryAccount);
float efficiency;
if (shiftTargetMinutesWise == 0) {
@ -113,9 +117,10 @@ public class DashboardService {
} else {
efficiency = (float) approvedStitchingOfflineItems / shiftTargetMinutesWise;
}
progress.put("Stitching", (float) approvedStitchingOfflineItems + qcReject);
progress.put("Stitching", (float) approvedStitchingOfflineItems + qcReject + approvedStitchingOfflineItemsThenReject);
progress.put("totalWips", (float) stitchingItemIds.size() - qcReject);
progress.put("Alteration", (float) qcReject);
progress.put("Alteration", (float) qcReject + approvedStitchingOfflineItemsThenReject);
progress.put("finishing", (float) approved + operationNotPerformed);
progress.put("ALTER", (float) alterationPieceFinish);