| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.io.Serializable;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.hibernate.HibernateException;
|
| | | import org.hibernate.Query;
|
| | | import org.hibernate.Session;
|
| | | import org.springframework.orm.hibernate4.HibernateCallback;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.user.ExtractRecordDao;
|
| | | import com.yeshi.fanli.entity.bus.user.Extract;
|
| | | import com.yeshi.fanli.dao.mybatis.ExtractRecordMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.ExtractRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.exception.AdminLimitException;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.ExtractRecordService;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | |
|
| | | @Service
|
| | | public class ExtractRecordServiceImpl implements ExtractRecordService {
|
| | |
|
| | | @Resource
|
| | | private ExtractRecordDao extractRecordDao;
|
| | | private ExtractRecordMapper extractRecordMapper;
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | public void setExtractRecord(Extract extract) throws AdminLimitException {
|
| | | long uid = extract.getUserInfo().getId();
|
| | | BigDecimal money = extract.getMoney();
|
| | | List<ExtractRecord> extractRecordList = extractRecordDao.list("from ExtractRecord er where er.userInfo.id=? ",
|
| | | new Serializable[] { uid });
|
| | | if (extractRecordList.size() == 0) {
|
| | | ExtractRecord er = new ExtractRecord();
|
| | | er.setCount(1);
|
| | | er.setMoney(money);
|
| | | er.setUserInfo(new UserInfo(uid));
|
| | | extractRecordDao.save(er);
|
| | | } else {
|
| | | ExtractRecord er = extractRecordList.get(0);
|
| | | int count = er.getCount();
|
| | | String maxCount = configService.get("extract_count_day");
|
| | | int maxCountInt = Integer.parseInt(maxCount);
|
| | | if (count >= maxCountInt) {
|
| | | throw new AdminLimitException("超出每日最大提现次数!");
|
| | | }
|
| | | BigDecimal oldMoney = er.getMoney();
|
| | | BigDecimal sumMoney = MoneyBigDecimalUtil.add(money, oldMoney);
|
| | | String maxMoney = configService.get("extract_money_day");
|
| | | BigDecimal maxMoneyDou = new BigDecimal(maxMoney);
|
| | | if (maxMoneyDou.compareTo(sumMoney) == -1) {
|
| | | BigDecimal exceedMoney = MoneyBigDecimalUtil.sub(sumMoney, maxMoneyDou);
|
| | | throw new AdminLimitException("超出每日最大提现金额!超出金额为:" + exceedMoney + "元");
|
| | | }
|
| | | er.setCount(count + 1);
|
| | | er.setMoney(sumMoney);
|
| | | extractRecordDao.update(er);
|
| | | }
|
| | | }
|
| | |
|
| | | // 定时删除ExtractRecord记录
|
| | | public void deleteExtractRecord() {
|
| | | extractRecordDao.excute(new HibernateCallback() {
|
| | |
|
| | | public Object doInHibernate(Session session) throws HibernateException {
|
| | | Query query = session.createQuery("DELETE FROM ExtractRecord");
|
| | | query.executeUpdate();
|
| | | return null;
|
| | | }
|
| | | });
|
| | | extractRecordMapper.deleteAll();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public ExtractRecord getExtractRecordByUid(Long uid) {
|
| | | List<ExtractRecord> extractRecordList = extractRecordDao
|
| | | .list("from ExtractRecord er where er.userInfo.id=" + uid);
|
| | | List<ExtractRecord> extractRecordList = extractRecordMapper.selectByUid(uid);
|
| | | if (extractRecordList == null || extractRecordList.size() == 0)
|
| | | return null;
|
| | | else
|