Commit 39b9879a authored by chenying's avatar chenying

3.12:修改模板和用户的接口

parent 6df80164
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.example.tdl.domain.vo;
public class AddUserVo {
private String userNumber;
private String userName;
private String password;
......@@ -13,6 +15,34 @@ public class AddUserVo {
private String roleName;
private Long createTime;
private Long updateTime;
public String getUserNumber() {
return userNumber;
}
public void setUserNumber(String userNumber) {
this.userNumber = userNumber;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
public Long getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Long updateTime) {
this.updateTime = updateTime;
}
public String getUserName() {
return userName;
}
......
......@@ -8,4 +8,6 @@ import java.util.List;
@Mapper
public interface RoleMapper {
List<String> getAllRoleName();
Integer getByRoleName(String roleName);
}
......@@ -15,4 +15,8 @@ public class RoleService {
public List<String> getAllRoleName(){
return roleMapper.getAllRoleName();
}
public Integer getByRoleName(String roleName){
return roleMapper.getByRoleName(roleName);
}
}
......@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.AddModelVo;
import com.example.tdl.domain.vo.UpdateModelVo;
import com.example.tdl.entity.TopicModel;
import com.example.tdl.service.ModelService;
import com.example.tdl.service.ProbesModelService;
import com.example.tdl.service.TopicModelService;
......@@ -23,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
......
......@@ -7,6 +7,7 @@ import com.example.tdl.domain.vo.AddModelInfoVo;
import com.example.tdl.domain.vo.DelModelInfoVo;
import com.example.tdl.domain.vo.ModelInfoTermVo;
import com.example.tdl.service.ModelInfoService;
import com.example.tdl.service.ModelService;
import com.google.gson.Gson;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -33,6 +34,9 @@ public class ModelInfoController {
@Autowired
private ModelInfoService modelInfoService;
@Autowired
private ModelService modelService;
@ApiOperation(value = "查询所有配置模板",notes = "modelName是查询的模板名,查询所有配置模板的返回值对应的意义:" +
" modelName: 模板名," +
......@@ -100,6 +104,11 @@ public class ModelInfoController {
fb.setMessage("需要添加的通道编号不能为空");
return gson.toJson(fb);
}
if (modelService.getByModelName(addModelInfoVo.getModelName())==null){
fb.setCode(0);
fb.setMessage("没有该配置模板");
return gson.toJson(fb);
}
if (modelInfoService.getByPortAndTopicName(new ModelInfoTermVo(addModelInfoVo.getModelName(),addModelInfoVo.getTopicModelName(),
addModelInfoVo.getTopicName(),addModelInfoVo.getProbesModelName(),addModelInfoVo.getPort()))!=null){
fb.setCode(0);
......@@ -154,6 +163,11 @@ public class ModelInfoController {
fb.setMessage("需要删除的通道编号不能为空");
return gson.toJson(fb);
}
if (modelService.getByModelName(delModelInfoVo.getModelName())==null){
fb.setCode(0);
fb.setMessage("没有该配置模板");
return gson.toJson(fb);
}
int a=modelInfoService.delModelInfo(delModelInfoVo);
if (a>0){
fb.setCode(1);
......
......@@ -51,6 +51,11 @@ public class ProbesModelInfoController {
public Object getAll(@RequestBody String probesModelName){
JSONObject jsonObject= JSON.parseObject(probesModelName);
probesModelName=(String) jsonObject.get("probesModelName");
if (StringUtils.isEmpty(probesModelName)){
fb.setCode(0);
fb.setMessage("需要查询的通道模板不能为空");
return gson.toJson(fb);
}
return probesModelInfoService.getAll(probesModelName);
}
......@@ -162,6 +167,12 @@ public class ProbesModelInfoController {
fb.setMessage("需要删除的通道模板编号不能为空");
return gson.toJson(fb);
}
if (probesModelService.getByProbesModelName(delProbesModelInfoVo.getProbesModelName())==null){
fb.setCode(0);
fb.setMessage("需要删除的模板名不存在");
return gson.toJson(fb);
}
Map<String,Object> params=new HashMap<String, Object>();
params.put("probesModelName",delProbesModelInfoVo.getProbesModelName());
params.put("port",delProbesModelInfoVo.getPort());
......@@ -187,7 +198,7 @@ public class ProbesModelInfoController {
//修改单个通道模板
@ApiOperation(value = "修改单个通道模板",notes = "修改单个通道模板,port不能:" +
@ApiOperation(value = "修改单个通道模板",notes = "修改单个通道模板,port不能:" +
" probesModelName: 需要修改的模板名," +
" port: 需要修改的通道模板编号," +
" unit: 通道模板单位," +
......@@ -241,6 +252,11 @@ public class ProbesModelInfoController {
fb.setMessage("通道模板报警下限不能为空");
return gson.toJson(fb);
}
if (probesModelService.getByProbesModelName(resultProbesModelInfoVo.getProbesModelName())==null){
fb.setCode(0);
fb.setMessage("需要修改的模板名不存在");
return gson.toJson(fb);
}
Integer probesModelId=probesModelService.getIdByProbesModel(resultProbesModelInfoVo.getProbesModelName());
ResultProbesModelInfoVo resultAlias=probesModelInfoService.getByAlias(probesModelId,resultProbesModelInfoVo.getAlias());
if (resultAlias!=null&&resultAlias.getPort()!=resultProbesModelInfoVo.getPort()){
......
......@@ -7,9 +7,7 @@ import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.AddRouteVo;
import com.example.tdl.domain.vo.RouteTermVo;
import com.example.tdl.domain.vo.UpdateRouteVo;
import com.example.tdl.domain.vo.UserVo;
import com.example.tdl.entity.Route;
import com.example.tdl.service.RoleService;
import com.example.tdl.service.RouteService;
import com.example.tdl.service.TokenRedisService;
import com.google.gson.Gson;
......@@ -17,7 +15,6 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -26,9 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@RestController
......
......@@ -110,6 +110,11 @@ public class TopicModelInfoController {
fb.setMessage("添加模板的主题名不能相同");
return gson.toJson(fb);
}
if (topicModelService.getByTopicModelName(topicModelInfoVo.getTopicModelName())==null){
fb.setCode(0);
fb.setMessage("没有该主题模板");
return gson.toJson(fb);
}
int a=topicModelInfoService.addTopicModelInfo(topicModelInfoVo);
if (a>0){
fb.setCode(1);
......@@ -168,6 +173,11 @@ public class TopicModelInfoController {
fb.setMessage("修改的主题名不能相同");
return gson.toJson(fb);
}
if (topicModelService.getByTopicModelName(updateTopicModelInfoVo.getTopicModelName())==null){
fb.setCode(0);
fb.setMessage("没有该主题模板");
return gson.toJson(fb);
}
int a=topicModelInfoService.updateTopicModelInfo(updateTopicModelInfoVo);
if (a>0){
fb.setCode(1);
......@@ -200,6 +210,11 @@ public class TopicModelInfoController {
fb.setMessage("删除的主题名不能为空");
return gson.toJson(fb);
}
if (topicModelService.getByTopicModelName(delTopicModelInfoVo.getTopicModelName())==null){
fb.setCode(0);
fb.setMessage("没有该主题模板");
return gson.toJson(fb);
}
try {
Map<String,Object> map=new HashMap<>();
map.put("topicModelName",delTopicModelInfoVo.getTopicModelName());
......
......@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.*;
import com.example.tdl.service.RoleHasPermissionService;
import com.example.tdl.service.RoleService;
import com.example.tdl.service.TokenRedisService;
import com.example.tdl.service.UserService;
import com.google.gson.Gson;
......@@ -42,6 +43,9 @@ public class UserController {
@Autowired
private TokenRedisService tokenRedisService;
@Autowired
private RoleService roleService;
//获取所有用户信息
@ApiOperation(value = "获取所有用户信息",notes = "获取所有用户信息")
......@@ -49,17 +53,9 @@ public class UserController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/getAll",method = RequestMethod.GET)
public Object getAll(HttpServletRequest request){
UserRedisVo user = gson.fromJson(tokenRedisService.get("TOKEN_" +request.getHeader("Account_token")),UserRedisVo.class);
List<String> permission=roleHasPermissionService.getByRoleName(user.getRoleName());
if (!permission.contains("用户列表")){
fb.setCode(0);
fb.setMessage("对不起,您没有此权限");
return gson.toJson(fb);
}else{
public Object getAll(){
return userService.getAll();
}
}
//根据条件查询
@ApiOperation(value = "根据条件查询",notes = "根据条件查询")
......@@ -68,21 +64,11 @@ public class UserController {
})
@RequestMapping(value="/getByTerm",method = RequestMethod.POST)
public Object getByTerm(@RequestBody UserTermVo userTermVo,HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
List<String> permission=roleHasPermissionService.getByRoleName(user.getRoleName());
if (!permission.contains("用户列表")){
fb.setCode(0);
fb.setMessage("对不起,您没有此权限");
return gson.toJson(fb);
}else{
return userService.getByTerm(userTermVo);
}
}
//新增用户
@ApiOperation(value = "新增用户",notes = "新增用户都要传:" +
@ApiOperation(value = "新增用户",notes = "新增用户时,userNumber,createTime,updateTime不用传。传递参数:" +
" userName:用户名," +
" password:密码," +
" nickName:昵称," +
......@@ -93,16 +79,7 @@ public class UserController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/addUser",method = RequestMethod.POST)
public Object addUser(@RequestBody AddUserVo userVo,HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
List<String> permission=roleHasPermissionService.getByRoleName(user.getRoleName());
if (!permission.contains("用户列表")){
fb.setCode(0);
fb.setMessage("对不起,您没有此权限");
return gson.toJson(fb);
}else{
public Object addUser(@RequestBody AddUserVo userVo){
if (StringUtils.isEmpty(userVo.getUserName())){
fb.setCode(0);
fb.setMessage("用户名不能为空");
......@@ -168,6 +145,15 @@ public class UserController {
fb.setMessage("角色名不能为空");
return gson.toJson(fb);
}
if (roleService.getByRoleName(userVo.getRoleName())==0){
fb.setCode(0);
fb.setMessage("没有该角色");
return gson.toJson(fb);
}
String userNumber="U"+System.currentTimeMillis();
userVo.setUserNumber(userNumber);
userVo.setCreateTime(System.currentTimeMillis());
userVo.setUpdateTime(System.currentTimeMillis());
int a=userService.addUser(userVo);
if (a>0){
fb.setCode(1);
......@@ -176,7 +162,6 @@ public class UserController {
fb.setCode(0);
fb.setMessage("添加用户失败");
}
}
return gson.toJson(fb);
}
......@@ -191,41 +176,8 @@ public class UserController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/updateUser",method = RequestMethod.POST)
public Object updateUser(@RequestBody UpdateUserVo userVo,HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
List<String> permission=roleHasPermissionService.getByRoleName(user.getRoleName());
if (!permission.contains("用户列表")){
fb.setCode(0);
fb.setMessage("对不起,您没有此权限");
return gson.toJson(fb);
}
ResultUserVo userInfo=userService.getByUserNumber(user.getUserNumber());
// if (userVo.getUserName().equals("")||userVo.getUserName()==null){
// fb.setCode(0);
// fb.setMessage("用户名不能为空");
// }
// if (!userVo.getUserName().matches("^[a-zA-Z][a-zA-Z0-9_]{5,19}$")) {
// fb.setCode(0);
// fb.setMessage("用户名以字母开头,可包含数字和_,6-20个字符");
// return gson.toJson(fb);
// }
// if( userInfo!=null&&!userInfo.getUserName().equals(userVo.getUserName())){
// fb.setCode(0);
// fb.setMessage("用户名已被占用");
// return gson.toJson(fb);
// }
// if(StringUtils.isEmpty(userVo.getPassword())){
// fb.setCode(0);
// fb.setMessage("密码不能为空");
// return gson.toJson(fb);
// }
// if(!userVo.getPassword().matches("^[a-zA-Z\\d_]{6,20}$")){
// fb.setCode(0);
// fb.setMessage("密码必须是6-20位的数字、字母和_");
// return gson.toJson(fb);
// }
public Object updateUser(@RequestBody UpdateUserVo userVo){
ResultUserVo userInfo=userService.getByUserNumber(userVo.getUserNumber());
if (StringUtils.isEmpty(userVo.getNickName())){
fb.setCode(0);
fb.setMessage("昵称不能为空");
......@@ -271,6 +223,11 @@ public class UserController {
fb.setMessage("需要修改的用户编号不能为空");
return gson.toJson(fb);
}
if (roleService.getByRoleName(userVo.getRoleName())==0){
fb.setCode(0);
fb.setMessage("修改的角色名不存在");
return gson.toJson(fb);
}
int a=userService.updateUser(userVo);
if (a>0){
fb.setCode(1);
......@@ -288,18 +245,14 @@ public class UserController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/delUser",method = RequestMethod.POST)
public Object delUser(@RequestBody String userNumber,HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
List<String> permission=roleHasPermissionService.getByRoleName(user.getRoleName());
if (!permission.contains("用户列表")){
public Object delUser(@RequestBody String userNumber){
JSONObject jsonObject= JSON.parseObject(userNumber);
userNumber=jsonObject.getString("userNumber");
if (StringUtils.isEmpty(userNumber)){
fb.setCode(0);
fb.setMessage("对不起,您没有此权限");
fb.setMessage("需要删除的用户编号不能为空");
return gson.toJson(fb);
}
JSONObject jsonObject= JSON.parseObject(userNumber);
userNumber=jsonObject.getString("userNumber");
int a = userService.delUser(userNumber);
if (a>0){
fb.setCode(0);
......@@ -317,18 +270,14 @@ public class UserController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value="/resetPassword",method = RequestMethod.POST)
public Object resetPassword(@RequestBody String userNumber, HttpServletRequest request){
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
List<String> permission=roleHasPermissionService.getByRoleName(user.getRoleName());
if (!permission.contains("用户列表")){
public Object resetPassword(@RequestBody String userNumber){
JSONObject jsonObject= JSON.parseObject(userNumber);
userNumber=jsonObject.getString("userNumber");
if (StringUtils.isEmpty(userNumber)) {
fb.setCode(0);
fb.setMessage("对不起,您没有此权限");
fb.setMessage("需要重置密码的用户编号不能为空");
return gson.toJson(fb);
}
JSONObject jsonObject= JSON.parseObject(userNumber);
userNumber=jsonObject.getString("userNumber");
String pwd=DigestUtils.sha256Hex("Witium123");
int a = userService.resetPassword(userNumber,pwd);
if (a>0){
......
......@@ -6,4 +6,7 @@
SELECT roleName from role;
</select>
<select id="getByRoleName" resultType="java.lang.Integer" parameterType="String">
SELECT COUNT(*) from role WHERE roleName=#{roleName,jdbcType=VARCHAR}
</select>
</mapper>
\ No newline at end of file
......@@ -68,18 +68,18 @@
</select>
<!--添加用户-->
<insert id="addUser" parameterType="com.example.tdl.domain.vo.UserVo">
<insert id="addUser" parameterType="com.example.tdl.domain.vo.AddUserVo">
INSERT INTO `user` VALUES(
null,
CONCAT("U",(unix_timestamp(now())*1000)),
#{userNumber,jdbcType=VARCHAR},
#{userName,jdbcType=VARCHAR},
#{password,jdbcType=VARCHAR},
#{nickName,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR},
#{email,jdbcType=VARCHAR},
(SELECT id from role WHERE roleName=#{roleName,jdbcType=VARCHAR}),
(unix_timestamp(now())*1000) ,
(unix_timestamp(now())*1000) ,
#{createTime,jdbcType=VARCHAR},
#{updateTime,jdbcType=VARCHAR},
1
)
</insert>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment