Quellcode durchsuchen

no message

master
[email protected] vor 2 Wochen
Ursprung
Commit
25c8abce57
3 geänderte Dateien mit 143 neuen und 947 gelöschten Zeilen
  1. +19
    -0
      src/main/java/com/ffii/core/utils/DateUtils.java
  2. +100
    -794
      src/main/java/com/ffii/lioner/modules/lioner/client/service/ClientService.java
  3. +24
    -153
      src/main/java/com/ffii/lioner/modules/lioner/client/web/ClientController.java

+ 19
- 0
src/main/java/com/ffii/core/utils/DateUtils.java Datei anzeigen

@@ -0,0 +1,19 @@
package com.ffii.core.utils;

import java.util.Calendar;
import java.util.Date;

/**
* String Utils based on Apache Commons StringUtils.
*
* @author Vin
*/
public abstract class DateUtils extends org.apache.commons.lang3.StringUtils {

public static final Date addDay(Date inputDate, int numDay) {
Calendar c = Calendar.getInstance();
c.setTime(inputDate);
c.add(Calendar.DATE, numDay);
return c.getTime();
}
}

+ 100
- 794
src/main/java/com/ffii/lioner/modules/lioner/client/service/ClientService.java Datei anzeigen

@@ -1,9 +1,15 @@
package com.ffii.lioner.modules.lioner.client.service;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.Date;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import com.ffii.core.support.AbstractBaseEntityService;
@@ -16,6 +22,9 @@ import com.ffii.lioner.modules.lioner.client.entity.Client;
import com.ffii.lioner.modules.lioner.client.entity.ClientRepository;
import com.ffii.lioner.modules.lioner.client.req.UpdateClientReq;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.*;

@Service
public class ClientService extends AbstractBaseEntityService<Client, Long, ClientRepository> {

@@ -64,56 +73,6 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien
return jdbcDao.queryForMap(sql.toString(), req).get();
}

// public Client saveImportRecord(ImpEvent req) {
// Client instance;
// if (req.getId() > 0) {
// instance = find(req.getId()).get();
// } else {
// instance = new Client();
// }
// // =====GET OLD AUDIT LOG=====//
// String tableName = instance.getClass().getAnnotation(Table.class).name();
// Map<String, Object> oldValueObject = new HashMap<String, Object>();
// Map<String, Object> newValueObject = new HashMap<String, Object>();

// if (instance != null && instance.getId() != null && instance.getId() > 0) {
// Map<String, Object> input = Map.of("id", instance.getId());
// Map<String, Object> logData = getAuditLogObject(input);
// logData.put("subDivision", this.getEventDivisionName(input));
// oldValueObject = logData;
// }
// // =====GET OLD AUDIT LOG=====//

// BeanUtils.copyProperties(req, instance);
// logger.info(instance.toString());
// instance = save(instance);
// Long eventId = instance.getId();
// updateSubDivision(req.getTempIdList(),new ArrayList<>(),eventId);

// // =====GET NEW AUDIT LOG=====//
// if (instance != null && instance.getId() != null && instance.getId() > 0) {
// Map<String, Object> input = Map.of("id", instance.getId());
// Map<String, Object> logData = getAuditLogObject(input);
// logData.put("subDivision", this.getEventDivisionName(input));
// newValueObject = logData;
// }

// if (auditLogService.compareMaps(newValueObject, oldValueObject).size() != 0 ||
// auditLogService.compareMaps(oldValueObject, newValueObject).size() != 0) {
// auditLogService.save(
// tableName,
// instance.getId(),
// instance.getFullname(),
// SecurityUtils.getUser() != null ? SecurityUtils.getUser().get().getId() : null,
// new Date(),
// JsonUtils.toJsonString(auditLogService.compareMaps(newValueObject, oldValueObject)),
// JsonUtils.toJsonString(auditLogService.compareMaps(oldValueObject, newValueObject)));
// }
// // =====GET NEW AUDIT LOG=====//

// return instance;
// }

public Map<String, Object> saveOrUpdate(UpdateClientReq req) {
Client instance;
@@ -139,61 +98,6 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien
return m;
}

// public void markDeleteWithAuditLog(Client instance){
// //=====GET OLD AUDIT LOG=====//
// String tableName = instance.getClass().getAnnotation(Table.class).name();
// StringBuilder sql = new StringBuilder("SELECT * FROM " + tableName + " WHERE id = :id");
// Map<String,Object> oldValueObject = new HashMap<String,Object>();
// Map<String,Object> newValueObject = new HashMap<String,Object>();
// if (instance != null && instance.getId() != null && instance.getId() > 0) {
// Map<String,Object> input = Map.of("id", instance.getId());
// Map<String,Object> logData= getAuditLogObject(input);
// logData.put("subDivision", this.getEventDivisionName(input));
// oldValueObject = logData;
// }
// //=====GET OLD AUDIT LOG=====//
// this.markDelete(instance.getId());
// this.deleteEventDivision(instance.getId().intValue());
// //=====GET NEW AUDIT LOG=====//
// if (instance != null && instance.getId() != null && instance.getId() > 0) {
// Map<String,Object> input = Map.of("id", instance.getId());
// Map<String,Object> logData= getAuditLogObject(input);
// logData.put("subDivision", this.getEventDivisionName(input));
// newValueObject = logData;
// }

// if(auditLogService.compareMaps(newValueObject,oldValueObject).size() != 0 ||
// auditLogService.compareMaps(oldValueObject,newValueObject).size() != 0
// ){
// auditLogService.save(
// tableName,
// instance.getId(),
// instance.getName(),
// SecurityUtils.getUser() != null ? SecurityUtils.getUser().get().getId() : null,
// new Date(),
// JsonUtils.toJsonString(auditLogService.compareMaps(newValueObject,oldValueObject)),
// JsonUtils.toJsonString(auditLogService.compareMaps(oldValueObject,newValueObject)));
// }
// //=====GET NEW AUDIT LOG=====//
// }

// public void deleteEventDivision(Integer eventId) {
// List<Integer> subDivisionIdList = this.getEventDivision(Map.of("id", eventId));
// List<Map<String, Integer>> deleteDivisionIds = subDivisionIdList.stream()
// .map(subDivisionId -> Map.of("eventId", eventId, "subDivisionId", subDivisionId))
// .collect(Collectors.toList());

// if (!deleteDivisionIds.isEmpty()) {
// jdbcDao.batchUpdate(
// "UPDATE event_sub_division esd"
// + " SET esd.deleted = TRUE"
// + " WHERE eventId = :eventId AND subDivisionId = :subDivisionId",
// deleteDivisionIds);
// }
// }

public List<Map<String,Object>> list(Map<String, Object> args){
long currentUserId = SecurityUtils.getUser().get().getId();
args.put("currentUserId", currentUserId);
@@ -247,695 +151,6 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien
return jdbcDao.queryForList(sql.toString(), args);
}

// public List<Map<String,Object>> listReport(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT e.*, "
// + " (SELECT "
// + " GROUP_CONCAT( DISTINCT d2.name) "
// + " FROM event e2 "
// + " LEFT JOIN event_sub_division esd2 ON e2.id = esd2.eventId "
// + " LEFT JOIN sub_division sd2 ON esd2.subDivisionId = sd2.id "
// + " LEFT JOIN division d2 ON d2.id = sd2.divisionId "
// + " WHERE e2.id = e.id "
// + " AND esd2.deleted = false "
// + " GROUP BY e2.id "
// + " ) AS divisionList, "
// + " u.name as username "
// + " FROM event e "
// + " LEFT JOIN event_sub_division esd ON e.id = esd.eventId "
// + " LEFT JOIN sub_division sd ON esd.subDivisionId = sd.id "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " LEFT JOIN `user` u ON u.id = e.createdBy "
// + " WHERE e.deleted = FALSE "
// );

// if (args != null) {
// if (args.containsKey("eventName"))
// sql.append(" AND e.name LIKE :eventName ");
// if (args.containsKey("description"))
// sql.append(" AND e.description LIKE :description ");
// if (args.containsKey("organization"))
// sql.append(" AND e.organization LIKE :organization ");
// if (args.containsKey("fromDate"))
// sql.append(" AND DATE(e.startDate) >= :fromDate");
// if (args.containsKey("toDate"))
// sql.append(" AND DATE(e.startDate) < :toDate");
// if (args.containsKey("region"))
// sql.append(" AND e.region LIKE :region ");
// if (args.containsKey("type"))
// sql.append(" AND e.eventType LIKE :type ");
// if (args.containsKey("divisionIdList"))
// sql.append(" AND sd.divisionId IN (:divisionIdList) ");
// if (args.containsKey("subDivisionIdList"))
// sql.append(" AND sd.id IN (:subDivisionIdList) ");
// if (args.containsKey("keyword")){
// sql.append(" AND ( e.createdBy LIKE :keyword ");
// sql.append(" OR u.username LIKE :keyword ");
// sql.append(" OR u.fullname LIKE :keyword ");
// sql.append(" OR u.email LIKE :keyword ");
// sql.append(" OR sd.name LIKE :keyword ");
// sql.append(" OR d.name LIKE :keyword ");
// sql.append(" OR e.name LIKE :keyword) ");
// }
// }
// sql.append(" ORDER BY e.id");

// return jdbcDao.queryForList(sql.toString(), args);
// }

// public List<Map<String,Object>> listByEvent(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT a.id, "
// + " a.name AS applicationName, "
// + " a.responsibleOfficer, "
// + " (SELECT "
// + " GROUP_CONCAT(t.name SEPARATOR ', ') "
// + " FROM application_tag at2 "
// + " LEFT JOIN tag t ON at2.tagId = t.id "
// + " WHERE at2.deleted = FALSE "
// + " AND at2.applicationId = a.id) AS tags, "
// + " (SELECT "
// + " GROUP_CONCAT(sd.name SEPARATOR ', ') "
// + " FROM application_sub_division asd2 "
// + " LEFT JOIN sub_division sd ON sd.id = asd2.subDivisionId "
// + " WHERE asd2.deleted = FALSE "
// + " AND asd2.applicationId = a.id) AS subDivisions "
// + " FROM application a "
// + " JOIN application_sub_division asd ON asd.applicationId = a.id "
// + " LEFT JOIN sub_division sd3 ON asd.subDivisionId = sd3.id"
// + " LEFT JOIN division d ON d.id = sd3.divisionId "
// + " WHERE a.deleted = FALSE "
// + " AND a.eventId = :eventId "
// );
// if (args.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");

// sql.append(" ORDER BY a.id");

// return jdbcDao.queryForList(sql.toString(), args);
// }

// public List<Client> getEventByWithinYear(Map<String,Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT e.* "
// + " FROM event e "
// + " LEFT JOIN event_sub_division esd ON e.id = esd.eventId "
// + " WHERE e.deleted = FALSE "
// + " AND e.reminderFlag = TRUE "
// + " AND e.startDate >= :yearRange "
// );

// if (args != null) {
// if (args.containsKey("announcementDate")) {
// sql.append(" AND e.announcementDate = :announcementDate");
// }
// }

// sql.append(" ORDER BY e.id");

// return jdbcDao.queryForList(sql.toString(), args, Client.class);
// }

// public List<Integer> getEventDivision(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " esd.subDivisionId "
// + " FROM event_sub_division esd "
// + " LEFT JOIN sub_division sd ON sd.id = esd.subDivisionId "
// + " WHERE esd.deleted = FALSE "
// + " AND sd.deleted = FALSE "
// + " AND esd.eventId = :id "
// );

// sql.append(" ORDER BY esd.id");

// return jdbcDao.queryForInts(sql.toString(), args);
// }

// public List<String> getEventDivisionName(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " sd.name "
// + " FROM event_sub_division esd "
// + " JOIN sub_division sd ON esd.subDivisionId = sd.id "
// + " WHERE esd.deleted = FALSE "
// + " AND esd.eventId = :id "
// );

// sql.append(" ORDER BY esd.id");

// return jdbcDao.queryForStrings(sql.toString(), args);
// }

// public List<Map<String,Object>> getEventDivisionAllData(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " esd.* "
// + " FROM event_sub_division esd "
// + " WHERE esd.deleted = FALSE "
// + " AND esd.eventId = :id "
// );

// sql.append(" ORDER BY esd.id");

// return jdbcDao.queryForList(sql.toString(), args);
// }

// public List<Map<String,Object>> listCombo(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT "
// + " e.id, "
// + " e.id as `key`, "
// + " e.name as label "
// + " FROM event e "
// + " LEFT JOIN event_sub_division esd ON esd.eventId = e.id "
// + " WHERE e.deleted = FALSE "
// );
// if (args != null) {
// if (args.containsKey("userSubDivisionId"))
// sql.append(" AND esd.subDivisionId = :userSubDivisionId ");
// }

// sql.append(" ORDER BY e.name asc");

// return jdbcDao.queryForList(sql.toString(), args);
// }

// private void updateSubDivision(List<Long> newIds, List<Long> removeIds, Long eventId){
// List<Map<String, Long>> newDivisionIds = newIds.stream()
// .map(subDivisionId -> Map.of("eventId", eventId, "subDivisionId", subDivisionId))
// .collect(Collectors.toList());
// List<Map<String, Long>> deleteDivisionIds = removeIds.stream()
// .map(subDivisionId -> Map.of("eventId", eventId, "subDivisionId", subDivisionId))
// .collect(Collectors.toList());
// if (!newDivisionIds.isEmpty()) {
// jdbcDao.batchUpdate(
// "INSERT IGNORE INTO event_sub_division (eventId, subDivisionId, newReminderCount, suppressedNewReminder, oldReminderCount, suppressedOldReminder )"
// + " VALUES (:eventId, :subDivisionId, 0, 0, 0, 0)",
// newDivisionIds);
// }
// if (!deleteDivisionIds.isEmpty()) {
// jdbcDao.batchUpdate(
// "UPDATE event_sub_division esd"
// + " SET esd.deleted = TRUE"
// + " WHERE eventId = :eventId AND subDivisionId = :subDivisionId",
// deleteDivisionIds);
// }

// }

// public boolean isNameTaken(String name, Long id) {
// StringBuilder sql = new StringBuilder("SELECT"
// + " Count(e.id) "
// + " FROM event e "
// + " WHERE e.deleted =FALSE "
// + " AND e.name = :name "
// + " AND e.id != :id "
// );
// return jdbcDao.queryForBoolean(sql.toString(), Map.of("name", name, "id", id));
// }

// public Boolean hasApplicationRecord(Map<String, Object> args){
// StringBuilder sql = new StringBuilder("SELECT"
// + " COUNT(*) "
// + " FROM event e "
// + " JOIN application a ON e.id = a.eventId "
// + " WHERE e.deleted = FALSE "
// + " AND e.id = :id "
// );

// sql.append(" ORDER BY e.id");

// return jdbcDao.queryForBoolean(sql.toString(), args);
// }

// public Map<String,Object> isReminderOvertime(Long id){
// Client event = find(id).get();

// if(event.getReminderFlag() == false){
// return Map.of("warning",false);
// }
// else{
// LocalDate firstIssueDate = null;
// Boolean hasApplicationRecord = hasApplicationRecord(Map.of("id",event.getId()));

// if(!hasApplicationRecord){
// firstIssueDate = event.getStartDate().minusDays(event.getReminderThreshold());
// }
// else{
// if(event.getNextApplicationDate() != null){
// firstIssueDate = event.getNextApplicationDate().minusDays(event.getReminderThreshold());
// }
// else{
// return Map.of(
// "warning", false
// );
// }
// }
// Integer limit = event.getReminderLimit().intValue();
// Integer interval = event.getReminderInterval().intValue();
// List<LocalDate> reminderDateSchedule = new ArrayList<LocalDate>();
// reminderDateSchedule.add(firstIssueDate);
// for(Integer i=1; i< limit+1 ; i++){
// reminderDateSchedule.add(firstIssueDate.plusDays(i*interval));
// }
// logger.info(reminderDateSchedule);
// LocalDate lastLocalDate = null;
// for (LocalDate localDate : reminderDateSchedule) {
// if(localDate.compareTo(event.getApplicationDeadline()) > 0){
// //reminder overflow
// return Map.of(
// "warning", true,
// "lastNotiDate", lastLocalDate
// );
// }
// else{
// lastLocalDate = localDate;
// }
// }
// return Map.of(
// "warning", false
// );
// }
// }

// public List<Map<String,Object>> getTop6(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " ROW_NUMBER() OVER (ORDER BY SUM(IF(temp.awardId IS NOT NULL, 1, 0)) DESC) as `rank`, "
// + " temp.eventId, "
// + " temp.eventName, "
// + " SUM(IF(temp.awardId IS NOT NULL, 1, 0)) as awardCount "
// + " FROM ( "
// + " (SELECT "
// + " e.id as eventId, "
// + " e.name as eventName, "
// + " a2.id as awardId "
// + " FROM event e "
// + " LEFT JOIN application a ON a.eventId = e.id "
// + " LEFT JOIN award a2 ON a2.applicationId = a.id "
// + " LEFT JOIN award_sub_division asd ON a2.id = asd.awardId AND asd.deleted = false "
// + " LEFT JOIN sub_division sd ON sd.id = asd.subDivisionId "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " WHERE e.deleted = FALSE "
// + " AND a.deleted = FALSE "
// + " AND a2.deleted = FALSE "
// );
// if (req.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");
// sql.append(
// " AND YEAR(e.startDate) = :year "
// + " GROUP BY e.id, e.name, a2.id) "
// + " UNION "
// + " (SELECT "
// + " e.id as eventId, "
// + " e.name as eventName, "
// + " null "
// + " FROM event e "
// + " LEFT JOIN event_sub_division esd ON e.id = esd.eventId AND esd.deleted = false "
// + " LEFT JOIN sub_division sd ON sd.id = esd.subDivisionId "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " WHERE e.deleted = FALSE "
// );
// if (req.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");
// sql.append(
// " AND YEAR(e.startDate) = :year "
// + " GROUP BY e.id, e.name) "
// + " ) temp "
// + " GROUP BY temp.eventId, temp.eventName "
// + " ORDER BY SUM(IF(temp.awardId IS NOT NULL, 1, 0)) DESC "
// + " LIMIT 6; "
// );

// return jdbcDao.queryForList(sql.toString(), req);
// }

// public List<Map<String,Object>> getDashboardCombo(){
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT year(e.startDate) AS id, "
// + " year(e.startDate) AS label "
// + " FROM event e "
// + " WHERE e.deleted = FALSE "
// + " ORDER BY id DESC "
// );

// return jdbcDao.queryForList(sql.toString());
// }

// public Map<String,Object> getYearEventCount(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " COUNT(temp.eventId) AS count "
// + " FROM( "
// + " SELECT "
// + " e.id AS eventId "
// + " FROM event e "
// + " LEFT JOIN event_sub_division esd ON e.id = esd.eventId "
// + " LEFT JOIN sub_division sd ON sd.id =esd.subDivisionId "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " WHERE e.deleted = FALSE "
// + " AND esd.deleted = false "
// );

// if (req.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");
// sql.append(" AND YEAR(e.startDate) = :year");
// sql.append(" GROUP BY e.id ");
// sql.append(" ) temp; ");

// return jdbcDao.queryForMap(sql.toString(),req).get();
// }

// public Map<String,Object> getYearAwardCount(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " COUNT(temp.awardId) AS count "
// + " FROM( "
// + " SELECT "
// + " a2.id AS awardId "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " LEFT JOIN award_sub_division asd ON a2.id = asd.awardId "
// + " LEFT JOIN sub_division sd ON sd.id = asd.subDivisionId AND asd.deleted = false "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " WHERE e.deleted = FALSE "
// + " AND a.deleted = FALSE "
// + " AND a2.deleted = FALSE "

// );

// if (req.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");
// sql.append(" AND YEAR(e.awardDate) = :year");
// sql.append(" GROUP BY a2.id, a2.id ");
// sql.append(" ) temp; ");

// return jdbcDao.queryForMap(sql.toString(),req).get();
// }

// public List<Map<String,Object>> getDummyDivisionAwardSummary(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " ROW_NUMBER() OVER (ORDER BY awardCount DESC) AS `rank`, "
// + " name, "
// + " awardCount "
// + " FROM ( "
// + " SELECT "
// + " queryResult.name, "
// + " COUNT(queryResult.awardName) AS awardCount "
// + " FROM ( "
// + " SELECT "
// + " DISTINCT "
// + " d.id, "
// + " d.name, "
// + " e.name AS eventName,"
// + " a.name AS application,"
// + " a2.name AS awardName "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " JOIN category c ON a2.categoryId = c.id "
// + " LEFT JOIN award_sub_division asd ON asd.awardId = a2.id "
// + " LEFT JOIN sub_division sd ON asd.subDivisionId = sd.id "
// + " LEFT JOIN division d ON sd.divisionId = d.id "
// + " WHERE d.deleted = FALSE "
// + " AND YEAR(e.startDate) = :year "
// + " AND asd.deleted = false "
// );

// if (req.containsKey("userSubDivisionId")) sql.append(" AND sd.id = :userSubDivisionId ");
// if (req.containsKey("branch")) sql.append(" AND d.branch LIKE :branch ");
// sql.append(
// " AND sd.deleted = FALSE "
// + " ) AS queryResult "
// + " GROUP BY queryResult.id "
// + " UNION ALL "
// + " SELECT "
// + " dummy.name, "
// + " 0 AS awardCount "
// + " FROM ( "
// + " SELECT 1 AS id, 'z' AS name "
// + " UNION ALL SELECT 2, 'z' "
// + " ) AS dummy "
// + " ) AS rankedData "
// + " ORDER BY name ASC "
// + " LIMIT 10; "
// );

// return jdbcDao.queryForList(sql.toString(),req);
// }


// public List<Map<String,Object>> getDivisionAwardSummaryUntil10(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " ROW_NUMBER() OVER (ORDER BY awardCount DESC) AS `rank`, "
// + " name, "
// + " awardCount "
// + " FROM ( "
// + " SELECT "
// + " queryResult.name, "
// + " COUNT(queryResult.awardName) AS awardCount "
// + " FROM ( "
// + " SELECT "
// + " DISTINCT "
// + " d.id, "
// + " d.name, "
// + " e.name AS eventName,"
// + " a.name AS application,"
// + " a2.name AS awardName "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " JOIN category c ON a2.categoryId = c.id "
// + " LEFT JOIN award_sub_division asd ON asd.awardId = a2.id "
// + " LEFT JOIN sub_division sd ON asd.subDivisionId = sd.id "
// + " LEFT JOIN division d ON sd.divisionId = d.id "
// + " WHERE d.deleted = FALSE "
// + " AND YEAR(e.startDate) = :year "
// + " AND sd.deleted = FALSE "
// + " AND d.branch LIKE :branch "
// + " AND asd.deleted = false "
// + " ) AS queryResult "
// + " GROUP BY queryResult.id "
// + " UNION ALL "
// + " SELECT "
// + " dummy.name, "
// + " 0 AS awardCount "
// + " FROM ( "
// + " SELECT 1 AS id, 'z' AS name "
// + " UNION ALL SELECT 2, 'z' "
// + " UNION ALL SELECT 3, 'z' "
// + " UNION ALL SELECT 4, 'z' "
// + " UNION ALL SELECT 5, 'z' "
// + " UNION ALL SELECT 6, 'z' "
// + " UNION ALL SELECT 7, 'z' "
// + " UNION ALL SELECT 8, 'z' "
// + " UNION ALL SELECT 9, 'z' "
// + " UNION ALL SELECT 10, 'z' "
// + " ) AS dummy "
// + " ) AS rankedData "
// + " ORDER BY name ASC "
// + " LIMIT 10; "
// );

// return jdbcDao.queryForList(sql.toString(),req);
// }

// public List<Map<String,Object>> getDivisionAwardSummary(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " ROW_NUMBER() OVER (ORDER BY awardCount DESC) AS `rank`, "
// + " name, "
// + " awardCount "
// + " FROM ( "
// + " SELECT "
// + " queryResult.name, "
// + " COUNT(queryResult.awardName) AS awardCount "
// + " FROM ( "
// + " SELECT "
// + " DISTINCT "
// + " d.id, "
// + " d.name, "
// + " e.name AS eventName, "
// + " a.name AS application, "
// + " a2.name AS awardName "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " JOIN category c ON a2.categoryId = c.id "
// + " LEFT JOIN award_sub_division asd ON asd.awardId = a2.id "
// + " LEFT JOIN sub_division sd ON asd.subDivisionId = sd.id "
// + " LEFT JOIN division d ON sd.divisionId = d.id "
// + " WHERE d.deleted = FALSE "
// + " AND YEAR(e.startDate) = :year "
// + " AND sd.deleted = FALSE "
// + " AND d.branch LIKE :branch "
// + " AND asd.deleted = false "
// + " ) AS queryResult "
// + " GROUP BY queryResult.id "
// + " ) AS rankedData "
// + " ORDER BY name ASC "
// );

// return jdbcDao.queryForList(sql.toString(),req);
// }

// public List<Map<String,Object>> getTagAwardSummary(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " temp.id, "
// + " temp.name, "
// + " COUNT(temp.awardId) AS awardCount "
// + " FROM( "
// + " SELECT "
// + " t.id, "
// + " t.name, "
// + " a2.id AS awardId "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN application_tag at2 ON at2.applicationId = a.id "
// + " JOIN tag t ON t.id = at2.tagId "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " LEFT JOIN award_sub_division asd ON a2.id = asd.awardId AND asd.deleted = FALSE "
// + " LEFT JOIN sub_division sd ON sd.id = asd.subDivisionId "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " WHERE e.deleted = FALSE "
// + " AND a.deleted = FALSE "
// + " AND a2.deleted = FALSE "
// );

// if (req.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");
// sql.append(" AND YEAR(e.startDate) = :year ");
// sql.append(" GROUP BY t.id, a2.id ");
// sql.append(" ) temp ");
// sql.append(" GROUP BY temp.id ");
// sql.append(" ORDER BY COUNT(temp.id) DESC");
// sql.append(" LIMIT 6 ;");

// return jdbcDao.queryForList(sql.toString(),req);
// }

// public List<Map<String,Object>> getCategoryAwardSummary(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " temp.id, "
// + " temp.name, "
// + " COUNT(temp.awardId) AS awardCount "
// + " FROM( "
// + " SELECT "
// + " c.id, "
// + " c.name, "
// + " a2.id AS awardId "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " LEFT JOIN award_sub_division asd ON a2.id = asd.awardId "
// + " LEFT JOIN sub_division sd ON sd.id = asd.subDivisionId "
// + " LEFT JOIN division d ON d.id = sd.divisionId "
// + " LEFT JOIN category c ON a2.categoryId = c.id "
// + " WHERE e.deleted = FALSE "
// + " AND a.deleted = FALSE "
// + " AND a2.deleted = FALSE "
// + " AND asd.deleted = false "

// );

// if (req.containsKey("userSubDivisionId")) sql.append(" AND d.id = (SELECT sd2.divisionId FROM sub_division sd2 WHERE sd2.id = :userSubDivisionId)");
// sql.append(" AND YEAR(e.startDate) = :year ");
// sql.append(" GROUP BY c.id, a2.id ");
// sql.append(" ) temp ");
// sql.append(" GROUP BY temp.id ");
// sql.append(" ORDER BY COUNT(temp.id) DESC");
// sql.append(" LIMIT 6 ;");

// return jdbcDao.queryForList(sql.toString(),req);
// }
// public List<Map<String,Object>> getAwardSummaryReportPage1(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " name, "
// + " count "
// + " FROM ( "
// + " SELECT "
// + " queryResult.name, "
// + " COUNT(queryResult.awardName) AS count "
// + " FROM ( "
// + " SELECT "
// + " DISTINCT "
// + " d.id, "
// + " d.name, "
// + " e.name AS eventName,"
// + " a.name AS application,"
// + " a2.name AS awardName "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " JOIN category c ON a2.categoryId = c.id "
// + " LEFT JOIN award_sub_division asd ON asd.awardId = a2.id "
// + " LEFT JOIN sub_division sd ON asd.subDivisionId = sd.id "
// + " LEFT JOIN division d ON sd.divisionId = d.id "
// + " WHERE d.deleted = FALSE "
// + " AND YEAR(e.startDate) = :year "
// + " AND asd.deleted = false "
// );

// if (req.containsKey("userSubDivisionId")) sql.append(" AND sd.id = :userSubDivisionId ");
// if (req.containsKey("branch")) sql.append(" AND d.branch LIKE :branch ");
// sql.append(
// " AND sd.deleted = FALSE "
// + " ) AS queryResult "
// + " GROUP BY queryResult.id "
// + " ) AS rankedData "
// + " ORDER BY count DESC "
// );

// return jdbcDao.queryForList(sql.toString(),req);
// }

// public List<Map<String,Object>> getAwardSummaryReportPage2(Map<String,Object> req){
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT "
// + " d.name, "
// + " (SELECT GROUP_CONCAT( DISTINCT sd.name SEPARATOR ', ') "
// + " FROM award_sub_division asd2 "
// + " LEFT JOIN sub_division sd ON sd.id = asd2.subDivisionId "
// + " LEFT JOIN division d2 ON sd.divisionId = d2.id "
// + " WHERE asd2.deleted = FALSE "
// + " AND d2.id = d.id "
// + " ) AS subDivision, "
// + " e.name AS eventName, "
// + " a.name AS applicationName, "
// + " a2.name AS awardName, "
// + " a2.receiveDate, "
// + " c.name AS category , "
// + " a2.responsibleOfficer "
// + " FROM event e "
// + " JOIN application a ON a.eventId = e.id "
// + " JOIN award a2 ON a2.applicationId = a.id "
// + " JOIN category c ON a2.categoryId = c.id "
// + " LEFT JOIN award_sub_division asd ON asd.awardId = a2.id AND asd.deleted = FALSE "
// + " LEFT JOIN sub_division sd ON asd.subDivisionId =sd.id "
// + " LEFT JOIN division d ON sd.divisionId = d.id "
// + " WHERE a.deleted = FALSE "
// + " AND a.deleted = FALSE "
// + " AND a2.deleted = FALSE "
// + " AND YEAR(e.startDate) = :year "
// );
// if (req.containsKey("userSubDivisionId")) sql.append(" AND sd.id = :userSubDivisionId ");
// if (req.containsKey("branch")) sql.append(" AND d.branch LIKE :branch ");

// return jdbcDao.queryForList(sql.toString(),req);
// }

// public List<SubDivision> getSelectedSubDivisionList(Long eventId) {
// StringBuilder sql = new StringBuilder("SELECT"
// + " DISTINCT "
// + " sd.* "
// + " FROM application a "
// + " JOIN application_sub_division asd ON a.id = asd.applicationId "
// + " LEFT JOIN sub_division sd ON asd.subDivisionId = sd.id "
// + " WHERE a.eventId = :eventId "
// );

// return jdbcDao.queryForList(sql.toString(), Map.of("eventId", eventId), SubDivision.class);
// }

public Integer getIdByName(String name) {
StringBuilder sql = new StringBuilder("SELECT"
+ " e.id "
@@ -962,5 +177,96 @@ public class ClientService extends AbstractBaseEntityService<Client, Long, Clien
return code;
}
public void generateClientConsultantReport(Map<String, Object> args, OutputStream outputStream) throws IOException {
// Using your existing SQL
String sql = "SELECT " +
" concat( ifnull(c.lastname, ''), ' ', ifnull(c.firstname,'') ) as clientName, " +
" ifnull(ct.name, '') as consultantName, " +
" c.* " +
" FROM client c " +
" LEFT JOIN consultant ct ON c.consultantId = ct.id " +
" WHERE 1 ";

if (args.containsKey("fromDate")) sql += " AND c.created >= :fromDate ";
if (args.containsKey("toDate")) sql += " AND c.created < :toDate ";
List<Map<String, Object>> data = jdbcDao.queryForList(sql, args);

try (Workbook workbook = new XSSFWorkbook()) {
Sheet sheet = workbook.createSheet("Report");

// --- Styles ---
CellStyle headerStyle = workbook.createCellStyle();
headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
Font boldFont = workbook.createFont();
boldFont.setBold(true);
headerStyle.setFont(boldFont);

// Summary Style (Bold with borders)
CellStyle summaryStyle = workbook.createCellStyle();
summaryStyle.setBorderTop(BorderStyle.DOUBLE); // Double line to separate from data
summaryStyle.setFont(boldFont);

// --- Header Row ---
String[] headers = {"Client Code", "Client Name", "Consultant Name", "Created Date"};
Row headerRow = sheet.createRow(0);
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
cell.setCellStyle(headerStyle);
}

// --- Data Rows ---
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
int rowIdx = 1;
for (Map<String, Object> d : data) {
Row row = sheet.createRow(rowIdx++);

int j = 0;
row.createCell(j++).setCellValue(String.valueOf(d.getOrDefault("clientCode", "")));
row.createCell(j++).setCellValue(String.valueOf(d.getOrDefault("clientName", "")));
row.createCell(j++).setCellValue(String.valueOf(d.getOrDefault("consultantName", "")));
Object createdObj = d.get("created");
String dateStr = "";
if (createdObj instanceof LocalDateTime) {
dateStr = ((LocalDateTime) createdObj).format(formatter);
} else if (createdObj != null) {
dateStr = createdObj.toString();
}
row.createCell(j++).setCellValue(dateStr);
}

// --- ADD SUMMARY AT THE BOTTOM ---
// Leave one empty row for better spacing
rowIdx++;
Row summaryRow = sheet.createRow(rowIdx);
// Label: "Total number of clients"
Cell labelCell = summaryRow.createCell(0);
labelCell.setCellValue("Total number of clients:");
labelCell.setCellStyle(summaryStyle);

// Value: The actual count
Cell countCell = summaryRow.createCell(1);
countCell.setCellValue(data.size()); // Size of the result list
countCell.setCellStyle(summaryStyle);

// --- Column Widths ---
for (int i = 0; i < headers.length; i++) {
sheet.autoSizeColumn(i);
sheet.setColumnWidth(i, sheet.getColumnWidth(i) + 512);
}

workbook.write(outputStream);
}
}
}

+ 24
- 153
src/main/java/com/ffii/lioner/modules/lioner/client/web/ClientController.java Datei anzeigen

@@ -6,12 +6,15 @@ import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.Date;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -39,11 +42,13 @@ import com.ffii.core.exception.NotFoundException;
import com.ffii.core.response.DataRes;
import com.ffii.core.response.RecordsRes;
import com.ffii.core.utils.CriteriaArgsBuilder;
import com.ffii.core.utils.DateUtils;
import com.ffii.core.utils.Params;
import com.ffii.lioner.modules.lioner.client.entity.Client;
import com.ffii.lioner.modules.lioner.commonField.service.CommonFieldService;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;

@RestController
@@ -143,158 +148,24 @@ public class ClientController{
.build()));
}
// @GetMapping("/export")
// public ResponseEntity<Resource> getEventExport(HttpServletRequest request) throws ServletRequestBindingException, IOException {
// List<Map<String,Object>> record = clientService.listReport(CriteriaArgsBuilder.withRequest(request)
// .addStringLike("eventName")
// .addStringLike("description")
// .addStringLike("organization")
// .addDate("fromDate")
// .addDateTo("toDate")
// .addStringLike("region")
// .addStringLike("type")
// .addIntegerList("divisionIdList")
// .addIntegerList("subDivisionIdList")
// .addStringLike("keyword")
// .build());
// byte[] reportResult = excelReportService.generateEventExcelReport(record);
// return ResponseEntity.ok()
// .header("filename", "event_export_" + LocalDate.now())
// .body(new ByteArrayResource(reportResult));
// }

// @GetMapping("/application")
// public RecordsRes<Map<String, Object>> listByEvent(HttpServletRequest request)
// throws ServletRequestBindingException {
// return new RecordsRes<>(clientService.listByEvent(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("eventId")
// .addInteger("userSubDivisionId")
// .build()
// ));
// }

// @GetMapping("/combo")
// public RecordsRes<Map<String, Object>> getEventCombo(HttpServletRequest request) throws ServletRequestBindingException {
// System.out.println(request);
// return new RecordsRes<>(clientService.listCombo(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("userSubDivisionId")
// .build()));
// }

// @GetMapping("/checkDuplicate")
// public Map<String, Boolean> checkDuplicate(@RequestParam String name, @RequestParam Long id) {
// boolean isNameTaken = clientService.isNameTaken(name,id);
// return Map.of(
// "isTaken", isNameTaken

// );
// }

// @GetMapping("/checkOvertime/{id}")
// public Map<String, Object> checkOvertime(@PathVariable Long id) {
// return clientService.isReminderOvertime(id);
// }
// @GetMapping("/dashboard/combo")
// public RecordsRes<Map<String, Object>> getDashboardCombo() {
// return new RecordsRes<>(clientService.getDashboardCombo());
// }

// @GetMapping("/dashboard/topRecord")
// public RecordsRes<Map<String, Object>> getTop6(HttpServletRequest request) throws ServletRequestBindingException {
// return new RecordsRes<>(clientService.getTop6(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("year")
// .addInteger("userSubDivisionId")
// .build()
// ));
// }
// @GetMapping("/dashboard/yearAward")
// public DataRes<Map<String, Object>> getYearAwardCount(HttpServletRequest request) throws ServletRequestBindingException {
// return new DataRes<>(clientService.getYearAwardCount(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("year")
// .addInteger("userSubDivisionId")
// .build()
// ));
// }

// @GetMapping("/dashboard/yearEvent")
// public DataRes<Map<String, Object>> getYearEventCount(HttpServletRequest request) throws ServletRequestBindingException {
// return new DataRes<>(clientService.getYearEventCount(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("year")
// .addInteger("userSubDivisionId")
// .build()
// ));
// }

// @GetMapping("/dashboard/yearDivisionSummary")
// public RecordsRes<Map<String, Object>> getDivisionAwardSummary(@RequestParam Integer year, @RequestParam String branch, @RequestParam Boolean viewDivisionOnly, @RequestParam Integer userSubDivisionId) {
// if(!viewDivisionOnly){
// List<Map<String,Object>> tempRecords = clientService.getDivisionAwardSummary(Map.of("year",year, "branch", branch));
// if(tempRecords.size() == 0){
// tempRecords = clientService.getDummyDivisionAwardSummary(Map.of("year",year,"branch", branch));
// }
// return new RecordsRes<>(tempRecords);

// }
// else{
// List<Map<String,Object>> tempRecords = clientService.getDummyDivisionAwardSummary(Map.of("year",year,"userSubDivisionId",userSubDivisionId));
// return new RecordsRes<>(tempRecords);

// }

// }

// @GetMapping("/dashboard/yearTagSummary")
// public RecordsRes<Map<String, Object>> getTagAwardSummary(HttpServletRequest request) throws ServletRequestBindingException {
// return new RecordsRes<>(clientService.getTagAwardSummary(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("year")
// .addInteger("userSubDivisionId")
// .build()
// ));
// }
// @GetMapping("/dashboard/yearCategorySummary")
// public RecordsRes<Map<String, Object>> getCategoryAwardSummary(HttpServletRequest request) throws ServletRequestBindingException {
// return new RecordsRes<>(clientService.getCategoryAwardSummary(
// CriteriaArgsBuilder.withRequest(request)
// .addInteger("year")
// .addInteger("userSubDivisionId")
// .build()
// ));
// }

// @GetMapping("/dashboard/awardSummaryReport")
// public ResponseEntity<Resource> getAwardSummaryReport(@RequestParam Integer year,
// @RequestParam Integer userSubDivisionId,
// @RequestParam String branch,
// @RequestParam Boolean viewDivisionOnly
// ) throws IOException {
// if(!viewDivisionOnly){
// List<Map<String,Object>> result = clientService.getAwardSummaryReportPage1(Map.of("year",year, "branch", branch));
// List<Map<String,Object>> detailResult = clientService.getAwardSummaryReportPage2(Map.of("year",year, "branch", branch));
// byte[] reportResult = excelReportService.generateDashboardExcelReport(result, detailResult, year);
// return ResponseEntity.ok()
// .header("filename", "award_summary_report_" + LocalDate.now())
// .body(new ByteArrayResource(reportResult));
// }
// else{
// List<Map<String,Object>> result = clientService.getAwardSummaryReportPage1(Map.of("year",year, "userSubDivisionId", userSubDivisionId));
// List<Map<String,Object>> detailResult = clientService.getAwardSummaryReportPage2(Map.of("year",year, "userSubDivisionId", userSubDivisionId));
// byte[] reportResult = excelReportService.generateDashboardExcelReport(result, detailResult, year);
// return ResponseEntity.ok()
// .header("filename", "award_summary_report_" + LocalDate.now())
// .body(new ByteArrayResource(reportResult));
// }

// }
@GetMapping("/excel-client-consultant-report")
public void exportClientConsultantReport(
@RequestParam("fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date fromDate,
@RequestParam("toDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date toDate,
HttpServletResponse response) throws IOException {
Map<String, Object> args = new HashMap<>();
if(fromDate != null)
args.put("fromDate", fromDate);
if(fromDate != null)
args.put("toDate", DateUtils.addDay(toDate, 1));

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
String fileName = "Client_Consultant_Report.xlsx";
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);

// Call service to generate Excel and write to response output stream
clientService.generateClientConsultantReport(args, response.getOutputStream());
}

}

Laden…
Abbrechen
Speichern