feat:mybatis Plus 联表查询
parent
06fbdd9fdb
commit
ec123412ee
|
@ -10,6 +10,10 @@
|
|||
</parent>
|
||||
|
||||
<artifactId>zhiLian-business</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>zhiLian-data-plus</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
|
@ -19,7 +23,5 @@
|
|||
<description>
|
||||
zhiLian-business系统模块
|
||||
</description>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<?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-business</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>zhiLian-data-plus</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>
|
||||
</project>
|
|
@ -20,6 +20,16 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join</artifactId>
|
||||
<version>1.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<!--rabbitMQ-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ManyJob {
|
|||
@Autowired
|
||||
private EntinfoServiceImpl entinfoService;
|
||||
|
||||
@Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次
|
||||
// @Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次
|
||||
public void manyJob(){
|
||||
redisService.deleteObject("entinfo");
|
||||
List<Entinfo> list = entinfoService.list();
|
||||
|
|
|
@ -4,8 +4,12 @@ import java.util.List;
|
|||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.zhiLian.business.domain.Cart;
|
||||
import com.zhiLian.business.domain.CartVo;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.business.service.IEntinfoService;
|
||||
import com.zhiLian.business.service.PlusService;
|
||||
import com.zhiLian.business.service.impl.PlusServiceImpl;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
import com.zhiLian.common.core.utils.poi.ExcelUtil;
|
||||
import com.zhiLian.common.core.web.controller.BaseController;
|
||||
|
@ -36,6 +40,16 @@ public class EntinfoController extends BaseController
|
|||
@Autowired
|
||||
private IEntinfoService entinfoService;
|
||||
|
||||
@Autowired
|
||||
private PlusService plusService;
|
||||
|
||||
@PostMapping("cartLiat")
|
||||
public Result cartList(@RequestBody CartVo cartVo){
|
||||
List<Cart> list = plusService.list();
|
||||
System.out.println(list);
|
||||
return plusService.cartList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询多数据源列表
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.zhiLian.business.controller;
|
||||
|
||||
|
||||
import com.zhiLian.business.domain.Business;
|
||||
import com.zhiLian.business.mapper.BusinessMapper;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusController
|
||||
* @Date 2024/06/09 15:28
|
||||
*/
|
||||
public class PlusController{
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.zhiLian.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName Cart
|
||||
* @Date 2024/06/09 15:40
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("cart")
|
||||
public class Cart {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "name")
|
||||
private String name;
|
||||
|
||||
@TableField(value = "type_id")
|
||||
private Long typeId;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.zhiLian.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.zhiLian.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName BusinessVo
|
||||
* @Date 2024/06/09 15:34
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class CartVo {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String typeName;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.zhiLian.business.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName Type
|
||||
* @Date 2024/06/09 15:40
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("type")
|
||||
public class Type {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "type_name")
|
||||
private String typeName;
|
||||
}
|
|
@ -10,8 +10,6 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* 企业Mapper接口
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-05-26
|
||||
*/
|
||||
public interface BusinessMapper extends BaseMapper<Business>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.zhiLian.business.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.zhiLian.business.domain.Cart;
|
||||
import com.zhiLian.business.domain.CartVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusMapper
|
||||
* @Date 2024/06/09 15:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface PlusMapper extends MPJBaseMapper<Cart> {
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.zhiLian.business.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.zhiLian.business.domain.Cart;
|
||||
import com.zhiLian.business.domain.Type;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusMapper
|
||||
* @Date 2024/06/09 15:33
|
||||
*/
|
||||
@Mapper
|
||||
public interface TypeMapper extends BaseMapper<Type> {
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.zhiLian.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.github.yulichang.base.MPJBaseService;
|
||||
import com.zhiLian.business.domain.Cart;
|
||||
import com.zhiLian.business.domain.CartVo;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
|
||||
/**
|
||||
* @ClassName PlusService
|
||||
* @Description 描述
|
||||
* @Author BingRui.Hou
|
||||
* @Date 2024/06/09 15:36
|
||||
*/
|
||||
public interface PlusService extends IService<Cart> {
|
||||
Result cartList();
|
||||
|
||||
}
|
|
@ -186,6 +186,12 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
new InputStreamReader(httpConn.getInputStream()));
|
||||
String resultData = br.readLine();
|
||||
System.out.println("从服务端返回结果: " + resultData);
|
||||
// 7.关闭HttpURLConnection连接
|
||||
httpConn.disconnect();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Entinfo build = Entinfo.builder()
|
||||
.entCode("test_" + business.getId())
|
||||
.ip("192.168.120.128")
|
||||
|
@ -195,11 +201,6 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
// 7.关闭HttpURLConnection连接
|
||||
httpConn.disconnect();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
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.yulichang.base.MPJBaseServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.zhiLian.business.domain.Cart;
|
||||
import com.zhiLian.business.domain.CartVo;
|
||||
import com.zhiLian.business.domain.Type;
|
||||
import com.zhiLian.business.mapper.PlusMapper;
|
||||
import com.zhiLian.business.mapper.TypeMapper;
|
||||
import com.zhiLian.business.service.PlusService;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName PlusServiceImpl
|
||||
* @Date 2024/06/09 15:37
|
||||
*/
|
||||
@Service
|
||||
public class PlusServiceImpl extends MPJBaseServiceImpl<PlusMapper, Cart> implements PlusService {
|
||||
|
||||
@Autowired
|
||||
private PlusMapper plusMapper;
|
||||
|
||||
@Autowired
|
||||
private TypeMapper typeMapper;
|
||||
|
||||
@Override
|
||||
public Result cartList() {
|
||||
MPJLambdaWrapper<Cart> mpjLambdaWrapper = new MPJLambdaWrapper<Cart>()
|
||||
.selectAll( Cart.class) //查询主表所有的字段
|
||||
.select(Type::getTypeName) //查询类型名称
|
||||
.leftJoin(Type.class, Type::getId, Cart::getTypeId);//左连接查询,相当于 left join type on dept.id=user.dept_id
|
||||
List<CartVo> cartList = plusMapper.selectJoinList(CartVo.class, mpjLambdaWrapper);
|
||||
// return Result.success(cartList);
|
||||
|
||||
|
||||
// MPJLambdaWrapper<Cart> mpjLambdaWrapper1 = new MPJLambdaWrapper<>();
|
||||
// MPJLambdaWrapper<Cart> lambdaWrapper = mpjLambdaWrapper1.eq(Cart::getId, "1");
|
||||
List<Cart> list = this.list();
|
||||
list.stream().forEach(cart -> {
|
||||
LambdaQueryWrapper<Type> typeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
Type type = typeMapper.selectOne(typeLambdaQueryWrapper.eq(Type::getId, cart.getTypeId()));
|
||||
cart.setName(type.getTypeName());
|
||||
});
|
||||
System.out.println(list);
|
||||
return Result.success(list,cartList.toString());
|
||||
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ spring:
|
|||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 192.168.120.128
|
||||
host: 122.51.111.225
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
|
|
|
@ -90,7 +90,7 @@ public class ManyDataSource {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
//删除队列ID
|
||||
log.info("消费重复");
|
||||
log.info("消费失败");
|
||||
try {
|
||||
//回退消息
|
||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.zhiLian.vehicle.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* @ClassName Type
|
||||
* @Date 2024/06/09 15:40
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName("type")
|
||||
public class Type {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "type_name")
|
||||
private String typeName;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.zhiLian.vehicle.domain.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zhiLian.common.core.annotation.Excel;
|
||||
import com.zhiLian.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 车辆录入对象 vehicle
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-05-27
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleVo extends BaseEntity
|
||||
{
|
||||
|
||||
|
||||
/** 车辆主键 */
|
||||
private Long id;
|
||||
|
||||
/** 车辆vin */
|
||||
private String number;
|
||||
|
||||
/** 电子围栏ID */
|
||||
private Long electonicId;
|
||||
|
||||
/** 电机厂商 */
|
||||
private String motor;
|
||||
|
||||
/** 电池厂商 */
|
||||
private String battery;
|
||||
|
||||
/** 电机编号 */
|
||||
private Long motorNumber;
|
||||
|
||||
/** 电池编号 */
|
||||
private Long batteryNumber;
|
||||
|
||||
/** 企业ID */
|
||||
// @Excel(name = "企业ID")
|
||||
// private Long businessId;
|
||||
private Long groupId;
|
||||
|
||||
private String typeName;
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ spring:
|
|||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 192.168.120.128
|
||||
host: 122.51.111.225
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
|
|
Loading…
Reference in New Issue