作者主页:源码空间站2022
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
管理员角色包含以下功能:
管理员登录,部门管理,员工管理,银行工资发放,工资设置,缴税设置,出勤管理,奖励与罚款,个人信息查看等功能。
由于本程序规模不大,可供课程设计,毕业设计学习演示之用
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
技术栈
HTML+CSS+JavaScript+jsp+mysql
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/login.jsp 登录
运行截图
相关代码
登录控制器
/**
* @Description: 管理员和员工登陆控制
**/
@Controller
public class LoginController {
@Autowired
private LoginServiceImpl loginService = null;
/**
* @Author: admin
* @Description:
* @Param: [request, response]
* @Return: void
**/
//获取验证码
@RequestMapping(value = "/changeCode.do")
@ResponseBody
public void getIdentifyingCode(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// 验证码存储在session的identifyingCode,属性中
CaptchaUtil.outputCaptcha(request, response);
}
// 获取员工登陆界面
@RequestMapping("/")
public String getLoginPage(){
return "employee/login.html";
}
// 获取管理员登陆界面
@RequestMapping("/admin.do")
public String getAdminLoginPage(){
return "admin/adminLogin.html";
}
//员工登录判断
@RequestMapping(value = "/employeeLogin.do")
@ResponseBody
public Map<String,String> employeeLogin(Model model, HttpSession httpSession, String username,
String password, String identifyingcode)
{
String code = (String) httpSession.getAttribute("identifyingCode");
HashMap<String, String> map = new HashMap<String, String>();
if(identifyingcode.equalsIgnoreCase(code)){
Employee employee = null;
try {
employee = loginService.findEmployeeByIdAndPassword(username, password);
} catch (CustomException e) {
map.put("msg",e.getMessage());
map.put("status","500");
return map;
}
// 保存到session
httpSession.setAttribute("employeeId",employee.geteId());
map.put("url","/ssm_esms/loginSuccess.do");
map.put("msg","成功");
map.put("status","200");
return map;
}else{
map.put("msg","验证码错误");
map.put("status","0");
return map;
}
}
@RequestMapping(value = "/loginSuccess.do")
public String loginSucceses(Model model) throws Exception
{
return "employee/index.html";
}
//管理员登录判断
@RequestMapping(value = "/adminLogin.do")
@ResponseBody
public Map<String,String> adminLogin(Model model, HttpSession httpSession, String username,
String password, String identifyingcode)
{
String code = (String) httpSession.getAttribute("identifyingCode");
HashMap<String, String> map = new HashMap<String, String>();
if(identifyingcode.equalsIgnoreCase(code)){
SystemManager manager = null;
try {
manager = loginService.findSystemManagerByIdAndPassword(username, password);
} catch (CustomException e) {
map.put("msg",e.getMessage());
map.put("status","500");
return map;
}
// 保存到session
httpSession.setAttribute("admin",manager);
map.put("url","toPage.do?url=admin/index.html");
map.put("msg","成功");
map.put("status","200");
return map;
}else{
map.put("msg","验证码错误");
map.put("status","0");
return map;
}
}
@RequestMapping(value = "/getAdminAccount.do")
@ResponseBody
public String getAdminAccount(HttpSession httpSession){
SystemManager systemManager = (SystemManager) httpSession.getAttribute("admin");
// SystemManager manager = loginService.findSystemManagerById(id);
return systemManager.getSmAccount();
}
@RequestMapping(value = "/getEmployeeAccount.do")
@ResponseBody
public Map<String,String> getEmployeeAccount(HttpSession httpSession){
Integer id = (Integer) httpSession.getAttribute("employeeId");
Employee employee = loginService.findEmployeeById(id);
HashMap<String, String> map = new HashMap<String, String>();
map.put("account",employee.geteAccount());
map.put("name",employee.geteName());
return map;
}
@RequestMapping(value = "/logout.do")
public String logout(HttpSession httpSession){
httpSession.removeAttribute("employeeId");
return "redirect:/";
}
@RequestMapping(value = "/logoutAdmin.do")
public String logoutAdmin(HttpSession httpSession){
httpSession.removeAttribute("admin");
return "redirect:/admin.do";
}
}
部门管理控制器
@Controller
@RequestMapping("/position")
public class PositionController {
@Autowired
public PositionService positionService = null;
/**
*
* @param pageNum
* @param limit
* @param p_name
* @return
* @throws Exception
*/
@RequestMapping("findSelective.do")
@ResponseBody
public PositionPages findSelective(
@RequestParam(value="page", defaultValue="1") int pageNum,
@RequestParam(value="limit", defaultValue="5") int limit,
@RequestParam(value="p_name", defaultValue="") String p_name) throws Exception {
List<Position> list;
//模糊查询,有多少个条件就接收多少个字段
Position position = new Position();
position.setpName(p_name);
//pageNum:起始页面 pageSize:每页的大小
PageHelper.startPage(pageNum,limit);
//查找条件,一定要紧跟在startPage后
list = positionService.findSelective(position);
PageInfo pageResult = new PageInfo(list);
//设置前台需要的数据
PositionPages positionPages = new PositionPages();
positionPages.setCode(0);
positionPages.setMsg("");
positionPages.setCount((int)pageResult.getTotal());
positionPages.setData(pageResult.getList());
return positionPages;
}
/**
* 添加
* @param p_name
* @param p_duty
* @param p_post_pay
* @return
* @throws Exception
*/
@RequestMapping("/add.do")
@ResponseBody
public int add(String p_name, String p_duty, Double p_post_pay) throws Exception {
Position position = positionService.findByDname(p_name);
//查找是否同名
if(position != null) {
return position.getpId();
} else {
Position p = new Position();
p.setpId(null);
p.setpName(p_name);
p.setpDuty(p_duty);
p.setpPostPay(p_post_pay);
p.setpIsdel(1);
positionService.insertSelective(p);
return 0;
}
}
/**
* 查找一个
* @param id
* @return
* @throws Exception
*/
@RequestMapping("/findByPrimaryKey.do")
@ResponseBody
public Position findByPrimaryKey(int id) throws Exception {
Position position = positionService.findByPrimaryKey(id);
return position;
}
/**
* 更新
* @param id
* @param p_name
* @param p_duty
* @param p_post_pay
* @throws Exception
*/
@RequestMapping("/updateByPrimaryKey.do")
@ResponseBody
public int updateByPrimaryKey(int id, String p_name, String p_duty, Double p_post_pay) throws Exception {
Position position = positionService.findByDname(p_name);
System.out.println(p_name);
System.out.println(position);
System.out.println(position != null && !position.getpName().equals(p_name));
//有同名的且不是同一个
if(position != null && !position.getpId().equals(id) ) {
return position.getpId();
} else {
Position p = new Position();
p.setpId(id);
p.setpName(p_name);
p.setpDuty(p_duty);
p.setpPostPay(p_post_pay);
p.setpIsdel(null);
positionService.updateByPrimaryKeySelective(p);
return 0;
}
}
/**
* 根据名称查找
* @param p_name
* @return
*/
@RequestMapping("/findByDname.do")
@ResponseBody
public int findByDname(String p_name) {
Position position = positionService.findByDname(p_name);
if(position != null) {
return position.getpId();
} else {
return 0;
}
}
/**
* 删除一个
* @param id
* @throws Exception
*/
@RequestMapping("/deleteByPrimaryKey.do")
@ResponseBody
public int deleteByPrimaryKey(int id) throws Exception {
//删除部门,调用更新操作,将状态改为0
Position position = new Position();
position.setpId(id);
positionService.deleteByPrimaryKey(id);
return 1;
}
/**
* 批量删除
* @param ids
*/
@RequestMapping("/deleteByQuery.do")
public void deleteByQuery (@RequestParam(value = "arr")int[] ids) {
//批量删除,实则修改状态为0
//如果有id才执行
if(ids.length > 0) {
positionService.deleteByQuery(ids);
}
}
}
工资控制器
@Controller
public class SalaryController {
@Autowired
private SalaryServiceImpl salaryService = null;
@RequestMapping("salarySettlementByAcount.do")
@ResponseBody
public Map<String, String> salarySettlementByAcount(String eAccount, String date) {
Map<String, String> stringMap = new HashMap<String, String>();
try {
salaryService.insertSalaryByAcountAndDate(eAccount, date);
stringMap.put("msg", "工资结算完成");
return stringMap;
} catch (CustomException e) {
stringMap.put("msg", e.getMessage());
return stringMap;
}
}
@RequestMapping("salarySettlementAll.do")
@ResponseBody
public Map<String, String> salarySettlementAll(String date) {
Map<String, String> stringMap = new HashMap<String, String>();
try {
salaryService.insertSalaryAllByDate(date);
stringMap.put("msg", "工资结算完成");
return stringMap;
} catch (CustomException e) {
stringMap.put("msg", e.getMessage());
return stringMap;
}
}
// 删除工资项目
@RequestMapping("deleteSalaryByEid.do")
@ResponseBody
public int deleteSalaryByEid(@RequestParam(value = "arr")int[] ids) {
salaryService.deleteSalaryByEid(ids);
return 1;
}
// 发放工资项目
@RequestMapping("issueSalaryByEid.do")
@ResponseBody
public void issueSalaryByEid(@RequestParam(value = "arr")int[] ids) {
salaryService.updateSalaryBySid(ids);
}
@RequestMapping(value = "selectSalaryByEaccountDIdDate.do",
produces = "application/json;charset=utf-8")
@ResponseBody
public String selectSalaryByEaccountDIdDate(@RequestParam(value = "page", defaultValue = "1") int pageNum,
@RequestParam(value = "limit", defaultValue = "5") int limit,
String eAccount, Integer dId, String sTime) {
/**
* @Author: 方宏泰
* @Description: 工资查询
* @Date: 12:37 2020/02/11
* @Param: [pageNum , limit, eAccount, dId, sTime]
* @Return: java.lang.String
**/
SalaryPages salaryPages = salaryService.selectSalaryByEaccountDIdDate(pageNum, limit, eAccount, dId, sTime);
//使用fastjson以字符串形式返回数据
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
return JSON.toJSONString(salaryPages, SerializerFeature.WriteDateUseDateFormat);
}
@RequestMapping(value = "selectSalaryByEaccountDIdDateState.do",
produces = "application/json;charset=utf-8")
@ResponseBody
public String selectSalaryByEaccountDIdDateState(@RequestParam(value = "page", defaultValue = "1") int pageNum,
@RequestParam(value = "limit", defaultValue = "5") int limit,
String eAccount, Integer dId, String sTime) {
SalaryPages salaryPages = salaryService.selectSalaryByEaccountDIdDateState(pageNum, limit, eAccount, dId, sTime);
//使用fastjson以字符串形式返回数据
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
return JSON.toJSONString(salaryPages, SerializerFeature.WriteDateUseDateFormat);
}
@RequestMapping(value = "updateSalaryByEidAndRissuePay.do")
@ResponseBody
public void updateSalaryByEidAndRissuePay(int sId, double rissuePay) {
salaryService.updateSalaryByEidAndRissuePay(sId, rissuePay);
}
}
如果也想学习本系统,下面领取。关注并回复:072jsp