SysAdminController
Posted Roam-G
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SysAdminController相关的知识,希望对你有一定的参考价值。
package com.mabang.controller.config;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONArray;
import com.mabang.entity.base.ResultCode;
import com.mabang.entity.config.TbEmployee;
import com.mabang.entity.config.TbRole;
import com.mabang.entity.config.TbSysAdmin;
import com.mabang.entity.config.TbWarehouse;
import com.mabang.entity.config.modal.SaveEmployee;
import com.mabang.entity.config.modal.SearchEmployee;
import com.mabang.entity.config.modal.UpdateEmployeePassword;
import com.mabang.entity.log.TbSyslog;
import com.mabang.entity.login.CacheEmployee;
import com.mabang.exceptionHandler.CommonEnum;
import com.mabang.service.config.EmployeeService;
import com.mabang.service.config.SysAdminService;
import com.mabang.service.config.TbRoleService;
import com.mabang.service.config.WarehouseService;
import com.mabang.service.log.TbSyslogService;
import com.mabang.util.Sys;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.util.StringUtil;
@Api(value="员工管理",tags="员工管理")
@RestController
public class SysAdminController
@Autowired
private SysAdminService sysAdminService;
@Autowired
private TbSyslogService syslogService;
@Autowired
private TbRoleService roleService;
@Autowired
private WarehouseService warehouseService;
@RequestMapping(value="/updateSysadminPassword",method=RequestMethod.POST)
@ApiOperation(value="修改马帮系统管理员密码")
@ApiImplicitParams(
@ApiImplicitParam(name="employee",value="传入的参数",required=false,paramType="body",dataType="UpdateEmployeePassword")
)
public ResultCode<TbEmployee> updateSysadminPassword(@RequestBody UpdateEmployeePassword employee)
ResultCode<TbEmployee> rc = new ResultCode<>();
//从缓存获取登录信息
CacheEmployee ce = (CacheEmployee) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
//如果该员工不是服务商
if(ce == null)
rc.setCode(CommonEnum.NO_PERMISSION.getCode());
rc.setMsg(CommonEnum.NO_PERMISSION.getMsg());
return rc;
if(ce == null || 2 == ce.getUserType())
rc.setCode(CommonEnum.NO_PERMISSION.getCode());
rc.setMsg("没有权限");
return rc;
try
//1.判断原始密码是否正确
Map<String, Object> params_find = new HashMap<String, Object>();
params_find.put("ordertables", "tb_sys_admin");
params_find.put("ids", Sys.isCheckNull(employee.getId()));
params_find.put("findallparams", "all");
List<TbSysAdmin> sysAdminList = sysAdminService.findSysAdmin(params_find);
if(sysAdminList == null || sysAdminList.size() <= 0)
rc.setCode(CommonEnum.NO_DATA.getCode());
rc.setMsg("账号不存在");
else
//TbSysAdmin sysAdmin = sysAdminList.get(0);//用ids只能查出1条记录
//2.判断新密码和确认密码是否相等
if (employee.getNewPassword1().equals(employee.getNewPassword2()))
Map<String, Object> params_update = new HashMap<String, Object>();
params_update.put("ordertables", "tb_sys_admin");
params_update.put("ids", Sys.isCheckNull(employee.getId()));
params_update.put("pass_word",Sys.getMD5(employee.getNewPassword1(),"UTF-8"));
sysAdminService.updateSysAdmin(params_update);
rc.setCode(CommonEnum.SUCCESS.getCode());
rc.setMsg("密码修改成功");
//保存日志
try
TbSyslog log = new TbSyslog();
log.setSupplierId(0);
log.setTitle("修改密码");
log.setContent("修改密码");
log.setServiceType(5);
log.setOperType(1);
log.setOperId(ce.getId());
log.setOper(ce.getEmployeeName());
log.setOperTime(new Date());
log.setIpAdress(ce.getIpaddress());
try
log.setWarehouseid(Sys.isCheckNull(ce.getWarehouseId()));
catch(Exception e) ;
syslogService.save(log);
catch(Exception e)
System.out.println("保存TbSyslog日志Exception:"+e.getMessage());
else
rc.setCode(CommonEnum.BODY_NOT_MATCH.getCode());
rc.setMsg("两次新密码不一致");
//end if
//end if
catch (SQLException e)
rc.setCode(CommonEnum.SQL_EXCEPTION.getCode());
rc.setMsg("SQLException:"+e.getMessage());
catch (Exception e)
rc.setCode(CommonEnum.OTHER_EXCEPTION.getCode());
rc.setMsg("Exception:"+e.getMessage());
return rc;
以上是关于SysAdminController的主要内容,如果未能解决你的问题,请参考以下文章