최초 세팅

This commit is contained in:
bd091
2025-10-18 11:06:19 +09:00
commit bf0778601f
2497 changed files with 572903 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
package com.madeu.batch;
import com.madeu.dao.crm.crmmemberpay.CrmMemberPaySqlMapDAO;
import com.madeu.dao.web.webmembership.WebMembershipSqlMapDAO;
import com.madeu.dao.web.webpayment.WebPaymentSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class InsertPaymentBatch {
@Autowired
private WebUserSqlMapDAO webUserSqlMapDAO;
@Autowired
private WebPaymentSqlMapDAO webPaymentSqlMapDAO;
@Autowired
private WebMembershipSqlMapDAO webMembershipSqlMapDAO;
@Autowired
private CrmMemberPaySqlMapDAO crmMemberPaySqlMapDAO;
// @Scheduled(fixedDelay = 33000000) // 5분30초마다 실행
public void go() {
log.debug("****************** InsertPaymentBatch START ******************");
try{
HashMap<String, Object> paramMap = new HashMap<String, Object>();
String tId = String.valueOf(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1 = Calendar.getInstance();
String tDate = sdf.format(c1.getTime());
paramMap.put("tId", tId);
paramMap.put("tDate", tDate);
// 대상자 조회 (PID 있는)
HashMap<String, Object> selectMap = new HashMap<String, Object>();
List<Map<String, Object>> listMap = webUserSqlMapDAO.selectListUserPid(selectMap);
int listMapSize = listMap.size();
if(0<listMapSize){
for(int i=0; i<listMapSize; i++){
log.debug("muUserId : "+listMap.get(i).get("muUserId"));
log.debug("crmMemberPid : "+listMap.get(i).get("crmMemberPid"));
paramMap.put("muUserId", listMap.get(i).get("muUserId"));
paramMap.put("crmMemberPid", listMap.get(i).get("crmMemberPid"));
List<Map<String, Object>> paymentListMap = crmMemberPaySqlMapDAO.selectListMemberPay(paramMap);
int paymentListMapSize = paymentListMap.size();
if(0<paymentListMapSize){
for(int j=0; j<paymentListMapSize; j++){
log.debug("crmMemberPayPid : "+paymentListMap.get(j).get("crmMemberPayPid"));
paramMap.put("crmMemberPayPid", paymentListMap.get(j).get("crmMemberPayPid"));
List<Map<String, Object>> checkListMap = webPaymentSqlMapDAO.selectListPaymentCheck(paramMap);
if(0==checkListMap.size()){
String mDivi1Name = String.valueOf(paymentListMap.get(j).get("mDivi1Name"));
String mDivi2Name = String.valueOf(paymentListMap.get(j).get("mDivi2Name"));
int payMembership = Integer.parseInt(String.valueOf(paymentListMap.get(j).get("payMembership")));
log.debug("mDivi1Name : "+mDivi1Name);
log.debug("mDivi2Name : "+mDivi2Name);
log.debug("payMembership : "+payMembership);
if(!("양도").equals(mDivi2Name) && !("양도받음").equals(mDivi2Name)){
String muPaymentId = ("PMT").concat(String.valueOf(System.currentTimeMillis()));
paramMap.put("muPaymentId", muPaymentId);
webPaymentSqlMapDAO.insertPaymentBatch(paramMap);
paramMap.put("muPaymentId", paramMap.get("id"));
// detail 등록
String muPaymentDetailId = ("PMD").concat(String.valueOf(System.currentTimeMillis()));
paramMap.put("muPaymentDetailId", muPaymentDetailId);
webPaymentSqlMapDAO.insertPaymentDetailBatch(paramMap);
}
if(("멤버쉽").equals(mDivi1Name) || 0>payMembership){
// 구분이 멤버쉽이거나 멤버쉽을 사용했으면
// 멤버십 등록
String muMembershipHistoryId = ("M").concat(String.valueOf(System.currentTimeMillis()));
paramMap.put("muMembershipHistoryId", muMembershipHistoryId);
webMembershipSqlMapDAO.insertMembershipHistoryBatch(paramMap);
}
}
}
// 최종 멤버십 업데이트
// 멤버십 고객 있는지 조회
List<Map<String, Object>> membershipListMap = webMembershipSqlMapDAO.selectMembershipCheckBatch(paramMap);
int membershipListMapSize = membershipListMap.size();
// 멤버십 이력 있는지 조회
List<Map<String, Object>> membershipHistoryListMap = webMembershipSqlMapDAO.selectMembershipHistoryCheckBatch(paramMap);
int membershipHistoryCount = Integer.parseInt(String.valueOf(membershipHistoryListMap.get(0).get("totalCount")));
if(0<membershipListMapSize){
paramMap.put("muMembershipId", membershipListMap.get(0).get("muMembershipId"));
webMembershipSqlMapDAO.updateMembershipBatch(paramMap);
}else{
if(0<membershipHistoryCount){
// 멤버십 이력이 있으면
HashMap<String, Object> insertMap = new HashMap<String, Object>();
// 고객 멤버십 여부 업데이트
webUserSqlMapDAO.updateMembershipYnBatch(paramMap);
// 등록
String muMembershipId = ("M").concat(String.valueOf(System.currentTimeMillis()));
insertMap.put("muMembershipId",muMembershipId);
insertMap.put("muUserId",paramMap.get("muUserId"));
// insertMap.put("regId",paramMap.get("regId"));
// insertMap.put("modId",paramMap.get("modId"));
insertMap.put("tId",paramMap.get("tId"));
insertMap.put("tDate",paramMap.get("tDate"));
webMembershipSqlMapDAO.insertMembershipBatch(insertMap);
}
}
}
}
}
}catch(Exception e){
log.debug("Exception InsertPaymentBatch - run : " + e.getMessage());
}
log.debug("****************** InsertPaymentBatch END ******************");
}
}

View File

@@ -0,0 +1,196 @@
package com.madeu.batch;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.madeu.dao.web.webpublicholiday.WebPublicHolidaySqlMapDAO;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class InsertPublicHolidayBatchExcute {
@Autowired
private WebPublicHolidaySqlMapDAO webPublicHolidaySqlMapDAO;
// 21~22년 (공공 api 조회 가능 연도가 내년꺼까지만 가능.) https://www.data.go.kr/dataset/15012690/openapi.do
@Scheduled(cron = "0 0 03 1 * ?") // 매월 1일 03:00
// @Scheduled(cron = "0 0/1 * * * ?")
public void go() {
log.debug("InsertPublicHolidayBatchExcute - run start");
List<HashMap<String, Object>> publicHolidayList = new ArrayList<HashMap<String, Object>>();
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
for (int i = year; i <= year+1; i++) {
// 공휴일을 가져온다
for(int j=1; j<=12; j++) {
int month = j;
if(i==year) {
month = c.get(Calendar.MONTH)+j;
}
if(12 < month) {
}else {
String yearString = String.valueOf(i);
String monthString = String.valueOf(month);
if(10 > month) {
//한자리수일시 01, 02같이 0을 필요로함, request param이 2자리수
monthString = "0" + monthString;
}
List<HashMap<String, Object>> listTemp = getPublicHolidayMap(yearString, monthString);
log.debug(yearString+""+monthString+"월 결과 : " + listTemp);
publicHolidayList.addAll(listTemp);
}
}
log.debug(i + "년의 totalPublicHolidayCount : " + publicHolidayList.size());
//logger.debug("publicHolidayList : " + publicHolidayList);
}
int insertedCount = 0;
for(int i=0; i<publicHolidayList.size(); i++) {
HashMap<String, Object> publicHolidayParamMap = publicHolidayList.get(i);
StringBuffer sbTemp = new StringBuffer(String.valueOf(publicHolidayParamMap.get("locdate")));
sbTemp.insert(6, "-");
sbTemp.insert(4, "-");
String dateName = publicHolidayParamMap.get("dateName").toString().replaceAll(" ", "");
publicHolidayParamMap.put("dateName", dateName);
publicHolidayParamMap.put("locDate", sbTemp.toString());
List<Map<String, Object>> listMapTemp = webPublicHolidaySqlMapDAO.selectListPublicHolidayDate(publicHolidayParamMap);
// 존재하는 공휴일일 경우
if(1 <= listMapTemp.size()) {
}
else{
String muPublicHolidayId = ("PH").concat(String.valueOf(System.currentTimeMillis()));
publicHolidayParamMap.put("muPublicHolidayId", muPublicHolidayId);
publicHolidayParamMap.put("regId", "BATCH_SYSTEM");
publicHolidayParamMap.put("modId", "BATCH_SYSTEM");
publicHolidayParamMap.put("useYn", "Y");
webPublicHolidaySqlMapDAO.insertPublicHoliday(publicHolidayParamMap);
insertedCount++;
}
}
log.debug("InsertPublicHolidayBatchExcute - " + insertedCount + " record inserted");
log.debug("InsertPublicHolidayBatchExcute - run end");
}
// 해당 년/월의 공휴일을 가져오는 메서드
public List<HashMap<String, Object>> getPublicHolidayMap(String year, String month) {
List<HashMap<String, Object>> holidayList = new ArrayList<HashMap<String, Object>>();
log.debug("InsertPublicHolidayBatchExcute getPublicHolidayMap START");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder;
Document doc = null;
String addr = "http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService";
String query = "/getRestDeInfo?";
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(addr);
stringBuffer.append(query);
stringBuffer.append("ServiceKey=" + "IMP1dVPnFLL2UYlH8yyENSeLeS5UMLYxnaomTs5L2IHp8qnyd%2FzApTGcCUV9%2FD76wZQzD24HegGoNFotIoh9GA%3D%3D");
stringBuffer.append("&solYear=" + year);
stringBuffer.append("&solMonth=" + month);
log.debug("stringBuffer.toString() "+ stringBuffer.toString());
try {
URL url = new URL(stringBuffer.toString());
URLConnection conn = url.openConnection();
BufferedReader rd = null;
rd = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
StringBuffer result = new StringBuffer();
String line;
while((line=rd.readLine())!=null){
result.append(line.trim());
}
// xml 리절트 출력부분
/*if(0<result.toString().length()){
logger.debug("result :"+result.toString());
}*/
rd.close();
InputSource is = new InputSource(new StringReader(result.toString()));
builder = factory.newDocumentBuilder();
doc = builder.parse(is);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
XPathExpression expr = xpath.compile("//items/item");
NodeList nodeList = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
NodeList child = nodeList.item(i).getChildNodes();
HashMap<String, Object> holidayMapTemp = new HashMap<String, Object>();
for (int j = 0; j < child.getLength(); j++) {
Node node = child.item(j);
log.debug("NodeName : " + node.getNodeName());
log.debug("NodeType: " + node.getNodeType());
log.debug("NodeContent: " + node.getTextContent());
holidayMapTemp.put(node.getNodeName(), node.getTextContent());
}
holidayList.add(holidayMapTemp);
}
}
catch (Exception e) {
e.printStackTrace();
}
log.debug("InsertPublicHolidayBatchExcute getPublicHolidayMap END");
return holidayList;
}
}

View File

@@ -0,0 +1,80 @@
package com.madeu.batch;
import com.madeu.dao.crm.crmmemberschedule.CrmMemberScheduleSqlMapDAO;
import com.madeu.dao.web.webreserve.WebReserveSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class InsertReserveBatch {
@Autowired
private WebUserSqlMapDAO webUserSqlMapDAO;
@Autowired
private WebReserveSqlMapDAO webReserveSqlMapDAO;
@Autowired
private CrmMemberScheduleSqlMapDAO crmMemberScheduleSqlMapDAO;
// @Scheduled(fixedDelay = 33000000) // 5분30초마다 실행
public void go() {
log.debug("****************** InsertReserveBatch START ******************");
try{
HashMap<String, Object> paramMap = new HashMap<String, Object>();
String tId = String.valueOf(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1 = Calendar.getInstance();
String tDate = sdf.format(c1.getTime());
paramMap.put("tId", tId);
paramMap.put("tDate", tDate);
// 대상자 조회 (PID 있는)
HashMap<String, Object> selectMap = new HashMap<String, Object>();
List<Map<String, Object>> listMap = webUserSqlMapDAO.selectListUserPid(selectMap);
int listMapSize = listMap.size();
if(0<listMapSize){
for(int i=0; i<listMapSize; i++){
log.debug("muUserId : "+listMap.get(i).get("muUserId"));
log.debug("crmMemberPid : "+listMap.get(i).get("crmMemberPid"));
paramMap.put("muUserId", listMap.get(i).get("muUserId"));
paramMap.put("crmMemberPid", listMap.get(i).get("crmMemberPid"));
List<Map<String, Object>> reserveListMap = crmMemberScheduleSqlMapDAO.selectListMemberSchedule(paramMap);
int reserveListMapSize = reserveListMap.size();
if(0<reserveListMapSize){
for(int j=0; j<reserveListMapSize; j++){
paramMap.put("crmMemberSchedulePid", reserveListMap.get(j).get("crmMemberSchedulePid"));
List<Map<String, Object>> checkListMap = webReserveSqlMapDAO.selectListReserveCheck(paramMap);
if(0==checkListMap.size()){
String muReserveId = ("R").concat(String.valueOf(System.currentTimeMillis()));
paramMap.put("muReserveId", muReserveId);
webReserveSqlMapDAO.insertReserveBatch(paramMap);
}
}
}
}
}
}catch(Exception e){
log.debug("Exception InsertReserveBatch - run" + e.getMessage());
}
log.debug("****************** InsertReserveBatch END ******************");
}
}

View File

@@ -0,0 +1,64 @@
package com.madeu.batch;
import com.madeu.dao.crm.crmmember.CrmMemberSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.*;
@Slf4j
@Component
public class InsertUserBatch {
@Autowired
private WebUserSqlMapDAO webUserSqlMapDAO;
@Autowired
private CrmMemberSqlMapDAO crmMemberSqlMapDAO;
// @Scheduled(fixedDelay = 33000000) // 5분30초마다 실행
public void go() {
log.debug("****************** InsertUserBatch START ******************");
try{
HashMap<String, Object> paramMap = new HashMap<String, Object>();
String tId = String.valueOf(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1 = Calendar.getInstance();
String tDate = sdf.format(c1.getTime());
paramMap.put("tId", tId);
paramMap.put("tDate", tDate);
// 대상자 조회 (기존 DB 식별자)
// 최근 등록된 사람 10000명
HashMap<String, Object> selectMap = new HashMap<String, Object>();
List<Map<String, Object>> listMap = crmMemberSqlMapDAO.selectListMember(selectMap);
int listMapSize = listMap.size();
if(0<listMapSize){
for(int i=0; i<listMapSize; i++){
log.debug("pId : "+listMap.get(i).get("pId"));
paramMap.put("pId", listMap.get(i).get("pId"));
List<Map<String, Object>> listMapCheck = webUserSqlMapDAO.selectUserCheck(paramMap);
if(0==listMapCheck.size()){
String muUserId = ("U").concat(String.valueOf(System.currentTimeMillis()));
paramMap.put("muUserId", muUserId);
webUserSqlMapDAO.insertUserBatch(paramMap);
}
}
}
}catch(Exception e){
log.debug("Exception InsertUserBatch - run" + e.getMessage());
}
log.debug("****************** InsertUserBatch END ******************");
}
}

View File

@@ -0,0 +1,149 @@
package com.madeu.batch;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.madeu.api.InBodyApiProvider;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class InsertUserPhysicalInbodyBatchExcute {
@Autowired
private WebUserSqlMapDAO webUserSqlMapDAO;
@Autowired
private InBodyApiProvider inBodyApiProvider;
@Scheduled(cron = "0 0 2 * * ?") // 매일 02:00
public void go() {
log.debug("InsertUserPhysicalInbodyBatchExcute - run start");
try {
HashMap<String, Object> paramMap = new HashMap<String, Object>();
String tId = String.valueOf(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1 = Calendar.getInstance();
String tDate = sdf.format(c1.getTime());
// 1. 사용자 정보 조회
List<Map<String, Object>> userList = webUserSqlMapDAO.selectListUserVisitLastMonthAll(paramMap);
// 2. 인바디 정보 등록
int insertedCount = 0;
for(int i=0; i<userList.size(); i++) {
// 고객 전화번호
String muUserId = String.valueOf(userList.get(i).get("muUserId"));
String usertoken = String.valueOf(userList.get(i).get("phoneNumber"));
// Inbody 날짜 정보 조회
String inbodyTimeInfo = inBodyApiProvider.getDateTimes(usertoken);
if(null!=inbodyTimeInfo && !("").equals(inbodyTimeInfo)) {
// Inbody 정보 조회
JSONParser parser = new JSONParser();
Object inbodyTimeObj = parser.parse( inbodyTimeInfo );
JSONArray inbodyTimeInfoObj = (JSONArray) inbodyTimeObj;
for (int y= 0; y < inbodyTimeInfoObj.size(); y++) {
String dataTimes = String.valueOf(inbodyTimeInfoObj.get(y));
log.debug("dataTimes ["+i+"] :" + dataTimes);
if(null!=dataTimes && !("").equals(dataTimes)) {
String inbodyInfo = inBodyApiProvider.getFullInBodyData(usertoken, dataTimes);
log.debug("inbodyInfo :" + inbodyInfo);
JSONParser parser3 = new JSONParser();
Object inbodyObj = parser3.parse( inbodyInfo );
JSONObject inbodyInfoObj = (JSONObject) inbodyObj;
String birthDay = (String)inbodyInfoObj.get("birthday");
String userName = (String)inbodyInfoObj.get("name");
String mobileNumber = (String)inbodyInfoObj.get("MobileNumber");
String dateTime = (String)inbodyInfoObj.get("TestDate/Time");
String height = (String)inbodyInfoObj.get("Height");
String weight = (String)inbodyInfoObj.get("Weight");
String bfm = (String)inbodyInfoObj.get("BFM(BodyFatMass)");
String bmi = (String)inbodyInfoObj.get("BMI(BodyMassIndex)");
String smm = (String)inbodyInfoObj.get("SMM(SkeletalMuscleMass)");
String pbf = (String)inbodyInfoObj.get("PBF(PercentBodyFat)");
log.debug("birthDay :"+birthDay);
log.debug("userName :"+userName);
log.debug("mobileNumber :"+mobileNumber);
log.debug("dateTime :"+dateTime);
log.debug("height :"+height);
log.debug("weight :"+weight);
log.debug("bfm :"+bfm);
log.debug("bmi :"+bmi);
log.debug("smm :"+smm);
log.debug("pbf :"+pbf);
HashMap<String, Object> selectParamMap = new HashMap<String, Object>();
selectParamMap.put("muUserId", muUserId);
selectParamMap.put("inbodyDateTimes", dataTimes);
List<Map<String, Object>> userPhysicalInbodyList = webUserSqlMapDAO.selectUserPhysicalInbodyDateTimes(selectParamMap);
int userPhysicalInbodyListSize = Integer.parseInt(String.valueOf(userPhysicalInbodyList.get(0).get("totalCount")));
if(0 == userPhysicalInbodyListSize) {
HashMap<String, Object> insertParamMap = new HashMap<String, Object>();
String muUserPhysicalId = ("UP").concat(String.valueOf(System.currentTimeMillis()));
insertParamMap.put("muUserPhysicalId", muUserPhysicalId);
insertParamMap.put("muUserId", muUserId);
insertParamMap.put("height", height);
insertParamMap.put("weight", weight);
insertParamMap.put("muscleMass", smm); // 골격근량
insertParamMap.put("fatMass", bfm); // 체지방량
insertParamMap.put("fatPercent", pbf); // 체지방률
insertParamMap.put("bmi", bmi); // bmi
//insertParamMap.put("muMemberId", paramMap.get("loginMemberId"));
insertParamMap.put("inbodyDateTimes", dataTimes);
insertParamMap.put("tId", tId);
insertParamMap.put("tDate", tDate);
insertParamMap.put("regId", "BATCH_SYSTEM");
insertParamMap.put("modId", "BATCH_SYSTEM");
webUserSqlMapDAO.insertPhysical(insertParamMap);
insertedCount++;
}
}
}
}
}
log.debug("InsertUserPhysicalInbodyBatchExcute - " + insertedCount + " record inserted");
log.debug("InsertUserPhysicalInbodyBatchExcute - run end");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,120 @@
package com.madeu.batch;
import com.madeu.dao.web.webkakao.WebKakaoSqlMapDAO;
import com.popbill.api.KakaoService;
import com.popbill.api.kakao.KakaoSentDetail;
import com.popbill.api.kakao.KakaoSentInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class KakaoPopbillStateUpdateBatch {
private static String corpNum;
private static String userId;
@Value("${popbill.corp-num}")
public void setCorpNum(String value){
corpNum = value;
}
@Value("${popbill.user-id}")
public void setUserId(String value){
userId = value;
}
@Autowired
private WebKakaoSqlMapDAO webKakaoSqlMapDAO;
@Autowired
private KakaoService kakaoService;
//https://blog.naver.com/lovemema/140200056062
// @Scheduled(cron = "30 0/5 * * * *") // 5분마다 실행 (30초에 실행)
public void go() {
log.debug("******************KakaoPopbillStateUpdateBatch START **********************************");
try{
log.debug("POPBILL_STATE, POPBILL_RESULT UPDATE START");
// KAKAO 환경설정 정보 호출
// 팝빌회원 사업자번호
// 팝빌회원 아이디
log.debug("corpNum : "+corpNum);
log.debug("userId : "+userId);
// 접수번호 대상자 조회
HashMap<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("popbillState", 0);
List<Map<String, Object>> kakaoListMap = webKakaoSqlMapDAO.selectListPopbillState(paramMap);
int kakaoListMapSize = kakaoListMap.size();
log.debug("접수번호 갯수 : "+kakaoListMapSize);
for(int i=0; i<kakaoListMapSize; i++) {
// 접수번호
String receiptNumber = String.valueOf(kakaoListMap.get(i).get("receiptNumber"));
KakaoSentInfo sentInfos = kakaoService.getMessages(corpNum, receiptNumber);
String templateCode = sentInfos.getTemplateCode();
log.debug("templateCode : "+templateCode);
// 전송갯수
int sentInfosLength = Integer.parseInt(String.valueOf(sentInfos.getSendCnt()));
for(int j=0; j<sentInfosLength; j++) {
List<KakaoSentDetail> kakaoSentDetail = sentInfos.getMsgs();
String receiveNumber = kakaoSentDetail.get(j).getReceiveNum();
String receiveName = kakaoSentDetail.get(j).getReceiveName();
String state = String.valueOf(kakaoSentDetail.get(j).getState());
String result = String.valueOf(kakaoSentDetail.get(j).getResult());
if(("3").equals(state)) {
HashMap<String, Object> kakaoParamMap = new HashMap<String, Object>();
kakaoParamMap.put("receiptNumber", receiptNumber);
kakaoParamMap.put("receiveNumber", receiveNumber);
kakaoParamMap.put("receiveName", receiveName);
kakaoParamMap.put("popbillState", 0);
kakaoParamMap.put("state", state);
kakaoParamMap.put("result", result);
kakaoParamMap.put("modId", "BatchSystem");
kakaoParamMap.put("templateCode", templateCode);
webKakaoSqlMapDAO.updateKakaoPopbillState(kakaoParamMap);
}else {
/*log.debug("receiptNumber : "+receiptNumber);
log.debug("sentInfos["+j+"] receiveNum : "+receiveNumber);
log.debug("sentInfos["+j+"] receiveName : "+receiveName);
log.debug("sentInfos["+j+"] state : "+state);
log.debug("sentInfos["+j+"] result : "+result);*/
}
}
}
log.debug("POPBILL_STATE, POPBILL_RESULT UPDATE END");
}catch(Exception e){
log.debug("Exception KakaoPopbillStateUpdateBatch - run" + e.getMessage());
}
log.debug("******************KakaoPopbillStateUpdateBatch END **********************************");
}
}

View File

@@ -0,0 +1,188 @@
package com.madeu.batch;
import com.madeu.dao.web.webkakao.WebKakaoSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import com.popbill.api.KakaoService;
import com.popbill.api.PopbillException;
import com.popbill.api.kakao.KakaoButton;
import com.popbill.api.kakao.KakaoReceiver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class KakaoSendBatch {
private static String corpNum; // 팝빌회원 사업자번호
private static String userId; // 팝빌회원 아이디
private static String senderName; // 발신자명
@Value("${popbill.corp-num}")
public void setCorpNum(String value){
corpNum = value;
}
@Value("${popbill.user-id}")
public void setUserId(String value){
userId = value;
}
@Value("${popbill.sender-nm}")
public void setSenderName(String value){
senderName = value;
}
@Autowired
private WebKakaoSqlMapDAO webKakaoSqlMapDAO;
@Autowired
private KakaoService kakaoService;
//https://blog.naver.com/lovemema/140200056062
// @Scheduled(cron = " 0 0/5 * * * *") // 5분마다 실행
// @Scheduled(fixedDelay = 300000) // 5분마다
public void go() {
log.debug("******************KakaoSendBatch START **********************************");
try {
// SMS 환경설정 정보 호출
log.debug("corpNum :" + corpNum);
log.debug("userId :" + userId);
log.debug("senderName :" + senderName);
HashMap<String, Object> kakaoParamMap = new HashMap<String, Object>();
kakaoParamMap.put("state", "R");
// 템플릿 코드별
List<Map<String, Object>> kakaoListMap = webKakaoSqlMapDAO.selectListKakaoTemplate(kakaoParamMap);
int kakaoListMapSize = kakaoListMap.size();
for(int i=0; i<kakaoListMapSize; i++) {
String sender = String.valueOf(kakaoListMap.get(i).get("sender")).replaceAll("-", "");
String orgSender = String.valueOf(kakaoListMap.get(i).get("sender"));
String templateCode = String.valueOf(kakaoListMap.get(i).get("templateCode"));
HashMap<String, Object> kakaoParamMap2 = new HashMap<String, Object>();
kakaoParamMap2.put("state", "R");
kakaoParamMap2.put("sender", orgSender);
kakaoParamMap2.put("templateCode", templateCode);
log.debug("state : " + kakaoParamMap2.get("state"));
log.debug("sender : " + kakaoParamMap2.get("sender"));
log.debug("templateCode : " + kakaoParamMap2.get("templateCode"));
List<Map<String, Object>> kakaoListMap2 = webKakaoSqlMapDAO.selectListKakaoState(kakaoParamMap2);
int kakaoListMap2Size = kakaoListMap2.size();
log.debug("갯수 : " + kakaoListMap2Size);
// R => G
for (int j = 0; j < kakaoListMap2Size; j++) {
kakaoParamMap = new HashMap<String, Object>();
kakaoParamMap.put("oldState", "R");
kakaoParamMap.put("chgState", "G");
kakaoParamMap.put("sendDateYn", "N");
kakaoParamMap.put("modId", "BatchSystem");
String muKakaoId = String.valueOf(kakaoListMap2.get(j).get("muKakaoId"));
kakaoParamMap.put("muKakaoId", muKakaoId);
webKakaoSqlMapDAO.updateKakaoState(kakaoParamMap);
}
// G => 카카오톡 전송
// 카카오톡 설정 정보 호출
// 카카오톡 수신정보 배열, 최대 1000건
// 승인된 알림톡 템플릿 코드는 ListATStemplate API, GetATSTemplateMgtURL API, 또는 팝빌사이트에서 확인 가능합니다.
KakaoReceiver[] receivers = new KakaoReceiver[kakaoListMap2Size];
for (int j = 0; j < kakaoListMap2Size; j++) {
String muKakaoId = String.valueOf(kakaoListMap2.get(j).get("muKakaoId"));
String receiver = String.valueOf(kakaoListMap2.get(j).get("receiver")).replaceAll("-", "");
String userName = String.valueOf(kakaoListMap2.get(j).get("userName"));
String content = String.valueOf(kakaoListMap2.get(j).get("content"));
templateCode = String.valueOf(kakaoListMap2.get(j).get("templateCode"));
log.debug("===== kakao INPUT START ====");
log.debug("muKakaoId :" + muKakaoId);
log.debug("sender :" + sender);
log.debug("receiver :" + receiver);
log.debug("userName :" + userName);
log.debug("content :" + content);
log.debug("templateCode:" + templateCode);
log.debug("==== kakao INPUT END ====");
KakaoReceiver msg = new KakaoReceiver();
msg.setReceiverNum(receiver); // 수신번호
msg.setReceiverName(userName); // 수신자명
msg.setMessage(content); // 알림톡 템플릿 내용
// 같은 템플릿끼리 receivers에 담겨야함
receivers[j] = msg;
}
String receiptNum = "미전송";
if (kakaoListMap2Size > 0) {
// 예약전송일시, 형태(yyyyMMddHHmmss)
String sndDT = "";
// 전송요청번호
// 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
String requestNum = "";
// 알림톡 버튼정보를 템플릿 신청시 기재한 버튼정보와 동일하게 전송하는 경우 null 처리.
KakaoButton[] btns = null;
// 대체문자 전송유형, 공백-미전송, C-알림톡 내용전송, A-대체문자 내용 전송
String altSendType = "";
String content = String.valueOf(kakaoListMap2.get(0).get("content"));
try {
receiptNum = kakaoService.sendATS(corpNum, templateCode, sender, altSendType, receivers, sndDT,
userId, requestNum, btns);
} catch (PopbillException e) {
log.debug("오류 코드 :" + e.getCode());
log.debug("오류 메시지 :" + e.getMessage());
}
}
// G => Y 전송
for (int j = 0; j < kakaoListMap2Size; j++) {
kakaoParamMap = new HashMap<String, Object>();
kakaoParamMap.put("oldState", "G");
kakaoParamMap.put("chgState", "Y");
kakaoParamMap.put("sendDateYn", "Y");
kakaoParamMap.put("receiptNum", receiptNum);
kakaoParamMap.put("modId", "BatchSystem");
String muKakaoId = String.valueOf(kakaoListMap2.get(j).get("muKakaoId"));
kakaoParamMap.put("muKakaoId", muKakaoId);
webKakaoSqlMapDAO.updateKakaoState(kakaoParamMap);
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("Exception KakaoSendBatch - run", e);
}
log.debug("******************KakaoSendBatch END **********************************");
}
}

View File

@@ -0,0 +1,124 @@
package com.madeu.batch;
import com.madeu.dao.web.websms.WebSmsSqlMapDAO;
import com.popbill.api.MessageService;
import com.popbill.api.message.SentMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class LmsPopbillStateUpdateBatch {
private static String corpNum;
private static String userId;
@Value("${popbill.corp-num}")
public void setCorpNum(String value){
corpNum = value;
}
@Value("${popbill.user-id}")
public void setUserId(String value){
userId = value;
}
@Autowired
private WebSmsSqlMapDAO webSmsSqlMapDAO;
@Autowired
private MessageService messageService;
//https://blog.naver.com/lovemema/140200056062
// @Scheduled(cron = "30 0/5 * * * *") // 5분마다 실행 (30초에 실행)
public void go() {
log.debug("******************LmsPopbillStateUpdateBatch START **********************************");
try{
log.debug("POPBILL_STATE, POPBILL_RESULT UPDATE START");
// SMS 환경설정 정보 호출
// 팝빌회원 사업자번호
// 팝빌회원 아이디
log.debug("corpNum : "+corpNum);
log.debug("userId : "+userId);
// 접수번호 대상자 조회
HashMap<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("type", "L");
paramMap.put("popbillState", 0);
List<Map<String, Object>> smsListMap = webSmsSqlMapDAO.selectListPopbillState(paramMap);
int smsListMapSize = smsListMap.size();
log.debug("접수번호 갯수 : "+smsListMapSize);
for(int i=0; i<smsListMapSize; i++) {
// 접수번호
String receiptNumber = String.valueOf(smsListMap.get(i).get("receiptNumber"));
SentMessage[] sentMessages = messageService.getMessages(corpNum, receiptNumber, userId);
int sentMessagesLength = sentMessages.length;
for(int j=0; j<sentMessagesLength; j++) {
String receiveNumber = sentMessages[j].getReceiveNum();
String receiveName = sentMessages[j].getReceiveName();
String subject = sentMessages[j].getSubject();
String content = sentMessages[j].getContent();
String state = String.valueOf(sentMessages[j].getState());
String result = String.valueOf(sentMessages[j].getResult());
String type = String.valueOf(sentMessages[j].getMessageType());
type = type.substring(0, 1);
if(("3").equals(state)) {
HashMap<String, Object> smsParamMap = new HashMap<String, Object>();
smsParamMap.put("receiptNumber", receiptNumber);
smsParamMap.put("receiveNumber", receiveNumber);
smsParamMap.put("receiveName", receiveName);
smsParamMap.put("popbillState", 0);
smsParamMap.put("subject", subject);
smsParamMap.put("content", content);
smsParamMap.put("state", state);
smsParamMap.put("result", result);
smsParamMap.put("type", type);
smsParamMap.put("modId", "BatchSystem");
webSmsSqlMapDAO.updateSmsPopbillState(smsParamMap);
}else {
/*log.debug("receiptNumber : "+receiptNumber);
log.debug("sentMessages["+j+"] receiveNum : "+receiveNumber);
log.debug("sentMessages["+j+"] receiveName : "+receiveName);
log.debug("sentMessages["+j+"] subject : "+subject);
log.debug("sentMessages["+j+"] content : "+content);
log.debug("sentMessages["+j+"] state : "+state);
log.debug("sentMessages["+j+"] result : "+result);
log.debug("sentMessages["+j+"] type : "+type);*/
}
}
}
log.debug("POPBILL_STATE, POPBILL_RESULT UPDATE END");
}catch(Exception e){
log.debug("Exception LmsPopbillStateUpdateBatch - run" + e.getMessage());
}
log.debug("******************LmsPopbillStateUpdateBatch END **********************************");
}
}

View File

@@ -0,0 +1,176 @@
package com.madeu.batch;
import com.madeu.dao.web.websms.WebSmsSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import com.popbill.api.MessageService;
import com.popbill.api.PopbillException;
import com.popbill.api.message.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class LmsSendBatch {
private static String corpNum; // 팝빌회원 사업자번호
private static String userId; // 팝빌회원 아이디
private static String senderName; // 발신자명
@Value("${popbill.corp-num}")
public void setCorpNum(String value){
corpNum = value;
}
@Value("${popbill.user-id}")
public void setUserId(String value){
userId = value;
}
@Value("${popbill.sender-nm}")
public void setSenderName(String value){
senderName = value;
}
@Autowired
private WebSmsSqlMapDAO webSmsSqlMapDAO;
@Autowired
private MessageService messageService;
//https://blog.naver.com/lovemema/140200056062
// @Scheduled(cron = "0 0/5 * * * *") // 5분마다 실행
// @Scheduled(fixedDelay = 300000) // 5분마다
public void go() {
log.debug("******************LmsSendBatch START **********************************");
try {
// SMS 환경설정 정보 호출
log.debug("corpNum :" + corpNum);
log.debug("userId :" + userId);
log.debug("senderName :" + senderName);
HashMap<String, Object> smsParamMap = new HashMap<String, Object>();
smsParamMap.put("state", "R");
smsParamMap.put("type", "L");
List<Map<String, Object>> smsListMap = webSmsSqlMapDAO.selectListSmsTime(smsParamMap);
int smsListMapSize = smsListMap.size();
for (int i = 0; i < smsListMapSize; i++) {
String sender = String.valueOf(smsListMap.get(i).get("sender")).replaceAll("-", "");
String orgSender = String.valueOf(smsListMap.get(i).get("sender"));
String title = String.valueOf(smsListMap.get(i).get("title"));
String content = String.valueOf(smsListMap.get(i).get("content"));
HashMap<String, Object> smsParamMap2 = new HashMap<String, Object>();
smsParamMap2.put("state", "R");
smsParamMap2.put("type", "L");
smsParamMap2.put("sender", orgSender);
smsParamMap2.put("title", title);
smsParamMap2.put("content", content);
List<Map<String, Object>> smsListMap2 = webSmsSqlMapDAO.selectListSmsState(smsParamMap2);
int smsListMap2Size = smsListMap2.size();
log.debug("갯수 : " + smsListMap2Size);
// R => G
for (int j = 0; j < smsListMap2Size; j++) {
smsParamMap2 = new HashMap<String, Object>();
smsParamMap2.put("oldState", "R");
smsParamMap2.put("chgState", "G");
smsParamMap2.put("sendDateYn", "N");
smsParamMap2.put("type", "L");
smsParamMap2.put("modId", "BatchSystem");
String muSmsId = String.valueOf(smsListMap2.get(j).get("muSmsId"));
smsParamMap2.put("muSmsId", muSmsId);
webSmsSqlMapDAO.updateSmsState(smsParamMap2);
}
// G => SMS 전송
Message[] messages = new Message[smsListMap2Size];
for (int j = 0; j < smsListMap2Size; j++) {
// 전송요청번호
// 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
String muSmsId = String.valueOf(smsListMap2.get(j).get("muSmsId"));
String receiver = String.valueOf(smsListMap2.get(j).get("receiver")).replaceAll("-", "");
String userName = String.valueOf(smsListMap2.get(j).get("userName"));
String type = String.valueOf(smsListMap2.get(j).get("type"));
log.debug("===== LMS INPUT START ====");
log.debug("type :" + type);
log.debug("muSmsId :" + muSmsId);
log.debug("sender :" + sender);
log.debug("receiver :" + receiver);
log.debug("userName :" + userName);
log.debug("content :" + content);
log.debug("===== LMS INPUT END ====");
Message msg = new Message();
msg.setSender(sender); //발신번호
msg.setSenderName(senderName); //발신자명
msg.setReceiver(receiver); //수신번호
msg.setReceiverName(userName); //수신자명
msg.setSubject(title); //문자제목
msg.setContent(content); //메시지내용
messages[j] = msg;
}
String receiptNum = "미전송";
if (smsListMap2Size > 0) {
// 예약전송일시, null 처리시 즉시전송
Date reserveDT = null;
// 광고문자 전송여부
Boolean adsYN = false;
// 전송요청번호
// 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
String requestNum = "";
try {
receiptNum = messageService.sendLMS(corpNum, sender, title, content, messages, reserveDT, adsYN, userId, requestNum);
} catch (PopbillException e) {
log.debug("오류 코드 :" + e.getCode());
log.debug("오류 메시지 :" + e.getMessage());
}
}
// G => Y 전송
for (int j = 0; j < smsListMap2Size; j++) {
smsParamMap2 = new HashMap<String, Object>();
smsParamMap2.put("oldState", "G");
smsParamMap2.put("chgState", "Y");
smsParamMap2.put("sendDateYn", "Y");
smsParamMap2.put("type", "L");
smsParamMap2.put("receiptNum", receiptNum);
smsParamMap2.put("modId", "BatchSystem");
String muSmsId = String.valueOf(smsListMap2.get(j).get("muSmsId"));
smsParamMap2.put("muSmsId", muSmsId);
webSmsSqlMapDAO.updateSmsState(smsParamMap2);
}
}
} catch (Exception e) {
log.debug("Exception LmsSendBatch - run" + e.getMessage());
}
log.debug("******************LmsSendBatch END **********************************");
}
}

View File

@@ -0,0 +1,93 @@
package com.madeu.batch;
import com.madeu.dao.web.webpush.WebPushSqlMapDAO;
import com.madeu.push.FCMProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class PushAutoSendBatch {
@Autowired
private WebPushSqlMapDAO webPushSqlMapDAO;
// @Scheduled(fixedDelay = 60000) // 1분마다
public void go() {
log.debug("PushAutoSendBatch - run start");
try {
// 푸시 전송할 대상자 조회 (group)
HashMap<String, Object> selectMap = new HashMap<String, Object>();
selectMap.put("state","R");
selectMap.put("pushType","A");
List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
HashMap<String, Object> messageParamMap = new HashMap<String, Object>();
messageParamMap.put("linkUrl",null);
List<Map<String, Object>> pushList2 = webPushSqlMapDAO.selectListPushTime2(selectMap);
int pushList2Size = pushList2.size();
if(0<pushList2Size){
for(int i=0; i<pushList2Size; i++){
// R -> G
String muPushId = String.valueOf(pushList2.get(i).get("muPushId"));
// 상태를 변경함. pushYn : G(진행중)
HashMap<String, Object> sendPushParamMap = new HashMap<String, Object>();
sendPushParamMap.put("muPushId", muPushId);
sendPushParamMap.put("oldState", "R");
sendPushParamMap.put("chgState", "G");
sendPushParamMap.put("modId", "BatchSystem");
sendPushParamMap.put("sendDateYn", "N");
webPushSqlMapDAO.updatePushState(sendPushParamMap);
String phoneType = String.valueOf(pushList2.get(i).get("phoneType"));
String pushKey = String.valueOf(pushList2.get(i).get("pushKey"));
String title = String.valueOf(pushList2.get(i).get("title"));
String content = String.valueOf(pushList2.get(i).get("content"));
HashMap<String, Object> userParamMap = new HashMap<String, Object>();
userParamMap.put("pushKey", pushKey);
userParamMap.put("phoneType", phoneType);
// pushKey, phoneType 리스트에 담음
// userList.add(userParamMap);
// 푸시 발송
FCMProvider fcmProvider = new FCMProvider();
fcmProvider.provider(phoneType, pushKey, title, content, messageParamMap);
// G -> Y
// 상태를 변경함. pushYn : Y(전송완료)
sendPushParamMap = new HashMap<String, Object>();
sendPushParamMap.put("muPushId", muPushId);
sendPushParamMap.put("oldState", "G");
sendPushParamMap.put("chgState", "Y");
sendPushParamMap.put("modId", "BatchSystem");
sendPushParamMap.put("sendDateYn", "Y");
webPushSqlMapDAO.updatePushState(sendPushParamMap);
}
}
}catch(Exception e){
e.printStackTrace();
log.error("Exception PushAutoSendBatch - run", e);
}
log.debug("PushAutoSendBatch - run end");
}
}

View File

@@ -0,0 +1,113 @@
package com.madeu.batch;
import com.madeu.dao.web.webpush.WebPushSqlMapDAO;
import com.madeu.push.FCMProvider;
import com.madeu.push.FCMProvider2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class PushMarketingSendBatch {
@Autowired
private WebPushSqlMapDAO webPushSqlMapDAO;
// @Scheduled(fixedDelay = 600000) // 10분마다
// @Scheduled(fixedDelay = 60000) // 1분마다
// @Scheduled(fixedDelay = 3600000) // 1시간마다
public void go() {
log.debug("PushMarketingSendBatch - run start");
try {
LocalTime now = LocalTime.now();
int hour = now.getHour();
// 오전 9시 ~ 오후 9시 전송
if(9 < hour && hour < 21) {
// 푸시 전송할 대상자 조회 (group)
HashMap<String, Object> selectMap = new HashMap<String, Object>();
selectMap.put("state","R");
selectMap.put("pushType","MKT");
List<Map<String, Object>> pushList = webPushSqlMapDAO.selectListPushTimeGroup(selectMap);
int pushListSize = pushList.size();
List<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
if(0<pushListSize){
String title = String.valueOf(pushList.get(0).get("title"));
String content = String.valueOf(pushList.get(0).get("content"));
String linkUrl = String.valueOf(pushList.get(0).get("linkUrl"));
String tId = String.valueOf(pushList.get(0).get("tId"));
selectMap.put("title",title);
selectMap.put("content",content);
selectMap.put("linkUrl",linkUrl);
selectMap.put("tId",tId);
HashMap<String, Object> messageParamMap = new HashMap<String, Object>();
messageParamMap.put("linkUrl",linkUrl);
List<Map<String, Object>> pushList2 = webPushSqlMapDAO.selectListPushTime(selectMap);
int pushList2Size = pushList2.size();
if(0<pushList2Size){
for(int i=0; i<pushList2Size; i++){
// R -> G
String muPushId = String.valueOf(pushList2.get(i).get("muPushId"));
// 상태를 변경함. pushYn : G(진행중)
HashMap<String, Object> sendPushParamMap = new HashMap<String, Object>();
sendPushParamMap.put("muPushId", muPushId);
sendPushParamMap.put("oldState", "R");
sendPushParamMap.put("chgState", "G");
sendPushParamMap.put("modId", "BatchSystem");
sendPushParamMap.put("sendDateYn", "N");
webPushSqlMapDAO.updatePushState(sendPushParamMap);
String phoneType = String.valueOf(pushList2.get(i).get("phoneType"));
String pushKey = String.valueOf(pushList2.get(i).get("pushKey"));
HashMap<String, Object> userParamMap = new HashMap<String, Object>();
userParamMap.put("pushKey", pushKey);
userParamMap.put("phoneType", phoneType);
// pushKey, phoneType 리스트에 담음
userList.add(userParamMap);
// 푸시 발송
FCMProvider fcmProvider = new FCMProvider();
fcmProvider.provider(phoneType, pushKey, title, content, messageParamMap);
// G -> Y
// 상태를 변경함. pushYn : Y(전송완료)
sendPushParamMap = new HashMap<String, Object>();
sendPushParamMap.put("muPushId", muPushId);
sendPushParamMap.put("oldState", "G");
sendPushParamMap.put("chgState", "Y");
sendPushParamMap.put("modId", "BatchSystem");
sendPushParamMap.put("sendDateYn", "Y");
webPushSqlMapDAO.updatePushState(sendPushParamMap);
}
}
}
}
}catch(Exception e){
e.printStackTrace();
log.error("Exception PushMarketingSendBatch - run", e);
}
log.debug("PushMarketingSendBatch - run end");
}
}

View File

@@ -0,0 +1,125 @@
package com.madeu.batch;
import com.madeu.dao.web.websms.WebSmsSqlMapDAO;
import com.popbill.api.MessageService;
import com.popbill.api.message.SentMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class SmsPopbillStateUpdateBatch {
private static String corpNum;
private static String userId;
@Value("${popbill.corp-num}")
public void setCorpNum(String value){
corpNum = value;
}
@Value("${popbill.user-id}")
public void setUserId(String value){
userId = value;
}
@Autowired
private WebSmsSqlMapDAO webSmsSqlMapDAO;
@Autowired
private MessageService messageService;
//https://blog.naver.com/lovemema/140200056062
// @Scheduled(cron = "30 0/5 * * * *") // 5분마다 실행 (30초에 실행)
public void go() {
log.debug("******************SmsPopbillStateUpdateBatch START **********************************");
try{
log.debug("POPBILL_STATE, POPBILL_RESULT UPDATE START");
// SMS 환경설정 정보 호출
// 팝빌회원 사업자번호
// 팝빌회원 아이디
log.debug("corpNum : "+corpNum);
log.debug("userId : "+userId);
// 접수번호 대상자 조회
HashMap<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("type", "S");
paramMap.put("popbillState", 0);
List<Map<String, Object>> smsListMap = webSmsSqlMapDAO.selectListPopbillState(paramMap);
int smsListMapSize = smsListMap.size();
log.debug("접수번호 갯수 : "+smsListMapSize);
for(int i=0; i<smsListMapSize; i++) {
// 접수번호
String receiptNumber = String.valueOf(smsListMap.get(i).get("receiptNumber"));
SentMessage[] sentMessages = messageService.getMessages(corpNum, receiptNumber);
int sentMessagesLength = sentMessages.length;
for(int j=0; j<sentMessagesLength; j++) {
String receiveNumber = sentMessages[j].getReceiveNum();
String receiveName = sentMessages[j].getReceiveName();
String subject = sentMessages[j].getSubject();
String content = sentMessages[j].getContent();
String state = String.valueOf(sentMessages[j].getState());
String result = String.valueOf(sentMessages[j].getResult());
String type = String.valueOf(sentMessages[j].getMessageType());
type = type.substring(0, 1);
if(("3").equals(state)) {
HashMap<String, Object> smsParamMap = new HashMap<String, Object>();
smsParamMap.put("receiptNumber", receiptNumber);
smsParamMap.put("receiveNumber", receiveNumber);
smsParamMap.put("receiveName", receiveName);
smsParamMap.put("popbillState", 0);
smsParamMap.put("subject", subject);
smsParamMap.put("content", content);
smsParamMap.put("state", state);
smsParamMap.put("result", result);
smsParamMap.put("type", type);
smsParamMap.put("modId", "BatchSystem");
webSmsSqlMapDAO.updateSmsPopbillState(smsParamMap);
}else {
/*log.debug("receiptNumber : "+receiptNumber);
log.debug("sentMessages["+j+"] receiveNum : "+receiveNumber);
log.debug("sentMessages["+j+"] receiveName : "+receiveName);
log.debug("sentMessages["+j+"] subject : "+subject);
log.debug("sentMessages["+j+"] content : "+content);
log.debug("sentMessages["+j+"] state : "+state);
log.debug("sentMessages["+j+"] result : "+result);
log.debug("sentMessages["+j+"] type : "+type);*/
}
}
}
log.debug("POPBILL_STATE, POPBILL_RESULT UPDATE END");
}catch(Exception e){
log.debug("Exception SmsPopbillStateUpdateBatch - run" + e.getMessage());
}
log.debug("******************SmsPopbillStateUpdateBatch END **********************************");
}
}

View File

@@ -0,0 +1,177 @@
package com.madeu.batch;
import com.madeu.dao.web.websms.WebSmsSqlMapDAO;
import com.madeu.dao.web.webuser.WebUserSqlMapDAO;
import com.popbill.api.MessageService;
import com.popbill.api.PopbillException;
import com.popbill.api.message.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class SmsSendBatch {
private static String corpNum; // 팝빌회원 사업자번호
private static String userId; // 팝빌회원 아이디
private static String senderName; // 발신자명
@Value("${popbill.corp-num}")
public void setCorpNum(String value){
corpNum = value;
}
@Value("${popbill.user-id}")
public void setUserId(String value){
userId = value;
}
@Value("${popbill.sender-nm}")
public void setSenderName(String value){
senderName = value;
}
@Autowired
private WebSmsSqlMapDAO webSmsSqlMapDAO;
@Autowired
private MessageService messageService;
//https://blog.naver.com/lovemema/140200056062
// @Scheduled(cron = "0 0/5 * * * *") // 5분마다 실행
// @Scheduled(fixedDelay = 300000) // 5분마다
public void go() {
log.debug("******************SmsSendBatch START **********************************");
try{
// SMS 환경설정 정보 호출
log.debug("corpNum :"+corpNum);
log.debug("userId :"+userId);
log.debug("senderName :"+senderName);
HashMap<String, Object> smsParamMap = new HashMap<String, Object>();
smsParamMap.put("state","R");
smsParamMap.put("type","S");
List<Map<String, Object>> smsListMap = webSmsSqlMapDAO.selectListSmsTime(smsParamMap);
int smsListMapSize = smsListMap.size();
for(int i = 0; i<smsListMapSize; i++){
String sender = String.valueOf(smsListMap.get(i).get("sender")).replaceAll("-","");
String orgSender = String.valueOf(smsListMap.get(i).get("sender"));
String title = String.valueOf(smsListMap.get(i).get("title"));
String content = String.valueOf(smsListMap.get(i).get("content"));
HashMap<String, Object> smsParamMap2 = new HashMap<String, Object>();
smsParamMap2.put("state","R");
smsParamMap2.put("type","S");
smsParamMap2.put("sender",orgSender);
smsParamMap2.put("title", title);
smsParamMap2.put("content",content);
List<Map<String, Object>> smsListMap2 = webSmsSqlMapDAO.selectListSmsState(smsParamMap2);
int smsListMap2Size = smsListMap2.size();
log.debug("갯수 : "+ smsListMap2Size);
// R => G
for(int j=0; j<smsListMap2Size; j++){
smsParamMap2 = new HashMap<String, Object>();
smsParamMap2.put("oldState","R");
smsParamMap2.put("chgState","G");
smsParamMap2.put("sendDateYn","N");
smsParamMap2.put("type","S");
smsParamMap2.put("modId","BatchSystem");
String muSmsId = String.valueOf(smsListMap2.get(j).get("muSmsId"));
smsParamMap2.put("muSmsId",muSmsId);
webSmsSqlMapDAO.updateSmsState(smsParamMap2);
}
// G => SMS 전송
Message[] messages = new Message[smsListMap2Size];
for(int j=0; j<smsListMap2Size; j++){
// 전송요청번호
// 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
String muSmsId = String.valueOf(smsListMap2.get(j).get("muSmsId"));
String receiver = String.valueOf(smsListMap2.get(j).get("receiver")).replaceAll("-","");
String userName = String.valueOf(smsListMap2.get(j).get("userName"));
String type = String.valueOf(smsListMap2.get(j).get("type"));
log.debug("===== SMS INPUT START ====");
log.debug("type :"+type);
log.debug("muSmsId :"+muSmsId);
log.debug("sender :"+sender);
log.debug("receiver :"+receiver);
log.debug("userName :"+userName);
log.debug("content :"+content);
log.debug("===== SMS INPUT END ====");
Message msg = new Message();
msg.setSender(sender); //발신번호
msg.setSenderName(senderName); //발신자명
msg.setReceiver(receiver); //수신번호
msg.setReceiverName(userName); //수신자명
//msg.setSubject(subject); //문자제목
msg.setContent(content); //메시지내용
messages[j] = msg;
}
String receiptNum = "미전송";
if(smsListMap2Size > 0){
// 예약전송일시, null 처리시 즉시전송
Date reserveDT = null;
// 광고문자 전송여부
Boolean adsYN = false;
// 전송요청번호
// 파트너가 전송 건에 대해 관리번호를 구성하여 관리하는 경우 사용.
// 1~36자리로 구성. 영문, 숫자, 하이픈(-), 언더바(_)를 조합하여 팝빌 회원별로 중복되지 않도록 할당.
String requestNum = "";
try {
receiptNum = messageService.sendSMS(corpNum, sender,
content, messages, reserveDT, adsYN, userId, requestNum);
} catch (PopbillException e) {
log.debug("오류 코드 :" + e.getCode());
log.debug("오류 메시지 :" + e.getMessage());
}
}
// G => Y 전송
for(int j=0; j<smsListMap2Size; j++){
smsParamMap2 = new HashMap<String, Object>();
smsParamMap2.put("oldState","G");
smsParamMap2.put("chgState","Y");
smsParamMap2.put("sendDateYn","Y");
smsParamMap2.put("type","S");
smsParamMap2.put("receiptNum",receiptNum);
smsParamMap2.put("modId","BatchSystem");
String muSmsId = String.valueOf(smsListMap2.get(j).get("muSmsId"));
smsParamMap2.put("muSmsId",muSmsId);
webSmsSqlMapDAO.updateSmsState(smsParamMap2);
}
}
}catch(Exception e){
log.debug("Exception SmsSendBatch - run" + e.getMessage());
}
log.debug("******************SmsSendBatch END **********************************");
}
}

View File

@@ -0,0 +1,156 @@
package com.madeu.batch;
import com.madeu.dao.web.webdevice.WebDeviceSqlMapDAO;
import com.madeu.dao.web.webkakaotemplate.WebKakaoTemplateSqlMapDAO;
import com.madeu.dao.web.webpush.WebPushSqlMapDAO;
import com.madeu.dao.web.webreserve.WebReserveSqlMapDAO;
import com.madeu.service.common.autokakao.AutoKakaoService;
import com.madeu.service.common.autopush.AutoPushService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
public class TodayReservePushAutoSendBatch {
@Autowired
private WebPushSqlMapDAO webPushSqlMapDAO;
@Autowired
private WebReserveSqlMapDAO webReserveSqlMapDAO;
@Autowired
private AutoPushService autoPushService;
@Autowired
private AutoKakaoService autoKakaoService;
@Value("${popbill.sender-phone-num}")
String senderPhoneNumber;
@Autowired
private WebKakaoTemplateSqlMapDAO webKakaoTemplateSqlMapDAO;
@Autowired
private WebDeviceSqlMapDAO webDeviceSqlMapDAO;
// @Scheduled(fixedDelay = 60000) // 1분마다
// @Scheduled(cron = "0 0 9 * * *") // 매일 9시
public void go() {
log.debug("TodayReservePushAutoSendBatch - run start");
try {
String tId = String.valueOf(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c1 = Calendar.getInstance();
String tDate = sdf.format(c1.getTime());
HashMap<String, Object> selectMap = new HashMap<String, Object>();
// 당일 예약자 조회
LocalDate today = LocalDate.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
selectMap.put("searchDate", today.format(dateTimeFormatter));
List<Map<String, Object>> reserveListMap = webReserveSqlMapDAO.selectListReserveTodayBatch(selectMap);
int reserveListSize = reserveListMap.size();
if(0<reserveListSize){
// 자동발송 (알림톡 + 푸시)
// 템플릿 조회
HashMap<String, Object> insertKakaoMap = new HashMap<String, Object>();
insertKakaoMap.put("templateCode", "024110000460");
List<Map<String, Object>> templateListMap = webKakaoTemplateSqlMapDAO.selectKakaoTemplate(insertKakaoMap);
// 고객명, 예약날짜, 예약시간, 시술명
String KakaoTemplateTitle = String.valueOf(templateListMap.get(0).get("title"));
String KakaoTemplateContent = String.valueOf(templateListMap.get(0).get("content"));
for(int i=0; i<reserveListSize; i++){
String muUserId = String.valueOf(reserveListMap.get(i).get("muUserId"));
String userName = String.valueOf(reserveListMap.get(i).get("userName"));
String phoneNumber = String.valueOf(reserveListMap.get(i).get("phoneNumber"));
String reserveDate = String.valueOf(reserveListMap.get(i).get("reserveDate"));
String reserveTime = String.valueOf(reserveListMap.get(i).get("reserveTime"));
String treatmentName = String.valueOf(reserveListMap.get(i).get("treatmentName"));
String treatmentProcedureName = String.valueOf(reserveListMap.get(i).get("treatmentProcedureName"));
// 자동발송 (알림톡 + 푸시)
// 고객명, 예약날짜, 예약시간, 시술명
String kakaoContent = KakaoTemplateContent;
kakaoContent = kakaoContent.replace("#{고객명}", userName);
kakaoContent = kakaoContent.replace("#{예약날짜}", reserveDate);
kakaoContent = kakaoContent.replace("#{예약시간}", reserveTime);
kakaoContent = kakaoContent.replace("#{시술명}", treatmentName.concat("-").concat(treatmentProcedureName));
insertKakaoMap.put("muKakaoId", ("K").concat(String.valueOf(System.currentTimeMillis())));
insertKakaoMap.put("muUserId", muUserId);
insertKakaoMap.put("userName", userName);
insertKakaoMap.put("phoneNumber", phoneNumber);
insertKakaoMap.put("content", kakaoContent);
insertKakaoMap.put("state", "R");
insertKakaoMap.put("popbillState", "0");
insertKakaoMap.put("sender", senderPhoneNumber);
insertKakaoMap.put("regId", "SYSTEM");
insertKakaoMap.put("modId", "SYSTEM");
insertKakaoMap.put("tId", tId);
insertKakaoMap.put("tDate", tDate);
autoKakaoService.send("reserve", insertKakaoMap);
// 사용자별 디바이스 조회
selectMap = new HashMap<String, Object>();
selectMap.put("muUserId", muUserId);
List<Map<String, Object>> deviceListMap = webDeviceSqlMapDAO.selectListDevice2(selectMap);
int deviceListSize = deviceListMap.size();
if(0<deviceListSize){
HashMap<String, Object> insertPushMap = new HashMap<String, Object>();
for(int j=0; j<deviceListSize; j++){
insertPushMap.put("muPushId", ("P").concat(String.valueOf(System.currentTimeMillis())));
insertPushMap.put("muUserId", muUserId);
insertPushMap.put("userName", userName);
insertPushMap.put("muDeviceId", deviceListMap.get(j).get("muDeviceId"));
insertPushMap.put("deviceUuid", deviceListMap.get(j).get("deviceUuid"));
insertPushMap.put("pushKey", deviceListMap.get(j).get("pushKey"));
insertPushMap.put("pushType", "A");
insertPushMap.put("phoneType", deviceListMap.get(j).get("phoneType"));
insertPushMap.put("title", KakaoTemplateTitle);
insertPushMap.put("content", kakaoContent);
insertPushMap.put("state", "R");
insertPushMap.put("regId", "SYSTEM");
insertPushMap.put("modId", "SYSTEM");
insertPushMap.put("tId", tId);
insertPushMap.put("tDate", tDate);
autoPushService.send("reserve", insertPushMap);
}
}
}
}
}catch(Exception e){
e.printStackTrace();
log.error("Exception TodayReservePushAutoSendBatch - run", e);
}
log.debug("TodayReservePushAutoSendBatch - run end");
}
}

View File

@@ -0,0 +1,23 @@
package com.madeu.batch;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class test {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String dateParam1 = "2024-01-30";
String dateParam2 = "2024-02-01";
Date format1 = new SimpleDateFormat("yyyy-MM-dd").parse(dateParam1);
Date format2 = new SimpleDateFormat("yyyy-MM-dd").parse(dateParam2);
long diffSec = (format2.getTime() - format1.getTime()) / 1000; //초 차이
long diffDays = diffSec / (24*60*60); //일자수 차이
System.out.println(diffDays+1);
}
}