|
|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
package com.jiudian.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
import com.jiudian.manage.mapper.UserMapper;
|
|
|
|
|
import com.jiudian.manage.model.User;
|
|
|
|
|
import com.jiudian.manage.service.UserService;
|
|
|
|
|
import com.jiudian.manage.until.UUIDUtil;
|
|
|
|
|
import com.github.pagehelper.PageHelper;//分页工具,实现分页查询
|
|
|
|
|
import com.jiudian.manage.mapper.UserMapper;//用户数据库接口
|
|
|
|
|
import com.jiudian.manage.model.User;//用户实现类
|
|
|
|
|
import com.jiudian.manage.service.UserService;//用户服务接口
|
|
|
|
|
import com.jiudian.manage.until.UUIDUtil;//生成用户唯一标识
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
@ -29,23 +29,28 @@ import java.util.List;
|
|
|
|
|
//登录验证:验证用户名密码,返回用户 ID 和权限
|
|
|
|
|
//权限管理:基于 power 字段实现用户权限控制
|
|
|
|
|
@Service
|
|
|
|
|
//实现UserService接口的所有方法
|
|
|
|
|
//实现UserService接口的所有抽象方法
|
|
|
|
|
public class UserServiceImpl implements UserService {
|
|
|
|
|
//服务层通过userMapper调用 Mapper 接口中定义的 SQL 操作,实现 “服务层 - 数据访问层” 的交互
|
|
|
|
|
@Autowired
|
|
|
|
|
UserMapper userMapper;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//查询用户
|
|
|
|
|
public User selectUser(int userid) {
|
|
|
|
|
return userMapper.selectByPrimaryKey(userid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean addUser(String account, String password, int power){
|
|
|
|
|
//1.创建用户,封装用户信息
|
|
|
|
|
User user = new User();
|
|
|
|
|
user.setUseraccount(account);
|
|
|
|
|
user.setPassword(password);
|
|
|
|
|
user.setPower(power);
|
|
|
|
|
user.setIdnumber(UUIDUtil.generateShortUuid());
|
|
|
|
|
// 2. 调用UserMapper的insertSelective方法:选择性插入用户(仅插入非null字段)
|
|
|
|
|
int insert = userMapper.insertSelective(user);
|
|
|
|
|
// 3. 根据插入结果返回布尔值:受影响行数>0表示插入成功(返回true),否则失败(返回false)
|
|
|
|
|
return insert>0?true:false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -56,9 +61,11 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//重写修改用户方法
|
|
|
|
|
public boolean alterUser(int userid, String password, String username, int age, int power, String IDnumber,String phonenumber) {
|
|
|
|
|
User user = new User();
|
|
|
|
|
user.setUserid(userid);
|
|
|
|
|
// 选择性设置字段:仅当参数不是默认值时,才设置(避免覆盖原有数据)
|
|
|
|
|
if(!password.equals("null")){
|
|
|
|
|
user.setPassword(password);
|
|
|
|
|
}
|
|
|
|
|
@ -77,28 +84,40 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
if(!phonenumber.equals("null")){
|
|
|
|
|
user.setPhonenumber(phonenumber);
|
|
|
|
|
}
|
|
|
|
|
//调用UserMapper的updateByPrimaryKeySelective方法:选择性更新(仅更新非null字段
|
|
|
|
|
int i = userMapper.updateByPrimaryKeySelective(user);
|
|
|
|
|
return i>0?true:false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean addSlary(int userid, double money) {
|
|
|
|
|
//重写addsalary方法
|
|
|
|
|
public boolean addSalary(int userid, double money) {
|
|
|
|
|
// . 先查询用户当前的薪水(money字段)
|
|
|
|
|
User user = userMapper.selectByPrimaryKey(userid);
|
|
|
|
|
// 获取用户当前薪水
|
|
|
|
|
Double money1 = user.getMoney();
|
|
|
|
|
//计算新薪水:原有薪水 + 提成(money)
|
|
|
|
|
user.setMoney(money+money1);
|
|
|
|
|
int i = userMapper.updateByPrimaryKey(user);
|
|
|
|
|
//根据更新结果返回布尔值
|
|
|
|
|
return i>0?true:false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//重写查询所有用户方法
|
|
|
|
|
public List<User> getAllUser(int pageNum,int pageSize) {
|
|
|
|
|
PageHelper.startPage(pageNum,pageSize);
|
|
|
|
|
// 1. 调用PageHelper.startPage:开启分页功能,传入页码(pageNum)和每页条数(pageSize)
|
|
|
|
|
return userMapper.getAllUser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
//重写根据页面查询用户
|
|
|
|
|
public List<User> getUserByPower(int power,int pageNum,int pageSize) {
|
|
|
|
|
//开启分页功能
|
|
|
|
|
PageHelper.startPage(pageNum,pageSize);
|
|
|
|
|
|
|
|
|
|
// 调用UserMapper的selectByPower方法:按权限(power)查询用户(自动分页)
|
|
|
|
|
return userMapper.selectByPower(power);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -114,11 +133,14 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean photo(int userid, String url) {
|
|
|
|
|
//创建User实体类对象,用于封装更新数据
|
|
|
|
|
User user = new User();
|
|
|
|
|
user.setUserid(userid);
|
|
|
|
|
user.setPhotourl(url);
|
|
|
|
|
int i = userMapper.updateByPrimaryKeySelective(user);
|
|
|
|
|
return i>0?true:false;
|
|
|
|
|
//执行后返回一个 int 类型的结果 i,表示 “受影响的行数”
|
|
|
|
|
// (即数据库中实际被更新的记录数,成功时通常为 1,失败时为 0)
|
|
|
|
|
return i > 0 ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|