mjon_git/src/main/java/itn/let/module/base/PriceAndPoint.java
2025-01-24 19:20:06 +09:00

161 lines
4.3 KiB
Java

package itn.let.module.base;
import java.math.BigDecimal;
import java.math.RoundingMode;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import egovframework.rte.fdl.idgnr.EgovIdGnrService;
import itn.let.mjo.event.service.MjonEventService;
import itn.let.mjo.event.service.MjonEventVO;
import itn.let.mjo.event.service.impl.MjonEventDAO;
import itn.let.mjo.msg.service.MjonMsgVO;
import itn.let.mjo.msgdata.service.impl.MjonMsgDataDAO;
import itn.let.mjo.pay.service.MjonPayVO;
import itn.let.mjo.pay.service.impl.MjonPayDAO;
import itn.let.uss.umt.service.MberManageVO;
/**
*
* @author : 이호영
* @fileName : PriceAndPoint.java
* @date : 2023.03.27
* @description : 금액 포인트 관련 module
* ===========================================================
* DATE AUTHOR NOTE
* ----------------------------------------------------------- *
* 2023.03.27 이호영 최초 생성
*
*
*
*/
@Component
public class PriceAndPoint {
@Autowired
private MjonMsgDataDAO mjonMsgDataDAO;
@Autowired
private MjonPayDAO mjonPayDAO;
@Autowired
private MjonEventService mjonEventService;
@Resource(name = "egovMjonCashIdGnrService")
private EgovIdGnrService idgenMjonCashId;
/**
* @methodName : getBefCash
* @author : 이호영
* @date : 2023.03.30
* @description : 사용자 보유 잔액
* @param userId
* @return
* @throws Exception
*/
public String getBefCash(String userId) throws Exception {
MjonMsgVO mjonMsgVO = new MjonMsgVO();
mjonMsgVO.setUserId(userId);
return mjonMsgDataDAO.selectBeforeCashData(mjonMsgVO);
}
/**
* @methodName : getBefPoint
* @author : 이호영
* @date : 2023.03.30
* @description : 사용자 보유 포인트
* @param userId
* @return
* @throws Exception
*/
public String getBefPoint(String userId) throws Exception {
MjonMsgVO mjonMsgVO = new MjonMsgVO();
mjonMsgVO.setUserId(userId);
return mjonMsgDataDAO.selectBeforePointData(mjonMsgVO);
}
/**
* @methodName : getUserMoney
* @author : 이호영
* @date : 2023.03.30
* @description : 사용자 보유 잔액
* @param userId
* @return
* @throws Exception
*/
public BigDecimal getUserMoney(String userId) throws Exception {
MberManageVO mberManageVO = mjonMsgDataDAO.selectMberManageInfo(userId);
BigDecimal userMoney = new BigDecimal(mberManageVO.getUserMoney()).setScale(2, RoundingMode.HALF_EVEN);
return userMoney;
}
/**
* @methodName : insertCashAndPoint
* @author : 이호영
* @date : 2024.03.26
* @description :
* @param mjonPayDAO
* @param idgenMjonCashId
* @param userId
* @param totPrice
* @param memo
* @param msgGroupId
* @throws Exception
*/
public void insertCashAndPoint(
String userId
, float totPrice
, String memo
, String msgGroupId
) throws Exception {
MjonPayVO mjonPayVO = new MjonPayVO();
mjonPayVO.setCashId(idgenMjonCashId.getNextStringId());
mjonPayVO.setUserId(userId);
mjonPayVO.setCash(totPrice);
mjonPayVO.setFrstRegisterId(userId);
mjonPayVO.setMemo(memo);
mjonPayVO.setMsgGroupId(msgGroupId);
mjonPayDAO.insertCash(mjonPayVO); //캐시
mjonPayDAO.updateMemberCash(mjonPayVO); //회원정보 업데이트
//이벤트 회원인 경우 이벤트 캐시도 함께 차감.
MjonEventVO mjonEventVO = new MjonEventVO();
mjonEventVO.setMberId(mjonPayVO.getUserId());
mjonEventVO.setEventStatus("Y");
MjonEventVO eventMberInfo = mjonEventService.selectEventMsgMberDefaultInfo(mjonEventVO);
if(eventMberInfo != null) {
float evntRemainCash = (float) eventMberInfo.getEventRemainCash();
totPrice = (float) Math.abs(mjonPayVO.getCash());
float totRemainCash = evntRemainCash - totPrice;
mjonEventVO.setEventInfoId(eventMberInfo.getEventInfoId());
if(totRemainCash <= 0.0) {//차감액이 남아있지 않으면 이벤트를 종료
//이벤트 상태값을 종료로 변경한다.
mjonEventVO.setEventStatus("E");
mjonEventVO.setEventRemainCash(0.0);
mjonEventService.updateEventEndStatus(mjonEventVO);
}else {//이벤트 회원 캐시 차감시킴
mjonEventVO.setEventRemainCash(totRemainCash);
mjonEventService.updateEventRemainCash(mjonEventVO);
}
}
}
}