Browse Source

fix: 车辆获取接口更新以及部门新增字段

TwoKe945 1 year ago
parent
commit
88a2ec09c7

+ 4 - 0
ljclw-core/pom.xml

@@ -33,6 +33,10 @@
             <version>1.6.2</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.ruoyi</groupId>
+            <artifactId>ruoyi-system</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>com.ruoyi</groupId>

+ 12 - 9
ljclw-core/src/main/java/com/ruizheng/clw/controller/CarInfoController.java

@@ -5,15 +5,20 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruizheng.clw.domain.CarInfo;
 import com.ruizheng.clw.service.CarInfoService;
 import com.ruoyi.common.annotation.DataSource;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.enums.DataSourceType;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-@Api("车辆信息")
+import java.util.List;
+import java.util.Objects;
+
+@Api(value = "车辆信息", tags = "车辆信息")
 @RestController
 @RequestMapping("/car")
 public class CarInfoController {
@@ -21,15 +26,13 @@ public class CarInfoController {
     @Autowired
     private CarInfoService carInfoService;
 
-    @GetMapping("/page")
+    @GetMapping("/list/{deptId}")
     @ApiOperation("查询车辆列表")
-    @DataSource(DataSourceType.SLAVE)
-    public Object get() {
-        return carInfoService.page(new Page<CarInfo>(1, 10));
+    public AjaxResult listByOnlineStatus(@PathVariable("deptId") Long deptId, Integer onlineStatus) {
+        List<Long> deptIds = carInfoService.getMeAndChildrenDeptId(deptId);
+        return AjaxResult.success(carInfoService.getCardInfoInDeptIdsAndOnline(deptIds, onlineStatus));
     }
 
-    @GetMapping("/list")
-    public String index() {
-        return "11";
-    }
+
+
 }

+ 0 - 3
ljclw-core/src/main/java/com/ruizheng/clw/mapper/CarInfoMapper.java

@@ -3,13 +3,10 @@ package com.ruizheng.clw.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruizheng.clw.domain.CarInfo;
-import com.ruoyi.common.annotation.DataSource;
-import com.ruoyi.common.enums.DataSourceType;
 import org.springframework.stereotype.Repository;
 
 
 @Repository
 public interface CarInfoMapper extends BaseMapper<CarInfo> {
 
-
 }

+ 12 - 0
ljclw-core/src/main/java/com/ruizheng/clw/service/CarInfoService.java

@@ -4,5 +4,17 @@ package com.ruizheng.clw.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruizheng.clw.domain.CarInfo;
 
+import java.util.List;
+
 public interface CarInfoService extends IService<CarInfo> {
+    /**
+     * 根据在线状态查询车辆点位信息
+     * @param deptIds
+     * @param onlineStatus
+     * @return
+     */
+    List<CarInfo> getCardInfoInDeptIdsAndOnline(List<Long> deptIds, Integer onlineStatus) ;
+
+    List<Long> getMeAndChildrenDeptId(Long deptId) ;
+
 }

+ 40 - 0
ljclw-core/src/main/java/com/ruizheng/clw/service/imple/CarInfoServiceImpl.java

@@ -1,12 +1,52 @@
 package com.ruizheng.clw.service.imple;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruizheng.clw.domain.CarInfo;
 import com.ruizheng.clw.mapper.CarInfoMapper;
 import com.ruizheng.clw.service.CarInfoService;
+import com.ruoyi.common.annotation.DataSource;
+import com.ruoyi.common.enums.DataSourceType;
+import com.ruoyi.system.mapper.SysDeptMapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Objects;
+
 @Service
 public class CarInfoServiceImpl extends ServiceImpl<CarInfoMapper, CarInfo> implements CarInfoService {
+    @Autowired
+    private SysDeptMapper sysDeptMapper;
+    @Autowired
+    private CarInfoMapper carInfoMapper;
+
+    /**
+     * 查询当前节点以及子节点ID
+     * @param deptId
+     * @return
+     */
+    @Override
+    @DataSource(DataSourceType.MASTER)
+    public List<Long> getMeAndChildrenDeptId(Long deptId) {
+        List<Long> deptIds = sysDeptMapper.selectChildrenDeptIdById(deptId);
+        deptIds.add(deptId);
+        return deptIds;
+    }
+
+
+    @Override
+    @DataSource(DataSourceType.SLAVE)
+    public List<CarInfo> getCardInfoInDeptIdsAndOnline(List<Long> deptIds, Integer onlineStatus) {
+        LambdaQueryWrapper<CarInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CarInfo>()
+                .in(CarInfo::getDepId, deptIds);
+        if (Objects.nonNull(onlineStatus)) {
+            lambdaQueryWrapper
+                    .eq(CarInfo::getOnlineStatus, onlineStatus);
+        }
+        return carInfoMapper
+                .selectList(lambdaQueryWrapper);
+    }
+
 
 }

+ 10 - 0
pom.xml

@@ -64,6 +64,16 @@
                 <groupId>com.github.pagehelper</groupId>
                 <artifactId>pagehelper-spring-boot-starter</artifactId>
                 <version>${pagehelper.boot.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.mybatis</groupId>
+                        <artifactId>mybatis</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.mybatis</groupId>
+                        <artifactId>mybatis-spring</artifactId>
+                    </exclusion>
+                </exclusions>
             </dependency>
 
             <!-- 获取系统信息 -->

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -120,7 +120,7 @@ swagger:
   # 是否开启swagger
   enabled: true
   # 请求前缀
-  pathMapping: /
+  pathMapping: /api
 
 # 防止XSS攻击
 xss: 

+ 28 - 1
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java

@@ -6,6 +6,8 @@ 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;
@@ -20,6 +22,7 @@ public class SysDept extends BaseEntity
     private static final long serialVersionUID = 1L;
 
     /** 部门ID */
+
     private Long deptId;
 
     /** 父部门ID */
@@ -68,11 +71,35 @@ public class SysDept extends BaseEntity
      * 单位级别
      */
     private String level;
-
+    /**
+     * 总人数
+     */
+    @TableField(exist = false)
+    private Long totalPerson;
+    /**
+     * 组织职责
+     */
+    private String dutyDescription;
     
     /** 子部门 */
     private List<SysDept> children = new ArrayList<SysDept>();
 
+    public String getDutyDescription() {
+        return dutyDescription;
+    }
+
+    public void setDutyDescription(String dutyDescription) {
+        this.dutyDescription = dutyDescription;
+    }
+
+    public Long getTotalPerson() {
+        return totalPerson;
+    }
+
+    public void setTotalPerson(Long totalPerson) {
+        this.totalPerson = totalPerson;
+    }
+
     public String getLat() {
         return lat;
     }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java

@@ -115,4 +115,6 @@ public interface SysDeptMapper
      * @return 结果
      */
     public int deleteDeptById(Long deptId);
+
+    List<Long> selectChildrenDeptIdById(Long deptId);
 }

+ 18 - 4
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -24,15 +24,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="lng" column="lng" />
 		<result property="address" column="address" />
 		<result property="level" column="level" />
+		<result property="dutyDescription" column="duty_description" />
 	</resultMap>
 	
 	<sql id="selectDeptVo">
-        select d.lat, d.lng, d.address, d.level,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.lat,
+            d.lng,
+            d.address, d.level,d.dept_id, d.duty_description, 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"/>
+	<select id="selectDeptList" parameterType="SysDept" resultType="SysDept">
+		select
+		d.lat,
+		d.lng,
+		d.address, d.level,d.dept_id, d.duty_description, 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 count(1) from sys_user u where u.dept_id = d.dept_id ) as total_person
+		from sys_dept d
         where d.del_flag = '0'
 		<if test="deptId != null and deptId != 0">
 			AND dept_id = #{deptId}
@@ -90,7 +99,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	    <include refid="selectDeptVo"/>
 		where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
 	</select>
-    
+    <select id="selectChildrenDeptIdById" resultType="java.lang.Long">
+		select dept_id from sys_dept where find_in_set(#{deptId}, ancestors)
+	</select>
+
     <insert id="insertDept" parameterType="SysDept">
  		insert into sys_dept(
  			<if test="deptId != null and deptId != 0">dept_id,</if>
@@ -107,6 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="lng != null and lng != ''">lng,</if>
  			<if test="address != null and lat != ''">address,</if>
  			<if test="level != null and level != ''">level,</if>
+ 			<if test="dutyDescription != null and dutyDescription != ''">duty_description,</if>
  			create_time
  		)values(
  			<if test="deptId != null and deptId != 0">#{deptId},</if>
@@ -123,6 +136,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="lng != null and lng != ''">#{lng},</if>
 			<if test="address != null and lat != ''">#{address},</if>
 			<if test="level != null and level != ''">#{level},</if>
+			<if test="dutyDescription != null and dutyDescription != ''">#{duty_description},</if>
  			sysdate()
  		)
 	</insert>