Created
September 9, 2022 16:56
-
-
Save SinTeZWh1te/ea927f369f4ef49e403d1dd1644c0573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.test.bgbilling.modules.bill; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import ru.bitel.bgbilling.common.BGException; | |
import ru.bitel.bgbilling.modules.bill.server.bean.ExtractorPositionValue; | |
import ru.bitel.bgbilling.modules.bill.server.bean.PositionValue; | |
import ru.bitel.bgbilling.modules.bill.server.bean.extractor.Extractor; | |
import ru.bitel.bgbilling.modules.voice.common.bean.VoiceAccount; | |
import ru.bitel.bgbilling.modules.voice.server.bean.VoiceAccountDao; | |
import ru.bitel.bgbilling.server.util.ServerUtils; | |
import ru.bitel.common.Utils; | |
import java.math.BigDecimal; | |
import java.sql.Connection; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.List; | |
public class NPayVoiceExtractor extends Extractor { | |
public NPayVoiceExtractor() { | |
} | |
private static final Logger logger = LogManager.getLogger(); | |
private Connection con; | |
private int npayModuleId; | |
private int voiceModuleId; | |
private Calendar month; | |
private String cids; | |
@Override | |
public List<PositionValue> extract(String function, Connection con, String cids, Calendar month, List<String> paramList, String posName) { | |
logger.info("extraction"); | |
List<PositionValue> result = new ArrayList(); | |
this.con = con; | |
this.npayModuleId = this.getIntParam(paramList, 0); | |
this.voiceModuleId = this.getIntParam(paramList, 1); | |
this.month = this.getMonthParam(month, paramList, 2); | |
this.cids = cids; | |
try { | |
extractDetail(result, paramList); | |
} catch (SQLException | BGException e) { | |
logger.error(e); | |
} | |
return result; | |
} | |
private void extractDetail(List<PositionValue> result, List<String> paramList) throws SQLException, BGException { | |
String sids = null; | |
if (paramList.size() > 3) { | |
sids = Utils.toString(paramList, 3); | |
} | |
String npayDetailTable = ServerUtils.getModuleMonthTableName("npay_detail", this.month.getTime(), this.npayModuleId); | |
if (ServerUtils.tableExists(this.con, npayDetailTable)) { | |
StringBuilder sb = new StringBuilder(100); | |
sb.append(" SELECT detail.sid, detail.col, SUM(detail.summa), service.title, detail.mid, detail.eid "); | |
sb.append(" FROM ").append(npayDetailTable).append(" AS detail "); | |
sb.append(" LEFT JOIN service ON service.id=detail.sid "); | |
sb.append(" WHERE detail.cid IN (").append(this.cids).append(") "); | |
if (Utils.notBlankString(sids)) { | |
sb.append(" AND detail.sid IN ( " + sids + " )"); | |
} | |
sb.append(" GROUP BY detail.sid, detail.eid, detail.summa/detail.col"); | |
try (PreparedStatement ps = this.con.prepareStatement(sb.toString()); | |
ResultSet rs = ps.executeQuery(); | |
VoiceAccountDao voiceAccountDao = new VoiceAccountDao(con, voiceModuleId)) { | |
while (rs.next()) { | |
int sid = rs.getInt(1); | |
BigDecimal quantity = BigDecimal.valueOf((long) rs.getInt(2)); | |
BigDecimal summa = Utils.roundBigDecimalSumm(rs.getBigDecimal(3)); | |
VoiceAccount voiceAccount = voiceAccountDao.get(rs.getInt("eid")); | |
String title = voiceAccount == null ? rs.getString(4) : (rs.getString(4) + "(" + voiceAccount.getTitle() + ")"); | |
ExtractorPositionValue value = new ExtractorPositionValue(); | |
value.setSum(summa); | |
value.setName(title); | |
value.setQuantity(quantity); | |
value.setSid(sid); | |
value.setMid(this.npayModuleId); | |
result.add(value); | |
} | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment