Browse Source

修改 车辆管理bug

11868 1 ngày trước cách đây
mục cha
commit
5203848a88

+ 141 - 17
supervision-admin/src/main/java/com/supervision/web/carGateManage/controller/CarInfoController.java

@@ -1,45 +1,169 @@
 package com.supervision.web.carGateManage.controller;
+
+
+import com.github.pagehelper.PageInfo;
 import com.supervision.web.carGateManage.service.CarInfoService;
 import com.supervision.web.carGateManage.entity.CarInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 @RestController
-@RequestMapping("/car/info")
+@RequestMapping("/car")
 public class CarInfoController {
 
     @Autowired
     private CarInfoService carInfoService;
 
     // 查询车辆列表
-    @GetMapping("/list")
-    public List<CarInfo> list(@RequestParam(required = false) String plateNumber,
-                              @RequestParam(required = false) String ownerName) {
-        return carInfoService.getCarList();
-    }
-    // 统计注册车辆总数
-    @GetMapping("/total")
-    public int total() {
-        return carInfoService.getCarCount();
+    @PostMapping("/list")
+    public Map<String, Object> listCars(@RequestBody Map<String, Object> params) {
+        Map<String, Object> result = new HashMap<>();
+        try {
+            PageInfo<CarInfo> pageInfo = carInfoService.searchByCondition(params);
+            result.put("total", pageInfo.getTotal());
+            result.put("list", pageInfo.getList());
+            result.put("pageNum", pageInfo.getPageNum());
+            result.put("pageSize", pageInfo.getPageSize());
+            result.put("status", true);
+            result.put("message", "获取所有设备列表成功");
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.put("status", false);
+            result.put("message", "获取所有设备列表失败: " + e.getMessage());
+            return result;
+        }
     }
 
     // 添加车辆
     @PostMapping("/add")
-    public int add(@RequestBody CarInfo carInfo) {
-        return carInfoService.addCar(carInfo);
+    public Map<String, Object> addDevice(@RequestBody Map<String, Object> params) {
+        Map<String, Object> result = new HashMap<>();
+        try {
+            CarInfo carInfo = new CarInfo();
+            // 一、车牌信息
+            carInfo.setPlateNumber((String) params.get("plateNumber"));
+            carInfo.setPlateColor((String) params.get("plateColor"));
+            carInfo.setPlateType((String) params.get("plateType"));
+
+            // 二、车辆信息
+            carInfo.setVehicleType((String) params.get("vehicleType"));
+            carInfo.setVehicleColor((String) params.get("vehicleColor"));
+            carInfo.setVehicleBrand((String) params.get("vehicleBrand"));
+            carInfo.setEngineNo((String) params.get("engineNo"));
+            carInfo.setEmissionNo((String) params.get("emissionNo"));
+            carInfo.setVin((String) params.get("vin"));
+            carInfo.setDisplacement((String) params.get("displacement"));
+            carInfo.setIdentifyCode((String) params.get("identifyCode"));
+            carInfo.setFleetName((String) params.get("fleetName"));
+
+            // 三、卡片信息
+            carInfo.setIssuerName((String) params.get("issuerName"));
+            carInfo.setIssuerDeviceType((String) params.get("issuerDeviceType"));
+            carInfo.setParkingType((String) params.get("parkingType"));
+            carInfo.setPackageInfo((String) params.get("packageInfo"));
+
+            // 四、车主信息
+            carInfo.setOwnerName((String) params.get("ownerName"));
+            carInfo.setPhoneNumber((String) params.get("phoneNumber"));
+            carInfo.setCertificateNo((String) params.get("certificateNo"));
+            carInfo.setAddress((String) params.get("address"));
+            carInfo.setPosition((String) params.get("position"));
+            carInfo.setCompany((String) params.get("company"));
+            carInfo.setDepartmentName((String) params.get("departmentName"));
+
+            // 五、分组与权限信息
+            carInfo.setGroupName((String) params.get("groupName"));
+            carInfo.setVehicleGroup((String) params.get("vehicleGroup"));
+
+            // parkingPermission 是 List<Long>,前端可能传 List<Integer> 或 List<Long>
+            if (params.get("parkingPermission") instanceof List<?>) {
+                List<?> list = (List<?>) params.get("parkingPermission");
+                List<Long> permissionList = list.stream()
+                        .filter(Objects::nonNull)
+                        .map(o -> Long.parseLong(o.toString()))
+                        .collect(Collectors.toList());
+                carInfo.setParkingPermission(permissionList);
+            }
+
+            carInfo.setParkingName((String) params.get("parkingName"));
+
+            // 六、有效期相关
+            // dailyValidTime 前端可能传 ["08:00", "18:00"]
+            if (params.get("dailyValidTime") instanceof List<?>) {
+                List<?> list = (List<?>) params.get("dailyValidTime");
+                List<LocalTime> times = list.stream()
+                        .filter(Objects::nonNull)
+                        .map(o -> LocalTime.parse(o.toString()))
+                        .collect(Collectors.toList());
+                carInfo.setDailyValidTime(times);
+            }
+
+            // historyValidTime 前端可能传 ["2025-11-01", "2025-12-01"]
+            if (params.get("historyValidTime") instanceof List<?>) {
+                List<?> list = (List<?>) params.get("historyValidTime");
+                List<LocalDate> dates = list.stream()
+                        .filter(Objects::nonNull)
+                        .map(o -> LocalDate.parse(o.toString()))
+                        .collect(Collectors.toList());
+                carInfo.setHistoryValidTime(dates);
+            }
+
+            // 七、其他信息
+            carInfo.setRemarks((String) params.get("remarks"));
+            carInfo.setDataVersion((String) params.get("dataVersion"));
+
+            carInfoService.add(carInfo);
+            result.put("status", true);
+            result.put("message", "添加车辆成功");
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.put("status", false);
+            result.put("message", "添加车辆失败: " + e.getMessage());
+            return result;
+        }
     }
 
     // 修改车辆
-    @PutMapping("/update")
-    public int update(@RequestBody CarInfo carInfo) {
-        return carInfoService.editCar(carInfo);
+    @PostMapping("/update")
+    public Map<String, Object> updateDevice(@RequestBody CarInfo carInfo) {
+        Map<String, Object> result = new HashMap<>();
+        try {
+            carInfoService.update(carInfo);
+            result.put("status", true);
+            result.put("message", "修改车辆成功");
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.put("status", false);
+            result.put("message", "修改车辆失败: " + e.getMessage());
+            return result;
+        }
     }
 
     // 删除车辆
     @DeleteMapping("/delete/{id}")
-    public int delete(@PathVariable Long id) {
-        return carInfoService.removeCar(id);
+    public Map<String, Object> deleteDevice(@PathVariable Long id) {
+        Map<String, Object> result = new HashMap<>();
+        try {
+            carInfoService.delete(id);
+            result.put("status", true);
+            result.put("message", "删除车辆成功");
+            return result;
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.put("status", false);
+            result.put("message", "删除车辆失败: " + e.getMessage());
+            return result;
+        }
     }
 }

+ 61 - 10
supervision-admin/src/main/java/com/supervision/web/carGateManage/entity/CarInfo.java

@@ -1,19 +1,70 @@
 package com.supervision.web.carGateManage.entity;
 
-import lombok.Data;
 
+import lombok.Data;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Date;
+import java.util.List;
 
+/**
+ * 车辆信息实体类(对应前端 formData)
+ */
 @Data
 public class CarInfo {
-    private Long id;
-    private String plateNumber;
-    private String ownerName;
-    private String orgName;     // 所属组织
-    private String carGroup;    // 车辆组群
-    private LocalDate validUntil; // 有效期
-    private LocalDateTime createTime;
-    private Boolean isTemporary;
+
+    private Long id; // 主键
+
+    // 一、车牌信息
+    private String plateNumber;      // 车牌号码
+    private String plateColor;       // 车牌颜色
+    private String plateType;        // 车牌类型
+
+    // 二、车辆信息
+    private String vehicleType;      // 车辆类型
+    private String vehicleColor;     // 车辆颜色
+    private String vehicleBrand;     // 车辆品牌
+    private String engineNo;         // 发动机号
+    private String emissionNo;       // 排放量号
+    private String vin;              // 车架号
+    private String displacement;     // 排量
+    private String identifyCode;     // 识别代码
+    private String fleetName;        // 车队名称
+
+    // 三、卡片信息
+    private String issuerName;       // 发卡人员
+    private String issuerDeviceType; // 发卡器类型
+    private String parkingType;      // 停车类型
+    private String packageInfo;      // 包时信息
+
+    // 四、车主信息
+    private String ownerName;        // 车主姓名
+    private String phoneNumber;      // 手机号码
+    private String certificateNo;    // 证件号码
+    private String address;          // 住址
+    private String position;         // 职位
+    private String company;          // 所属公司
+    private String departmentName;   // 部门名称
+
+    // 五、分组与权限信息
+    private String groupName;        // 分组名称
+    private String vehicleGroup;     // 车辆群组
+    private List<Long> parkingPermission; // 场库权限(ID 列表)
+    private String parkingName;      // 场库名称
+    private List<LocalTime> dailyValidTime; // 每日有效时段
+    private List<LocalDate> historyValidTime; // 历史有效期
+
+    // 六、其他信息
+    private String remarks;          // 备注
+    private String dataVersion;      // 数据版本
+
+    private Date validUntil;           // 有效期
+
+    private String isTemporary; // 是否临时车辆
+
+    private Boolean enable; // 是否启用
+
+    private Date createTime; // 创建时间
+    private Date updateTime; // 修改时间
 }
 

+ 12 - 5
supervision-admin/src/main/java/com/supervision/web/carGateManage/mapper/CarInfoMapper.java

@@ -1,19 +1,26 @@
 package com.supervision.web.carGateManage.mapper;
 
+
 import com.supervision.web.carGateManage.entity.CarInfo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
 @Mapper
 public interface CarInfoMapper {
-    List<CarInfo> getCarList();
 
-    int countCars();
+    List<CarInfo> searchByCondition(
+            @Param("plateNumber") String plateNumber,
+            @Param("plateType") String plateType,
+            @Param("vehicleType") String vehicleType,
+            @Param("vehicleBrand") String vehicleBrand
+    );
+
+    int insert(CarInfo carInfo);
 
-    int insertCar(CarInfo carInfo);
+    int update(CarInfo carInfo);
 
-    int updateCar(CarInfo carInfo);
+    int delete(Long id);
 
-    int deleteCar(Long id);
 }

+ 9 - 7
supervision-admin/src/main/java/com/supervision/web/carGateManage/service/CarInfoService.java

@@ -1,16 +1,18 @@
 package com.supervision.web.carGateManage.service;
 
-import com.supervision.web.carGateManage.entity.CarInfo;
 
-import java.util.List;
+import com.github.pagehelper.PageInfo;
+import com.supervision.web.carGateManage.entity.CarInfo;
+import java.util.Map;
 
 public interface CarInfoService {
-    List<CarInfo>   getCarList();
-    int getCarCount();
 
-    int addCar(CarInfo carInfo);
+    PageInfo<CarInfo> searchByCondition(Map<String, Object> params);
+
+    int add(CarInfo carInfo);
+
+    int update(CarInfo carInfo);
 
-    int editCar(CarInfo carInfo);
+    int delete(Long id);
 
-    int removeCar(Long id);
 }

+ 26 - 12
supervision-admin/src/main/java/com/supervision/web/carGateManage/service/impl/CarInfoServiceImpl.java

@@ -1,4 +1,8 @@
 package com.supervision.web.carGateManage.service.impl;
+
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import com.supervision.web.carGateManage.entity.CarInfo;
 import com.supervision.web.carGateManage.mapper.CarInfoMapper;
 import com.supervision.web.carGateManage.service.CarInfoService;
@@ -6,33 +10,43 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class CarInfoServiceImpl implements CarInfoService {
+
     @Autowired
     private CarInfoMapper carInfoMapper;
 
     @Override
-    public List<CarInfo> getCarList() {
-        return carInfoMapper.getCarList();
-    }
+    public PageInfo<CarInfo> searchByCondition(Map<String, Object> params) {
+        int page = (int) params.getOrDefault("page", 1);
+        int size = (int) params.getOrDefault("size", 10);
 
-    @Override
-    public int getCarCount() {
-        return carInfoMapper.countCars();  // 假设你有个 mapper
+        String plateNumber = (String) params.getOrDefault("plateNumber", null);
+        String plateType = (String) params.getOrDefault("plateType", null);
+        String vehicleType = (String) params.getOrDefault("vehicleType", null);
+        String vehicleBrand = (String) params.getOrDefault("vehicleBrand", null);
+
+        PageHelper.startPage(page, size);
+
+        List<CarInfo> list = carInfoMapper.searchByCondition(plateNumber, plateType, vehicleType, vehicleBrand);
+
+        return new PageInfo<>(list);
     }
+
     @Override
-    public int addCar(CarInfo carInfo) {
-        return carInfoMapper.insertCar(carInfo);
+    public int add(CarInfo carInfo) {
+        return carInfoMapper.insert(carInfo);
     }
 
     @Override
-    public int editCar(CarInfo carInfo) {
-        return carInfoMapper.updateCar(carInfo);
+    public int update(CarInfo carInfo) {
+        return carInfoMapper.update(carInfo);
     }
 
     @Override
-    public int removeCar(Long id) {
-        return carInfoMapper.deleteCar(id);
+    public int delete(Long id) {
+        return carInfoMapper.delete(id);
     }
 }

+ 1 - 0
supervision-admin/src/main/java/com/supervision/web/peopleGateManage/service/impl/DeviceServiceImpl.java

@@ -1,5 +1,6 @@
 package com.supervision.web.peopleGateManage.service.impl;
 
+
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.supervision.web.peopleGateManage.mapper.DeviceMapper;

+ 83 - 25
supervision-admin/src/main/resources/mapper/carGateManage/CarInfoMapper.xml

@@ -9,53 +9,111 @@
     <resultMap id="CarInfoResultMap" type="com.supervision.web.carGateManage.entity.CarInfo">
         <id column="id" property="id"/>
         <result column="plate_number" property="plateNumber"/>
+        <result column="plate_color" property="plateColor"/>
+        <result column="plate_type" property="plateType"/>
+        <result column="vehicle_type" property="vehicleType"/>
+        <result column="vehicle_color" property="vehicleColor"/>
+        <result column="vehicle_brand" property="vehicleBrand"/>
+        <result column="engine_no" property="engineNo"/>
+        <result column="emission_no" property="emissionNo"/>
+        <result column="vin" property="vin"/>
+        <result column="displacement" property="displacement"/>
+        <result column="identify_code" property="identifyCode"/>
+        <result column="fleet_name" property="fleetName"/>
+        <result column="issuer_name" property="issuerName"/>
+        <result column="issuer_device_type" property="issuerDeviceType"/>
+        <result column="parking_type" property="parkingType"/>
+        <result column="package_info" property="packageInfo"/>
         <result column="owner_name" property="ownerName"/>
-        <result column="org_name" property="orgName"/>
-        <result column="car_group" property="carGroup"/>
+        <result column="phone_number" property="phoneNumber"/>
+        <result column="certificate_no" property="certificateNo"/>
+        <result column="address" property="address"/>
+        <result column="position" property="position"/>
+        <result column="company" property="company"/>
+        <result column="department_name" property="departmentName"/>
+        <result column="group_name" property="groupName"/>
+        <result column="vehicle_group" property="vehicleGroup"/>
+        <result column="parking_name" property="parkingName"/>
+        <result column="remarks" property="remarks"/>
+        <result column="data_version" property="dataVersion"/>
         <result column="valid_until" property="validUntil"/>
         <result column="create_time" property="createTime"/>
         <result column="is_temporary" property="isTemporary"/>
+        <result column="enable" property="enable"/>
     </resultMap>
 
     <!-- 查询全部 -->
-    <select id="getCarList" resultMap="CarInfoResultMap">
-        SELECT * FROM new_car_info
-    </select>
-
-    <!-- 查询注册车辆数量 -->
-    <select id="countCars" resultType="int">
-        SELECT COUNT(*) FROM new_car_info
-    </select>
-
-
-    <!-- 条件查询 -->
-    <select id="selectCarList" parameterType="map" resultMap="CarInfoResultMap">
-        SELECT * FROM new_car_info
+    <select id="searchByCondition" resultMap="CarInfoResultMap">
+        SELECT *
+        FROM new_car_info
         <where>
             <if test="plateNumber != null and plateNumber != ''">
                 AND plate_number LIKE CONCAT('%', #{plateNumber}, '%')
             </if>
-            <if test="ownerName != null and ownerName != ''">
-                AND owner_name LIKE CONCAT('%', #{ownerName}, '%')
+            <if test="plateType != null and plateType != ''">
+                AND plate_type = #{plateType}
+            </if>
+            <if test="vehicleType != null and vehicleType != ''">
+                AND vehicle_type = #{vehicleType}
+            </if>
+            <if test="vehicleBrand != null and vehicleBrand != ''">
+                AND vehicle_brand = #{vehicleBrand}
             </if>
         </where>
         ORDER BY create_time DESC
     </select>
 
     <!-- 添加 -->
-    <insert id="insertCar" parameterType="com.supervision.web.carGateManage.entity.CarInfo"
-            useGeneratedKeys="true" keyProperty="id">
-        INSERT INTO new_car_info (plate_number, owner_name, org_name, car_group, valid_until, create_time,is_temporary)
-        VALUES (#{plateNumber}, #{ownerName}, #{orgName}, #{carGroup}, #{validUntil}, #{createTime}, #{isTemporary})
+    <insert id="insert" parameterType="com.supervision.web.carGateManage.entity.CarInfo" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO new_car_info (
+            plate_number, plate_color, plate_type,
+            vehicle_type, vehicle_color, vehicle_brand, engine_no, emission_no, vin, displacement, identify_code, fleet_name,
+            issuer_name, issuer_device_type, parking_type, package_info,
+            owner_name, phone_number, certificate_no, address, position, company, department_name,
+            group_name, vehicle_group, parking_name,
+            remarks, data_version, valid_until, create_time, is_temporary
+        )
+        VALUES (
+                   #{plateNumber}, #{plateColor}, #{plateType},
+                   #{vehicleType}, #{vehicleColor}, #{vehicleBrand}, #{engineNo}, #{emissionNo}, #{vin}, #{displacement}, #{identifyCode}, #{fleetName},
+                   #{issuerName}, #{issuerDeviceType}, #{parkingType}, #{packageInfo},
+                   #{ownerName}, #{phoneNumber}, #{certificateNo}, #{address}, #{position}, #{company}, #{departmentName},
+                   #{groupName}, #{vehicleGroup}, #{parkingName},
+                   #{remarks}, #{dataVersion}, #{validUntil}, #{createTime}, #{isTemporary}
+               )
     </insert>
 
     <!-- 修改 -->
-    <update id="updateCar" parameterType="com.supervision.web.carGateManage.entity.CarInfo">
+    <update id="update" parameterType="com.supervision.web.carGateManage.entity.CarInfo">
         UPDATE new_car_info
         SET plate_number = #{plateNumber},
+            plate_color = #{plateColor},
+            plate_type = #{plateType},
+            vehicle_type = #{vehicleType},
+            vehicle_color = #{vehicleColor},
+            vehicle_brand = #{vehicleBrand},
+            engine_no = #{engineNo},
+            emission_no = #{emissionNo},
+            vin = #{vin},
+            displacement = #{displacement},
+            identify_code = #{identifyCode},
+            fleet_name = #{fleetName},
+            issuer_name = #{issuerName},
+            issuer_device_type = #{issuerDeviceType},
+            parking_type = #{parkingType},
+            package_info = #{packageInfo},
             owner_name = #{ownerName},
-            org_name = #{orgName},
-            car_group = #{carGroup},
+            phone_number = #{phoneNumber},
+            certificate_no = #{certificateNo},
+            address = #{address},
+            position = #{position},
+            company = #{company},
+            department_name = #{departmentName},
+            group_name = #{groupName},
+            vehicle_group = #{vehicleGroup},
+            parking_name = #{parkingName},
+            remarks = #{remarks},
+            data_version = #{dataVersion},
             valid_until = #{validUntil},
             create_time = #{createTime},
             is_temporary = #{isTemporary}
@@ -63,7 +121,7 @@
     </update>
 
     <!-- 删除 -->
-    <delete id="deleteCar" parameterType="long">
+    <delete id="delete" parameterType="long">
         DELETE FROM new_car_info WHERE id = #{id}
     </delete>