Commit b5c58818 by guojuxing

账号分组接口

parent 1f10d8e3
......@@ -84,4 +84,15 @@ public interface AccountGroupService {
* @return int


 */
int updateStatusByAccountGroupId(Integer accountGroupId);
/**
* 排序
* @Title: setSort

* @Description:

 * @author guojuxing
* @param record
* @param sortValue

* @return void


 */
void setSort(TabSysAccountGroup record, Integer sortValue);
}
package com.gic.auth.service.impl;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.gic.auth.dao.mapper.TabSysAccountGroupMapper;
import com.gic.auth.dto.AccountGroupDTO;
import com.gic.auth.entity.TabSysAccountGroup;
import com.gic.auth.service.AccountGroupService;
import com.gic.commons.util.EntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service("AccountGroupService")
public class AccountGroupServiceImpl implements AccountGroupService{
......@@ -55,6 +57,7 @@ public class AccountGroupServiceImpl implements AccountGroupService{
return tabSysAccountGroupMapper.listAccountGroupByEnterpriseId(enterpriseId);
}
@Transactional(rollbackFor = Exception.class)
@Override
public int updateStatusByAccountGroupId(Integer accountGroupId) {
TabSysAccountGroup record = new TabSysAccountGroup();
......@@ -62,4 +65,38 @@ public class AccountGroupServiceImpl implements AccountGroupService{
record.setStatus(0);
return tabSysAccountGroupMapper.updateByPrimaryKeySelective(record);
}
@Override
public void setSort(TabSysAccountGroup record, Integer sortValue) {
List<TabSysAccountGroup> list = tabSysAccountGroupMapper.listAccountGroupByEnterpriseId(record.getEnterpriseId());
Integer fromSortValue = record.getSort();
if (fromSortValue > sortValue) {
//向上拖拽
for (int i = 0, length = list.size(); i < length; i++) {
TabSysAccountGroup temp = list.get(i);
//如果大于sortValue,都需要降低排序值,往后推
boolean isNeedDown = temp.getSort() >= sortValue && temp.getSort() < fromSortValue;
if (isNeedDown) {
updateSort(list.get(i + 1).getSort(), temp.getAccountGroupId());
}
}
} else if (fromSortValue < sortValue) {
//向下拖拽
for (int i = 0, length = list.size(); i < length; i++) {
TabSysAccountGroup temp = list.get(i);
boolean isNeedUp = temp.getSort() <= sortValue && temp.getSort() > fromSortValue;
if (isNeedUp) {
updateSort(list.get(i - 1).getSort(), temp.getAccountGroupId());
}
}
}
updateSort(sortValue, record.getAccountGroupId());
}
private void updateSort(Integer sort, Integer accountGroupId) {
TabSysAccountGroup record = new TabSysAccountGroup();
record.setAccountGroupId(accountGroupId);
record.setSort(sort);
tabSysAccountGroupMapper.updateByPrimaryKeySelective(record);
}
}
......@@ -12,6 +12,7 @@ import com.gic.auth.dto.AccountGroupDTO;
import com.gic.auth.service.AccountGroupApiService;
import com.gic.auth.service.AccountGroupService;
import com.gic.enterprise.utils.valid.ValidParamsUtils;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
......@@ -22,6 +23,7 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService{
private AccountGroupService accountGroupService;
@Override
public ServiceResponse<Integer> save(AccountGroupDTO dto) {
//参数校验
ServiceResponse paramValid = ValidParamsUtils.allCheckValidate(AccountGroupDTO.class, AccountGroupDTO.SaveValid.class);
if (!paramValid.isSuccess()) {
return paramValid;
......@@ -41,6 +43,7 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService{
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组id有误,查无数据");
}
//参数校验
ServiceResponse paramValid = ValidParamsUtils.allCheckValidate(AccountGroupDTO.class, AccountGroupDTO.EditValid.class);
if (!paramValid.isSuccess()) {
return paramValid;
......@@ -63,6 +66,7 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService{
return ServiceResponse.success(new ArrayList<>());
}
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResponse<Void> deleteByAccountGroupId(Integer accountGroupId) {
TabSysAccountGroup record = accountGroupService.getById(accountGroupId);
......@@ -75,4 +79,14 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService{
return ServiceResponse.success();
}
@Override
public ServiceResponse<Void> sort(Integer accountGroupId, Integer sort) {
TabSysAccountGroup record = accountGroupService.getById(accountGroupId);
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组id有误,查无数据");
}
accountGroupService.setSort(record, sort);
return ServiceResponse.success();
}
}
package com.gic.auth.web.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gic.auth.dto.AccountGroupDTO;
import com.gic.auth.service.AccountGroupApiService;
import com.gic.auth.web.vo.AccountGroupListVO;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.enterprise.utils.UserDetailUtils;
@RestController
@RequestMapping("/account-group")
public class AccountGroupController {
private final static Logger LOGGER = LogManager.getLogger(AccountGroupApiService.class);
@Autowired
private AccountGroupApiService accountGroupApiService;
/**
* 新增账号分组
* @Title: saveAccountGroup

* @Description:

 * @author guojuxing
* @param dto

* @return com.gic.commons.webapi.reponse.RestResponse


 */
@RequestMapping("/save")
public RestResponse saveAccountGroup(AccountGroupDTO dto) {
return ResultControllerUtils.commonResult(accountGroupApiService.save(dto));
}
@RequestMapping("/edit")
public RestResponse editAccountGroup(AccountGroupDTO dto) {
return ResultControllerUtils.commonResult(accountGroupApiService.update(dto));
}
@RequestMapping("/list")
public RestResponse listAccountGroup() {
Integer enterpriseId = UserDetailUtils.getUserDetail().getEnterpriseId();
return ResultControllerUtils.commonResult(accountGroupApiService.listAccountGroupByEnterpriseId(enterpriseId),
AccountGroupListVO.class);
}
@RequestMapping("/delete")
public RestResponse deleteAccountGroup(Integer accountGroupId) {
return ResultControllerUtils.commonResult(accountGroupApiService.deleteByAccountGroupId(accountGroupId));
}
@RequestMapping("/sort")
public RestResponse sortAccountGroup(Integer accountGroupId, Integer sort) {
return ResultControllerUtils.commonResult(accountGroupApiService.sort(accountGroupId, sort));
}
}
package com.gic.auth.web.vo;
import java.io.Serializable;
/**
* 账号分组列表
* @ClassName: AccountGroupListVO

* @Description: 

* @author guojuxing

* @date 2019/10/29 9:44 AM

*/
public class AccountGroupListVO implements Serializable{
private static final long serialVersionUID = -2848584820559101482L;
private Integer accountGroupId;
private String accountGroupName;
private Integer enterpriseId;
public Integer getAccountGroupId() {
return accountGroupId;
}
public void setAccountGroupId(Integer accountGroupId) {
this.accountGroupId = accountGroupId;
}
public String getAccountGroupName() {
return accountGroupName;
}
public void setAccountGroupName(String accountGroupName) {
this.accountGroupName = accountGroupName;
}
public Integer getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
}
}
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