多对多

pull/8/head
xiaoSu 2024-04-08 10:06:40 +08:00
parent 86d2643da9
commit ae34564232
29 changed files with 206 additions and 139 deletions

View File

@ -250,6 +250,11 @@
<version>${mqttv3.version}</version>
</dependency>
<dependency>
<groupId>com.zhilian</groupId>
<artifactId>zhilian-common-business</artifactId>
<version>${zhilian.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -19,6 +19,7 @@
<module>zhilian-common-datasource</module>
<module>zhilian-common-system</module>
<module>zhilian-common-resolver</module>
<module>zhilian-common-business</module>
</modules>
<artifactId>zhilian-common</artifactId>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhilian</groupId>
<artifactId>zhilian-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>zhilian-common-business</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- zhilian Common Core-->
<dependency>
<groupId>com.zhilian</groupId>
<artifactId>zhilian-common-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -28,7 +28,8 @@ public class Markers extends BaseEntity {
@Excel(name = "标识名称")
private String markersName;
@TableField(exist = false)
List<Fence> fenceList;
List<Long> fenceIds;
}

View File

@ -9,6 +9,8 @@ import com.zhilian.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
* business_vehicle
*/
@ -31,50 +33,39 @@ public class Vehicle extends BaseEntity {
/**
* VIN
*/
@Excel(name = "车辆VIN")
@TableField(value = "vehicle_vin")
@TableField("vehicle_vin")
private String vehicleVIN;
/**
*
*/
@Excel(name = "车辆类型编号")
@TableField(value = "vehicle_type_id")
private Long vehicleTypeId;
/**
*
*/
@Excel(name = "电子围栏")
@TableField(value = "fence_id")
private Long fenceId;
@TableField(exist = false)
private Long vehicleTypeName;
/**
*
*/
@Excel(name = "电机厂商")
@TableField(value = "vehicle_motor")
private String motorBusiness;
private String vehicleMotor;
/**
*
*/
@Excel(name = "电池厂商")
@TableField(value = "vehicle_battery")
private String batteryBusiness;
private String vehicleBattery;
/**
* ID
*/
@Excel(name = "电机ID")
@TableField(value = "motor_id")
private String motorID;
private String motorId;
/**
* ID
*/
@Excel(name = "电池ID")
@TableField(value = "battery_id")
private String batteryID;
private String batteryId;
/**
*
*/
@Excel(name = "车辆状态")
@TableField(value = "vehicle_state")
private Long vehicleState;
@TableField(exist = false)
private List<Long> markersIds;
}

View File

@ -1,13 +1,9 @@
package com.zhilian.business.domain.middle;
import com.baomidou.mybatisplus.annotation.*;
import com.zhilian.business.domain.Fence;
import com.zhilian.business.domain.Markers;
import lombok.Data;
import lombok.ToString;
import java.util.List;
@Data
@ToString
@TableName("business_markers_fence")

View File

@ -0,0 +1,7 @@
package com.zhilian.business.remote;
import org.springframework.stereotype.Component;
@Component
public interface RemoteFenceService {
}

View File

@ -0,0 +1,8 @@
package com.zhilian.business.remote.factory;
import com.zhilian.common.core.constant.ServiceNameConstants;
import org.springframework.cloud.openfeign.FeignClient;
//@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public class RemoteFenceFallbackFactory {
}

View File

@ -73,6 +73,12 @@
<artifactId>zhilian-common-log</artifactId>
</dependency>
<dependency>
<groupId>com.zhilian</groupId>
<artifactId>zhilian-common-business</artifactId>
</dependency>
<!-- zhilian Common Swagger -->
<dependency>
<groupId>com.zhilian</groupId>
@ -106,4 +112,4 @@
</plugins>
</build>
</project>
</project>

View File

@ -3,7 +3,6 @@ package com.zhilian.business.controller;
import com.zhilian.common.core.domain.Result;
import com.zhilian.common.core.web.controller.BaseController;
import com.zhilian.business.domain.Fence;
import com.zhilian.business.domain.vo.FenceVo;
import com.zhilian.business.service.FenceService;
import com.zhilian.common.core.web.page.TableDataInfo;
import com.zhilian.common.security.utils.SecurityUtils;

View File

@ -3,7 +3,6 @@ package com.zhilian.business.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.middle.MarkersFence;
import com.zhilian.business.domain.middle.VehicleMarkers;
import com.zhilian.business.service.MarkersFenceService;
import com.zhilian.business.service.MarkersService;
import com.zhilian.common.core.domain.Result;
@ -34,6 +33,12 @@ public class MarkersController extends BaseController {
return getDataTable(result);
}
@GetMapping("markersVehicle")
public Result<List<Markers>> markersVehicle() {
List<Markers> listMarkers = markersService.listMarkers();
return Result.success(listMarkers);
}
@PostMapping("insert")
public Result insert(@RequestBody Markers markers){
return toAjax(markersService.save(markers));
@ -44,8 +49,8 @@ public class MarkersController extends BaseController {
return toAjax(markersService.updateById(markers));
}
@PostMapping("delete")
public Result delete(@RequestParam Long markersId) {
@PostMapping("delete/{markersId}")
public Result delete(@PathVariable Long markersId) {
markersFenceList(markersId).forEach(markersFence -> {
markersFenceService.removeById(markersId);
});
@ -57,7 +62,8 @@ public class MarkersController extends BaseController {
return toAjax(markersFenceService.save(markersFence));
}
public List<MarkersFence> markersFenceList(Long markersId){
@PostMapping("markersFenceList/{markersId}")
public List<MarkersFence> markersFenceList(@PathVariable Long markersId){
LambdaQueryWrapper<MarkersFence> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MarkersFence::getMarkerId, markersId);
return markersFenceService.list(queryWrapper);

View File

@ -1,12 +1,13 @@
package com.zhilian.business.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.Vehicle;
import com.zhilian.business.domain.middle.VehicleMarkers;
import com.zhilian.business.service.MarkersService;
import com.zhilian.business.service.VehicleMarkersService;
import com.zhilian.business.service.VehicleService;
import com.zhilian.common.core.domain.Result;
import com.zhilian.common.core.utils.StringUtils;
import com.zhilian.common.core.web.controller.BaseController;
import com.zhilian.common.core.web.page.TableDataInfo;
import com.zhilian.common.security.utils.SecurityUtils;
@ -25,12 +26,17 @@ public class VehicleController extends BaseController {
@Autowired
private VehicleMarkersService vehicleMarkersService;
@Autowired
private MarkersService markersService;
/**
*
* @param vehicle
* @return
*/
@GetMapping("/list")
@PostMapping("/list")
public Result<TableDataInfo<Vehicle>> list(@RequestBody Vehicle vehicle) {
startPage();
List<Vehicle> list = vehicleService.selectVehicleList(vehicle);
@ -58,7 +64,16 @@ public class VehicleController extends BaseController {
public Result vehicleUpdate(@RequestBody Vehicle vehicle){
vehicle.setUpdateBy(SecurityUtils.getUsername());
vehicle.setUpdateTime(new Date());
return toAjax(vehicleService.updateById(vehicle));
//删除中间表全部关联数据
vehicleMarkersService.removeAllVehicle(vehicle);
//修改原表数据
boolean update =vehicleService.updateById(vehicle);
//重新添加中间表数据
vehicleMarkersService.insert(vehicle);
return toAjax(update);
}
/**
@ -66,20 +81,30 @@ public class VehicleController extends BaseController {
* @param vehicleId
* @return
*/
public List<VehicleMarkers> getVehicleMarkers(Long vehicleId){
@PostMapping("/getVehicleMarkers/{vehicleId}")
public List<VehicleMarkers> getVehicleMarkers(@PathVariable Long vehicleId){
LambdaQueryWrapper<VehicleMarkers> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(VehicleMarkers::getVehicleId, vehicleId);
return vehicleMarkersService.list(queryWrapper);
}
// @PostMapping("/getMarkers/{vehicleId}")
// public List<Markers> getMarkers(@PathVariable Long vehicleId){
// LambdaQueryWrapper<VehicleMarkers> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(VehicleMarkers::getVehicleId, vehicleId);
// List<VehicleMarkers> list = vehicleMarkersService.list(queryWrapper);
// list.forEach(vehicleMarkers -> {
// Markers markers = markersService.getById(vehicleMarkers.getMarkersId());
// });
// return null;
// }
/**
*
* @param vehicleId
* @return
*/
@PostMapping("/vehicleDelete")
public Result vehicleDelete(@RequestParam Long vehicleId){
@PostMapping("/vehicleDelete/{vehicleId}")
public Result vehicleDelete(@PathVariable Long vehicleId){
getVehicleMarkers(vehicleId).forEach(vehicleMarkers -> {
vehicleMarkersService.removeById(vehicleId);
});
@ -88,11 +113,12 @@ public class VehicleController extends BaseController {
/**
*
* @param vehicleMarkers
* @param vehicle
* @return
*/
@PostMapping("/vehicleInsertMarkers")
public Result vehicleInsertMarkers(@RequestBody VehicleMarkers vehicleMarkers){
return toAjax(vehicleMarkersService.save(vehicleMarkers));
public Result vehicleInsertMarkers(@RequestBody Vehicle vehicle){
boolean insert = vehicleMarkersService.insert(vehicle);
return toAjax(insert);
}
}

View File

@ -1,7 +1,5 @@
package com.zhilian.business.controller;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.middle.MarkersFence;
import com.zhilian.business.domain.middle.VehicleMarkers;
import com.zhilian.business.service.VehicleMarkersService;
import com.zhilian.common.core.domain.Result;

View File

@ -1,12 +1,8 @@
package com.zhilian.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhilian.business.domain.Fence;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.middle.MarkersFence;
import java.util.List;
public interface MarkersFenceService extends IService<MarkersFence> {
// List<MarkersFence> selectFenceByIdAndMarkersBuyId(List<MarkersFence> list, List<Fence> list1, List<Markers> list2,MarkersFence markersFence);
}

View File

@ -2,13 +2,12 @@ package com.zhilian.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.middle.MarkersFence;
import com.zhilian.common.core.domain.Result;
import com.zhilian.common.core.web.page.TableDataInfo;
import java.util.List;
public interface MarkersService extends IService<Markers> {
List<Markers> selectMarkersList(Markers markers);
List<Markers> listMarkers();
}

View File

@ -1,10 +1,14 @@
package com.zhilian.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhilian.business.domain.Vehicle;
import com.zhilian.business.domain.middle.VehicleMarkers;
import org.springframework.stereotype.Service;
@Service
public interface VehicleMarkersService extends IService<VehicleMarkers> {
boolean insert(Vehicle vehicle);
void removeAllVehicle(Vehicle vehicle);
}

View File

@ -2,17 +2,10 @@ package com.zhilian.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhilian.business.domain.Fence;
import com.zhilian.business.domain.Vehicle;
import com.zhilian.business.domain.vo.FenceVo;
import com.zhilian.business.mapper.FenceMapper;
import com.zhilian.business.mapper.MarkersFenceMapper;
import com.zhilian.business.mapper.MarkersMapper;
import com.zhilian.business.service.FenceService;
import com.zhilian.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

View File

@ -1,18 +1,12 @@
package com.zhilian.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.business.domain.Fence;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.middle.MarkersFence;
import com.zhilian.business.mapper.MarkersFenceMapper;
import com.zhilian.business.service.MarkersFenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class MarkersFenceServiceImpl extends ServiceImpl<MarkersFenceMapper, MarkersFence> implements MarkersFenceService {
@Autowired

View File

@ -3,17 +3,19 @@ package com.zhilian.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.business.domain.Markers;
import com.zhilian.business.domain.Vehicle;
import com.zhilian.business.mapper.MarkersMapper;
import com.zhilian.business.service.MarkersService;
import com.zhilian.common.core.utils.StringUtils;
import com.zhilian.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class MarkersServiceImpl extends ServiceImpl<MarkersMapper, Markers> implements MarkersService {
@Autowired
RedisService service;
@Override
public List<Markers> selectMarkersList(Markers markers) {
LambdaQueryWrapper<Markers> queryWrapper = new LambdaQueryWrapper<>();
@ -22,4 +24,20 @@ public class MarkersServiceImpl extends ServiceImpl<MarkersMapper, Markers> impl
return this.list(queryWrapper);
}
/**
*
* @return
*/
@Override
public List<Markers> listMarkers() {
if(service.hasKey("markers")){
List<Markers> markers = service.getCacheList("markers");
return markers;
}
List<Markers> list = this.list();
service.setCacheList("markers",list);
return list;
}
}

View File

@ -1,11 +1,36 @@
package com.zhilian.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.business.domain.Vehicle;
import com.zhilian.business.domain.middle.VehicleMarkers;
import com.zhilian.business.mapper.VehicleMarkersMapper;
import com.zhilian.business.service.VehicleMarkersService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class VehicleMarkersServiceImpl extends ServiceImpl<VehicleMarkersMapper, VehicleMarkers> implements VehicleMarkersService {
@Transactional(rollbackFor=Exception.class)
@Override
public boolean insert(Vehicle vehicle) {
vehicle.getMarkersIds().forEach(markerId -> {
VehicleMarkers vehicleMarkers = new VehicleMarkers();
vehicleMarkers.setVehicleId(vehicle.getVehicleId());
vehicleMarkers.setMarkersId(markerId);
this.save(vehicleMarkers);
});
return true;
}
@Override
public void removeAllVehicle(Vehicle vehicle) {
List<VehicleMarkers> list = this.list(new LambdaQueryWrapper<VehicleMarkers>().eq(VehicleMarkers::getVehicleId, vehicle.getVehicleId()));
list.forEach(item -> {
this.removeById(item.getVehicleId());
});
}
}

View File

@ -3,41 +3,61 @@ package com.zhilian.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.business.domain.Vehicle;
import com.zhilian.business.domain.middle.VehicleMarkers;
import com.zhilian.business.mapper.VehicleMapper;
import com.zhilian.business.mapper.VehicleMarkersMapper;
import com.zhilian.business.service.VehicleService;
import com.zhilian.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Service
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {
@Override
public List<Vehicle> selectVehicleList(Vehicle vehicle) {
LambdaQueryWrapper<Vehicle> queryWrapper = new LambdaQueryWrapper<>();
//模糊条件 查询车辆VIN
queryWrapper.like(StringUtils.isNotEmpty(vehicle.getVehicleVIN()), Vehicle::getVehicleVIN, vehicle.getVehicleVIN());
//精确查询 查询车辆类型
queryWrapper.eq(StringUtils.isNotEmpty(String.valueOf(vehicle.getVehicleTypeId())), Vehicle::getVehicleTypeId, vehicle.getVehicleTypeId());
//模糊条件 查询VIN
if (StringUtils.isNotEmpty(vehicle.getVehicleVIN())) {
queryWrapper.like(Vehicle::getVehicleVIN, vehicle.getVehicleVIN());
}
// 精确查询 - 查询类型
if (vehicle.getVehicleTypeId() != null) {
queryWrapper.eq(Vehicle::getVehicleTypeId, vehicle.getVehicleTypeId());
}
//模糊查询 车辆电机厂商
queryWrapper.like(StringUtils.isNotEmpty(vehicle.getMotorID()), Vehicle::getMotorID, vehicle.getMotorID());
if (StringUtils.isNotEmpty(vehicle.getMotorId())) {
queryWrapper.like(Vehicle::getMotorId, vehicle.getMotorId());
}
//模糊查询 车辆电池厂商
queryWrapper.like(StringUtils.isNotEmpty(vehicle.getBatteryID()), Vehicle::getBatteryID, vehicle.getBatteryID());
if (StringUtils.isNotEmpty(vehicle.getBatteryId())) {
queryWrapper.like(Vehicle::getBatteryId, vehicle.getBatteryId());
}
//模糊查询 车辆电机ID
queryWrapper.like(StringUtils.isNotEmpty(vehicle.getMotorBusiness()),Vehicle::getMotorBusiness, vehicle.getMotorBusiness());
if (StringUtils.isNotEmpty(vehicle.getVehicleMotor())) {
queryWrapper.like(Vehicle::getVehicleMotor, vehicle.getVehicleMotor());
}
//模糊查询 车辆电池ID
queryWrapper.like(StringUtils.isNotEmpty(vehicle.getBatteryBusiness()),Vehicle::getBatteryBusiness,vehicle.getBatteryBusiness());
if (StringUtils.isNotEmpty(vehicle.getVehicleBattery())) {
queryWrapper.like(Vehicle::getVehicleBattery, vehicle.getVehicleBattery());
}
//精确查询 车辆状态
if (vehicle.getVehicleState() != null) {
queryWrapper.eq(Vehicle::getVehicleState, vehicle.getVehicleState());
}
// queryWrapper.like(StringUtils.isNotEmpty(vehicle.getVehicleVIN()), Vehicle::getVehicleVIN, vehicle.getVehicleVIN())
// .eq(vehicle.getVehicleTypeId() != null, Vehicle::getVehicleTypeId, vehicle.getVehicleTypeId())
// .like(StringUtils.isNotEmpty(vehicle.getMotorID()), Vehicle::getMotorID, vehicle.getMotorID())
// .like(StringUtils.isNotEmpty(vehicle.getBatteryID()), Vehicle::getBatteryID, vehicle.getBatteryID())
// .like(StringUtils.isNotEmpty(vehicle.getMotorBusiness()), Vehicle::getMotorBusiness, vehicle.getMotorBusiness())
// .like(StringUtils.isNotEmpty(vehicle.getBatteryBusiness()), Vehicle::getBatteryBusiness, vehicle.getBatteryBusiness())
// .eq(vehicle.getVehicleState() != null, Vehicle::getVehicleState, vehicle.getVehicleState());
return this.list(queryWrapper);
}
}

View File

@ -3,57 +3,5 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhilian.business.mapper.FenceMapper">
<!-- <resultMap type="com.zhilian.business.domain.Fence" id="FenceResult">-->
<!-- <id property="fenceId" column="fence_id"/>-->
<!-- <result property="fenceName" column="fence_name"/>-->
<!-- <result property="fenceTypeId" column="fence_type_id"/>-->
<!-- <result property="fenceState" column="fence_state"/>-->
<!-- <result property="fenceMessage" column="fence_message"/>-->
<!-- <result property="createBy" column="create_by"/>-->
<!-- <result property="createTime" column="create_time"/>-->
<!-- <result property="updateBy" column="update_by"/>-->
<!-- <result property="updateTime" column="update_time"/>-->
<!-- <result property="remark" column="remark"/>-->
<!-- </resultMap>-->
<select id="fenceList" resultType="com.zhilian.business.domain.Fence">
select * from business_fence
<where>
<if test="fenceName!=null and fenceName!=''">
and fence_name like concat('%',#{fenceName},'%')
</if>
<if test="fenceTypeId!=null">
and fence_type_id=#{fenceTypeId}
</if>
<if test="fenceState!=null">
and fence_state=#{fenceState}
</if>
</where>
</select>
<!-- <sql id="selectFenceVo">-->
<!-- select fence_id,-->
<!-- fence_name,-->
<!-- fence_type_id,-->
<!-- fence_state,-->
<!-- fence_message,-->
<!-- create_by,-->
<!-- create_time,-->
<!-- update_by,-->
<!-- update_time,-->
<!-- remark-->
<!-- from business_fence-->
<!-- </sql>-->
<!-- <select id="fenceList" parameterType="com.zhilian.business.domain.Fence">-->
<!-- <include refid="selectFenceVo"/>-->
<!-- <where>-->
<!-- <if test="fenceName != null and fenceName != ''">-->
<!-- AND fence_name like concat('%', #{fenceName}, '%')-->
<!-- </if>-->
<!-- <if test="fenceTypeId != null">-->
<!-- AND fenceTypeId = #{fenceTypeId}-->
<!-- </if>-->
<!-- </where>-->
<!-- </select>-->
</mapper>

View File

@ -4,6 +4,4 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhilian.business.mapper.VehicleMapper">
</mapper>