From 7349a9550805ea7f923963e0a125fd0fdfa75546 Mon Sep 17 00:00:00 2001 From: anthonywj Date: Tue, 27 Dec 2022 16:18:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=85=B3=E8=81=94=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/auth/DeptUserController.java | 35 ++++++++ .../inventory/InvWarehouseController.java | 81 ++++++++++++++++--- .../glxp/api/admin/dao/auth/DeptUserDao.java | 26 ++++++ .../api/admin/entity/auth/DeptUserEntity.java | 10 +++ .../api/admin/req/auth/DeptUserReqeust.java | 10 +++ .../api/admin/res/auth/DeptUserResponse.java | 12 +++ .../admin/service/auth/DeptUserService.java | 23 ++++++ .../auth/impl/DeptUserServiceImpl.java | 57 +++++++++++++ .../mybatis/mapper/auth/DeptUserDao.xml | 72 +++++++++++++++++ 9 files changed, 316 insertions(+), 10 deletions(-) create mode 100644 api-admin/src/main/java/com/glxp/api/admin/controller/auth/DeptUserController.java create mode 100644 api-admin/src/main/java/com/glxp/api/admin/dao/auth/DeptUserDao.java create mode 100644 api-admin/src/main/java/com/glxp/api/admin/entity/auth/DeptUserEntity.java create mode 100644 api-admin/src/main/java/com/glxp/api/admin/req/auth/DeptUserReqeust.java create mode 100644 api-admin/src/main/java/com/glxp/api/admin/res/auth/DeptUserResponse.java create mode 100644 api-admin/src/main/java/com/glxp/api/admin/service/auth/DeptUserService.java create mode 100644 api-admin/src/main/java/com/glxp/api/admin/service/auth/impl/DeptUserServiceImpl.java create mode 100644 api-admin/src/main/resources/mybatis/mapper/auth/DeptUserDao.xml diff --git a/api-admin/src/main/java/com/glxp/api/admin/controller/auth/DeptUserController.java b/api-admin/src/main/java/com/glxp/api/admin/controller/auth/DeptUserController.java new file mode 100644 index 00000000..4433d35c --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/controller/auth/DeptUserController.java @@ -0,0 +1,35 @@ +package com.glxp.api.admin.controller.auth; + +import com.github.pagehelper.PageInfo; +import com.glxp.api.admin.annotation.AuthRuleAnnotation; +import com.glxp.api.admin.req.auth.DeptUserReqeust; +import com.glxp.api.admin.res.PageSimpleResponse; +import com.glxp.api.admin.res.auth.DeptUserResponse; +import com.glxp.api.admin.service.auth.DeptUserService; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +@RestController +public class DeptUserController { + + + @Resource + DeptUserService deptUserService; + + @AuthRuleAnnotation("") + @GetMapping("udi/auth/dept/user/filter") + public BaseResponse filterList(DeptUserReqeust deptUserReqeust) { + List deptEntityList = deptUserService.selectJoinDeptUser(deptUserReqeust); + PageInfo pageInfo = new PageInfo<>(deptEntityList); + PageSimpleResponse deptEntityPageSimpleResponse = new PageSimpleResponse<>(); + deptEntityPageSimpleResponse.setTotal(pageInfo.getTotal()); + deptEntityPageSimpleResponse.setList(deptEntityList); + return ResultVOUtils.success(deptEntityPageSimpleResponse); + } + +} diff --git a/api-admin/src/main/java/com/glxp/api/admin/controller/inventory/InvWarehouseController.java b/api-admin/src/main/java/com/glxp/api/admin/controller/inventory/InvWarehouseController.java index 7de149e6..2cc2ce80 100644 --- a/api-admin/src/main/java/com/glxp/api/admin/controller/inventory/InvWarehouseController.java +++ b/api-admin/src/main/java/com/glxp/api/admin/controller/inventory/InvWarehouseController.java @@ -200,9 +200,9 @@ public class InvWarehouseController { } @AuthRuleAnnotation("") - @PostMapping("/spms/inv/warehouse/save") - public BaseResponse save(@RequestBody @Valid InvWarehouseEntity invWarehouseEntity, - BindingResult bindingResult) { + @PostMapping("/spms/inv/warehouse/save1") + public BaseResponse save1(@RequestBody @Valid InvWarehouseEntity invWarehouseEntity, + BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); @@ -218,9 +218,9 @@ public class InvWarehouseController { } } List invWarehouseEntityList = invWarehouseService.selectByNameList(invWarehouseEntity.getName()); - if (invWarehouseEntityList!=null && invWarehouseEntityList.size()>0) { - for (InvWarehouseEntity obj:invWarehouseEntityList){ - if(obj.getName().equals(invWarehouseEntity.getName()) && !obj.getId().equals(invWarehouseEntity.getId())){ + if (invWarehouseEntityList != null && invWarehouseEntityList.size() > 0) { + for (InvWarehouseEntity obj : invWarehouseEntityList) { + if (obj.getName().equals(invWarehouseEntity.getName()) && !obj.getId().equals(invWarehouseEntity.getId())) { return ResultVOUtils.error(500, "已存在相同名称的仓库,无法继续添加!"); } } @@ -266,6 +266,67 @@ public class InvWarehouseController { return ResultVOUtils.success("添加成功!"); } + + @AuthRuleAnnotation("") + @PostMapping("/spms/inv/warehouse/save") + public BaseResponse save(@RequestBody @Valid InvWarehouseEntity invWarehouseEntity, + BindingResult bindingResult) { + + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + + List invWarehouseEntityList = invWarehouseService.selectByNameList(invWarehouseEntity.getName()); + if (invWarehouseEntityList != null && invWarehouseEntityList.size() > 0) { + for (InvWarehouseEntity obj : invWarehouseEntityList) { + if (obj.getName().equals(invWarehouseEntity.getName()) && !obj.getId().equals(invWarehouseEntity.getId())) { + return ResultVOUtils.error(500, "已存在相同名称的仓库,无法继续添加!"); + } + } + } + //顶级部门 + if (invWarehouseEntity.getPid() == null || invWarehouseEntity.getPid() == 0) { + invWarehouseEntity.setPid(0); // 默认设置 + FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest(); + filterInvWarehouseRequest.setPid(invWarehouseEntity.getPid()); + InvWarehouseEntity codeEntity = invWarehouseService.selectMaxCode(filterInvWarehouseRequest); + invWarehouseEntity.setCode(Integer.parseInt(codeEntity.getCode()) + 1 + ""); + invWarehouseEntity.setPcode("0"); + invWarehouseEntity.setLevel(1); + + //限制只有一个根节点 + FilterInvWarehouseRequest levelRequest = new FilterInvWarehouseRequest(); + filterInvWarehouseRequest.setStatus(invWarehouseEntity.getStatus()); + filterInvWarehouseRequest.setLevel(1); + List invWarehouseEntities = invWarehouseService.filterInvWarehouse(levelRequest); + if (CollUtil.isNotEmpty(invWarehouseEntities)) { + return ResultVOUtils.error(500, "已存在相同类型的一级部门,无法继续添加!"); + } + } else { + //子级部门 + FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest(); + filterInvWarehouseRequest.setPid(invWarehouseEntity.getPid()); + InvWarehouseEntity codeEntity = invWarehouseService.selectMaxCode(filterInvWarehouseRequest); + InvWarehouseEntity pEntity = invWarehouseService.selectById(invWarehouseEntity.getPid() + ""); + if (codeEntity == null) { + int code = Integer.parseInt(pEntity.getCode()) * 1000; + invWarehouseEntity.setCode(code + ""); + } else { + invWarehouseEntity.setCode(Integer.parseInt(codeEntity.getCode()) + 1 + ""); + } + invWarehouseEntity.setAdvanceType(pEntity.getAdvanceType()); + invWarehouseEntity.setLevel(pEntity.getLevel() + 1); + invWarehouseEntity.setPcode(pEntity.getPcode()); + } + invWarehouseEntity.setUpdateTime(new Date()); + boolean b = invWarehouseService.insertInvWarehouse(invWarehouseEntity); + if (!b) { + return ResultVOUtils.error(ResultEnum.NOT_NETWORK); + } + return ResultVOUtils.success("添加成功!"); + } + + @AuthRuleAnnotation("") @PostMapping("/spms/inv/warehouse/edit") public BaseResponse edit(@RequestBody @Valid InvWarehouseEntity invWarehouseEntity, @@ -279,9 +340,9 @@ public class InvWarehouseController { } List invWarehouseEntityList = invWarehouseService.selectByNameList(invWarehouseEntity.getName()); - if (invWarehouseEntityList!=null && invWarehouseEntityList.size()>0) { - for (InvWarehouseEntity obj:invWarehouseEntityList){ - if(obj.getName().equals(invWarehouseEntity.getName()) && !obj.getId().equals(invWarehouseEntity.getId())){ + if (invWarehouseEntityList != null && invWarehouseEntityList.size() > 0) { + for (InvWarehouseEntity obj : invWarehouseEntityList) { + if (obj.getName().equals(invWarehouseEntity.getName()) && !obj.getId().equals(invWarehouseEntity.getId())) { return ResultVOUtils.error(500, "已存在相同名称的仓库,无法继续添加!"); } } @@ -312,7 +373,7 @@ public class InvWarehouseController { List invSubWarehouseEntities = invSubWarehouseService.findByParentId(invWarehouseEntity.getCode()); if (CollUtil.isNotEmpty(invSubWarehouseEntities)) { - return ResultVOUtils.error(500, "请先移除该仓库关联的分库!"); + return ResultVOUtils.error(500, "删除失败,请先移除该部门关联仓库信息!"); } boolean b = invWarehouseService.deleteById(deleteRequest.getId()); if (!b) { diff --git a/api-admin/src/main/java/com/glxp/api/admin/dao/auth/DeptUserDao.java b/api-admin/src/main/java/com/glxp/api/admin/dao/auth/DeptUserDao.java new file mode 100644 index 00000000..49538aed --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/dao/auth/DeptUserDao.java @@ -0,0 +1,26 @@ +package com.glxp.api.admin.dao.auth; + +import com.glxp.api.admin.entity.auth.DeptUserEntity; +import com.glxp.api.admin.req.auth.DeptUserReqeust; +import com.glxp.api.admin.res.auth.DeptUserResponse; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface DeptUserDao { + + + List selectDeptUser(DeptUserReqeust deptUserReqeust); + + List selectJoinDeptUser(DeptUserReqeust deptUserReqeust); + + int deleteById(Integer id); + + int deleteByList(@Param("ids") List ids); + + int insertBatch(List list); + + +} diff --git a/api-admin/src/main/java/com/glxp/api/admin/entity/auth/DeptUserEntity.java b/api-admin/src/main/java/com/glxp/api/admin/entity/auth/DeptUserEntity.java new file mode 100644 index 00000000..645118ff --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/entity/auth/DeptUserEntity.java @@ -0,0 +1,10 @@ +package com.glxp.api.admin.entity.auth; + +import lombok.Data; + +@Data +public class DeptUserEntity { + private Integer deptId; + private Integer userId; + +} diff --git a/api-admin/src/main/java/com/glxp/api/admin/req/auth/DeptUserReqeust.java b/api-admin/src/main/java/com/glxp/api/admin/req/auth/DeptUserReqeust.java new file mode 100644 index 00000000..d83f7b79 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/req/auth/DeptUserReqeust.java @@ -0,0 +1,10 @@ +package com.glxp.api.admin.req.auth; + +import com.glxp.api.admin.req.ListPageRequest; +import lombok.Data; + +@Data +public class DeptUserReqeust extends ListPageRequest { + private Integer deptId; + private Integer userId; +} diff --git a/api-admin/src/main/java/com/glxp/api/admin/res/auth/DeptUserResponse.java b/api-admin/src/main/java/com/glxp/api/admin/res/auth/DeptUserResponse.java new file mode 100644 index 00000000..fef9ee24 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/res/auth/DeptUserResponse.java @@ -0,0 +1,12 @@ +package com.glxp.api.admin.res.auth; + +import lombok.Data; + +@Data +public class DeptUserResponse { + + private Integer deptId; + private Integer userId; + private String userName; + private String employeeName; +} diff --git a/api-admin/src/main/java/com/glxp/api/admin/service/auth/DeptUserService.java b/api-admin/src/main/java/com/glxp/api/admin/service/auth/DeptUserService.java new file mode 100644 index 00000000..f3c63e9d --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/service/auth/DeptUserService.java @@ -0,0 +1,23 @@ +package com.glxp.api.admin.service.auth; + +import com.glxp.api.admin.entity.auth.DeptUserEntity; +import com.glxp.api.admin.req.auth.DeptUserReqeust; +import com.glxp.api.admin.res.auth.DeptUserResponse; + +import java.util.List; + +public interface DeptUserService { + + + List selectDeptUser(DeptUserReqeust deptUserReqeust); + + List selectJoinDeptUser(DeptUserReqeust deptUserReqeust); + + int deleteById(Integer id); + + int deleteByList(List ids); + + int insertBatch(List list); + + +} diff --git a/api-admin/src/main/java/com/glxp/api/admin/service/auth/impl/DeptUserServiceImpl.java b/api-admin/src/main/java/com/glxp/api/admin/service/auth/impl/DeptUserServiceImpl.java new file mode 100644 index 00000000..a7c0731e --- /dev/null +++ b/api-admin/src/main/java/com/glxp/api/admin/service/auth/impl/DeptUserServiceImpl.java @@ -0,0 +1,57 @@ +package com.glxp.api.admin.service.auth.impl; + +import cn.hutool.core.collection.CollUtil; +import com.github.pagehelper.PageHelper; +import com.glxp.api.admin.dao.auth.DeptUserDao; +import com.glxp.api.admin.entity.auth.DeptUserEntity; +import com.glxp.api.admin.req.auth.DeptUserReqeust; +import com.glxp.api.admin.res.auth.DeptUserResponse; +import com.glxp.api.admin.service.auth.DeptUserService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class DeptUserServiceImpl implements DeptUserService { + + @Resource + DeptUserDao deptUserDao; + + + @Override + public List selectDeptUser(DeptUserReqeust deptUserReqeust) { + if (deptUserReqeust.getPage() != null) { + int offset = (deptUserReqeust.getPage() - 1) * deptUserReqeust.getLimit(); + PageHelper.offsetPage(offset, deptUserReqeust.getLimit()); + } + return deptUserDao.selectDeptUser(deptUserReqeust); + } + + @Override + public List selectJoinDeptUser(DeptUserReqeust deptUserReqeust) { + if (deptUserReqeust.getPage() != null) { + int offset = (deptUserReqeust.getPage() - 1) * deptUserReqeust.getLimit(); + PageHelper.offsetPage(offset, deptUserReqeust.getLimit()); + } + return deptUserDao.selectJoinDeptUser(deptUserReqeust); + } + + @Override + public int deleteById(Integer id) { + return deptUserDao.deleteById(id); + } + + @Override + public int deleteByList(List ids) { + return deptUserDao.deleteByList(ids); + } + + @Override + public int insertBatch(List list) { + if (CollUtil.isNotEmpty(list)) + return deptUserDao.insertBatch(list); + + return 0; + } +} diff --git a/api-admin/src/main/resources/mybatis/mapper/auth/DeptUserDao.xml b/api-admin/src/main/resources/mybatis/mapper/auth/DeptUserDao.xml new file mode 100644 index 00000000..d2a0fff3 --- /dev/null +++ b/api-admin/src/main/resources/mybatis/mapper/auth/DeptUserDao.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + delete + from auth_dept_user + where deptId = #{id} + + + + delete + from auth_dept_user + where deptId in + + #{item} + + + + + + + insert INTO auth_dept_user + ( + deptId,userId + ) + values + + ( + #{item.deptId}, + #{item.userId} + ) + + + +