diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java index 59e7588..ce1e263 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/SysDeptController.java @@ -1,6 +1,8 @@ package com.ruoyi.web.controller.system; import java.util.List; + +import com.ruoyi.system.service.IEtOperatingAreaService; import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -24,7 +26,7 @@ import com.ruoyi.system.service.ISysDeptService; /** * 部门信息 - * + * * @author ruoyi */ @RestController @@ -34,6 +36,10 @@ public class SysDeptController extends BaseController @Autowired private ISysDeptService deptService; + @Autowired + private IEtOperatingAreaService etOperatingAreaService; + + /** * 获取部门列表 */ @@ -64,8 +70,11 @@ public class SysDeptController extends BaseController @GetMapping(value = "/{deptId}") public AjaxResult getInfo(@PathVariable Long deptId) { + AjaxResult ajax = AjaxResult.success(); deptService.checkDeptDataScope(deptId); - return success(deptService.selectDeptById(deptId)); + ajax.put(AjaxResult.DATA_TAG,deptService.selectDeptById(deptId)); + ajax.put("areaIds", etOperatingAreaService.selectAreaListByDeptId(deptId)); + return ajax; } /** @@ -78,7 +87,7 @@ public class SysDeptController extends BaseController { if (!deptService.checkDeptNameUnique(dept)) { - return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + return error("新增运营商'" + dept.getDeptName() + "'失败,部门名称已存在"); } dept.setCreateBy(getUsername()); return toAjax(deptService.insertDept(dept)); @@ -96,15 +105,15 @@ public class SysDeptController extends BaseController deptService.checkDeptDataScope(deptId); if (!deptService.checkDeptNameUnique(dept)) { - return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + return error("修改运营商'" + dept.getDeptName() + "'失败,部门名称已存在"); } else if (dept.getParentId().equals(deptId)) { - return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); + return error("修改运营商'" + dept.getDeptName() + "'失败,上级部门不能是自己"); } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()) && deptService.selectNormalChildrenDeptById(deptId) > 0) { - return error("该部门包含未停用的子部门!"); + return error("该运营商包含未停用的子部门!"); } dept.setUpdateBy(getUsername()); return toAjax(deptService.updateDept(dept)); diff --git a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java index fb18c5c..8e4de58 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java +++ b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java @@ -6,13 +6,15 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; + +import com.baomidou.mybatisplus.annotation.TableField; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.domain.BaseEntity; /** * 部门表 sys_dept - * + * * @author ruoyi */ public class SysDept extends BaseEntity @@ -51,7 +53,18 @@ public class SysDept extends BaseEntity /** 父部门名称 */ private String parentName; - + + /** 运营区id */ + private Long[] areaIds; + + public Long[] getAreaIds() { + return areaIds; + } + + public void setAreaIds(Long[] areaIds) { + this.areaIds = areaIds; + } + /** 子部门 */ private List children = new ArrayList(); diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtAreaDept.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtAreaDept.java new file mode 100644 index 0000000..0f78590 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtAreaDept.java @@ -0,0 +1,28 @@ +package com.ruoyi.system.domain; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +/** + * 运营商与运营区(部门)关联表 et_area_dept + * + * @author 邱贞招 + * @date 2024-05-19 + */ +@Data +@Builder +@TableName(value = "et_area_dept") +public class EtAreaDept implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 区域id */ + private Long areaId; + + /** 收费规则id */ + private Long deptId; + +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java index 671daea..f78ea93 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtFeeRule.java @@ -144,7 +144,7 @@ public class EtFeeRule extends BaseEntity /** 骑行价格说明*/ @Excel(name = "骑行价格说明") - private BigDecimal instructions; + private String instructions; /** 是否缴纳过押金*/ @Excel(name = "是否缴纳过押金") diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaDeptMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaDeptMapper.java new file mode 100644 index 0000000..2d4a8b6 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaDeptMapper.java @@ -0,0 +1,20 @@ +package com.ruoyi.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.system.domain.EtAreaDept; + +/** + * 区域与部门关联 数据层 + * + * @author ruoyi + */ +public interface EtAreaDeptMapper extends BaseMapper +{ + /** + * 通过用运营区ID删除区域与部门关联 + * + * @param deptId 部门id + * @return 结果 + */ + public int deleteAreaDeptByDeptId(Long deptId); +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaRuleMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaRuleMapper.java index 7b0a31e..60f11a2 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaRuleMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtAreaRuleMapper.java @@ -10,4 +10,11 @@ import com.ruoyi.system.domain.EtAreaRule; */ public interface EtAreaRuleMapper extends BaseMapper { + /** + * 通过用运营区ID删除区域与收费方式关联 + * + * @param areaId 运营区id + * @return 结果 + */ + public int deleteAreaRuleByAreaId(Long areaId); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOperatingAreaMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOperatingAreaMapper.java index 7dfb88a..02916fd 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOperatingAreaMapper.java +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOperatingAreaMapper.java @@ -28,6 +28,14 @@ public interface EtOperatingAreaMapper extends BaseMapper * @return 运营区集合 */ public List selectEtOperatingAreaList(EtOperatingArea etOperatingArea); + + /** + * 根据部门ID获取运营区选择框列表 运营商 + * + * @param deptId 用户ID + * @return 选中运营区ID列表 + */ + List selectAreaListByDeptId(Long deptId); // // /** // * 新增运营区 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java index 10b0630..6b8c6cc 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOperatingAreaService.java @@ -87,4 +87,12 @@ public interface IEtOperatingAreaService extends IService * @return 结果 */ EtOperatingArea getAreaInfoByLocation(String longitude, String latitude); + + /** + * 根据部门ID获取运营区选择框列表 + * + * @param deptId 用户ID + * @return 选中运营区ID列表 + */ + public List selectAreaListByDeptId(Long deptId); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOperatingAreaServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOperatingAreaServiceImpl.java index a20084f..df035c3 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOperatingAreaServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOperatingAreaServiceImpl.java @@ -130,6 +130,7 @@ public class EtOperatingAreaServiceImpl extends ServiceImpl selectAreaListByDeptId(Long deptId) { + return dao.selectAreaListByDeptId(deptId); + } } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index f7fb088..e64563c 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -4,6 +4,11 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; + +import com.ruoyi.system.domain.EtAreaDept; +import com.ruoyi.system.domain.EtAreaRule; +import com.ruoyi.system.mapper.EtAreaDeptMapper; +import com.ruoyi.system.service.IEtOperatingAreaService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.common.annotation.DataScope; @@ -20,10 +25,13 @@ import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.mapper.SysDeptMapper; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysDeptService; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; /** * 部门管理 服务实现 - * + * * @author ruoyi */ @Service @@ -35,9 +43,12 @@ public class SysDeptServiceImpl implements ISysDeptService @Autowired private SysRoleMapper roleMapper; + @Resource + private EtAreaDeptMapper etAreaDeptMapper; + /** * 查询部门管理数据 - * + * * @param dept 部门信息 * @return 部门信息集合 */ @@ -50,7 +61,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 查询部门树结构信息 - * + * * @param dept 部门信息 * @return 部门树信息集合 */ @@ -63,7 +74,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 构建前端所需要树结构 - * + * * @param depts 部门列表 * @return 树结构列表 */ @@ -90,7 +101,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 构建前端所需要下拉树结构 - * + * * @param depts 部门列表 * @return 下拉树结构列表 */ @@ -103,7 +114,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 根据角色ID查询部门树信息 - * + * * @param roleId 角色ID * @return 选中部门列表 */ @@ -116,7 +127,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 根据部门ID查询信息 - * + * * @param deptId 部门ID * @return 部门信息 */ @@ -128,7 +139,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 根据ID查询所有子部门(正常状态) - * + * * @param deptId 部门ID * @return 子部门数 */ @@ -140,7 +151,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 是否存在子节点 - * + * * @param deptId 部门ID * @return 结果 */ @@ -153,7 +164,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 查询部门是否存在用户 - * + * * @param deptId 部门ID * @return 结果 true 存在 false 不存在 */ @@ -166,7 +177,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 校验部门名称是否唯一 - * + * * @param dept 部门信息 * @return 结果 */ @@ -184,7 +195,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 校验部门是否有数据权限 - * + * * @param deptId 部门id */ @Override @@ -204,11 +215,12 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 新增保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @Override + @Transactional public int insertDept(SysDept dept) { SysDept info = deptMapper.selectDeptById(dept.getParentId()); @@ -218,16 +230,22 @@ public class SysDeptServiceImpl implements ISysDeptService throw new ServiceException("部门停用,不允许新增"); } dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); - return deptMapper.insertDept(dept); + int i = deptMapper.insertDept(dept); + Long[] areaIds = dept.getAreaIds(); + for (Long areaId:areaIds){ + etAreaDeptMapper.insert(EtAreaDept.builder().areaId(areaId).deptId(dept.getDeptId()).build()); + } + return i; } /** * 修改保存部门信息 - * + * * @param dept 部门信息 * @return 结果 */ @Override + @Transactional public int updateDept(SysDept dept) { SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); @@ -246,12 +264,17 @@ public class SysDeptServiceImpl implements ISysDeptService // 如果该部门是启用状态,则启用该部门的所有上级部门 updateParentDeptStatusNormal(dept); } + etAreaDeptMapper.deleteAreaDeptByDeptId(dept.getDeptId()); + Long[] areaIds = dept.getAreaIds(); + for (Long areaId:areaIds){ + etAreaDeptMapper.insert(EtAreaDept.builder().areaId(areaId).deptId(dept.getDeptId()).build()); + } return result; } /** * 修改该部门的父级部门状态 - * + * * @param dept 当前部门 */ private void updateParentDeptStatusNormal(SysDept dept) @@ -263,7 +286,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 修改子元素关系 - * + * * @param deptId 被修改的部门ID * @param newAncestors 新的父ID集合 * @param oldAncestors 旧的父ID集合 @@ -283,7 +306,7 @@ public class SysDeptServiceImpl implements ISysDeptService /** * 删除部门管理信息 - * + * * @param deptId 部门ID * @return 结果 */ diff --git a/electripper-system/src/main/resources/mapper/system/EtAreaDeptMapper.xml b/electripper-system/src/main/resources/mapper/system/EtAreaDeptMapper.xml new file mode 100644 index 0000000..7a9aef0 --- /dev/null +++ b/electripper-system/src/main/resources/mapper/system/EtAreaDeptMapper.xml @@ -0,0 +1,10 @@ + + + + + + delete from et_area_dept where dept_id=#{deptId} + + diff --git a/electripper-system/src/main/resources/mapper/system/EtAreaRuleMapper.xml b/electripper-system/src/main/resources/mapper/system/EtAreaRuleMapper.xml index a522dc5..f36810f 100644 --- a/electripper-system/src/main/resources/mapper/system/EtAreaRuleMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtAreaRuleMapper.xml @@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + delete from et_area_rule where area_id=#{areaId} + diff --git a/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml index 69505bf..04c564c 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOperatingAreaMapper.xml @@ -61,4 +61,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where area_id = #{areaId} + + diff --git a/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml b/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml index cf439f6..2d72851 100644 --- a/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -21,12 +21,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + - select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time + select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time from sys_dept d - + - + - + - + - + - + - + - + - - + + insert into sys_dept( dept_id, parent_id, @@ -114,7 +114,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sysdate() ) - + update sys_dept @@ -131,7 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where dept_id = #{deptId} - + update sys_dept set ancestors = - + - update sys_dept set status = '0' where dept_id in + update sys_dept set status = '0' where dept_id in #{deptId} - + update sys_dept set del_flag = '2' where dept_id = #{deptId} - \ No newline at end of file +