implements Base
String operator, operateDate;
try {
if (flag) {
+ //添加 id uuid支持
+ Field idField = clazz.getDeclaredField(ID);
+ idField.setAccessible(true);
+ Object o = idField.get(record);
+ Class> type = idField.getType();
+ String name = type.getName();
+ if ((o == null) && STR.equals(name)) {
+ //已经有值的情况下 不覆盖
+ idField.set(record, UUID.randomUUID().toString().replace("-", "").toLowerCase());
+ }
operator = CREATE_BY;
operateDate = CREATE_DATE;
} else {
operator = UPDATE_BY;
operateDate = UPDATE_DATE;
-
}
Field field = clazz.getDeclaredField(operator);
field.setAccessible(true);
diff --git a/len-sys/src/main/java/com/len/core/quartz/JobTask.java b/len-sys/src/main/java/com/len/core/quartz/JobTask.java
index 0d51de5..37be416 100644
--- a/len-sys/src/main/java/com/len/core/quartz/JobTask.java
+++ b/len-sys/src/main/java/com/len/core/quartz/JobTask.java
@@ -3,141 +3,131 @@ package com.len.core.quartz;
import com.len.core.annotation.Log;
import com.len.core.annotation.Log.LOG_TYPE;
import com.len.entity.SysJob;
-import java.util.Date;
-import java.util.HashSet;
-
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.quartz.CronScheduleBuilder;
-import org.quartz.CronTrigger;
-import org.quartz.JobBuilder;
-import org.quartz.JobDetail;
-import org.quartz.JobKey;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.Trigger;
-import org.quartz.TriggerBuilder;
-import org.quartz.TriggerKey;
+import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;
+import java.util.Date;
+import java.util.HashSet;
+
/**
* @author zhuxiaomeng
* @date 2018/1/5.
* @email 154040976@qq.com
- *
+ *
* 定时任务类 增删改 可参考api:http://www.quartz-scheduler.org/api/2.2.1/
- *
+ *
* 任务名称 默认为 SysJob 类 id
*/
@Service
@Slf4j
public class JobTask {
- @Autowired
- SchedulerFactoryBean schedulerFactoryBean;
+ @Autowired
+ SchedulerFactoryBean schedulerFactoryBean;
- /**
- * true 存在 false 不存在
- * @param
- * @return
- */
- public boolean checkJob(SysJob job){
- Scheduler scheduler = schedulerFactoryBean.getScheduler();
- TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
- try {
- if(scheduler.checkExists(triggerKey)){
- return true;
- }
- } catch (SchedulerException e) {
- e.printStackTrace();
- }
- return false;
- }
-
- /**
- * 开启
- */
- @Log(desc = "开启定时任务")
- public boolean startJob(SysJob job) {
- Scheduler scheduler = schedulerFactoryBean.getScheduler();
- try {
- Class clazz = Class.forName(job.getClazzPath());
- JobDetail jobDetail = JobBuilder.newJob(clazz).build();
- // 触发器
- TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
- CronTrigger trigger = TriggerBuilder.newTrigger()
- .withIdentity(triggerKey)
- .withSchedule(CronScheduleBuilder.cronSchedule(job.getCron())).build();
- scheduler.scheduleJob(jobDetail, trigger);
- // 启动
- if (!scheduler.isShutdown()) {
- scheduler.start();
- log.info("---任务[" + triggerKey.getName() + "]启动成功-------");
- return true;
- }else{
- log.info("---任务[" + triggerKey.getName() + "]已经运行,请勿再次启动-------");
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return false;
- }
-
- /**
- * 更新
- */
- @Log(desc = "更新定时任务", type = LOG_TYPE.UPDATE)
- public boolean updateJob(SysJob job) {
- Scheduler scheduler = schedulerFactoryBean.getScheduler();
- String createTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
-
- TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
- try {
- if (scheduler.checkExists(triggerKey)) {
+ /**
+ * true 存在 false 不存在
+ *
+ * @param
+ * @return
+ */
+ public boolean checkJob(SysJob job) {
+ Scheduler scheduler = schedulerFactoryBean.getScheduler();
+ TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
+ try {
+ if (scheduler.checkExists(triggerKey)) {
+ return true;
+ }
+ } catch (SchedulerException e) {
+ e.printStackTrace();
+ }
return false;
- }
-
- JobKey jobKey = JobKey.jobKey(job.getId(), Scheduler.DEFAULT_GROUP);
-
- CronScheduleBuilder schedBuilder = CronScheduleBuilder.cronSchedule(job.getCron())
- .withMisfireHandlingInstructionDoNothing();
- CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey)
- .withDescription(createTime).withSchedule(schedBuilder).build();
- Class clazz = null;
- JobDetail jobDetail = scheduler.getJobDetail(jobKey);
- HashSet triggerSet = new HashSet<>();
- triggerSet.add(trigger);
- scheduler.scheduleJob(jobDetail, triggerSet, true);
- log.info("---任务["+triggerKey.getName()+"]更新成功-------");
- return true;
- } catch (SchedulerException e) {
- e.printStackTrace();
}
- return false;
- }
- /**
- * 删除
- */
- @Log(desc = "删除定时任务", type = LOG_TYPE.DEL)
- public boolean remove(SysJob job) {
- Scheduler scheduler = schedulerFactoryBean.getScheduler();
- TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
- try {
- if (checkJob(job)) {
- scheduler.pauseTrigger(triggerKey);
- scheduler.unscheduleJob(triggerKey);
- scheduler.deleteJob(JobKey.jobKey(job.getId(), Scheduler.DEFAULT_GROUP));
- log.info("---任务[" + triggerKey.getName() + "]删除成功-------");
- return true;
- }
- } catch (SchedulerException e) {
- e.printStackTrace();
+ /**
+ * 开启
+ */
+ @Log(desc = "开启定时任务")
+ public boolean startJob(SysJob job) {
+ Scheduler scheduler = schedulerFactoryBean.getScheduler();
+ try {
+ Class clazz = Class.forName(job.getClazzPath());
+ JobDetail jobDetail = JobBuilder.newJob(clazz).build();
+ // 触发器
+ TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
+ CronTrigger trigger = TriggerBuilder.newTrigger()
+ .withIdentity(triggerKey)
+ .withSchedule(CronScheduleBuilder.cronSchedule(job.getCron())).build();
+ scheduler.scheduleJob(jobDetail, trigger);
+ // 启动
+ if (!scheduler.isShutdown()) {
+ scheduler.start();
+ log.info("---任务[" + triggerKey.getName() + "]启动成功-------");
+ return true;
+ } else {
+ log.info("---任务[" + triggerKey.getName() + "]已经运行,请勿再次启动-------");
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return false;
+ }
+
+ /**
+ * 更新
+ */
+ @Log(desc = "更新定时任务", type = LOG_TYPE.UPDATE)
+ public boolean updateJob(SysJob job) {
+ Scheduler scheduler = schedulerFactoryBean.getScheduler();
+ String createTime = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
+
+ TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
+ try {
+ if (scheduler.checkExists(triggerKey)) {
+ return false;
+ }
+
+ JobKey jobKey = JobKey.jobKey(job.getId(), Scheduler.DEFAULT_GROUP);
+
+ CronScheduleBuilder schedBuilder = CronScheduleBuilder.cronSchedule(job.getCron())
+ .withMisfireHandlingInstructionDoNothing();
+ CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey)
+ .withDescription(createTime).withSchedule(schedBuilder).build();
+ Class clazz = null;
+ JobDetail jobDetail = scheduler.getJobDetail(jobKey);
+ HashSet triggerSet = new HashSet<>();
+ triggerSet.add(trigger);
+ scheduler.scheduleJob(jobDetail, triggerSet, true);
+ log.info("---任务[" + triggerKey.getName() + "]更新成功-------");
+ return true;
+ } catch (SchedulerException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ /**
+ * 删除
+ */
+ @Log(desc = "删除定时任务", type = LOG_TYPE.DEL)
+ public boolean remove(SysJob job) {
+ Scheduler scheduler = schedulerFactoryBean.getScheduler();
+ TriggerKey triggerKey = TriggerKey.triggerKey(job.getId(), Scheduler.DEFAULT_GROUP);
+ try {
+ if (checkJob(job)) {
+ scheduler.pauseTrigger(triggerKey);
+ scheduler.unscheduleJob(triggerKey);
+ scheduler.deleteJob(JobKey.jobKey(job.getId(), Scheduler.DEFAULT_GROUP));
+ log.info("---任务[" + triggerKey.getName() + "]删除成功-------");
+ return true;
+ }
+ } catch (SchedulerException e) {
+ e.printStackTrace();
+ }
+ return false;
}
- return false;
- }
}
diff --git a/len-sys/src/main/java/com/len/mapper/SysLogMapper.java b/len-sys/src/main/java/com/len/mapper/SysLogMapper.java
index 4cc1b8a..615f19f 100644
--- a/len-sys/src/main/java/com/len/mapper/SysLogMapper.java
+++ b/len-sys/src/main/java/com/len/mapper/SysLogMapper.java
@@ -1,9 +1,11 @@
package com.len.mapper;
+import com.len.base.BaseMapper;
+import com.len.entity.SysJob;
import com.len.entity.SysLog;
import java.util.List;
-public interface SysLogMapper {
+public interface SysLogMapper extends BaseMapper {
int deleteByPrimaryKey(Integer id);
int insert(SysLog record);
diff --git a/len-sys/src/main/resources/mapper/SysJobMapper.xml b/len-sys/src/main/resources/mapper/SysJobMapper.xml
index 95a5fee..ee91b70 100644
--- a/len-sys/src/main/resources/mapper/SysJobMapper.xml
+++ b/len-sys/src/main/resources/mapper/SysJobMapper.xml
@@ -28,9 +28,6 @@
where id = #{id,jdbcType=VARCHAR}
-
- select replace(uuid(),'-','') from dual
-
insert into sys_job (id, job_name, cron,
status, clazz_path, job_desc,
create_by, create_date, update_by,
@@ -41,9 +38,6 @@
#{updateDate,jdbcType=TIMESTAMP})
-
- select replace(uuid(),'-','') from dual
-
insert into sys_job
@@ -160,9 +154,9 @@
SELECT
from sys_job
- and job_name like "%" #{job_name} "%"
- and clazz_path like "%" #{clazz_path} "%"
- and job_desc like "%" #{job_desc} "%"
+ and job_name like '%${job_name}%'
+ and clazz_path like '%${clazz_path}%'
+ and job_desc like '%${job_desc}%'
and status =#{status}
diff --git a/len-sys/src/main/resources/mapper/SysLogMapper.xml b/len-sys/src/main/resources/mapper/SysLogMapper.xml
index aa53e59..6185381 100644
--- a/len-sys/src/main/resources/mapper/SysLogMapper.xml
+++ b/len-sys/src/main/resources/mapper/SysLogMapper.xml
@@ -24,10 +24,10 @@
where id = #{id,jdbcType=INTEGER}
- insert into sys_log (id, user_name, ip,
+ insert into sys_log (user_name, ip,
type, text,param,create_time
)
- values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR},
+ values (#{userName,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR}, #{text,jdbcType=VARCHAR},#{param,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}
)
@@ -35,9 +35,6 @@
insert into sys_log
-
- id,
-
user_name,
@@ -58,9 +55,6 @@
-
- #{id,jdbcType=INTEGER},
-
#{userName,jdbcType=VARCHAR},
@@ -120,8 +114,8 @@
SELECT
from sys_log
- and user_name like "%" #{userName} "%"
- and type like "%" #{type} "%"
+ and user_name like '%${userName}%'
+ and type like '%${type}%'
ORDER BY create_time desc
diff --git a/len-sys/src/main/resources/mapper/SysMenuMapper.xml b/len-sys/src/main/resources/mapper/SysMenuMapper.xml
index 6436e66..1cbc609 100644
--- a/len-sys/src/main/resources/mapper/SysMenuMapper.xml
+++ b/len-sys/src/main/resources/mapper/SysMenuMapper.xml
@@ -49,9 +49,6 @@
where id = #{id,jdbcType=VARCHAR}
-
- select replace(uuid(),'-','') from dual
-
insert into sys_menu (id, name, p_id,
url, order_num, icon,
create_by, create_date, update_by,
@@ -64,9 +61,6 @@
)
-
- select replace(uuid(),'-','') from dual
-
insert into sys_menu
diff --git a/len-sys/src/main/resources/mapper/SysRoleMapper.xml b/len-sys/src/main/resources/mapper/SysRoleMapper.xml
index 86fb8f8..ec9c088 100644
--- a/len-sys/src/main/resources/mapper/SysRoleMapper.xml
+++ b/len-sys/src/main/resources/mapper/SysRoleMapper.xml
@@ -32,9 +32,6 @@
)
-
- select replace(uuid(),"-","") from dual
-
insert into sys_role
@@ -121,8 +118,8 @@
SELECT
from sys_role
- and role_name like "%" #{roleName} "%"
- and remark like "%" #{remark} "%"
+ and role_name like '%${roleName}%'
+ and remark like '%${remark}%'
order by create_date desc
diff --git a/len-sys/src/main/resources/mapper/SysUserMapper.xml b/len-sys/src/main/resources/mapper/SysUserMapper.xml
index 58626be..173d1bc 100644
--- a/len-sys/src/main/resources/mapper/SysUserMapper.xml
+++ b/len-sys/src/main/resources/mapper/SysUserMapper.xml
@@ -125,9 +125,6 @@
-
- select replace(uuid(),"-","") from dual
-
insert into sys_user
@@ -301,17 +298,14 @@
from sys_user
del_flag=0
- and username like "%" #{username} "%"
- and email like "%" #{email} "%"
+ and username like '%${username}%'
+ and email like '%${email}%'
-
- select replace(uuid(),"-","") from dual
-
insert into sys_user(
) values (
diff --git a/len-web/src/main/resources/application-dev.yml b/len-web/src/main/resources/application-mysql-dev.yml
similarity index 81%
rename from len-web/src/main/resources/application-dev.yml
rename to len-web/src/main/resources/application-mysql-dev.yml
index 0d34583..5c59cc3 100644
--- a/len-web/src/main/resources/application-dev.yml
+++ b/len-web/src/main/resources/application-mysql-dev.yml
@@ -3,13 +3,16 @@ server:
spring:
datasource:
url: jdbc:mysql://localhost:3306/lenos?useUnicode=true&characterEncoding=UTF-8
+# url: jdbc:sqlserver://103.46.128.47:48632;DatabaseName=lenos
+# username: sa
username: root
-# password: 123456
password: 123456
+# password: 123
# password: l123456
# 使用druid数据源
- type: com.alibaba.druid.pool.DruidDataSource
+# type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
+# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
filters: stat
maxActive: 20
initialSize: 1
@@ -41,7 +44,7 @@ mapper:
mappers:
- com.len.base.BaseMapper
not-empty: false
- identity: MYSQL
+ identity: mysql
# PageHelperConfig 可以替代此方案
@@ -60,4 +63,6 @@ lenosp:
logging:
file: ./logs/lenosp-log.log
level:
- com.len.mapper: debug
\ No newline at end of file
+ com.len.mapper: debug
+
+dataType: mysql
\ No newline at end of file
diff --git a/len-web/src/main/resources/application-sqlserver-dev.yml b/len-web/src/main/resources/application-sqlserver-dev.yml
new file mode 100644
index 0000000..9cf10f6
--- /dev/null
+++ b/len-web/src/main/resources/application-sqlserver-dev.yml
@@ -0,0 +1,63 @@
+server:
+ port: 8081
+spring:
+ datasource:
+ url: jdbc:sqlserver://localhost:1433;DatabaseName=lenos
+ username: sa
+ password: 123
+ # 使用druid数据源
+ type: com.alibaba.druid.pool.DruidDataSource
+ driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+ filters: stat
+ maxActive: 20
+ initialSize: 1
+ maxWait: 60000
+ minIdle: 1
+ timeBetweenEvictionRunsMillis: 60000
+ minEvictableIdleTimeMillis: 300000
+ validationQuery: select 'x'
+ testWhileIdle: true
+ testOnBorrow: false
+ testOnReturn: false
+ poolPreparedStatements: true
+ maxOpenPreparedStatements: 20
+ http:
+ encoding:
+ force: true
+ boot:
+ admin:
+ client:
+ prefer-ip: true
+ url: http://localhost:8082
+
+mybatis:
+ type-aliases-package: com.len.entity
+ mapper-locations: classpath*:mapper/*.xml
+ check-config-location: true
+
+mapper:
+ mappers:
+ - com.len.base.BaseMapper
+ not-empty: false
+ identity: sqlserver
+
+
+# PageHelperConfig 可以替代此方案
+pagehelper:
+ helperDialect: sqlserver
+ reasonable: true
+ supportMethodsArguments: true
+ params: count=countSql
+
+lenosp:
+ uploadPath: ./file/
+ isDayType: false
+
+ imagePath: ./image/
+
+logging:
+ file: ./logs/lenosp-log.log
+ level:
+ com.len.mapper: debug
+
+dataType: mssql
\ No newline at end of file
diff --git a/len-web/src/main/resources/application.yml b/len-web/src/main/resources/application.yml
index caf4dfc..a3f6659 100644
--- a/len-web/src/main/resources/application.yml
+++ b/len-web/src/main/resources/application.yml
@@ -1,3 +1,5 @@
spring:
profiles:
- active: dev
\ No newline at end of file
+ active: mysql-dev
+# 可切换sqlserver
+# active: sqlserver-dev
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 1ba8c6c..015757e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,11 +90,20 @@
mysql-connector-java
5.1.6
-
+
+
+
+ com.microsoft.sqlserver
+ sqljdbc4
+ 4.0
+ compile
+
+
+
com.alibaba