Commit 1c2850f3 authored by 周健威's avatar 周健威

Merge remote-tracking branch 'origin/base-modify' into base-modify

parents 7bbb7553 4abb6c63
...@@ -48,6 +48,7 @@ public class UserBiz extends BaseBiz<UserMapper,User> { ...@@ -48,6 +48,7 @@ public class UserBiz extends BaseBiz<UserMapper,User> {
@Override @Override
@CacheClear(pre="user{1.username}") @CacheClear(pre="user{1.username}")
@Transactional(rollbackFor = Exception.class)
public void updateSelectiveById(User entity) { public void updateSelectiveById(User entity) {
User user1= super.selectById(entity.getId()); User user1= super.selectById(entity.getId());
if(user1!=null&&StringUtils.isNotBlank(entity.getPassword())&&!user1.getPassword().equals(entity.getPassword())){ if(user1!=null&&StringUtils.isNotBlank(entity.getPassword())&&!user1.getPassword().equals(entity.getPassword())){
......
...@@ -22,13 +22,12 @@ import org.apache.commons.lang3.StringUtils; ...@@ -22,13 +22,12 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.github.wxiaoqi.security.common.context.BaseContextHandler;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.github.wxiaoqi.security.auth.common.constatns.CommonConstants.DATA_ALL_TRUE; import static com.github.wxiaoqi.security.auth.common.constatns.CommonConstants.DATA_ALL_TRUE;
import static com.github.wxiaoqi.security.auth.common.constatns.CommonConstants.DATA_ALL_FALSE;
/** /**
* ${DESCRIPTION} * ${DESCRIPTION}
* *
...@@ -66,16 +65,17 @@ public class UserController extends CommonBaseController { ...@@ -66,16 +65,17 @@ public class UserController extends CommonBaseController {
@Data @Data
public static class UserVO extends User { public static class UserVO extends User {
List<Integer> dataLimit; // List<Integer> dataLimit;
Integer dataLimit;
List<Integer> members; List<Integer> members;
} }
@RequestMapping(value = "",method = RequestMethod.POST) @RequestMapping(value = "", method = RequestMethod.POST)
@IgnoreClientToken @IgnoreClientToken
public ObjectRestResponse<User> add(@RequestBody UserVO vo){ public ObjectRestResponse<User> add(@RequestBody UserVO vo) {
handleDataLimit(vo); handleDataLimit(vo);
String username=vo.getUsername(); String username = vo.getUsername();
if(StringUtils.isNotBlank(username)) { if (StringUtils.isNotBlank(username)) {
List<User> list = userBiz.getCountByUsername(username); List<User> list = userBiz.getCountByUsername(username);
if (list.size() > 0) { if (list.size() > 0) {
throw new RuntimeException("用户名不能重复"); throw new RuntimeException("用户名不能重复");
...@@ -88,15 +88,18 @@ public class UserController extends CommonBaseController { ...@@ -88,15 +88,18 @@ public class UserController extends CommonBaseController {
} }
private void handleDataLimit(@RequestBody UserVO dto) { private void handleDataLimit(@RequestBody UserVO dto) {
if(null != dto.getDataLimit()) { if (null != dto.getDataLimit()) {
if(dto.getDataLimit().contains(CURRENT_COMPANY)&&dto.getCompanyId()!=null) { dto.setDataCompany("");
dto.setDataAll(DATA_ALL_FALSE);
dto.setDataZone("");
if (dto.getDataLimit()>=CURRENT_COMPANY && dto.getCompanyId() != null) {
dto.setDataCompany(dto.getCompanyId().toString()); dto.setDataCompany(dto.getCompanyId().toString());
}
if(dto.getDataLimit().contains(CURRENT_ZONE)&&dto.getZoneId()!=null) {
}
if (dto.getDataLimit()>=CURRENT_ZONE && dto.getZoneId() != null) {
dto.setDataZone(dto.getZoneId().toString()); dto.setDataZone(dto.getZoneId().toString());
} }
if(dto.getDataLimit().contains(DATA_ALL)) { if (dto.getDataLimit()>=DATA_ALL) {
dto.setDataAll(DATA_ALL_TRUE); dto.setDataAll(DATA_ALL_TRUE);
} }
} }
...@@ -140,53 +143,54 @@ public class UserController extends CommonBaseController { ...@@ -140,53 +143,54 @@ public class UserController extends CommonBaseController {
} }
@RequestMapping(value = "/{id}",method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public ObjectRestResponse<User> get(@PathVariable int id){ public ObjectRestResponse<User> get(@PathVariable int id) {
ObjectRestResponse<User> entityObjectRestResponse = new ObjectRestResponse<>(); ObjectRestResponse<User> entityObjectRestResponse = new ObjectRestResponse<>();
User o = userBiz.selectById(id); User o = userBiz.selectById(id);
entityObjectRestResponse.data(o); entityObjectRestResponse.data(o);
return entityObjectRestResponse; return entityObjectRestResponse;
} }
@RequestMapping(value = "/{id}/group",method = RequestMethod.GET) @RequestMapping(value = "/{id}/group", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public ObjectRestResponse<GroupUsers> getGroup(@PathVariable int id){ public ObjectRestResponse<GroupUsers> getGroup(@PathVariable int id) {
return new ObjectRestResponse<GroupUsers>().rel(true).data(groupBiz.getUserGroups(id)); return new ObjectRestResponse<GroupUsers>().rel(true).data(groupBiz.getUserGroups(id));
} }
@RequestMapping(value = "/{id}",method = RequestMethod.PUT) @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
@ResponseBody @ResponseBody
public ObjectRestResponse<User> update(@RequestBody UserVO vo){ public ObjectRestResponse<User> update(@RequestBody UserVO vo) {
handleDataLimit(vo); handleDataLimit(vo);
String username=vo.getUsername(); String username = vo.getUsername();
if(StringUtils.isNotBlank(username)){ if (StringUtils.isNotBlank(username)) {
List<User> list=userBiz.getCountByUsername(username); List<User> list = userBiz.getCountByUsername(username);
if(list.size()>1){ if (list.size() > 1) {
throw new RuntimeException("用户名不能重复"); throw new RuntimeException("用户名不能重复");
} }
if(list.size()==1){ if (list.size() == 1) {
User user=list.get(0); User user = list.get(0);
if(!user.getId().equals(vo.getId())){ if (!user.getId().equals(vo.getId())) {
throw new RuntimeException("用户名不能重复"); throw new RuntimeException("用户名不能重复");
} }
} }
} }
userBiz.updateSelectiveById(vo); userBiz.updateSelectiveById(vo);
//添加权限关系 //添加权限关系
groupBiz.modifyUserGroups(vo.getId(), vo.getMembers()); groupBiz.modifyUserGroups(vo.getId(), vo.getMembers());
return new ObjectRestResponse<User>(); return new ObjectRestResponse<User>();
} }
@RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@ResponseBody @ResponseBody
public ObjectRestResponse<User> remove(@PathVariable int id){ public ObjectRestResponse<User> remove(@PathVariable int id) {
userBiz.deleteById(id); userBiz.deleteById(id);
return new ObjectRestResponse<User>(); return new ObjectRestResponse<User>();
} }
@RequestMapping(value = "/all",method = RequestMethod.GET) @RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public List<User> all(){ public List<User> all() {
return userBiz.selectListAll(); return userBiz.selectListAll();
} }
} }
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