Skip to content

Commit

Permalink
Merge branch 'rest_java_combine' into bugfix_combine
Browse files Browse the repository at this point in the history
  • Loading branch information
pengm2ng committed Jun 3, 2021
2 parents 5e61183 + 3760358 commit 6f9a4f4
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 74 deletions.
157 changes: 92 additions & 65 deletions jmt_webapp/src/main/java/dao/impl/ExpendtrExcutDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,77 +15,104 @@
import jdbc.ConnectionProvider;

public class ExpendtrExcutDAO implements ExpendtrExcutI {
private static final String EXPENDTREXCUT_QUERY1 ="select place_nm, sum(expendtr_rsltn_amt) total_amt, coalesce(like_count,0)\n"
+ "from \"ExpendtrTotalExcut\"\n"
+ "where dept_div_nm like '?' and govofc_div_nm like '?' and hgdept_div_nm like '?' and dept_nm like '?'\n"
+ "and paymnt_command_de >= '?'' and paymnt_command_de <= '?'"
+ "group by place_nm, like_count order by total_amt desc limit 10";

private ExpendtrExcutDAO() { }
private static final String EXPENDTREXCUT_QUERY2 ="select place_nm, sum(expendtr_rsltn_amt) total_amt, coalesce(like_count,0)\n"
+ "from \"ExpendtrTotalExcut\"\n"
+ "where dept_div_nm like '?' and govofc_div_nm like '?' and hgdept_div_nm like '?' and dept_nm like '?'\n"
+ "group by place_nm, like_count order by total_amt desc limit 10";

public static ExpendtrExcutDAO getInstance() {
return InstHolder.INSTANCE;
}
private ExpendtrExcutDAO() { }

private static class InstHolder {
public static final ExpendtrExcutDAO INSTANCE = new ExpendtrExcutDAO();
}
public static ExpendtrExcutDAO getInstance() {
return InstHolder.INSTANCE;
}

private static class InstHolder {
public static final ExpendtrExcutDAO INSTANCE = new ExpendtrExcutDAO();
}

// 범위를 지정했을때
@Override
public List<ExpendtrExcut> getPlaceTopTen(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv,
Organization dept, Date startDate, Date endDate) {

String deptDivName = deptDiv == null ? "%" : deptDiv.getOrganizationName();
String govofcDivName = govofcDiv == null ? "%" : govofcDiv.getOrganizationName();
String hgdeptDivName = hgdeptDiv == null ? "%" : hgdeptDiv.getOrganizationName();
String deptName = dept == null ? "%" : dept.getOrganizationName();

List<ExpendtrExcut> placeTopTen = new ArrayList<>();
try (var conn = ConnectionProvider.getJDBCConnection()) {
PreparedStatement pstmt = conn.prepareStatement(EXPENDTREXCUT_QUERY1);

pstmt.setString(1, deptDivName);
pstmt.setString(2, govofcDivName);
pstmt.setString(3, hgdeptDivName);
pstmt.setString(4, deptName);
pstmt.setDate(5, startDate);
pstmt.setDate(6, endDate);

ResultSet rs = pstmt.executeQuery();

@Override
public List<ExpendtrExcut> getPlaceTopTen(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv,
Organization dept, Date startDate, Date endDate) {

/*
select dept_div_nm,
govofc_div_nm,
hgdept_div_nm,
dept_nm,
paymnt_command_de,
like_count,
accnut_yy,
place_nm,
sum(expendtr_rsltn_amt) total_amt
from "ExpendtrTotalExcut"
group by dept_div_nm, govofc_div_nm, hgdept_div_nm, dept_nm, paymnt_command_de, like_count, accnut_yy, place_nm
order by total_amt desc
limit 10
*/

List<ExpendtrExcut> data = new ArrayList<>();
// try (var conn = ConnectionProvider.getJDBCConnection()) {
// PreparedStatement pstmt = conn.prepareStatement("select dept_div_nm,
// govofc_div_nm,
// hgdept_div_nm,
// dept_nm,
// paymnt_command_de,
// like_count,
// accnut_yy,
// place_nm,
// sum(expendtr_rsltn_amt) total_amt
// from "ExpendtrTotalExcut"
// group by dept_div_nm, govofc_div_nm, hgdept_div_nm, dept_nm, paymnt_command_de, like_count, accnut_yy, place_nm
// order by total_amt desc
// limit 10
// where paymnt_command_de >= ? and
// paymnt_command_de <= ?");
// pstmt.setDate(1, new Date(2020, 12, 5));
// pstmt.setDate(2, new Date(2021, 1, 5));
// ResultSet rs = pstmt.executeQuery();

// Place place = new Place(rs.get, rs.get, 0)

// while (rs.next()) {
// Organization deptDivTemp = new DeptDiv(rs.getString(1), rs.getString(2));
// Organization govoTemp = new GovofcDiv(rs.getString(3), rs.getString(4));
// ExpendtrExcut expTemp = new ExpendtrExcut(deptDivTemp, govoTemp, hgdeptDiv, dept, null, 0, null);
// data.add(expTemp);
// }
// } catch (SQLException e) {
// e.printStackTrace();
// }
return data;
while(rs.next()){
pstmt = conn.prepareStatement("select * from BizPlace where place_nm='?");
pstmt.setString(1, rs.getString("place_nm"));
ResultSet rsPlace = pstmt.executeQuery();
Place place = new Place(rsPlace.getString("biz_reg_no"), rs.getString("place_nm"), rs.getInt("like_count"));
placeTopTen.add(ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv, dept, startDate, endDate, rs.getlong("total_amt"), place));
}

pstmt.close();
rs.close();

return placeTopTen;
}catch (SQLException e) {
e.printStackTrace();
}
}

//범위를 지정하지 않았을때
@Override
public List<ExpendtrExcut> getPlaceTopTen(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv,
Organization dept) {

String deptDivName = deptDiv == null ? "%" : deptDiv.getOrganizationName();
String govofcDivName = govofcDiv == null ? "%" : govofcDiv.getOrganizationName();
String hgdeptDivName = hgdeptDiv == null ? "%" : hgdeptDiv.getOrganizationName();
String deptName = dept == null ? "%" : dept.getOrganizationName();

List<ExpendtrExcut> placeTopTen = new ArrayList<>();
try (var conn = ConnectionProvider.getJDBCConnection()) {
PreparedStatement pstmt = conn.prepareStatement(EXPENDTREXCUT_QUERY2);

@Override
public List<ExpendtrExcut> getPlaceTopTen(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv,
Organization dept) {
// TODO Auto-generated method stub
return null;
pstmt.setString(1, deptDivName);
pstmt.setString(2, govofcDivName);
pstmt.setString(3, hgdeptDivName);
pstmt.setString(4, deptName);

ResultSet rs = pstmt.executeQuery();

while(rs.next()){
pstmt = conn.prepareStatement("select * from BizPlace where place_nm='?");
pstmt.setString(1, rs.getString("place_nm"));
ResultSet rsPlace = pstmt.executeQuery();
Place place = new Place(rsPlace.getString("biz_reg_no"), rs.getString("place_nm"), rs.getInt("like_count"));
placeTopTen.add(ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv, dept, null, null, rs.getLong("total_amt"), place));
}

pstmt.close();
rs.close();

return placeTopTen;
}catch (SQLException e) {
e.printStackTrace();
}

return null;
}
}
60 changes: 60 additions & 0 deletions jmt_webapp/src/main/java/dao/test/ExpendtrExcutTestDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package dao.test;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import dao.ExpendtrExcutI;
import entity.ExpendtrExcut;
import entity.Organization;
import entity.Place;

public class ExpendtrExcutTestDAO implements ExpendtrExcutI {


private ExpendtrExcutTestDAO() { }

public static ExpendtrExcutTestDAO getInstance() {
return InstHolder.INSTANCE;
}

private static class InstHolder {
public static final ExpendtrExcutTestDAO INSTANCE = new ExpendtrExcutTestDAO();
}

@Override
public List<ExpendtrExcut> getPlaceTopTen(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv,
Organization dept, Date startDate, Date endDate) {
// TODO Auto-generated method stub

return null;
}

@Override
public List<ExpendtrExcut> getPlaceTopTen(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv,
Organization dept) {

// Place place = new Place("0000", "앗싸곱창", 623);
// ExpendtrExcut exp = new ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv , dept, "2015",222232, place);
// Place place1 = new Place("0001", "교촌치킨", 232);
// ExpendtrExcut exp1 = new ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv , dept, "2019",12222, place1);
// Place place2 = new Place("0002", "수원왕갈비", 9233);
// ExpendtrExcut exp2 = new ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv , dept, "2020",123222, place2);
// Place place3 = new Place("0003", "찌개지존", 213);
// ExpendtrExcut exp3 = new ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv , dept, "2017",11222, place3);
// Place place4 = new Place("0004", "아주캠프", 234);
// ExpendtrExcut exp4 = new ExpendtrExcut(deptDiv, govofcDiv, hgdeptDiv , dept, "2018",434122, place4);
// List<ExpendtrExcut> list = new ArrayList<>();
// list.add(exp);
// list.add(exp1);
// list.add(exp2);
// list.add(exp3);
// list.add(exp4);


// return list;
return null;
}


}
27 changes: 18 additions & 9 deletions jmt_webapp/src/main/java/entity/ExpendtrExcut.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package entity;

import java.sql.Date;

public class ExpendtrExcut {
private Organization deptDiv;
private Organization govofcDiv;
private Organization hgdeptDiv;
private Organization dept;
private String accnutYY;
private int totalAmt;
private Date startDate;
private Date endDate;
private long totalAmt;
private Place place;

public ExpendtrExcut(Organization deptDiv, Organization govofcDiv, Organization hgdeptDiv, Organization dept,
String accnutYY, int totalAmt, Place place) {
Date startDate, Date endDate, long totalAmt, Place place) {

if (!deptDiv.getClass().equals(DeptDiv.class)) {
throw new RuntimeException("deptDiv argument has to be DeptDiv type");
Expand All @@ -29,13 +32,15 @@ public ExpendtrExcut(Organization deptDiv, Organization govofcDiv, Organization
this.govofcDiv = govofcDiv;
this.hgdeptDiv = hgdeptDiv;
this.dept = dept;
this.accnutYY = accnutYY;
this.startDate = startDate;
this.endDate = endDate;
this.totalAmt = totalAmt;
this.place = place;
}

public ExpendtrExcut(String accnutYY, int totalAmt, Place place) {
this.accnutYY = accnutYY;
public ExpendtrExcut(Date startDate, Date endDate, long totalAmt, Place place) {
this.startDate = startDate;
this.endDate = endDate;
this.totalAmt = totalAmt;
this.place = place;
}
Expand All @@ -56,15 +61,19 @@ public Organization getDept() {
return this.dept;
}

public String getAccnutYY() {
return this.accnutYY;
public Date startDate() {
return this.startDate;
}

public Date endDate(){
return this.endDate;
}

/**
* 총 사용 금액 가져오기
* @return 총 사용 금액
*/
public int getTotalAmt() {
public long getTotalAmt() {
return this.totalAmt;
}

Expand Down

0 comments on commit 6f9a4f4

Please sign in to comment.