package com.xzx.gc.user.service; import cn.hutool.core.date.DateUtil; import com.xzx.gc.common.constant.Constants; import com.xzx.gc.common.utils.BusinessUtil; import com.xzx.gc.common.utils.IdUtils; import com.xzx.gc.entity.AccountInfo; import com.xzx.gc.user.mapper.AccountMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import tk.mybatis.mapper.entity.Example; import java.math.BigDecimal; import java.util.List; @Service @Transactional public class AccountService { @Autowired private AccountMapper accountMapper; @Autowired private IdUtils idUtils; @Autowired private BusinessUtil businessUtil; public List findAll(){ Example example = new Example(AccountInfo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("delFlag", 0); criteria.andEqualTo("isProhibit", 0); List accountInfos = accountMapper.selectByExample(example); return accountInfos; } public AccountInfo findById(String accountId){ return accountMapper.selectByPrimaryKey(accountId); } public AccountInfo findByUserId(String userId){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setDelFlag(Constants.DEL_NOT_FLAG); accountInfo.setUserId(userId); accountInfo.setIsProhibit("0"); AccountInfo accountInfo1 = accountMapper.selectOne(accountInfo); return accountInfo1; } public AccountInfo findByUserIdForbidden(String userId){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setDelFlag(Constants.DEL_NOT_FLAG); accountInfo.setUserId(userId); AccountInfo accountInfo1 = accountMapper.selectOne(accountInfo); return accountInfo1; } public List findByMobile(String mobile){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setAccountName(mobile); accountInfo.setDelFlag(Constants.DEL_NOT_FLAG); List select = accountMapper.select(accountInfo); return select; } public void deleteByUserId(String userId){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setDelFlag(Constants.DEL_FLAG); accountInfo.setUpdateTime(DateUtil.now()); Example example=new Example(AccountInfo.class); example.createCriteria().andEqualTo("userId",userId); accountMapper.updateByExampleSelective(accountInfo,example); } public void deleteByAccountId(String accountId){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setDelFlag(Constants.DEL_FLAG); accountInfo.setAccountId(accountId); accountMapper.updateByPrimaryKeySelective(accountInfo); } /** * 添加默认账户 * @param mobile * @param userId */ public int addDefault(String mobile,String userId){ AccountInfo accountInfo =init(mobile,userId); return accountMapper.insertSelective(accountInfo); } public void add(AccountInfo accountInfo){ accountMapper.insertSelective(accountInfo); } public AccountInfo init(String mobile,String userId){ AccountInfo accountInfo =new AccountInfo(); accountInfo.setAccountId(idUtils.generate("ZH",4)); accountInfo.setAccountName(mobile); accountInfo.setUserId(userId); accountInfo.setFreezeMoney("0"); accountInfo.setWithdrawMoney("0"); accountInfo.setMoney("0"); accountInfo.setDelFlag(0); accountInfo.setErrorTimes(0); accountInfo.setIsProhibit("0"); accountInfo.setCreateTime(DateUtil.now()); accountInfo.setUpdateTime(DateUtil.now()); accountInfo.setCollectScore("0"); return accountInfo; } public void updateOverLimitByAccountId(String accountId,BigDecimal overdraftLimit){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setAccountId(accountId); accountInfo.setOverdraftLimit(businessUtil.changeMoney(overdraftLimit)); accountMapper.updateByPrimaryKeySelective(accountInfo); } public void updateFixLimitByAccountId(String accountId,BigDecimal overdraftLimit){ AccountInfo accountInfo=new AccountInfo(); accountInfo.setAccountId(accountId); accountInfo.setFixedLimit(businessUtil.changeMoney(overdraftLimit)); accountMapper.updateByPrimaryKeySelective(accountInfo); } }