pull/2/head
2593162056@qq.com 9 months ago
parent 3cb4760892
commit e43f48d102

@ -39,7 +39,6 @@ import com.utils.MD5Util;
import com.utils.MPUtil; import com.utils.MPUtil;
import com.utils.CommonUtil; import com.utils.CommonUtil;
/** /**
* *
* *
@ -47,68 +46,66 @@ import com.utils.CommonUtil;
* @email * @email
* @date 2023-02-21 09:46:06 * @date 2023-02-21 09:46:06
*/ */
@RestController // 标记这是一个REST控制器 @RestController
@RequestMapping("/yonghu") // 设置请求路径的前缀为/yonghu @RequestMapping("/yonghu")
public class YonghuController { public class YonghuController {
@Autowired @Autowired
private YonghuService yonghuService; // 自动注入YonghuService服务 private YonghuService yonghuService;
@Autowired
private TokenService tokenService; // 自动注入TokenService服务
/**
*
*/
@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);
}
/**
@Autowired
private TokenService tokenService;
/**
*
*/
@IgnoreAuth
@RequestMapping(value = "/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("账号或密码不正确");
}
String token = tokenService.generateToken(u.getId(), username,"yonghu", "用户" );
return R.ok().put("token", token);
}
/**
* *
*/ */
@IgnoreAuth // 忽略权限验证 @IgnoreAuth
@RequestMapping("/register") // 设置请求路径为/register @RequestMapping("/register")
public R register(@RequestBody YonghuEntity yonghu){ public R register(@RequestBody YonghuEntity yonghu){
// 检查用户是否已存在 //ValidatorUtils.validateEntity(yonghu);
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao())); YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao()));
if(u!=null) { if(u!=null) {
return R.error("注册用户已存在"); return R.error("注册用户已存在");
} }
// 生成用户ID并插入用户数据 Long uId = new Date().getTime();
Long uId = new Date().getTime(); yonghu.setId(uId);
yonghu.setId(uId);
yonghuService.insert(yonghu); yonghuService.insert(yonghu);
return R.ok(); return R.ok();
} }
/**
* 退
*/
@RequestMapping("/logout") // 设置请求路径为/logout
public R logout(HttpServletRequest request) {
// 使当前会话失效
request.getSession().invalidate();
return R.ok("退出成功");
}
/** /**
* 退
*/
@RequestMapping("/logout")
public R logout(HttpServletRequest request) {
request.getSession().invalidate();
return R.ok("退出成功");
}
/**
* session * session
*/ */
@RequestMapping("/session") // 设置请求路径为/session @RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){ public R getCurrUser(HttpServletRequest request){
// 从session中获取用户ID Long id = (Long)request.getSession().getAttribute("userId");
Long id = (Long)request.getSession().getAttribute("userId");
// 根据ID查询用户信息
YonghuEntity u = yonghuService.selectById(id); YonghuEntity u = yonghuService.selectById(id);
return R.ok().put("data", u); return R.ok().put("data", u);
} }
@ -116,72 +113,72 @@ public class YonghuController {
/** /**
* *
*/ */
@IgnoreAuth // 忽略权限验证 @IgnoreAuth
@RequestMapping(value = "/resetPass") // 设置请求路径为/resetPass @RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){ public R resetPass(String username, HttpServletRequest request){
// 根据用户名查询用户 YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", username));
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", username)); if(u==null) {
if(u==null) { return R.error("账号不存在");
return R.error("账号不存在"); }
}
// 重置密码为123456
u.setMima("123456"); u.setMima("123456");
yonghuService.updateById(u); yonghuService.updateById(u);
return R.ok("密码已重置为123456"); return R.ok("密码已重置为123456");
} }
/** /**
* *
*/ */
@RequestMapping("/page") // 设置请求路径为/page @RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,YonghuEntity yonghu, public R page(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
HttpServletRequest request){ HttpServletRequest request){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>(); EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 分页查询用户列表
PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params)); PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
request.setAttribute("data", page); request.setAttribute("data", page);
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
*/ */
@IgnoreAuth // 忽略权限验证 @IgnoreAuth
@RequestMapping("/list") // 设置请求路径为/list @RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,YonghuEntity yonghu, public R list(@RequestParam Map<String, Object> params,YonghuEntity yonghu,
HttpServletRequest request){ HttpServletRequest request){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>(); EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
// 分页查询用户列表
PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params)); PageUtils page = yonghuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
request.setAttribute("data", page); request.setAttribute("data", page);
return R.ok().put("data", page); return R.ok().put("data", page);
} }
/** /**
* *
*/ */
@RequestMapping("/lists") // 设置请求路径为/lists @RequestMapping("/lists")
public R list( YonghuEntity yonghu){ public R list( YonghuEntity yonghu){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>(); EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu")); ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
return R.ok().put("data", yonghuService.selectListView(ew)); return R.ok().put("data", yonghuService.selectListView(ew));
} }
/** /**
* *
*/ */
@RequestMapping("/query") // 设置请求路径为/query @RequestMapping("/query")
public R query(YonghuEntity yonghu){ public R query(YonghuEntity yonghu){
EntityWrapper< YonghuEntity> ew = new EntityWrapper< YonghuEntity>(); EntityWrapper< YonghuEntity> ew = new EntityWrapper< YonghuEntity>();
ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu")); ew.allEq(MPUtil.allEQMapPre( yonghu, "yonghu"));
YonghuView yonghuView = yonghuService.selectView(ew); YonghuView yonghuView = yonghuService.selectView(ew);
return R.ok("查询用户成功").put("data", yonghuView); return R.ok("查询用户成功").put("data", yonghuView);
} }
/** /**
* *
*/ */
@RequestMapping("/info/{id}") // 设置请求路径为/info/{id} @RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){ public R info(@PathVariable("id") Long id){
YonghuEntity yonghu = yonghuService.selectById(id); YonghuEntity yonghu = yonghuService.selectById(id);
return R.ok().put("data", yonghu); return R.ok().put("data", yonghu);
@ -190,24 +187,29 @@ public class YonghuController {
/** /**
* *
*/ */
@IgnoreAuth // 忽略权限验证 @IgnoreAuth
@RequestMapping("/detail/{id}") // 设置请求路径为/detail/{id} @RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){ public R detail(@PathVariable("id") Long id){
YonghuEntity yonghu = yonghuService.selectById(id); YonghuEntity yonghu = yonghuService.selectById(id);
return R.ok().put("data", yonghu); return R.ok().put("data", yonghu);
} }
/** /**
* *
*/ */
@RequestMapping("/save") // 设置请求路径为/save @RequestMapping("/save")
public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){ public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao())); //ValidatorUtils.validateEntity(yonghu);
if(u!=null) { YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao()));
return R.error("用户已存在"); if(u!=null) {
} return R.error("用户已存在");
yonghu.setId(new Date().getTime()); }
yonghu.setId(new Date().getTime());
yonghuService.insert(yonghu); yonghuService.insert(yonghu);
return R.ok(); return R.ok();
} }
@ -215,32 +217,38 @@ public class YonghuController {
/** /**
* *
*/ */
@RequestMapping("/add") // 设置请求路径为/add @RequestMapping("/add")
public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){ public R add(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue()); yonghu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao())); //ValidatorUtils.validateEntity(yonghu);
if(u!=null) { YonghuEntity u = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("zhanghao", yonghu.getZhanghao()));
return R.error("用户已存在"); if(u!=null) {
} return R.error("用户已存在");
yonghu.setId(new Date().getTime()); }
yonghu.setId(new Date().getTime());
yonghuService.insert(yonghu); yonghuService.insert(yonghu);
return R.ok(); return R.ok();
} }
/** /**
* *
*/ */
@RequestMapping("/update") // 设置请求路径为/update @RequestMapping("/update")
@Transactional // 开启事务 @Transactional
public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){ public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
//ValidatorUtils.validateEntity(yonghu);
yonghuService.updateById(yonghu);//全部更新 yonghuService.updateById(yonghu);//全部更新
return R.ok(); return R.ok();
} }
/** /**
* *
*/ */
@RequestMapping("/delete") // 设置请求路径为/delete @RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){ public R delete(@RequestBody Long[] ids){
yonghuService.deleteBatchIds(Arrays.asList(ids)); yonghuService.deleteBatchIds(Arrays.asList(ids));
return R.ok(); return R.ok();
@ -249,49 +257,56 @@ public class YonghuController {
/** /**
* *
*/ */
@RequestMapping("/remind/{columnName}/{type}") // 设置请求路径为/remind/{columnName}/{type} @RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request, public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) { @PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName); map.put("column", columnName);
map.put("type", type); map.put("type", type);
if(type.equals("2")) { if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
Date remindStartDate = null; Date remindStartDate = null;
Date remindEndDate = null; Date remindEndDate = null;
if(map.get("remindstart")!=null) { if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString()); Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart); c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime(); remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate)); map.put("remindstart", sdf.format(remindStartDate));
} }
if(map.get("remindend")!=null) { if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString()); Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd); c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime(); remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate)); map.put("remindend", sdf.format(remindEndDate));
} }
} }
Wrapper<YonghuEntity> wrapper = new EntityWrapper<YonghuEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = yonghuService.selectCount(wrapper);
return R.ok().put("count", count);
}
Wrapper<YonghuEntity> wrapper = new EntityWrapper<YonghuEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = yonghuService.selectCount(wrapper);
return R.ok().put("count", count);
}
/** /**
* *
*/ */
@RequestMapping("/value/{xColumnName}/{yColumnName}") // 设置请求路径为/value/{xColumnName}/{yColumnName} @RequestMapping("/value/{xColumnName}/{yColumnName}")
public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName,HttpServletRequest request) { public R value(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName,HttpServletRequest request) {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put("xColumn", xColumnName); params.put("xColumn", xColumnName);
@ -312,7 +327,7 @@ public class YonghuController {
/** /**
* *
*/ */
@RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}") // 设置请求路径为/value/{xColumnName}/{yColumnName}/{timeStatType} @RequestMapping("/value/{xColumnName}/{yColumnName}/{timeStatType}")
public R valueDay(@PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName, @PathVariable("timeStatType") String timeStatType,HttpServletRequest request) { 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>(); Map<String, Object> params = new HashMap<String, Object>();
params.put("xColumn", xColumnName); params.put("xColumn", xColumnName);
@ -334,7 +349,7 @@ public class YonghuController {
/** /**
* *
*/ */
@RequestMapping("/group/{columnName}") // 设置请求路径为/group/{columnName} @RequestMapping("/group/{columnName}")
public R group(@PathVariable("columnName") String columnName,HttpServletRequest request) { public R group(@PathVariable("columnName") String columnName,HttpServletRequest request) {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put("column", columnName); params.put("column", columnName);
@ -351,13 +366,18 @@ public class YonghuController {
return R.ok().put("data", result); return R.ok().put("data", result);
} }
/** /**
* *
*/ */
@RequestMapping("/count") // 设置请求路径为/count @RequestMapping("/count")
public R count(@RequestParam Map<String, Object> params,YonghuEntity yonghu, HttpServletRequest request){ public R count(@RequestParam Map<String, Object> params,YonghuEntity yonghu, HttpServletRequest request){
EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>(); EntityWrapper<YonghuEntity> ew = new EntityWrapper<YonghuEntity>();
int count = yonghuService.selectCount(MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params)); int count = yonghuService.selectCount(MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yonghu), params), params));
return R.ok().put("data", count); return R.ok().put("data", count);
} }
} }

Loading…
Cancel
Save