package com.fzzy.sys;
|
|
import com.bstek.dorado.annotation.DataProvider;
|
import com.bstek.dorado.annotation.DataResolver;
|
import com.bstek.dorado.annotation.Expose;
|
import com.bstek.dorado.data.entity.EntityState;
|
import com.bstek.dorado.data.entity.EntityUtils;
|
import com.fzzy.sys.entity.SysUser;
|
import com.fzzy.sys.repository.UserRepository;
|
import org.apache.commons.lang.math.RandomUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 用户维护
|
*/
|
@Component("sys.userPR")
|
public class UserPR {
|
|
|
@Autowired
|
private UserRepository userRepository;
|
|
|
/**
|
* sys.userPR#findAll
|
* @return
|
*/
|
@DataProvider
|
public List<SysUser> findAll() {
|
return userRepository.findAll();
|
}
|
|
/**
|
* sys.userPR#updateSave
|
* @param entity
|
*/
|
@DataResolver
|
public String updateSave(SysUser entity) {
|
EntityState state = EntityUtils.getState(entity);
|
if(state.equals(EntityState.NEW)){
|
//登录账号是主键,不能重复
|
SysUser user = this.listById(entity.getUsername());
|
if(user != null){
|
return "登录账户已存在,请重新录入!";
|
}
|
|
if (null == entity.getCreateDate()) {
|
entity.setCreateDate(new Date());
|
}
|
// if (null == entity.getCompanyId()) {
|
// entity.setCompanyId(ContextUtil.getCompanyId(true));
|
// }
|
//密码加密
|
int salt = RandomUtils.nextInt(27);
|
salt += 4;
|
// bCryptPasswordEncoder = new BCryptPasswordEncoder(salt);
|
// String password = bCryptPasswordEncoder.encode(entity.getPassword());
|
// boolean b= bCryptPasswordEncoder.matches(entity.getPassword(),password);
|
entity.setPassword(entity.getPassword());
|
entity.setSalt(String.valueOf(salt));
|
}
|
// 手动将doradoEntity对象转换为标准Bean对象
|
SysUser data = new SysUser();
|
BeanUtils.copyProperties(entity, data);
|
userRepository.save(data);
|
return null;
|
}
|
|
|
/**
|
* sys.userPR#delData
|
*
|
* @param data
|
*/
|
@Expose
|
public String delData(SysUser data) {
|
userRepository.deleteById(data.getUsername());
|
return null;
|
}
|
|
/**
|
* 重置密码为"123456"
|
* sys.userPR#resetPassword
|
* @param entity
|
* @return
|
*/
|
@Expose
|
public String resetPassword(SysUser entity) {
|
//密码加密
|
int salt = RandomUtils.nextInt(27);
|
salt += 4;
|
// bCryptPasswordEncoder = new BCryptPasswordEncoder(salt);
|
// String password = bCryptPasswordEncoder.encode(Constant.DEFAULT_USER_PASSWORD);
|
entity.setPassword(entity.getPassword());
|
entity.setSalt(String.valueOf(salt));
|
|
SysUser data = new SysUser();
|
BeanUtils.copyProperties(entity, data);
|
userRepository.save(data);
|
return null;
|
}
|
|
public SysUser listById(String username) {
|
List<SysUser> list = userRepository.listById(username);
|
if(list != null && list.size() > 0){
|
return list.get(0);
|
}
|
return null;
|
}
|
|
}
|