package com.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.YuangongEntity;
import com.entity.view.YuangongView;
import com.service.YuangongService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.CommonUtil;
/**
* 员工
* 后端接口
* @author
* @email
* @date 2021-03-22 17:32:51
*/
@RestController
@RequestMapping("/yuangong")
public class YuangongController {
@Autowired
private YuangongService yuangongService;
@Autowired
private TokenService tokenService;
/**
* 登录
*/
@IgnoreAuth
@RequestMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
YuangongEntity user = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("gonghao", username));
if(user==null || !user.getMima().equals(password)) {
return R.error("账号或密码不正确");
}
String token = tokenService.generateToken(user.getId(), username,"yuangong", "员工" );
return R.ok().put("token", token);
}
/**
* 注册
*/
@IgnoreAuth
@RequestMapping("/register")
public R register(@RequestBody YuangongEntity yuangong){
//ValidatorUtils.validateEntity(yuangong);
YuangongEntity user = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("gonghao", yuangong.getGonghao()));
if(user!=null) {
return R.error("注册用户已存在");
}
Long uId = new Date().getTime();
yuangong.setId(uId);
yuangongService.insert(yuangong);
return R.ok();
}
/**
* 退出
*/
@RequestMapping("/logout")
public R logout(HttpServletRequest request) {
request.getSession().invalidate();
return R.ok("退出成功");
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
YuangongEntity user = yuangongService.selectById(id);
return R.ok().put("data", user);
}
/**
* 密码重置
*/
@IgnoreAuth
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){
YuangongEntity user = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("gonghao", username));
if(user==null) {
return R.error("账号不存在");
}
user.setMima("123456");
yuangongService.updateById(user);
return R.ok("密码已重置为:123456");
}
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,YuangongEntity yuangong,
HttpServletRequest request){
EntityWrapper<YuangongEntity> ew = new EntityWrapper<YuangongEntity>();
PageUtils page = yuangongService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yuangong), params), params));
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,YuangongEntity yuangong, HttpServletRequest request){
EntityWrapper<YuangongEntity> ew = new EntityWrapper<YuangongEntity>();
PageUtils page = yuangongService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yuangong), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/lists")
public R list( YuangongEntity yuangong){
EntityWrapper<YuangongEntity> ew = new EntityWrapper<YuangongEntity>();
ew.allEq(MPUtil.allEQMapPre( yuangong, "yuangong"));
return R.ok().put("data", yuangongService.selectListView(ew));
}
/**
* 查询
*/
@RequestMapping("/query")
public R query(YuangongEntity yuangong){
EntityWrapper< YuangongEntity> ew = new EntityWrapper< YuangongEntity>();
ew.allEq(MPUtil.allEQMapPre( yuangong, "yuangong"));
YuangongView yuangongView = yuangongService.selectView(ew);
return R.ok("查询员工成功").put("data", yuangongView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
YuangongEntity yuangong = yuangongService.selectById(id);
return R.ok().put("data", yuangong);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
YuangongEntity yuangong = yuangongService.selectById(id);
return R.ok().put("data", yuangong);
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
yuangong.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(yuangong);
YuangongEntity user = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("gonghao", yuangong.getGonghao()));
if(user!=null) {
return R.error("用户已存在");
}
yuangong.setId(new Date().getTime());
yuangongService.insert(yuangong);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
yuangong.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(yuangong);
YuangongEntity user = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("gonghao", yuangong.getGonghao()));
if(user!=null) {
return R.error("用户已存在");
}
yuangong.setId(new Date().getTime());
yuangongService.insert(yuangong);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
//ValidatorUtils.validateEntity(yuangong);
yuangongService.updateById(yuangong);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
yuangongService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/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);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remind
gdutxiaoxu
- 粉丝: 1546
- 资源: 3523
最新资源
- 基于重复控制的单相桥式逆变系统设计仿真研究:Simulink仿真应用与性能分析,#Simulink仿真#基于重复控制的单相桥式逆变系统设计仿真 ,核心关键词:Simulink仿真; 重复控制; 单相桥
- 飞常准航班统计国际航线按机场内地机场总计划航班量20190101-20250101日度数据.xlsx
- 飞常准航班统计国际航线按机场内地机场总执行航班量20190101-20250101日度数据.xlsx
- 飞常准航班统计国际航线按机场内地机场总取消航班量20190101-20250101日度数据.xlsx
- 飞常准航班统计国际航线按机场内地机场总取消率20190101-20250101日度数据.xlsx
- 基于28035芯片的同步机无传感滑膜观测器模型与代码实现:典型smo+pll方案,实际应用级可比性,含simulink模型,一个同步机无传感滑膜观测器模型加代码,该模型基于28035芯片,采用了典型的
- 基于电子病历的疾病风险预测.pdf
- 电力系统故障分析与短路类型解析:从短路电流波形到中性点小电流接地故障定位模拟研究,电力系统故障点分析,短路类型分析,中性点小电流接地 不接地故障分析,故障点定位,可模拟三相变压器三相短路、单相短路、两
- 西门子SMART LINE触摸屏实现与ABB 510变频器直接通讯的程序设计与应用,西门子SMART LINE触摸屏485直接通讯ABB 510程序 实例采用V3触摸屏,485通讯方式,可以控制ABB
- STm32锅炉控制项目:从C原程序到实际应用的全方位教程,涵盖多路AD、Modbus、CRC等关键技术,STm32真实项目程序 c原程序,有电路图,PcB (AD工程),适合没有参加工作或初学STm
- 三菱FX3U精准控制配料系统:配方多样化、智能监控与数据传输功能一体化,三菱FX3U,用ST语言与梯形图,混合编写的16仓位的配方程序,程序大小约12984步,可以配1到16种不同的产品,16种配方可
- 基于Matlab的卡尔曼滤波语音去噪程序:对含有人为噪声的语音信号进行滤波处理,matlab,基于卡尔曼滤波的语音处理程序,针对现有语音信号,人为添加噪声,使用卡尔曼滤波器对其噪声进行滤波,达到语音去
- 基于形态学的权重自适应图像去噪算法与MATLAB数字图像处理实践:代码工程目录及运行效果展示,基于形态学的权重自适应图像去噪 MATLAB数字图像处理 基于形态学的权重自适应图像去噪 代码工程目录及运
- 电动汽车Simulink仿真模型:整车动力性能仿真与NEDC能耗测试综合平台,电动汽车 simulink仿真模型, 可进行整车动力性仿真测试(最高车速,最大爬坡,加入时间)和NEDC工况能耗测试(电耗
- 经过验证的Verilog串口收发程序,高低温环境下稳定传输数据,遵循特定的帧格式 ,Verilog编写的串口收发程序,工作稳定 代码经过实际应用验证,经过高低温等环境实验验证 有需要的可以联系了
- 西门子锂电池项目:PLC程序块集成与对接机器人系统、视觉、MES通信模块 使用STL与LAD编写 ,西门子锂电池项目,1500安全型PLC程序 包含对接雅马哈机器人,视觉,库卡机器人,MES通信程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页