|
|
@@ -0,0 +1,395 @@
|
|
|
+///*
|
|
|
+// * To change this template, choose Tools | Templates
|
|
|
+// * and open the template in the editor.
|
|
|
+// */
|
|
|
+//package com.vas.portal.process;
|
|
|
+//
|
|
|
+//import com.viettel.cluster.agent.integration.Record;
|
|
|
+//import com.vas.portal.utils.common.Common;
|
|
|
+//import com.vas.portal.utils.common.MessageResponse;
|
|
|
+//import com.vas.portal.utils.database.DbProcessor;
|
|
|
+//import com.vas.portal.utils.object.ChargeLog;
|
|
|
+//import com.vas.portal.utils.object.ExecutePrizeObj;
|
|
|
+//import com.vas.portal.utils.object.LuckyCode;
|
|
|
+//import com.vas.portal.utils.common.LuckyCallUtils;
|
|
|
+//import com.vas.portal.utils.object.MtRecord;
|
|
|
+//import com.vas.portal.utils.object.PrizeObj;
|
|
|
+//import com.vas.portal.utils.object.PrizeWinner;
|
|
|
+//import com.vas.portal.utils.object.ProcessedDate;
|
|
|
+//import com.viettel.smsfw.process.ProcessRecordAbstract;
|
|
|
+//import java.sql.Timestamp;
|
|
|
+//import java.text.SimpleDateFormat;
|
|
|
+//import java.util.ArrayList;
|
|
|
+//import java.util.Calendar;
|
|
|
+//import java.util.Date;
|
|
|
+//import java.util.HashMap;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Random;
|
|
|
+//import org.apache.log4j.Logger;
|
|
|
+//
|
|
|
+///**
|
|
|
+// *
|
|
|
+// * @author
|
|
|
+// */
|
|
|
+//public class PrizeProcessOnline extends ProcessRecordAbstract {
|
|
|
+//
|
|
|
+//// private WSProcessor ws;
|
|
|
+// private DbProcessor db;
|
|
|
+// private StringBuilder br = new StringBuilder();
|
|
|
+// private final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
|
|
+//
|
|
|
+// public PrizeProcessOnline() {
|
|
|
+// super();
|
|
|
+// logger = Logger.getLogger(PrizeProcessOnline.class);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void initBeforeStart() throws Exception {
|
|
|
+//// ws = new WSProcessor(logger, "../etc/webservice.cfg");
|
|
|
+// db = new DbProcessor(dbName, logger);
|
|
|
+// if (!MessageResponse.init) {
|
|
|
+// HashMap listMsg = db.getListConfig("PROCESS");
|
|
|
+// logger.info("====> MESSAGE CONFIG:\n" + listMsg);
|
|
|
+// MessageResponse.setMessage(listMsg);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (Common.iLoadConfig) {
|
|
|
+// Common.mapPrize = db.loadPrize(0);
|
|
|
+// logger.info("List prize: " + Common.mapPrize);
|
|
|
+// Common.loadConfig(logger);
|
|
|
+// logger.info("Map group prize: " + Common.mapGroupPrize);
|
|
|
+// Common.mapMpsConfig = db.loadMpsConfig();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<Record> validateContraint(List<Record> listRecord) throws Exception {
|
|
|
+//
|
|
|
+// return listRecord;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<Record> processListRecord(List<Record> listMo) throws Exception {
|
|
|
+//
|
|
|
+// List<MtRecord> listMt = new ArrayList();
|
|
|
+// List<ChargeLog> listChargeLog = new ArrayList();
|
|
|
+// List<ExecutePrizeObj> listCmd = new ArrayList();
|
|
|
+// List<PrizeWinner> listWinner = new ArrayList();
|
|
|
+// List<LuckyCode> listLuckyCode = new ArrayList();
|
|
|
+//
|
|
|
+// ProcessedDate processedDate = (ProcessedDate) listMo.get(0);
|
|
|
+// if (processedDate.getLastProcess().getDay() != (new Date()).getDay()) {
|
|
|
+// LuckyCallUtils.counterCdr.set(0);
|
|
|
+//// Common.mochaList = db.loadMochaUser();
|
|
|
+// }
|
|
|
+//
|
|
|
+//// if (Common.mochaList == null || Common.mochaList.isEmpty()) {
|
|
|
+//// Common.mochaList = db.loadMochaUser();
|
|
|
+//// }
|
|
|
+// int numPrize = 0;
|
|
|
+// for (List<List<PrizeObj>> subGroups : Common.mapGroupPrize.values()) {
|
|
|
+// for (List<PrizeObj> prizesInSub : subGroups) {
|
|
|
+// PrizeObj prizeSub = prizesInSub.get(0);
|
|
|
+// // total prize group
|
|
|
+// int numberPrizeSubGroup = prizeSub.getNumberPrize();
|
|
|
+//// logger.info("Number prize in sub group " + prizesInSub.get(0).getSubGroupPrize() + ": " + numberPrizeSubGroup
|
|
|
+//// + ", prize type: " + prizeSub.getNumberPrizeType());
|
|
|
+// if (prizeSub.getNumberPrizeType() == LuckyCallUtils.NumberPrizeType.FIXED_TIMES
|
|
|
+// && prizeSub.getPeriod() == LuckyCallUtils.Period.DAILY) {
|
|
|
+// numPrize += numberPrizeSubGroup;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (int codeType = 0; codeType < 2; codeType++) {
|
|
|
+// List<LuckyCode> listCodeWinner = db.getLuckyCodeDaily(codeType);
|
|
|
+//
|
|
|
+// for (LuckyCode luckyCode : listCodeWinner) {
|
|
|
+//// boolean isPrized = false;
|
|
|
+// int confirmChannel = luckyCode.getConfirmChannel() == 1 ? 1 : 0;
|
|
|
+// // loop prize
|
|
|
+// for (List<List<PrizeObj>> subGroups : Common.mapGroupPrize.values()) {
|
|
|
+//
|
|
|
+// logger.info("Subgroups: " + subGroups);
|
|
|
+// // get total winner in group
|
|
|
+// PrizeObj temp = subGroups.get(0).get(0);
|
|
|
+// if ((temp.getChannel() == -1 || temp.getChannel() == confirmChannel)
|
|
|
+// && (temp.getPeriod() == luckyCode.getPeriod())
|
|
|
+// && (temp.getTimesPrize() == 0 || temp.getTimesPrize() == luckyCode.getCountTimes())) {
|
|
|
+// // check prize percent of fixed
|
|
|
+// //<editor-fold defaultstate="collapsed" desc="check prize">
|
|
|
+// if (temp.getNumberPrizeType() == LuckyCallUtils.NumberPrizeType.PERCENT) {
|
|
|
+// // get randome prize
|
|
|
+// //<editor-fold defaultstate="collapsed" desc="percent">
|
|
|
+// int numPrizePercent = temp.getNumberPrize();
|
|
|
+// Random ran = new Random();
|
|
|
+// int check = ran.nextInt(100);
|
|
|
+// if (check >= numPrizePercent) {
|
|
|
+// // no prize
|
|
|
+// processNoPrize(luckyCode, listMt);
|
|
|
+// } else {
|
|
|
+// //
|
|
|
+// ExecutePrizeObj cmd = new ExecutePrizeObj();
|
|
|
+// cmd.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// cmd.setPrizeId(temp.getId());
|
|
|
+// cmd.setCodeType(codeType);
|
|
|
+// listCmd.add(cmd);
|
|
|
+// // add winner
|
|
|
+// PrizeWinner winner = new PrizeWinner();
|
|
|
+// winner.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// winner.setPrizeId(temp.getId());
|
|
|
+// winner.setCode(luckyCode.getCode());
|
|
|
+// winner.setCodeTime(luckyCode.getConfirmTime());
|
|
|
+// winner.setCodeType(luckyCode.getCodeType());
|
|
|
+// listWinner.add(winner);
|
|
|
+//
|
|
|
+// //return message
|
|
|
+// String key = Common.Message.MSG_PRIZE_WINNER;
|
|
|
+// String message = MessageResponse.get(key + "_" + temp.getChannel() + "_" + temp.getId(),
|
|
|
+// key + "_" + temp.getId(), logger);
|
|
|
+// message = message.replaceAll("%prize%", temp.getDescription());
|
|
|
+// message = message.replaceAll("%code%", luckyCode.getCode());
|
|
|
+//
|
|
|
+// MtRecord mtRecord = new MtRecord();
|
|
|
+// mtRecord.setChannel(Common.CHANNEL);
|
|
|
+// mtRecord.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// mtRecord.setMessage(message);
|
|
|
+// listMt.add(mtRecord);
|
|
|
+//
|
|
|
+// // present 1 code for 1st redeem mocha lucky calll
|
|
|
+// if (codeType == LuckyCallUtils.CodeType.LUCKY_CALL
|
|
|
+// && temp.getChannel() == LuckyCallUtils.Channel.MOCHA
|
|
|
+// && temp.getTimesPrize() == LuckyCallUtils.PrizeTimes.FIRST_TIMES) {
|
|
|
+// String codeId = String.format("%08d", db.getNextCode());
|
|
|
+// String code = codeId.substring(codeId.length() - 8);
|
|
|
+//
|
|
|
+// LuckyCode lc = new LuckyCode();
|
|
|
+// lc.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// lc.setPeriod(LuckyCallUtils.Period.DAILY);
|
|
|
+// lc.setCode(code);
|
|
|
+// lc.setExpireTime(getExpireCode(LuckyCallUtils.Period.DAILY));
|
|
|
+// lc.setStatus(LuckyCallUtils.Status.NOT_REDEEM);
|
|
|
+// lc.setCodeType(LuckyCallUtils.CodeType.LUCKY_CALL);
|
|
|
+// listLuckyCode.add(lc);
|
|
|
+//
|
|
|
+// key = Common.Message.MSG_GOT_LUCKY_CODE_BONUS;
|
|
|
+// // return message
|
|
|
+// message = MessageResponse.getMessage(key, logger);
|
|
|
+// message = message.replaceAll("%code%", code);
|
|
|
+// message = message.replaceAll("%expire%", sdf.format(lc.getExpireTime()));
|
|
|
+// mtRecord = new MtRecord();
|
|
|
+// mtRecord.setChannel(Common.CHANNEL);
|
|
|
+// mtRecord.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// mtRecord.setMessage(message);
|
|
|
+// listMt.add(mtRecord);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //</editor-fold>
|
|
|
+// } else {
|
|
|
+// //<editor-fold defaultstate="collapsed" desc="fixed">
|
|
|
+// Random ran = new Random();
|
|
|
+// int check = ran.nextInt(120);
|
|
|
+// if (check >= numPrize) {
|
|
|
+// // no prize
|
|
|
+// processNoPrize(luckyCode, listMt);
|
|
|
+// } else {
|
|
|
+// // check remain in DB
|
|
|
+// PrizeObj nextPrize = db.getNextDailyPrize(temp.getChannel(), temp.getPeriod(), temp.getTimesPrize(), codeType);
|
|
|
+// if (nextPrize == null || nextPrize.getSubGroupPrize() == 0) {
|
|
|
+// // no prize
|
|
|
+// if (nextPrize != null) {
|
|
|
+// // update prize used
|
|
|
+// db.updateDailyPrizeUsed(nextPrize.getId(), luckyCode.getMsisdn());
|
|
|
+// }
|
|
|
+// processNoPrize(luckyCode, listMt);
|
|
|
+// } else {
|
|
|
+// PrizeObj prizeObj = null;
|
|
|
+// List<PrizeObj> listPrizeTmp = getPrizeInSubGroup(nextPrize.getSubGroupPrize());
|
|
|
+// // get prize in subgroup
|
|
|
+// if (listPrizeTmp.size() == 1) {
|
|
|
+// prizeObj = listPrizeTmp.get(0);
|
|
|
+// } else {
|
|
|
+// for (PrizeObj pr : listPrizeTmp) {
|
|
|
+// if (pr.getPrefixMsisdn() == null || pr.getPrefixMsisdn().isEmpty()) {
|
|
|
+// prizeObj = pr;
|
|
|
+// break;
|
|
|
+// } else {
|
|
|
+// for (String prefix : pr.getPrefixMsisdn()) {
|
|
|
+// if (luckyCode.getMsisdn().startsWith(prefix)) {
|
|
|
+// prizeObj = pr;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (prizeObj != null) {
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (prizeObj == null) {
|
|
|
+// logger.warn("Not found prize valid: " + luckyCode.getMsisdn() + ", subgroup: " + temp.getSubGroupPrize());
|
|
|
+// } else {
|
|
|
+// // update prize used
|
|
|
+// db.updateDailyPrizeUsed(nextPrize.getId(), luckyCode.getMsisdn());
|
|
|
+//
|
|
|
+// // add cmd execute
|
|
|
+// ExecutePrizeObj cmd = new ExecutePrizeObj();
|
|
|
+// cmd.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// cmd.setPrizeId(prizeObj.getId());
|
|
|
+// cmd.setCodeType(codeType);
|
|
|
+// listCmd.add(cmd);
|
|
|
+// // add winner
|
|
|
+// PrizeWinner winner = new PrizeWinner();
|
|
|
+// winner.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// winner.setPrizeId(prizeObj.getId());
|
|
|
+// winner.setCode(luckyCode.getCode());
|
|
|
+// winner.setCodeTime(luckyCode.getConfirmTime());
|
|
|
+// winner.setCodeType(luckyCode.getCodeType());
|
|
|
+// listWinner.add(winner);
|
|
|
+//
|
|
|
+// //return message
|
|
|
+// String key = Common.Message.MSG_PRIZE_WINNER;
|
|
|
+// String message = MessageResponse.get(key + "_" + prizeObj.getChannel() + "_" + prizeObj.getId(),
|
|
|
+// key + "_" + prizeObj.getId(), logger);
|
|
|
+// message = message.replaceAll("%prize%", prizeObj.getDescription());
|
|
|
+// message = message.replaceAll("%code%", luckyCode.getCode());
|
|
|
+//
|
|
|
+// MtRecord mtRecord = new MtRecord();
|
|
|
+// mtRecord.setChannel(Common.CHANNEL);
|
|
|
+// mtRecord.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// mtRecord.setMessage(message);
|
|
|
+// listMt.add(mtRecord);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //</editor-fold>
|
|
|
+// }
|
|
|
+//
|
|
|
+// //</editor-fold>
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // delete lucky code all expired
|
|
|
+// if (listCodeWinner.size() > 0) {
|
|
|
+// db.deleteLuckyCode(listCodeWinner);
|
|
|
+// listCodeWinner.clear();
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (listMt.size() > 0) {
|
|
|
+// db.insertMt(listMt);
|
|
|
+// listMt.clear();
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (listChargeLog.size() > 0) {
|
|
|
+// db.insertChargeLog(listChargeLog);
|
|
|
+// listChargeLog.clear();
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (listCmd.size() > 0) {
|
|
|
+// db.insertExecutePrize(listCmd);
|
|
|
+// listCmd.clear();
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (listWinner.size() > 0) {
|
|
|
+// db.insertPrizeWinner(listWinner);
|
|
|
+// listWinner.clear();
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (listLuckyCode.size() > 0) {
|
|
|
+// db.insertLuckyCode(listLuckyCode);
|
|
|
+// listLuckyCode.clear();
|
|
|
+// }
|
|
|
+//
|
|
|
+// return listMo;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private void processNoPrize(LuckyCode luckyCode, List<MtRecord> listMt) {
|
|
|
+// // message code not win
|
|
|
+// String key = Common.Message.MSG_CODE_NO_PRIZE;
|
|
|
+// if (db.checkMochaUser(luckyCode.getMsisdn())) {
|
|
|
+// key = Common.Message.MSG_CODE_NO_PRIZE_MOCHA;
|
|
|
+// }
|
|
|
+// String message = MessageResponse.getMessage(key, logger);
|
|
|
+// message = message.replaceAll("%code%", luckyCode.getCode());
|
|
|
+//
|
|
|
+// MtRecord mtRecord = new MtRecord();
|
|
|
+// mtRecord.setChannel(Common.CHANNEL);
|
|
|
+// mtRecord.setMsisdn(luckyCode.getMsisdn());
|
|
|
+// mtRecord.setMessage(message);
|
|
|
+// listMt.add(mtRecord);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void printListRecord(List<Record> listRecord) throws Exception {
|
|
|
+// br.setLength(0);
|
|
|
+// br.append("\r\n").
|
|
|
+// append("|\tLAST_PROCESS\t\t").
|
|
|
+// append("|\tTYPE\t\t\r\n");
|
|
|
+// for (Record record : listRecord) {
|
|
|
+// ProcessedDate resultObj = (ProcessedDate) record;
|
|
|
+// br.append("|\t").
|
|
|
+// append(resultObj.getLastProcess()).
|
|
|
+// append("\t|\t").
|
|
|
+// append(resultObj.getTypeProcess()).
|
|
|
+// append("\t|\r\n");
|
|
|
+// }
|
|
|
+// logger.info(br);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<Record> processException(List<Record> listRecord) {
|
|
|
+// logger.error("Exception when processing....");
|
|
|
+// return listRecord;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public boolean startProcessRecord() {
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private String validateMsisdn(String input) {
|
|
|
+// if (input != null) {
|
|
|
+// if (input.startsWith(Common.COUNTRY_CODE)) {
|
|
|
+// return input;
|
|
|
+// } else {
|
|
|
+// return Common.COUNTRY_CODE + input;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return Common.COUNTRY_CODE;
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static void main(String[] args) {
|
|
|
+// System.out.println(3 * 35 / 100);
|
|
|
+// }
|
|
|
+//
|
|
|
+// private Timestamp getExpireCode(int type) {
|
|
|
+// Calendar cal = Calendar.getInstance();
|
|
|
+// cal.set(Calendar.HOUR_OF_DAY, 23);
|
|
|
+// cal.set(Calendar.MINUTE, 59);
|
|
|
+// cal.set(Calendar.SECOND, 59);
|
|
|
+// cal.set(Calendar.MILLISECOND, 0);
|
|
|
+// if (type == LuckyCallUtils.Period.WEEKLY) {
|
|
|
+// cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
|
|
+// if (cal.getTimeInMillis() < System.currentTimeMillis()) {
|
|
|
+// cal.add(Calendar.DAY_OF_MONTH, 7);
|
|
|
+// }
|
|
|
+// } else if (type == LuckyCallUtils.Period.MONTHLY) {
|
|
|
+// cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+// }
|
|
|
+// return new Timestamp(cal.getTimeInMillis());
|
|
|
+// }
|
|
|
+//
|
|
|
+// private List<PrizeObj> getPrizeInSubGroup(int subGroupId) {
|
|
|
+// List<PrizeObj> listPrize = new ArrayList();
|
|
|
+// for (PrizeObj prize : Common.mapPrize.values()) {
|
|
|
+// if (prize.getSubGroupPrize() == subGroupId) {
|
|
|
+// listPrize.add(prize);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return listPrize;
|
|
|
+// }
|
|
|
+//}
|