数据推送修改保存
This commit is contained in:
parent
936dc784f4
commit
f8ada962b3
12
ifishMQ.iml
12
ifishMQ.iml
|
|
@ -20,7 +20,7 @@
|
|||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/classes" />
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
|
|
@ -37,13 +37,13 @@
|
|||
<orderEntry type="library" name="Maven: com.aliyun:aliyun-java-sdk-core:4.4.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.stream:stax-api:1.0-2" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jacoco:org.jacoco.agent:runtime:0.8.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.ini4j:ini4j:0.5.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.activemq:activemq-all:5.15.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.8.RELEASE" level="project" />
|
||||
|
|
@ -62,6 +62,14 @@
|
|||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.0.8.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-boot-starter:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-generator:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-extension:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-core:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-annotation:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.28" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba:druid:1.1.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
|
||||
|
|
|
|||
37
pom.xml
37
pom.xml
|
|
@ -44,6 +44,11 @@
|
|||
<version>[4.3.2,5.0.0)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.9</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Active MQ -->
|
||||
<dependency>
|
||||
|
|
@ -137,6 +142,37 @@
|
|||
<version>${mybatis-spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mybaits-plus 插件 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>*</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.28</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据源 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
|
@ -194,7 +230,6 @@
|
|||
<build>
|
||||
<finalName>ifishMQ</finalName>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
<outputDirectory>${basedir}/src/main/webapp/WEB-INF/classes</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/src/main/resources</directory>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
package com.ifish7.mq.business.device.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblDevice{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "device_id", type = IdType.AUTO)
|
||||
private Integer deviceId;
|
||||
|
||||
private String serverIp;
|
||||
|
||||
private String deviceIp;
|
||||
|
||||
private String macAddress;
|
||||
|
||||
private Integer loginCount;
|
||||
|
||||
private LocalDateTime loginTime;
|
||||
|
||||
private String isBlacklist;
|
||||
|
||||
private LocalDateTime firstActivate;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String hardwareType;
|
||||
|
||||
private String softwareVersion;
|
||||
|
||||
private String onOff;
|
||||
|
||||
private String todayRemind;
|
||||
|
||||
private String waterRemind;
|
||||
|
||||
private LocalDate remindDate;
|
||||
|
||||
private Integer remindCycle;
|
||||
|
||||
private String factoryCode;
|
||||
|
||||
private String brandCode;
|
||||
|
||||
private Integer sdkVersion;
|
||||
|
||||
private LocalDate sdkTime;
|
||||
|
||||
private LocalDate createDate;
|
||||
|
||||
private String isUpgrade;
|
||||
|
||||
private Integer upgradeVersion;
|
||||
|
||||
private LocalDateTime upgradeTime;
|
||||
|
||||
private LocalDateTime authorizeTime;
|
||||
|
||||
private String createCode;
|
||||
|
||||
private String isCharge;
|
||||
|
||||
private Integer number1;
|
||||
|
||||
private Integer number2;
|
||||
|
||||
private Integer number3;
|
||||
|
||||
private Integer number4;
|
||||
|
||||
private Integer number5;
|
||||
|
||||
/**
|
||||
* 收费时间
|
||||
*/
|
||||
private LocalDateTime chargeTime;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.ifish7.mq.business.device.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@TableName("tbl_device_heater")
|
||||
public class TblDeviceHeater {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId(value = "heater_id", type = IdType.AUTO)
|
||||
private Integer heaterId;
|
||||
|
||||
/**
|
||||
* mac 地址
|
||||
*/
|
||||
private String heaterMacAddress;
|
||||
|
||||
/**
|
||||
* 水温
|
||||
*/
|
||||
private String heaterWaterTemperature;
|
||||
|
||||
/**
|
||||
* 水流量
|
||||
*/
|
||||
private String heaterPh;
|
||||
|
||||
/**
|
||||
* 数据采集时间
|
||||
*/
|
||||
private String heaterGatheringTime;
|
||||
|
||||
/**
|
||||
* 日期
|
||||
*/
|
||||
private String heaterGatheringDate;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.ifish7.mq.business.device.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblFactoryHardware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String factoryCode;
|
||||
|
||||
private String hardwareType;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.ifish7.mq.business.device.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblFactoryList {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String factoryCode;
|
||||
|
||||
private String factoryName;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String isTax;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package com.ifish7.mq.business.device.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblHardwareType {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String hardwareType;
|
||||
|
||||
private String hardwareName;
|
||||
|
||||
private String hardwareDesc;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private Integer controlAmount;
|
||||
|
||||
private Integer timerAmount;
|
||||
|
||||
private String isCustomIcon;
|
||||
|
||||
private String iconLink;
|
||||
|
||||
private String allIconName;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private String isLightness;
|
||||
|
||||
private String isSarkLamp;
|
||||
|
||||
private String isWorkModel;
|
||||
|
||||
private String allShowName;
|
||||
|
||||
private String defaultShowName;
|
||||
|
||||
private String defaultIconName;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.mapper;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblDeviceHeater;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblDeviceHeaterMapper extends BaseMapper<TblDeviceHeater> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.mapper;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblDevice;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblDeviceMapper extends BaseMapper<TblDevice> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.mapper;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblFactoryHardware;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblFactoryHardwareMapper extends BaseMapper<TblFactoryHardware> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.mapper;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblFactoryList;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblFactoryListMapper extends BaseMapper<TblFactoryList> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.mapper;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblHardwareType;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblHardwareTypeMapper extends BaseMapper<TblHardwareType> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.service;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblDeviceHeater;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblDeviceHeaterService extends IService<TblDeviceHeater> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.service;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblDevice;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblDeviceService extends IService<TblDevice> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.service;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblFactoryHardware;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblFactoryHardwareService extends IService<TblFactoryHardware> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.service;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblFactoryList;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblFactoryListService extends IService<TblFactoryList> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.device.service;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblHardwareType;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblHardwareTypeService extends IService<TblHardwareType> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.device.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblDeviceHeater;
|
||||
import com.ifish7.mq.business.device.mapper.TblDeviceHeaterMapper;
|
||||
import com.ifish7.mq.business.device.service.ITblDeviceHeaterService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblDeviceHeaterServiceImpl extends ServiceImpl<TblDeviceHeaterMapper, TblDeviceHeater> implements ITblDeviceHeaterService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.device.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblDevice;
|
||||
import com.ifish7.mq.business.device.mapper.TblDeviceMapper;
|
||||
import com.ifish7.mq.business.device.service.ITblDeviceService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblDeviceServiceImpl extends ServiceImpl<TblDeviceMapper, TblDevice> implements ITblDeviceService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.device.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblFactoryHardware;
|
||||
import com.ifish7.mq.business.device.mapper.TblFactoryHardwareMapper;
|
||||
import com.ifish7.mq.business.device.service.ITblFactoryHardwareService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblFactoryHardwareServiceImpl extends ServiceImpl<TblFactoryHardwareMapper, TblFactoryHardware> implements ITblFactoryHardwareService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.device.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblFactoryList;
|
||||
import com.ifish7.mq.business.device.mapper.TblFactoryListMapper;
|
||||
import com.ifish7.mq.business.device.service.ITblFactoryListService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblFactoryListServiceImpl extends ServiceImpl<TblFactoryListMapper, TblFactoryList> implements ITblFactoryListService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.device.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.device.entity.TblHardwareType;
|
||||
import com.ifish7.mq.business.device.mapper.TblHardwareTypeMapper;
|
||||
import com.ifish7.mq.business.device.service.ITblHardwareTypeService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblHardwareTypeServiceImpl extends ServiceImpl<TblHardwareTypeMapper, TblHardwareType> implements ITblHardwareTypeService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.ifish7.mq.business.user.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblDeviceUser {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private Integer deviceId;
|
||||
|
||||
private String isMaster;
|
||||
|
||||
private String showName;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private String customIconName;
|
||||
|
||||
private String customShowName;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.ifish7.mq.business.user.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblLoginRecord {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "record_id", type = IdType.AUTO)
|
||||
private Integer recordId;
|
||||
|
||||
private String macAddress;
|
||||
|
||||
private LocalDateTime loginTime;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package com.ifish7.mq.business.user.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblPushList {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "push_id", type = IdType.AUTO)
|
||||
private Integer pushId;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private Integer deviceId;
|
||||
|
||||
private String showName;
|
||||
|
||||
private String phoneType;
|
||||
|
||||
private String pushType;
|
||||
|
||||
private String pushTitle;
|
||||
|
||||
private String pushContext;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String pushLink;
|
||||
|
||||
private String jpushStatus;
|
||||
|
||||
private String neteaseStatus;
|
||||
|
||||
private Integer reportId;
|
||||
|
||||
private Integer number1;
|
||||
|
||||
private Integer number2;
|
||||
|
||||
private Integer number3;
|
||||
|
||||
private Integer number4;
|
||||
|
||||
private Integer number5;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.ifish7.mq.business.user.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class TblUser {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "user_id", type = IdType.AUTO)
|
||||
private Integer userId;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String userPassword;
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String userImg;
|
||||
|
||||
private String userSex;
|
||||
|
||||
private String signature;
|
||||
|
||||
private Integer loginCount;
|
||||
|
||||
private String phoneType;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private LocalDateTime loginTime;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String loginType;
|
||||
|
||||
private String remarks;
|
||||
|
||||
private String address;
|
||||
|
||||
@TableField("P2PVerify_code1")
|
||||
private String p2pverifyCode1;
|
||||
|
||||
@TableField("P2PVerify_code2")
|
||||
private String p2pverifyCode2;
|
||||
|
||||
@TableField("gwell_userID")
|
||||
private String gwellUserid;
|
||||
|
||||
private String isRegisterGwell;
|
||||
|
||||
private String userType;
|
||||
|
||||
private Integer shopsUserId;
|
||||
|
||||
private String neteaseToken;
|
||||
|
||||
private String isRegisterNetease;
|
||||
|
||||
private Double latitude;
|
||||
|
||||
private Double longitude;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.mapper;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblDeviceUser;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblDeviceUserMapper extends BaseMapper<TblDeviceUser> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.mapper;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblLoginRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblLoginRecordMapper extends BaseMapper<TblLoginRecord> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.mapper;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblPushList;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblPushListMapper extends BaseMapper<TblPushList> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.mapper;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblUser;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface TblUserMapper extends BaseMapper<TblUser> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.service;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblDeviceUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblDeviceUserService extends IService<TblDeviceUser> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.service;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblLoginRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblLoginRecordService extends IService<TblLoginRecord> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.service;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblPushList;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblPushListService extends IService<TblPushList> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.ifish7.mq.business.user.service;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
public interface ITblUserService extends IService<TblUser> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.user.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblDeviceUser;
|
||||
import com.ifish7.mq.business.user.mapper.TblDeviceUserMapper;
|
||||
import com.ifish7.mq.business.user.service.ITblDeviceUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblDeviceUserServiceImpl extends ServiceImpl<TblDeviceUserMapper, TblDeviceUser> implements ITblDeviceUserService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.user.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblLoginRecord;
|
||||
import com.ifish7.mq.business.user.mapper.TblLoginRecordMapper;
|
||||
import com.ifish7.mq.business.user.service.ITblLoginRecordService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblLoginRecordServiceImpl extends ServiceImpl<TblLoginRecordMapper, TblLoginRecord> implements ITblLoginRecordService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.user.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblPushList;
|
||||
import com.ifish7.mq.business.user.mapper.TblPushListMapper;
|
||||
import com.ifish7.mq.business.user.service.ITblPushListService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblPushListServiceImpl extends ServiceImpl<TblPushListMapper, TblPushList> implements ITblPushListService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ifish7.mq.business.user.service.impl;
|
||||
|
||||
import com.ifish7.mq.business.user.entity.TblUser;
|
||||
import com.ifish7.mq.business.user.mapper.TblUserMapper;
|
||||
import com.ifish7.mq.business.user.service.ITblUserService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yan.y
|
||||
* @since 2019-04-09
|
||||
*/
|
||||
@Service
|
||||
public class TblUserServiceImpl extends ServiceImpl<TblUserMapper, TblUser> implements ITblUserService {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.ifish7.mq.queues.event;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.ifish7.mq.business.device.entity.TblDeviceHeater;
|
||||
import com.ifish7.mq.business.device.service.ITblDeviceHeaterService;
|
||||
import com.ifish7.mq.business.device.service.impl.TblDeviceHeaterServiceImpl;
|
||||
import com.ifish7.mq.queues.event.support.EventSupport;
|
||||
import com.ifish7.mq.utils.AppBeans;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
/**
|
||||
* @author: yan.y
|
||||
* @Description: 智能加热棒事件
|
||||
* @Date: Created in 22:13 2019/4/9
|
||||
*/
|
||||
@Log4j
|
||||
public class IntelligentHeatingRodEvent extends EventSupport {
|
||||
|
||||
/**
|
||||
* 智能加热棒新增或修改
|
||||
* @param eventBody
|
||||
*/
|
||||
public void intelligentHeatingRodSaveOrUpdate(String eventBody){
|
||||
log.info("eventBody : " + eventBody);
|
||||
JSONObject json = JSON.parseObject(eventBody);
|
||||
String entity = json.getString("entity");
|
||||
try {
|
||||
TblDeviceHeater deviceHeater = (TblDeviceHeater) JSON.parseObject(json.getString("data"), Class.forName(entity));
|
||||
//获取service
|
||||
ITblDeviceHeaterService deviceHeaterService = AppBeans.getBean(TblDeviceHeaterServiceImpl.class);
|
||||
//查询
|
||||
TblDeviceHeater tblDeviceHeater = deviceHeaterService.getOne(new QueryWrapper<TblDeviceHeater>().lambda()
|
||||
.eq(TblDeviceHeater::getHeaterGatheringDate, deviceHeater.getHeaterGatheringDate())
|
||||
.eq(TblDeviceHeater::getHeaterGatheringTime, deviceHeater.getHeaterGatheringTime())
|
||||
.eq(TblDeviceHeater::getHeaterMacAddress, deviceHeater.getHeaterMacAddress()));
|
||||
//更新
|
||||
if (tblDeviceHeater != null) {
|
||||
tblDeviceHeater.setHeaterPh(deviceHeater.getHeaterPh());
|
||||
tblDeviceHeater.setHeaterWaterTemperature(deviceHeater.getHeaterWaterTemperature());
|
||||
deviceHeaterService.updateById(tblDeviceHeater);
|
||||
} else {
|
||||
//新增
|
||||
deviceHeaterService.save(deviceHeater);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.info(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.ifish7.mq.queues.event.support;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author: yan.y
|
||||
* @Description: 事件总线处理
|
||||
* @Date: Created in 22:15 2019/4/9
|
||||
*/
|
||||
@Log4j
|
||||
@Data
|
||||
public class EventSupport {
|
||||
//事件处理类型
|
||||
protected String eventProcess;
|
||||
|
||||
//事件名称
|
||||
protected String eventName;
|
||||
|
||||
//事件体
|
||||
protected String eventBody;
|
||||
|
||||
//事件处理
|
||||
public void process() {
|
||||
try {
|
||||
Class<?> eventClazz = Class.forName(this.eventName);
|
||||
Method method = eventClazz.getMethod(this.eventProcess, Class.forName("java.lang.String"));
|
||||
method.setAccessible(true);
|
||||
method.invoke(eventClazz.newInstance(),this.eventBody);
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.ifish7.mq.queues.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
|
||||
import com.ifish7.mq.queues.event.support.EventSupport;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
|
|
@ -18,10 +21,11 @@ public class IfishDataQueueMessageListener implements MessageListener{
|
|||
|
||||
@Override
|
||||
public void onMessage(Message message) {
|
||||
|
||||
TextMessage tm = (TextMessage) message;
|
||||
try {
|
||||
log.info("Ifish7 - Data : " + tm.getText());
|
||||
EventSupport eventSupport = JSON.parseObject(tm.getText(), EventSupport.class);
|
||||
eventSupport.process();
|
||||
} catch (JMSException e) {
|
||||
log.error(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package com.ifish7.mq.utils;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* @author: yan.y
|
||||
* @Description: 获取spring管理的bean
|
||||
* @Date: Created in 22:13 2019/4/9
|
||||
*/
|
||||
public class AppBeans implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext app;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException {
|
||||
AppBeans.app = applicationContext;
|
||||
}
|
||||
|
||||
public static <T> T getBean(Class<T> clazz){
|
||||
if (app == null)
|
||||
return null;
|
||||
else
|
||||
return app.getBean(clazz);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.ifish7.mq.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @author: yan.y
|
||||
* @Description: mybatis代码生成
|
||||
* @Date: Created in 20:30 2019/4/9
|
||||
*/
|
||||
public class MybatisCodeGenerator {
|
||||
/**
|
||||
* <p>
|
||||
* 读取控制台内容
|
||||
* </p>
|
||||
*/
|
||||
public static String scanner(String tip) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
StringBuilder help = new StringBuilder();
|
||||
help.append("请输入" + tip + ":");
|
||||
System.out.println(help.toString());
|
||||
if (scanner.hasNext()) {
|
||||
String ipt = scanner.next();
|
||||
if (StringUtils.isNotEmpty(ipt)) {
|
||||
return ipt;
|
||||
}
|
||||
}
|
||||
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/src/main/java");
|
||||
gc.setAuthor("yan.y");
|
||||
gc.setOpen(false);
|
||||
// gc.setSwagger2(true); 实体属性 Swagger2 注解
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://localhost:3306/myfishdb?useUnicode=true&useSSL=false&characterEncoding=utf8");
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName("com.mysql.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("123456");
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(scanner("模块名"));
|
||||
pc.setParent("com.ifish7.mq.business");
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
// to do nothing
|
||||
}
|
||||
};
|
||||
|
||||
// 如果模板引擎是 freemarker
|
||||
String templatePath = "/templates/mapper.xml.ftl";
|
||||
// 如果模板引擎是 velocity
|
||||
// String templatePath = "/templates/mapper.xml.vm";
|
||||
|
||||
// 自定义输出配置
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
// 自定义配置会被优先输出
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
|
||||
return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
|
||||
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
// 配置模板
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
|
||||
// 配置自定义输出模板
|
||||
//指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
|
||||
// templateConfig.setEntity("templates/entity2.java");
|
||||
// templateConfig.setService();
|
||||
// templateConfig.setController();
|
||||
|
||||
templateConfig.setXml(null);
|
||||
mpg.setTemplate(templateConfig);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
|
||||
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
|
||||
strategy.setSuperEntityColumns("id");
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setTablePrefix(pc.getModuleName() + "_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||
mpg.execute();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,682 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2019, hubin (jobob@qq.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
* <p>
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.ifish7.mq.utils;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.MybatisSqlSessionFactoryBuilder;
|
||||
import com.baomidou.mybatisplus.core.MybatisXMLConfigBuilder;
|
||||
import com.baomidou.mybatisplus.core.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.core.enums.IEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
|
||||
import com.baomidou.mybatisplus.extension.handlers.EnumTypeHandler;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.AopUtils;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.PackageHelper;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import lombok.Setter;
|
||||
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
||||
import org.apache.ibatis.cache.Cache;
|
||||
import org.apache.ibatis.executor.ErrorContext;
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.io.VFS;
|
||||
import org.apache.ibatis.mapping.DatabaseIdProvider;
|
||||
import org.apache.ibatis.mapping.Environment;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.reflection.factory.ObjectFactory;
|
||||
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
||||
import org.apache.ibatis.transaction.TransactionFactory;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.mybatis.spring.transaction.SpringManagedTransactionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.core.NestedIOException;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.core.type.ClassMetadata;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.springframework.util.Assert.notNull;
|
||||
import static org.springframework.util.Assert.state;
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
import static org.springframework.util.StringUtils.hasLength;
|
||||
import static org.springframework.util.StringUtils.tokenizeToStringArray;
|
||||
|
||||
/**
|
||||
* 拷贝类 {@link SqlSessionFactoryBean} 修改方法 buildSqlSessionFactory() 加载自定义
|
||||
* <p>MybatisXmlConfigBuilder</p>
|
||||
*
|
||||
* @author hubin
|
||||
* @since 2017-01-04
|
||||
*/
|
||||
public class MybatisSqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MybatisSqlSessionFactoryBean.class);
|
||||
|
||||
private static final ResourcePatternResolver RESOURCE_PATTERN_RESOLVER = new PathMatchingResourcePatternResolver();
|
||||
private static final MetadataReaderFactory METADATA_READER_FACTORY = new CachingMetadataReaderFactory();
|
||||
|
||||
private Resource configLocation;
|
||||
|
||||
private MybatisConfiguration configuration;
|
||||
|
||||
private Resource[] mapperLocations;
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private TransactionFactory transactionFactory;
|
||||
|
||||
private Properties configurationProperties;
|
||||
|
||||
private SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new MybatisSqlSessionFactoryBuilder();
|
||||
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
//EnvironmentAware requires spring 3.1
|
||||
private String environment = MybatisSqlSessionFactoryBean.class.getSimpleName();
|
||||
|
||||
private boolean failFast;
|
||||
|
||||
private Interceptor[] plugins;
|
||||
|
||||
private TypeHandler<?>[] typeHandlers;
|
||||
|
||||
private String typeHandlersPackage;
|
||||
|
||||
private Class<?>[] typeAliases;
|
||||
|
||||
private String typeAliasesPackage;
|
||||
|
||||
private Class<?> typeAliasesSuperType;
|
||||
|
||||
//issue #19. No default provider.
|
||||
private DatabaseIdProvider databaseIdProvider;
|
||||
|
||||
private Class<? extends VFS> vfs;
|
||||
|
||||
private Cache cache;
|
||||
|
||||
private ObjectFactory objectFactory;
|
||||
|
||||
private ObjectWrapperFactory objectWrapperFactory;
|
||||
|
||||
// TODO 自定义枚举包
|
||||
@Setter
|
||||
private String typeEnumsPackage;
|
||||
|
||||
// TODO 自定义全局配置
|
||||
@Setter
|
||||
private GlobalConfig globalConfig;
|
||||
|
||||
/**
|
||||
* Sets the ObjectFactory.
|
||||
*
|
||||
* @param objectFactory a custom ObjectFactory
|
||||
* @since 1.1.2
|
||||
*/
|
||||
public void setObjectFactory(ObjectFactory objectFactory) {
|
||||
this.objectFactory = objectFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ObjectWrapperFactory.
|
||||
*
|
||||
* @param objectWrapperFactory a specified ObjectWrapperFactory
|
||||
* @since 1.1.2
|
||||
*/
|
||||
public void setObjectWrapperFactory(ObjectWrapperFactory objectWrapperFactory) {
|
||||
this.objectWrapperFactory = objectWrapperFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DatabaseIdProvider
|
||||
*
|
||||
* @return a specified DatabaseIdProvider
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public DatabaseIdProvider getDatabaseIdProvider() {
|
||||
return databaseIdProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the DatabaseIdProvider.
|
||||
* As of version 1.2.2 this variable is not initialized by default.
|
||||
*
|
||||
* @param databaseIdProvider a DatabaseIdProvider
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public void setDatabaseIdProvider(DatabaseIdProvider databaseIdProvider) {
|
||||
this.databaseIdProvider = databaseIdProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the VFS.
|
||||
*
|
||||
* @return a specified VFS
|
||||
*/
|
||||
public Class<? extends VFS> getVfs() {
|
||||
return this.vfs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the VFS.
|
||||
*
|
||||
* @param vfs a VFS
|
||||
*/
|
||||
public void setVfs(Class<? extends VFS> vfs) {
|
||||
this.vfs = vfs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Cache.
|
||||
*
|
||||
* @return a specified Cache
|
||||
*/
|
||||
public Cache getCache() {
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Cache.
|
||||
*
|
||||
* @param cache a Cache
|
||||
*/
|
||||
public void setCache(Cache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mybatis plugin list.
|
||||
*
|
||||
* @param plugins list of plugins
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public void setPlugins(Interceptor[] plugins) {
|
||||
this.plugins = plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Packages to search for type aliases.
|
||||
*
|
||||
* <p>Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.model}.
|
||||
*
|
||||
* @param typeAliasesPackage package to scan for domain objects
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public void setTypeAliasesPackage(String typeAliasesPackage) {
|
||||
this.typeAliasesPackage = typeAliasesPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Super class which domain objects have to extend to have a type alias created.
|
||||
* No effect if there is no package to scan configured.
|
||||
*
|
||||
* @param typeAliasesSuperType super class for domain objects
|
||||
* @since 1.1.2
|
||||
*/
|
||||
public void setTypeAliasesSuperType(Class<?> typeAliasesSuperType) {
|
||||
this.typeAliasesSuperType = typeAliasesSuperType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Packages to search for type handlers.
|
||||
*
|
||||
* <p>Since 2.0.1, allow to specify a wildcard such as {@code com.example.*.typehandler}.
|
||||
*
|
||||
* @param typeHandlersPackage package to scan for type handlers
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public void setTypeHandlersPackage(String typeHandlersPackage) {
|
||||
this.typeHandlersPackage = typeHandlersPackage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type handlers. They must be annotated with {@code MappedTypes} and optionally with {@code MappedJdbcTypes}
|
||||
*
|
||||
* @param typeHandlers Type handler list
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public void setTypeHandlers(TypeHandler<?>[] typeHandlers) {
|
||||
this.typeHandlers = typeHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of type aliases to register. They can be annotated with {@code Alias}
|
||||
*
|
||||
* @param typeAliases Type aliases list
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public void setTypeAliases(Class<?>[] typeAliases) {
|
||||
this.typeAliases = typeAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, a final check is done on Configuration to assure that all mapped
|
||||
* statements are fully loaded and there is no one still pending to resolve
|
||||
* includes. Defaults to false.
|
||||
*
|
||||
* @param failFast enable failFast
|
||||
* @since 1.0.1
|
||||
*/
|
||||
public void setFailFast(boolean failFast) {
|
||||
this.failFast = failFast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the location of the MyBatis {@code SqlSessionFactory} config file. A typical value is
|
||||
* "WEB-INF/mybatis-configuration.xml".
|
||||
*
|
||||
* @param configLocation a location the MyBatis config file
|
||||
*/
|
||||
public void setConfigLocation(Resource configLocation) {
|
||||
this.configLocation = configLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a customized MyBatis configuration.
|
||||
* TODO 这里的入参使用 MybatisConfiguration 而不是 Configuration
|
||||
*
|
||||
* @param configuration MyBatis configuration
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public void setConfiguration(MybatisConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set locations of MyBatis mapper files that are going to be merged into the {@code SqlSessionFactory}
|
||||
* configuration at runtime.
|
||||
* <p>
|
||||
* This is an alternative to specifying "<sqlmapper>" entries in an MyBatis config file.
|
||||
* This property being based on Spring's resource abstraction also allows for specifying
|
||||
* resource patterns here: e.g. "classpath*:sqlmap/*-mapper.xml".
|
||||
*
|
||||
* @param mapperLocations location of MyBatis mapper files
|
||||
*/
|
||||
public void setMapperLocations(Resource[] mapperLocations) {
|
||||
this.mapperLocations = mapperLocations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set optional properties to be passed into the SqlSession configuration, as alternative to a
|
||||
* {@code <properties>} tag in the configuration xml file. This will be used to
|
||||
* resolve placeholders in the config file.
|
||||
*
|
||||
* @param sqlSessionFactoryProperties optional properties for the SqlSessionFactory
|
||||
*/
|
||||
public void setConfigurationProperties(Properties sqlSessionFactoryProperties) {
|
||||
this.configurationProperties = sqlSessionFactoryProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the JDBC {@code DataSource} that this instance should manage transactions for. The {@code DataSource}
|
||||
* should match the one used by the {@code SqlSessionFactory}: for example, you could specify the same
|
||||
* JNDI DataSource for both.
|
||||
* <p>
|
||||
* A transactional JDBC {@code Connection} for this {@code DataSource} will be provided to application code
|
||||
* accessing this {@code DataSource} directly via {@code DataSourceUtils} or {@code DataSourceTransactionManager}.
|
||||
* <p>
|
||||
* The {@code DataSource} specified here should be the target {@code DataSource} to manage transactions for, not
|
||||
* a {@code TransactionAwareDataSourceProxy}. Only data access code may work with
|
||||
* {@code TransactionAwareDataSourceProxy}, while the transaction manager needs to work on the
|
||||
* underlying target {@code DataSource}. If there's nevertheless a {@code TransactionAwareDataSourceProxy}
|
||||
* passed in, it will be unwrapped to extract its target {@code DataSource}.
|
||||
*
|
||||
* @param dataSource a JDBC {@code DataSource}
|
||||
*/
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
if (dataSource instanceof TransactionAwareDataSourceProxy) {
|
||||
// If we got a TransactionAwareDataSourceProxy, we need to perform
|
||||
// transactions for its underlying target DataSource, else data
|
||||
// access code won't see properly exposed transactions (i.e.
|
||||
// transactions for the target DataSource).
|
||||
this.dataSource = ((TransactionAwareDataSourceProxy) dataSource).getTargetDataSource();
|
||||
} else {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@code SqlSessionFactoryBuilder} to use when creating the {@code SqlSessionFactory}.
|
||||
* <p>
|
||||
* This is mainly meant for testing so that mock SqlSessionFactory classes can be injected. By
|
||||
* default, {@code SqlSessionFactoryBuilder} creates {@code DefaultSqlSessionFactory} instances.
|
||||
*
|
||||
* @param sqlSessionFactoryBuilder a SqlSessionFactoryBuilder
|
||||
*/
|
||||
public void setSqlSessionFactoryBuilder(SqlSessionFactoryBuilder sqlSessionFactoryBuilder) {
|
||||
this.sqlSessionFactoryBuilder = sqlSessionFactoryBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MyBatis TransactionFactory to use. Default is {@code SpringManagedTransactionFactory}
|
||||
* <p>
|
||||
* The default {@code SpringManagedTransactionFactory} should be appropriate for all cases:
|
||||
* be it Spring transaction management, EJB CMT or plain JTA. If there is no active transaction,
|
||||
* SqlSession operations will execute SQL statements non-transactionally.
|
||||
*
|
||||
* <b>It is strongly recommended to use the default {@code TransactionFactory}.</b> If not used, any
|
||||
* attempt at getting an SqlSession through Spring's MyBatis framework will throw an exception if
|
||||
* a transaction is active.
|
||||
*
|
||||
* @param transactionFactory the MyBatis TransactionFactory
|
||||
* @see SpringManagedTransactionFactory
|
||||
*/
|
||||
public void setTransactionFactory(TransactionFactory transactionFactory) {
|
||||
this.transactionFactory = transactionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>NOTE:</b> This class <em>overrides</em> any {@code Environment} you have set in the MyBatis
|
||||
* config file. This is used only as a placeholder name. The default value is
|
||||
* {@code SqlSessionFactoryBean.class.getSimpleName()}.
|
||||
*
|
||||
* @param environment the environment name
|
||||
*/
|
||||
public void setEnvironment(String environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
notNull(dataSource, "Property 'dataSource' is required");
|
||||
notNull(sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required");
|
||||
state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
|
||||
"Property 'configuration' and 'configLocation' can not specified with together");
|
||||
|
||||
this.sqlSessionFactory = buildSqlSessionFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@code SqlSessionFactory} instance.
|
||||
* <p>
|
||||
* The default implementation uses the standard MyBatis {@code XMLConfigBuilder} API to build a
|
||||
* {@code SqlSessionFactory} instance based on an Reader. Since 1.3.0, it can be specified a
|
||||
* {@link Configuration} instance directly(without config file).
|
||||
* </p>
|
||||
*
|
||||
* @return SqlSessionFactory
|
||||
* @throws IOException if loading the config file failed
|
||||
*/
|
||||
protected SqlSessionFactory buildSqlSessionFactory() throws Exception {
|
||||
|
||||
final MybatisConfiguration targetConfiguration;
|
||||
|
||||
// TODO 使用 MybatisXmlConfigBuilder 而不是 XMLConfigBuilder
|
||||
MybatisXMLConfigBuilder xmlConfigBuilder = null;
|
||||
if (this.configuration != null) {
|
||||
targetConfiguration = this.configuration;
|
||||
if (targetConfiguration.getVariables() == null) {
|
||||
targetConfiguration.setVariables(this.configurationProperties);
|
||||
} else if (this.configurationProperties != null) {
|
||||
targetConfiguration.getVariables().putAll(this.configurationProperties);
|
||||
}
|
||||
} else if (this.configLocation != null) {
|
||||
// TODO 使用 MybatisXMLConfigBuilder
|
||||
xmlConfigBuilder = new MybatisXMLConfigBuilder(this.configLocation.getInputStream(), null, this.configurationProperties);
|
||||
targetConfiguration = xmlConfigBuilder.getConfiguration();
|
||||
} else {
|
||||
LOGGER.debug("Property 'configuration' or 'configLocation' not specified, using default MyBatis Configuration");
|
||||
// TODO 使用 MybatisConfiguration
|
||||
targetConfiguration = new MybatisConfiguration();
|
||||
Optional.ofNullable(this.configurationProperties).ifPresent(targetConfiguration::setVariables);
|
||||
}
|
||||
|
||||
// TODO 无配置启动所必须的
|
||||
this.globalConfig = Optional.ofNullable(this.globalConfig).orElseGet(GlobalConfigUtils::defaults);
|
||||
this.globalConfig.setDbConfig(Optional.ofNullable(this.globalConfig.getDbConfig()).orElseGet(GlobalConfig.DbConfig::new));
|
||||
|
||||
// TODO 初始化 id-work 以及 打印骚东西
|
||||
targetConfiguration.init(this.globalConfig);
|
||||
|
||||
// TODO 自动注入 map 接收返回结果下是否下划线转驼峰
|
||||
if (targetConfiguration.isMapUnderscoreToCamelCase()) {
|
||||
targetConfiguration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
|
||||
}
|
||||
|
||||
// TODO 设置元数据相关 如果用户没有配置 dbType 则自动获取
|
||||
if (globalConfig.getDbConfig().getDbType() == DbType.OTHER) {
|
||||
try (Connection connection = AopUtils.getTargetObject(this.dataSource).getConnection()) {
|
||||
globalConfig.getDbConfig().setDbType(JdbcUtils.getDbType(connection.getMetaData().getURL()));
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtils.mpe("Error: GlobalConfigUtils setMetaData Fail ! Cause:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 自定义枚举类扫描处理
|
||||
if (hasLength(this.typeEnumsPackage)) {
|
||||
Set<Class> classes;
|
||||
if (typeEnumsPackage.contains(StringPool.STAR) && !typeEnumsPackage.contains(StringPool.COMMA)
|
||||
&& !typeEnumsPackage.contains(StringPool.SEMICOLON)) {
|
||||
classes = PackageHelper.scanTypePackage(typeEnumsPackage);
|
||||
if (classes.isEmpty()) {
|
||||
LOGGER.warn("Can't find class in '[" + typeEnumsPackage + "]' package. Please check your configuration.");
|
||||
}
|
||||
} else {
|
||||
String[] typeEnumsPackageArray = tokenizeToStringArray(this.typeEnumsPackage,
|
||||
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
||||
Assert.notNull(typeEnumsPackageArray, "not find typeEnumsPackage:" + typeEnumsPackage);
|
||||
classes = new HashSet<>();
|
||||
Stream.of(typeEnumsPackageArray).forEach(typePackage -> {
|
||||
Set<Class> scanTypePackage = PackageHelper.scanTypePackage(typePackage);
|
||||
if (scanTypePackage.isEmpty()) {
|
||||
LOGGER.warn("Can't find class in '[" + typePackage + "]' package. Please check your configuration.");
|
||||
} else {
|
||||
classes.addAll(PackageHelper.scanTypePackage(typePackage));
|
||||
}
|
||||
});
|
||||
}
|
||||
// 取得类型转换注册器
|
||||
TypeHandlerRegistry typeHandlerRegistry = targetConfiguration.getTypeHandlerRegistry();
|
||||
classes.stream()
|
||||
.filter(Class::isEnum)
|
||||
.filter(cls -> IEnum.class.isAssignableFrom(cls) || EnumTypeHandler.dealEnumType(cls).isPresent())
|
||||
.forEach(cls -> typeHandlerRegistry.register(cls, EnumTypeHandler.class));
|
||||
}
|
||||
|
||||
Optional.ofNullable(this.objectFactory).ifPresent(targetConfiguration::setObjectFactory);
|
||||
Optional.ofNullable(this.objectWrapperFactory).ifPresent(targetConfiguration::setObjectWrapperFactory);
|
||||
Optional.ofNullable(this.vfs).ifPresent(targetConfiguration::setVfsImpl);
|
||||
|
||||
if (hasLength(this.typeAliasesPackage)) {
|
||||
scanClasses(this.typeAliasesPackage, this.typeAliasesSuperType)
|
||||
.forEach(targetConfiguration.getTypeAliasRegistry()::registerAlias);
|
||||
}
|
||||
|
||||
if (!isEmpty(this.typeAliases)) {
|
||||
Stream.of(this.typeAliases).forEach(typeAlias -> {
|
||||
targetConfiguration.getTypeAliasRegistry().registerAlias(typeAlias);
|
||||
LOGGER.debug("Registered type alias: '" + typeAlias + "'");
|
||||
});
|
||||
}
|
||||
|
||||
if (!isEmpty(this.plugins)) {
|
||||
Stream.of(this.plugins).forEach(plugin -> {
|
||||
targetConfiguration.addInterceptor(plugin);
|
||||
LOGGER.debug("Registered plugin: '" + plugin + "'");
|
||||
});
|
||||
}
|
||||
|
||||
if (hasLength(this.typeHandlersPackage)) {
|
||||
scanClasses(this.typeHandlersPackage, TypeHandler.class).stream()
|
||||
.filter(clazz -> !clazz.isInterface())
|
||||
.filter(clazz -> !Modifier.isAbstract(clazz.getModifiers()))
|
||||
.filter(clazz -> ClassUtils.getConstructorIfAvailable(clazz) != null)
|
||||
.forEach(targetConfiguration.getTypeHandlerRegistry()::register);
|
||||
}
|
||||
|
||||
if (!isEmpty(this.typeHandlers)) {
|
||||
Stream.of(this.typeHandlers).forEach(typeHandler -> {
|
||||
targetConfiguration.getTypeHandlerRegistry().register(typeHandler);
|
||||
LOGGER.debug("Registered type handler: '" + typeHandler + "'");
|
||||
});
|
||||
}
|
||||
|
||||
if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
|
||||
try {
|
||||
targetConfiguration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
|
||||
} catch (SQLException e) {
|
||||
throw new NestedIOException("Failed getting a databaseId", e);
|
||||
}
|
||||
}
|
||||
|
||||
Optional.ofNullable(this.cache).ifPresent(targetConfiguration::addCache);
|
||||
|
||||
if (xmlConfigBuilder != null) {
|
||||
try {
|
||||
xmlConfigBuilder.parse();
|
||||
LOGGER.debug("Parsed configuration file: '" + this.configLocation + "'");
|
||||
} catch (Exception ex) {
|
||||
throw new NestedIOException("Failed to parse config resource: " + this.configLocation, ex);
|
||||
} finally {
|
||||
ErrorContext.instance().reset();
|
||||
}
|
||||
}
|
||||
|
||||
targetConfiguration.setEnvironment(new Environment(this.environment,
|
||||
this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,
|
||||
this.dataSource));
|
||||
|
||||
if (this.mapperLocations != null) {
|
||||
if (this.mapperLocations.length == 0) {
|
||||
LOGGER.warn("Property 'mapperLocations' was specified but matching resources are not found.");
|
||||
} else {
|
||||
for (Resource mapperLocation : this.mapperLocations) {
|
||||
if (mapperLocation == null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(),
|
||||
targetConfiguration, mapperLocation.toString(), targetConfiguration.getSqlFragments());
|
||||
xmlMapperBuilder.parse();
|
||||
} catch (Exception e) {
|
||||
throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", e);
|
||||
} finally {
|
||||
ErrorContext.instance().reset();
|
||||
}
|
||||
LOGGER.debug("Parsed mapper file: '" + mapperLocation + "'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOGGER.debug("Property 'mapperLocations' was not specified.");
|
||||
}
|
||||
|
||||
SqlSessionFactory sqlSessionFactory = this.sqlSessionFactoryBuilder.build(targetConfiguration);
|
||||
|
||||
// TODO SqlRunner
|
||||
SqlHelper.FACTORY = sqlSessionFactory;
|
||||
|
||||
// TODO 设置全局参数属性 以及 缓存 sqlSessionFactory
|
||||
globalConfig.signGlobalConfig(sqlSessionFactory);
|
||||
|
||||
return sqlSessionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public SqlSessionFactory getObject() throws Exception {
|
||||
if (this.sqlSessionFactory == null) {
|
||||
afterPropertiesSet();
|
||||
}
|
||||
|
||||
return this.sqlSessionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Class<? extends SqlSessionFactory> getObjectType() {
|
||||
return this.sqlSessionFactory == null ? SqlSessionFactory.class : this.sqlSessionFactory.getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (failFast && event instanceof ContextRefreshedEvent) {
|
||||
// fail-fast -> check all statements are completed
|
||||
this.sqlSessionFactory.getConfiguration().getMappedStatementNames();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Class<?>> scanClasses(String packagePatterns, Class<?> assignableType)
|
||||
throws IOException {
|
||||
Set<Class<?>> classes = new HashSet<>();
|
||||
String[] packagePatternArray = tokenizeToStringArray(packagePatterns,
|
||||
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
||||
for (String packagePattern : packagePatternArray) {
|
||||
Resource[] resources = RESOURCE_PATTERN_RESOLVER.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
|
||||
org.springframework.util.ClassUtils.convertClassNameToResourcePath(packagePattern) + "/**/*.class");
|
||||
for (Resource resource : resources) {
|
||||
try {
|
||||
ClassMetadata classMetadata = METADATA_READER_FACTORY.getMetadataReader(resource).getClassMetadata();
|
||||
Class<?> clazz = Resources.classForName(classMetadata.getClassName());
|
||||
if (assignableType == null || assignableType.isAssignableFrom(clazz)) {
|
||||
classes.add(clazz);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LOGGER.warn("Cannot load the '" + resource + "'. Cause by " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
jdbc.driver=com.mysql.jdbc.Driver
|
||||
jdbc.url=jdbc\:mysql\://localhost\:3306/myfishdb?characterEncoding\=UTF-8
|
||||
#jdbc.url=jdbc\:mysql\://139.196.24.156\:3306/myfishdb?characterEncoding\=UTF-8
|
||||
jdbc.username=ifish
|
||||
jdbc.password=ifish7pwd
|
||||
jdbc.username=root
|
||||
jdbc.password=123456
|
||||
#jdbc.username=ifish
|
||||
#jdbc.password=ifish7pwd
|
||||
#jdbc.username=root
|
||||
#jdbc.password=ifish7mysql
|
||||
#jdbc.testWhileIdle=true
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
log4j.rootLogger=INFO,Console,File
|
||||
log4j.rootLogger=DEBUG,Console,File
|
||||
#\u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u76EE\u7684\u5730\u4E3A\u63A7\u5236\u53F0
|
||||
log4j.appender.Console=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.Console.Target=System.out
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.device.mapper.TblDeviceHeaterMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.device.mapper.TblDeviceMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.device.mapper.TblFactoryHardwareMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.device.mapper.TblFactoryListMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.device.mapper.TblHardwareTypeMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.user.mapper.TblDeviceUserMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.user.mapper.TblLoginRecordMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.user.mapper.TblPushListMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?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.ifish7.mq.business.user.mapper.TblUserMapper">
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<bean id="propertyConfigurer"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="locations" >
|
||||
<list>
|
||||
<value>classpath:mq.properties</value>
|
||||
<value>classpath:jdbc.properties</value>
|
||||
<value>classpath:log4j.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
<import resource="spring/spring-mq.xml" />
|
||||
<import resource="spring/spring-mybatis.xml" />
|
||||
|
||||
<!-- 自动扫描 -->
|
||||
<context:component-scan base-package="com.ifish7.mq.*" />
|
||||
<bean id="app" class="com.ifish7.mq.utils.AppBeans" />
|
||||
</beans>
|
||||
|
|
@ -1,21 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:amq="http://activemq.apache.org/schema/core"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-4.1.xsd
|
||||
http://activemq.apache.org/schema/core
|
||||
http://activemq.apache.org/schema/core/activemq-core-5.14.1.xsd">
|
||||
|
||||
<bean id="propertyConfigurer"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:mq.properties" />
|
||||
</bean>
|
||||
<context:component-scan base-package="com.ifish7.mq.queues.*" />
|
||||
|
||||
<amq:connectionFactory id="amqConnectionFactory"
|
||||
brokerURL="${broker_url}"
|
||||
userName="${username}"
|
||||
|
|
@ -1,27 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/tx
|
||||
http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
<!-- 自动扫描 -->
|
||||
<context:component-scan base-package="com.ifish7.mq.data">
|
||||
<!-- 这里要把controler下面的 controller去除,他们是在spring-mvc.xml中配置的,如果不去除会影响事务管理的。 -->
|
||||
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
|
||||
</context:component-scan>
|
||||
<!-- 引入配置文件 -->
|
||||
<bean id="propertyConfigurer"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:jdbc.properties" />
|
||||
</bean>
|
||||
|
||||
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
|
||||
<property name="driverClassName" value="${jdbc.driver}" />
|
||||
<property name="url" value="${jdbc.url}" />
|
||||
|
|
@ -59,15 +47,15 @@
|
|||
</bean>
|
||||
|
||||
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
|
||||
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
||||
<bean id="sqlSessionFactory" class="com.ifish7.mq.utils.MybatisSqlSessionFactoryBean">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<!-- 自动扫描mapping.xml文件 -->
|
||||
<property name="mapperLocations" value="classpath:com/ifish7/mq/data/mapping/*.xml"></property>
|
||||
</bean>
|
||||
|
||||
<property name="mapperLocations" value="classpath:mapper/*/*.xml"></property>
|
||||
</bean>
|
||||
|
||||
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
|
||||
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
||||
<property name="basePackage" value="com.dnkx.dao" />
|
||||
<property name="basePackage" value="com.ifish7.mq.business.*.mapper" />
|
||||
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
|
||||
</bean>
|
||||
|
||||
|
|
@ -86,7 +74,7 @@
|
|||
|
||||
<aop:config>
|
||||
<!-- 定义切点 -->
|
||||
<aop:pointcut id="allServiceMethods" expression="execution(* com.ifish7.mq.data.*.service.impl.*.*(..))"/>
|
||||
<aop:pointcut id="allServiceMethods" expression="execution(* com.ifish7.mq.business.*.service.impl.*.*(..))"/>
|
||||
<!-- 植入切面通知(增强处理) -->
|
||||
<aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethods"/>
|
||||
</aop:config>
|
||||
|
|
@ -95,9 +83,15 @@
|
|||
<tx:attributes>
|
||||
<tx:method name="find*" read-only="true"/>
|
||||
<tx:method name="load*" read-only="true"/>
|
||||
<tx:method name="get*" read-only="true"/>
|
||||
<tx:method name="list*" read-only="true"/>
|
||||
<tx:method name="page*" read-only="true"/>
|
||||
<tx:method name="query*" read-only="true"/>
|
||||
<tx:method name="add*" propagation="REQUIRED"/>
|
||||
<tx:method name="save*" propagation="REQUIRED"/>
|
||||
<tx:method name="update*" propagation="REQUIRED"/>
|
||||
</tx:attributes>
|
||||
<tx:method name="remove*" propagation="REQUIRED"/>
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
|
||||
</beans>
|
||||
Loading…
Reference in New Issue