package com.taoke.autopay.service.impl;
|
|
import com.taoke.autopay.dao.ClientInfoMapper;
|
import com.taoke.autopay.entity.ClientInfo;
|
import com.taoke.autopay.exception.LoginException;
|
import com.taoke.autopay.service.ClientInfoService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author hxh
|
* @title: ClientInfoServiceImpl
|
* @description: TODO
|
* @date 2024/6/14 18:43
|
*/
|
@Service
|
public class ClientInfoServiceImpl implements ClientInfoService {
|
@Resource
|
private ClientInfoMapper clientInfoMapper;
|
|
@Override
|
public ClientInfo login(String account, String pwd) throws LoginException {
|
ClientInfoMapper.DaoQuery query = new ClientInfoMapper.DaoQuery();
|
query.start = 0;
|
query.count = 1;
|
query.account = account;
|
List<ClientInfo> list = clientInfoMapper.list(query);
|
if (list.size() == 0) {
|
throw new LoginException("账号不存在");
|
}
|
if (!list.get(0).getPwd().equalsIgnoreCase(pwd)) {
|
throw new LoginException("密码错误");
|
}
|
|
return list.get(0);
|
}
|
|
@Override
|
public void logout(Long uid) {
|
clientInfoMapper.clearActiveTime(uid);
|
}
|
|
@Override
|
public ClientInfo selectByPrimaryKey(Long id) {
|
return clientInfoMapper.selectByPrimaryKey(id);
|
}
|
|
@Override
|
public void setActiveTime(Long id, Date date) {
|
ClientInfo info = new ClientInfo();
|
info.setId(id);
|
info.setActiveTime(date);
|
clientInfoMapper.updateByPrimaryKeySelective(info);
|
}
|
|
@Override
|
public List<ClientInfo> listByIds(List<Long> ids) {
|
return clientInfoMapper.listByIds(ids);
|
}
|
|
@Override
|
public List<ClientInfo> list(ClientInfoMapper.DaoQuery query) {
|
return clientInfoMapper.list(query);
|
}
|
|
@Override
|
public long count(ClientInfoMapper.DaoQuery query) {
|
return clientInfoMapper.count(query);
|
}
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public void add(ClientInfo info) {
|
if(info.getPwd()==null){
|
info.setPwd("123456");
|
}
|
if(info.getRule()==null){
|
info.setRule(ClientInfo.RULE_COMMON);
|
}
|
if(info.getCreateTime()==null){
|
info.setCreateTime(new Date());
|
}
|
|
if(info.getAccount()==null) {
|
// 查询最大的账号
|
ClientInfoMapper.DaoQuery query = new ClientInfoMapper.DaoQuery();
|
query.sortList = Arrays.asList(new String[]{"id desc"});
|
query.count = 1;
|
List<ClientInfo> list = list(query);
|
long maxId = 0;
|
if (list.size() > 0) {
|
maxId = list.get(0).getId();
|
}
|
info.setAccount("c" + maxId);
|
}
|
clientInfoMapper.insertSelective(info);
|
ClientInfo update=new ClientInfo();
|
update.setId(info.getId());
|
update.setName("客户端"+(info.getId()-1));
|
|
clientInfoMapper.updateByPrimaryKeySelective(update);
|
}
|
|
@Override
|
public void setPwd(Long id, String pwd) {
|
ClientInfo update=new ClientInfo();
|
update.setId(id);
|
update.setPwd(pwd);
|
clientInfoMapper.updateByPrimaryKeySelective(update);
|
}
|
}
|