1.部门绑定运营区

This commit is contained in:
邱贞招 2024-05-25 18:47:31 +08:00
parent 66d22c623d
commit da26d6b2b1
14 changed files with 200 additions and 46 deletions

View File

@ -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));

View File

@ -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<SysDept> children = new ArrayList<SysDept>();

View File

@ -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;
}

View File

@ -144,7 +144,7 @@ public class EtFeeRule extends BaseEntity
/** 骑行价格说明*/
@Excel(name = "骑行价格说明")
private BigDecimal instructions;
private String instructions;
/** 是否缴纳过押金*/
@Excel(name = "是否缴纳过押金")

View File

@ -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<EtAreaDept>
{
/**
* 通过用运营区ID删除区域与部门关联
*
* @param deptId 部门id
* @return 结果
*/
public int deleteAreaDeptByDeptId(Long deptId);
}

View File

@ -10,4 +10,11 @@ import com.ruoyi.system.domain.EtAreaRule;
*/
public interface EtAreaRuleMapper extends BaseMapper<EtAreaRule>
{
/**
* 通过用运营区ID删除区域与收费方式关联
*
* @param areaId 运营区id
* @return 结果
*/
public int deleteAreaRuleByAreaId(Long areaId);
}

View File

@ -28,6 +28,14 @@ public interface EtOperatingAreaMapper extends BaseMapper<EtOperatingArea>
* @return 运营区集合
*/
public List<EtOperatingArea> selectEtOperatingAreaList(EtOperatingArea etOperatingArea);
/**
* 根据部门ID获取运营区选择框列表 运营商
*
* @param deptId 用户ID
* @return 选中运营区ID列表
*/
List<Long> selectAreaListByDeptId(Long deptId);
//
// /**
// * 新增运营区

View File

@ -87,4 +87,12 @@ public interface IEtOperatingAreaService extends IService<EtOperatingArea>
* @return 结果
*/
EtOperatingArea getAreaInfoByLocation(String longitude, String latitude);
/**
* 根据部门ID获取运营区选择框列表
*
* @param deptId 用户ID
* @return 选中运营区ID列表
*/
public List<Long> selectAreaListByDeptId(Long deptId);
}

View File

@ -130,6 +130,7 @@ public class EtOperatingAreaServiceImpl extends ServiceImpl<EtOperatingAreaMappe
* @return 结果
*/
@Override
@Transactional
public int updateEtOperatingArea(EtOperatingArea etOperatingArea)
{
/** 将边界值转Geometry对象*/
@ -137,7 +138,13 @@ public class EtOperatingAreaServiceImpl extends ServiceImpl<EtOperatingAreaMappe
Geometry geometry = GeoUtils.toGeometry(boundaryStr);
String wkt = GeoUtils.wkt(geometry);
etOperatingArea.setBoundary(wkt);
return dao.updateById(etOperatingArea);
etAreaRuleMapper.deleteAreaRuleByAreaId(etOperatingArea.getAreaId());
int i = dao.updateById(etOperatingArea);
Long[] ruleIds = etOperatingArea.getRuleIds();
for (Long ruleId:ruleIds){
etAreaRuleMapper.insert(EtAreaRule.builder().areaId(etOperatingArea.getAreaId()).ruleId(ruleId).build());
}
return i;
}
/**
@ -251,6 +258,16 @@ public class EtOperatingAreaServiceImpl extends ServiceImpl<EtOperatingAreaMappe
}
}
/**
* 根据部门ID获取运营区选择框列表
*
* @param deptId 用户ID
* @return 选中运营区ID列表
*/
@Override
public List<Long> selectAreaListByDeptId(Long deptId) {
return dao.selectAreaListByDeptId(deptId);
}
}

View File

@ -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 结果
*/

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.EtAreaDeptMapper">
<delete id="deleteAreaDeptByDeptId">
delete from et_area_dept where dept_id=#{deptId}
</delete>
</mapper>

View File

@ -4,4 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.EtAreaRuleMapper">
<delete id="deleteAreaRuleByAreaId">
delete from et_area_rule where area_id=#{areaId}
</delete>
</mapper>

View File

@ -61,4 +61,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where area_id = #{areaId}
</select>
<select id="selectAreaListByDeptId" resultType="java.lang.Long" parameterType="Long">
select a.area_id
from et_operating_area a
left join et_area_dept ad on ad.area_id = a.area_id
left join sys_dept d on d.dept_id = ad.dept_id
where d.dept_id = #{deptId}
</select>
</mapper>

View File

@ -21,12 +21,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectDeptVo">
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
</sql>
<select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where d.del_flag = '0'
@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
${params.dataScope}
order by d.parent_id, d.order_num
</select>
<select id="selectDeptListByRoleId" resultType="Long">
select d.dept_id
from sys_dept d
@ -57,37 +57,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
order by d.parent_id, d.order_num
</select>
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
from sys_dept d
where d.dept_id = #{deptId}
</select>
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
</select>
<select id="hasChildByDeptId" parameterType="Long" resultType="int">
select count(1) from sys_dept
where del_flag = '0' and parent_id = #{deptId} limit 1
</select>
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
select * from sys_dept where find_in_set(#{deptId}, ancestors)
</select>
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
</select>
<select id="checkDeptNameUnique" resultMap="SysDeptResult">
<include refid="selectDeptVo"/>
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select>
<insert id="insertDept" parameterType="SysDept">
<insert id="insertDept" parameterType="SysDept" useGeneratedKeys="true" keyProperty="deptId">
insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>
@ -114,7 +114,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sysdate()
)
</insert>
<update id="updateDept" parameterType="SysDept">
update sys_dept
<set>
@ -131,7 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</set>
where dept_id = #{deptId}
</update>
<update id="updateDeptChildren" parameterType="java.util.List">
update sys_dept set ancestors =
<foreach collection="depts" item="item" index="index"
@ -144,16 +144,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.deptId}
</foreach>
</update>
<update id="updateDeptStatusNormal" parameterType="Long">
update sys_dept set status = '0' where dept_id in
update sys_dept set status = '0' where dept_id in
<foreach collection="array" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</update>
<delete id="deleteDeptById" parameterType="Long">
update sys_dept set del_flag = '2' where dept_id = #{deptId}
</delete>
</mapper>
</mapper>