|
|
|
@ -39,6 +39,7 @@ import com.utils.MD5Util;
|
|
|
|
|
import com.utils.MPUtil;
|
|
|
|
|
import com.utils.CommonUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户
|
|
|
|
|
* 后端接口
|
|
|
|
@ -46,56 +47,56 @@ import com.utils.CommonUtil;
|
|
|
|
|
* @email
|
|
|
|
|
* @date 2023-02-21 09:46:06
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/yonghu")
|
|
|
|
|
@RestController // 标记这是一个REST控制器
|
|
|
|
|
@RequestMapping("/yonghu") // 设置请求路径的前缀为/yonghu
|
|
|
|
|
public class YonghuController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private YonghuService yonghuService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private YonghuService yonghuService; // 自动注入YonghuService服务
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TokenService tokenService;
|
|
|
|
|
private TokenService tokenService; // 自动注入TokenService服务
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping(value = "/login")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证
|
|
|
|
|
@RequestMapping(value = "/login") // 设置请求路径为/login
|
|
|
|
|
public R login(String username, String password, String captcha, HttpServletRequest request) {
|
|
|
|
|
// 根据用户名查询用户
|
|
|
|
|
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", username));
|
|
|
|
|
// 验证用户名和密码
|
|
|
|
|
if(u==null || !u.getMima().equals(password)) {
|
|
|
|
|
return R.error("账号或密码不正确");
|
|
|
|
|
}
|
|
|
|
|
// 生成并返回token
|
|
|
|
|
String token = tokenService.generateToken(u.getId(), username,"yonghu", "用户" );
|
|
|
|
|
return R.ok().put("token", token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 注册
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/register")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证
|
|
|
|
|
@RequestMapping("/register") // 设置请求路径为/register
|
|
|
|
|
public R register(@RequestBody YonghuEntity yonghu){
|
|
|
|
|
//ValidatorUtils.validateEntity(yonghu);
|
|
|
|
|
// 检查用户是否已存在
|
|
|
|
|
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao()));
|
|
|
|
|
if(u!=null) {
|
|
|
|
|
return R.error("注册用户已存在");
|
|
|
|
|
}
|
|
|
|
|
// 生成用户ID并插入用户数据
|
|
|
|
|
Long uId = new Date().getTime();
|
|
|
|
|
yonghu.setId(uId);
|
|
|
|
|
yonghuService.insert(yonghu);
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 退出
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/logout")
|
|
|
|
|
@RequestMapping("/logout") // 设置请求路径为/logout
|
|
|
|
|
public R logout(HttpServletRequest request) {
|
|
|
|
|
// 使当前会话失效
|
|
|
|
|
request.getSession().invalidate();
|
|
|
|
|
return R.ok("退出成功");
|
|
|
|
|
}
|
|
|
|
@ -103,9 +104,11 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户的session用户信息
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/session")
|
|
|
|
|
@RequestMapping("/session") // 设置请求路径为/session
|
|
|
|
|
public R getCurrUser(HttpServletRequest request){
|
|
|
|
|
// 从session中获取用户ID
|
|
|
|
|
Long id = (Long)request.getSession().getAttribute("userId");
|
|
|
|
|
// 根据ID查询用户信息
|
|
|
|
|
YonghuEntity u = yonghuService.selectById(id);
|
|
|
|
|
return R.ok().put("data", u);
|
|
|
|
|
}
|
|
|
|
@ -113,28 +116,28 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 密码重置
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping(value = "/resetPass")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证
|
|
|
|
|
@RequestMapping(value = "/resetPass") // 设置请求路径为/resetPass
|
|
|
|
|
public R resetPass(String username, HttpServletRequest request){
|
|
|
|
|
// 根据用户名查询用户
|
|
|
|
|
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", username));
|
|
|
|
|
if(u==null) {
|
|
|
|
|
return R.error("账号不存在");
|
|
|
|
|
}
|
|
|
|
|
// 重置密码为123456
|
|
|
|
|
u.setMima("123456");
|
|
|
|
|
yonghuService.updateById(u);
|
|
|
|
|
return R.ok("密码已重置为:123456");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后端列表
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/page")
|
|
|
|
|
@RequestMapping("/page") // 设置请求路径为/page
|
|
|
|
|
public R page(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
|
|
|
|
|
HttpServletRequest request){
|
|
|
|
|
|
|
|
|
|
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
|
|
|
|
|
|
|
|
|
|
// 分页查询用户列表
|
|
|
|
|
PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
|
|
|
|
|
request.setAttribute("data", page);
|
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
@ -143,12 +146,12 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 前端列表
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/list")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证
|
|
|
|
|
@RequestMapping("/list") // 设置请求路径为/list
|
|
|
|
|
public R list(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
|
|
|
|
|
HttpServletRequest request){
|
|
|
|
|
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
|
|
|
|
|
|
|
|
|
|
// 分页查询用户列表
|
|
|
|
|
PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
|
|
|
|
|
request.setAttribute("data", page);
|
|
|
|
|
return R.ok().put("data", page);
|
|
|
|
@ -157,7 +160,7 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 列表
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/lists")
|
|
|
|
|
@RequestMapping("/lists") // 设置请求路径为/lists
|
|
|
|
|
public R list( YonghuEntity yonghu){
|
|
|
|
|
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
|
|
|
|
|
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
|
|
|
|
@ -167,7 +170,7 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 查询
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/query")
|
|
|
|
|
@RequestMapping("/query") // 设置请求路径为/query
|
|
|
|
|
public R query(YonghuEntity yonghu){
|
|
|
|
|
EntityWrapper< YonghuEntity> ew = new EntityWrapper< YonghuEntity>();
|
|
|
|
|
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
|
|
|
|
@ -178,7 +181,7 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 后端详情
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/info/{id}")
|
|
|
|
|
@RequestMapping("/info/{id}") // 设置请求路径为/info/{id}
|
|
|
|
|
public R info(@PathVariable("id") Long id){
|
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
|
|
|
|
return R.ok().put("data", yonghu);
|
|
|
|
@ -187,28 +190,23 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 前端详情
|
|
|
|
|
*/
|
|
|
|
|
@IgnoreAuth
|
|
|
|
|
@RequestMapping("/detail/{id}")
|
|
|
|
|
@IgnoreAuth // 忽略权限验证
|
|
|
|
|
@RequestMapping("/detail/{id}") // 设置请求路径为/detail/{id}
|
|
|
|
|
public R detail(@PathVariable("id") Long id){
|
|
|
|
|
YonghuEntity yonghu = yonghuService.selectById(id);
|
|
|
|
|
return R.ok().put("data", yonghu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后端保存
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/save")
|
|
|
|
|
@RequestMapping("/save") // 设置请求路径为/save
|
|
|
|
|
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
|
|
|
|
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
|
|
|
|
|
//ValidatorUtils.validateEntity(yonghu);
|
|
|
|
|
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao()));
|
|
|
|
|
if(u!=null) {
|
|
|
|
|
return R.error("用户已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yonghu.setId(new Date().getTime());
|
|
|
|
|
yonghuService.insert(yonghu);
|
|
|
|
|
return R.ok();
|
|
|
|
@ -217,38 +215,32 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 前端保存
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/add")
|
|
|
|
|
@RequestMapping("/add") // 设置请求路径为/add
|
|
|
|
|
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
|
|
|
|
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
|
|
|
|
|
//ValidatorUtils.validateEntity(yonghu);
|
|
|
|
|
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao()));
|
|
|
|
|
if(u!=null) {
|
|
|
|
|
return R.error("用户已存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yonghu.setId(new Date().getTime());
|
|
|
|
|
yonghuService.insert(yonghu);
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/update")
|
|
|
|
|
@Transactional
|
|
|
|
|
@RequestMapping("/update") // 设置请求路径为/update
|
|
|
|
|
@Transactional // 开启事务
|
|
|
|
|
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
|
|
|
|
|
//ValidatorUtils.validateEntity(yonghu);
|
|
|
|
|
yonghuService.updateById(yonghu);//全部更新
|
|
|
|
|
return R.ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/delete")
|
|
|
|
|
@RequestMapping("/delete") // 设置请求路径为/delete
|
|
|
|
|
public R delete(@RequestBody Long[] ids){
|
|
|
|
|
yonghuService.deleteBatchIds(Arrays.asList(ids));
|
|
|
|
|
return R.ok();
|
|
|
|
@ -257,7 +249,7 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 提醒接口
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/remind/{columnName}/{type}")
|
|
|
|
|
@RequestMapping("/remind/{columnName}/{type}") // 设置请求路径为/remind/{columnName}/{type}
|
|
|
|
|
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
|
|
|
|
|
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
|
|
|
|
|
map.put("column", columnName);
|
|
|
|
@ -292,21 +284,14 @@ public class YonghuController {
|
|
|
|
|
wrapper.le(columnName, map.get("remindend"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int count = yonghuService.selectCount(wrapper);
|
|
|
|
|
return R.ok().put("count", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (按值统计)
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/value/{xColumnName}/{yColumnName}")
|
|
|
|
|
@RequestMapping("/value/{xColumnName}/{yColumnName}") // 设置请求路径为/value/{xColumnName}/{yColumnName}
|
|
|
|
|
public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName,HttpServletRequest request) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("xColumn", xColumnName);
|
|
|
|
@ -327,7 +312,7 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* (按值统计)时间统计类型
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}")
|
|
|
|
|
@RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}") // 设置请求路径为/value/{xColumnName}/{yColumnName}/{timeStatType}
|
|
|
|
|
public R valueDay(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,HttpServletRequest request) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("xColumn", xColumnName);
|
|
|
|
@ -349,7 +334,7 @@ public class YonghuController {
|
|
|
|
|
/**
|
|
|
|
|
* 分组统计
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/group/{columnName}")
|
|
|
|
|
@RequestMapping("/group/{columnName}") // 设置请求路径为/group/{columnName}
|
|
|
|
|
public R group(@PathVariable("columnName") String columnName,HttpServletRequest request) {
|
|
|
|
|
Map<String, Object> params = new HashMap<String, Object>();
|
|
|
|
|
params.put("column", columnName);
|
|
|
|
@ -366,18 +351,13 @@ public class YonghuController {
|
|
|
|
|
return R.ok().put("data", result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 总数量
|
|
|
|
|
*/
|
|
|
|
|
@RequestMapping("/count")
|
|
|
|
|
@RequestMapping("/count") // 设置请求路径为/count
|
|
|
|
|
public R count(@RequestParam Map<String, Object> params,YonghuEntity yonghu, HttpServletRequest request){
|
|
|
|
|
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
|
|
|
|
|
int count = yonghuService.selectCount(MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
|
|
|
|
|
return R.ok().put("data", count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|