完成组织管理开发,修复根据id删除多个数据时,id找不到的问题
This commit is contained in:
+1
-1
@@ -59,7 +59,7 @@ public class ${pojoName}Controller {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse delete${pojoName}(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") ArrayList<${mybatisGenerator.primaryKeyType}> ids){
|
||||
public ServerResponse delete${pojoName}(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<${mybatisGenerator.primaryKeyType}> ids){
|
||||
return ${varPojoName}Service.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,8 @@ public class UpmsLogController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsLog(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsLog(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids")
|
||||
@RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsLogService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,7 @@ public class UpmsOrganizationController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsOrganization(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsOrganization(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsOrganizationService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class UpmsPermissionController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsPermission(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsPermission(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsPermissionService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class UpmsRoleController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsRole(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsRole(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsRoleService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class UpmsRolePermissionController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsRolePermission(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsRolePermission(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsRolePermissionService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -90,7 +91,7 @@ public class UpmsUserController {
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUser(
|
||||
@NotEmpty(message = BaseConst.BASEMSG_PREFIX + "请传入id") List<Integer> ids) {
|
||||
@NotEmpty(message = BaseConst.BASEMSG_PREFIX + "请传入id") @RequestParam("ids") ArrayList<Integer> ids) {
|
||||
return upmsUserService.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class UpmsUserOrganizationController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsUserOrganization(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsUserOrganization(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsUserOrganizationService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class UpmsUserPermissionController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsUserPermission(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsUserPermission(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsUserPermissionService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -59,7 +60,7 @@ public class UpmsUserRoleController {
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsUserRole(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") List<Integer> ids){
|
||||
public ServerResponse deleteUpmsUserRole(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsUserRoleService.deleteByIds(ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,30 @@ package com.micro.fast.upms.dao;
|
||||
import com.micro.fast.common.dao.SsmMapper;
|
||||
import com.micro.fast.upms.pojo.UpmsOrganization;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UpmsOrganizationMapper extends SsmMapper<UpmsOrganization,Integer> {
|
||||
@Override
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
|
||||
@Override
|
||||
int insert(UpmsOrganization record);
|
||||
|
||||
@Override
|
||||
int insertSelective(UpmsOrganization record);
|
||||
|
||||
@Override
|
||||
UpmsOrganization selectByPrimaryKey(Integer id);
|
||||
|
||||
@Override
|
||||
int updateByPrimaryKeySelective(UpmsOrganization record);
|
||||
|
||||
@Override
|
||||
int updateByPrimaryKey(UpmsOrganization record);
|
||||
|
||||
@Override
|
||||
List<UpmsOrganization> selectByCondition(UpmsOrganization record);
|
||||
|
||||
@Override
|
||||
int deleteByPrimaryKeys(List<Integer> integers);
|
||||
}
|
||||
@@ -3,13 +3,14 @@ package com.micro.fast.upms.pojo;
|
||||
import com.micro.fast.boot.starter.common.response.BaseConst;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class UpmsOrganization implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
@NotBlank(message = BaseConst.BASEMSG_PREFIX+"请填写上级组织")
|
||||
@NotNull(message = BaseConst.BASEMSG_PREFIX+"请填写上级组织")
|
||||
private Integer pid;
|
||||
|
||||
@NotBlank(message = BaseConst.BASEMSG_PREFIX+"请填写组织名称")
|
||||
|
||||
+66
@@ -1,5 +1,6 @@
|
||||
package com.micro.fast.upms.service.impl;
|
||||
|
||||
import com.micro.fast.boot.starter.common.response.ServerResponse;
|
||||
import com.micro.fast.common.service.impl.SsmServiceImpl;
|
||||
import com.micro.fast.upms.dao.UpmsOrganizationMapper;
|
||||
import com.micro.fast.upms.pojo.UpmsOrganization;
|
||||
@@ -8,6 +9,8 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
*/
|
||||
@@ -18,6 +21,69 @@ implements UpmsOrganizationService<UpmsOrganization,Integer>,InitializingBean {
|
||||
@Autowired
|
||||
private UpmsOrganizationMapper mapper;
|
||||
|
||||
@Override
|
||||
public ServerResponse add(UpmsOrganization pojo) {
|
||||
if (pojo.getPid() == 0) {
|
||||
// 如果是创建根节点就检查根节点是否已经被创建
|
||||
UpmsOrganization upmsOrganization = new UpmsOrganization();
|
||||
upmsOrganization.setPid(0);
|
||||
List<UpmsOrganization> upmsOrganizations = mapper.selectByCondition(upmsOrganization);
|
||||
if (upmsOrganizations.size() == 0){
|
||||
return super.add(pojo);
|
||||
} else {
|
||||
return ServerResponse.errorMsg("根节点已经被创建");
|
||||
}
|
||||
} else {
|
||||
// 如果不是根节点就查询父节点是否存在
|
||||
UpmsOrganization upmsOrganization = mapper.selectByPrimaryKey(pojo.getPid());
|
||||
if (upmsOrganization == null){
|
||||
return ServerResponse.errorMsg("上级组织不存在,请重新输入上级组织id");
|
||||
} else {
|
||||
// 添加添加组织
|
||||
return super.add(pojo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse update(UpmsOrganization pojo) {
|
||||
|
||||
if ( pojo.getPid() == 0) {
|
||||
UpmsOrganization upmsOrganization = new UpmsOrganization();
|
||||
upmsOrganization.setPid(0);
|
||||
List<UpmsOrganization> upmsOrganizations = mapper.selectByCondition(pojo);
|
||||
if (upmsOrganizations.size() == 0) {
|
||||
return super.update(pojo);
|
||||
} else {
|
||||
return ServerResponse.errorMsg("只允许有一个根组织");
|
||||
}
|
||||
}
|
||||
// 检查上级组织是否存在
|
||||
UpmsOrganization upmsOrganization = mapper.selectByPrimaryKey(pojo.getPid());
|
||||
if (upmsOrganization == null){
|
||||
return ServerResponse.errorMsg("上级组织不存在,请重新输入上级组织id");
|
||||
} else {
|
||||
// 更新组织信息
|
||||
return super.update(pojo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse deleteByIds(List<Integer> integers) {
|
||||
// 1. 检查这个id下面还有没有下级组织,如果有就不能删除组织
|
||||
UpmsOrganization upmsOrganization = new UpmsOrganization();
|
||||
for (Integer integer : integers) {
|
||||
upmsOrganization.setPid(integer);
|
||||
List<UpmsOrganization> upmsOrganizations = mapper.selectByCondition(upmsOrganization);
|
||||
if (upmsOrganizations !=null && upmsOrganizations.size() >0){
|
||||
// 该部门下有子节点,不允许删除
|
||||
return ServerResponse.errorMsg("组织下尚有子组织,请删除部门下子组织后再进行删除操作");
|
||||
}
|
||||
}
|
||||
//todo 2. 处理组织和用户关联情况
|
||||
return super.deleteByIds(integers);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在这个bean初始化完成后覆盖父类的mapper
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
from upms_organization
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
||||
delete from upms_organization
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</delete>
|
||||
@@ -92,4 +92,29 @@
|
||||
ctime = #{ctime,jdbcType=BIGINT}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
|
||||
<!--自定义的部分-->
|
||||
<!--条件查询-->
|
||||
<select id="selectByCondition" resultType="com.micro.fast.upms.pojo.UpmsOrganization">
|
||||
SELECT <include refid="Base_Column_List"/> FROM upms_organization
|
||||
<where>
|
||||
<if test="id !=null ">
|
||||
and id = #{id}
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
and pid = #{pid}
|
||||
</if>
|
||||
<if test="name != null">
|
||||
and name like #{name}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<!--删除多个-->
|
||||
<delete id="deleteByPrimaryKeys">
|
||||
DELETE FROM upms_organization
|
||||
WHERE id IN
|
||||
<foreach collection="list" close=")" item="item" open="(" separator="," >
|
||||
#{item}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user