Commit b7aa1363 authored by mlchun's avatar mlchun

1. 基本功能实现,界面可正常增删改查

parent ec25288a
package io.hmit.modules.area.controller;
import io.hmit.common.annotation.LogOperation;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.ExcelUtils;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.modules.area.dto.AreaDTO;
import io.hmit.modules.area.excel.AreaExcel;
import io.hmit.modules.area.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 区市管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@RestController
@RequestMapping("area/area")
@Api(tags="区市管理")
public class AreaController {
@Autowired
private AreaService areaService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
@RequiresPermissions("area:area:page")
public Result<PageData<AreaDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<AreaDTO> page = areaService.page(params);
return new Result<PageData<AreaDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("area:area:info")
public Result<AreaDTO> get(@PathVariable("id") Long id){
AreaDTO data = areaService.get(id);
return new Result<AreaDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("area:area:save")
public Result save(@RequestBody AreaDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
areaService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("area:area:update")
public Result update(@RequestBody AreaDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
areaService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("area:area:delete")
public Result delete(@RequestBody Long[] ids){
//校验数据
AssertUtils.isArrayEmpty(ids, "id");
areaService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("area:area:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<AreaDTO> list = areaService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, AreaExcel.class);
}
}
\ No newline at end of file
package io.hmit.modules.job.dao;
package io.hmit.modules.area.dao;
import io.hmit.common.dao.BaseDao;
import io.hmit.modules.job.entity.ScheduleJobLogEntity;
import io.hmit.modules.area.entity.AreaEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 定时任务日志
* 区市管理
*
* @author zsh 408538940@qq.com
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Mapper
public interface ScheduleJobLogDao extends BaseDao<ScheduleJobLogEntity> {
}
public interface AreaDao extends BaseDao<AreaEntity> {
}
\ No newline at end of file
package io.hmit.modules.area.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 区市管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@ApiModel(value = "区市管理")
public class AreaDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "区市ID")
private Long id;
@ApiModelProperty(value = "父类ID")
private Long parentId;
@ApiModelProperty(value = "区市名")
private String name;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "创建者")
private Long creator;
@ApiModelProperty(value = "创建时间")
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.area.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.hmit.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 区市管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("wl_area")
public class AreaEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 父类ID
*/
private Long parentId;
/**
* 区市名
*/
private String name;
/**
* 排序
*/
private Integer sort;
}
\ No newline at end of file
package io.hmit.modules.area.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* 区市管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
public class AreaExcel {
@Excel(name = "区市ID")
private Long id;
@Excel(name = "父类ID")
private Long parentId;
@Excel(name = "区市名")
private String name;
@Excel(name = "排序")
private Integer sort;
@Excel(name = "创建者")
private Long creator;
@Excel(name = "创建时间")
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.area.service;
import io.hmit.common.service.CrudService;
import io.hmit.modules.area.dto.AreaDTO;
import io.hmit.modules.area.entity.AreaEntity;
/**
* 区市管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
public interface AreaService extends CrudService<AreaEntity, AreaDTO> {
}
\ No newline at end of file
package io.hmit.modules.area.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.modules.area.dao.AreaDao;
import io.hmit.modules.area.dto.AreaDTO;
import io.hmit.modules.area.entity.AreaEntity;
import io.hmit.modules.area.service.AreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 区市管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Service
public class AreaServiceImpl extends CrudServiceImpl<AreaDao, AreaEntity, AreaDTO> implements AreaService {
@Override
public QueryWrapper<AreaEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
QueryWrapper<AreaEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
return wrapper;
}
}
\ No newline at end of file
package io.hmit.modules.job.controller;
package io.hmit.modules.committee.controller;
import io.hmit.common.annotation.LogOperation;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.ExcelUtils;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.modules.job.dto.ScheduleJobDTO;
import io.hmit.modules.job.service.ScheduleJobService;
import io.hmit.modules.committee.dto.CommitteeDTO;
import io.hmit.modules.committee.excel.CommitteeExcel;
import io.hmit.modules.committee.service.CommitteeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
......@@ -19,57 +22,57 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 定时任务
* 委员会管理
*
* @author zsh 408538940@qq.com
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@RestController
@RequestMapping("/sys/schedule")
@Api(tags = "定时任务")
public class ScheduleJobController {
@RequestMapping("committee/committee")
@Api(tags="委员会管理")
public class CommitteeController {
@Autowired
private ScheduleJobService scheduleJobService;
private CommitteeService committeeService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"),
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "beanName", value = "beanName", paramType = "query", dataType = "String")
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
@RequiresPermissions("sys:schedule:page")
public Result<PageData<ScheduleJobDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params) {
PageData<ScheduleJobDTO> page = scheduleJobService.page(params);
@RequiresPermissions("committee:committee:page")
public Result<PageData<CommitteeDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<CommitteeDTO> page = committeeService.page(params);
return new Result<PageData<ScheduleJobDTO>>().ok(page);
return new Result<PageData<CommitteeDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("sys:schedule:info")
public Result<ScheduleJobDTO> info(@PathVariable("id") Long id) {
@RequiresPermissions("committee:committee:info")
public Result<CommitteeDTO> get(@PathVariable("id") Long id){
CommitteeDTO data = committeeService.get(id);
ScheduleJobDTO schedule = scheduleJobService.get(id);
return new Result<ScheduleJobDTO>().ok(schedule);
return new Result<CommitteeDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("sys:schedule:save")
public Result save(@RequestBody ScheduleJobDTO dto) {
@RequiresPermissions("committee:committee:save")
public Result save(@RequestBody CommitteeDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
scheduleJobService.save(dto);
committeeService.save(dto);
return new Result();
}
......@@ -77,12 +80,12 @@ public class ScheduleJobController {
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("sys:schedule:update")
public Result update(@RequestBody ScheduleJobDTO dto) {
@RequiresPermissions("committee:committee:update")
public Result update(@RequestBody CommitteeDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
scheduleJobService.update(dto);
committeeService.update(dto);
return new Result();
}
......@@ -90,45 +93,24 @@ public class ScheduleJobController {
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("sys:schedule:delete")
public Result delete(@RequestBody Long[] ids) {
scheduleJobService.deleteBatch(ids);
return new Result();
}
@PutMapping("/run")
@ApiOperation("立即执行")
@LogOperation("立即执行")
@RequiresPermissions("sys:schedule:run")
public Result run(@RequestBody Long[] ids) {
@RequiresPermissions("committee:committee:delete")
public Result delete(@RequestBody Long[] ids){
//校验数据
AssertUtils.isArrayEmpty(ids, "id");
scheduleJobService.run(ids);
committeeService.delete(ids);
return new Result();
}
@PutMapping("/pause")
@ApiOperation("暂停")
@LogOperation("暂停")
@RequiresPermissions("sys:schedule:pause")
public Result pause(@RequestBody Long[] ids) {
scheduleJobService.pause(ids);
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("committee:committee:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<CommitteeDTO> list = committeeService.list(params);
return new Result();
}
@PutMapping("/resume")
@ApiOperation("恢复")
@LogOperation("恢复")
@RequiresPermissions("sys:schedule:resume")
public Result resume(@RequestBody Long[] ids) {
scheduleJobService.resume(ids);
return new Result();
ExcelUtils.exportExcelToTarget(response, null, list, CommitteeExcel.class);
}
}
\ No newline at end of file
package io.hmit.modules.committee.dao;
import io.hmit.common.dao.BaseDao;
import io.hmit.modules.committee.entity.CommitteeEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 委员会管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Mapper
public interface CommitteeDao extends BaseDao<CommitteeEntity> {
}
\ No newline at end of file
package io.hmit.modules.committee.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 委员会管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@ApiModel(value = "委员会管理")
public class CommitteeDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "委员会ID")
private Long id;
@ApiModelProperty(value = "委员会名称")
private String name;
@ApiModelProperty(value = "排序")
private Integer sort;
@ApiModelProperty(value = "创建者")
private Long creator;
@ApiModelProperty(value = "创建时间")
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.committee.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.hmit.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 委员会管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("wl_committee")
public class CommitteeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 委员会名称
*/
private String name;
/**
* 排序
*/
private Integer sort;
}
\ No newline at end of file
package io.hmit.modules.committee.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* 委员会管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
public class CommitteeExcel {
@Excel(name = "委员会ID")
private Long id;
@Excel(name = "委员会名称")
private String name;
@Excel(name = "排序")
private Integer sort;
@Excel(name = "创建者")
private Long creator;
@Excel(name = "创建时间")
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.committee.service;
import io.hmit.common.service.CrudService;
import io.hmit.modules.committee.dto.CommitteeDTO;
import io.hmit.modules.committee.entity.CommitteeEntity;
/**
* 委员会管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
public interface CommitteeService extends CrudService<CommitteeEntity, CommitteeDTO> {
}
\ No newline at end of file
package io.hmit.modules.committee.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.modules.committee.dao.CommitteeDao;
import io.hmit.modules.committee.dto.CommitteeDTO;
import io.hmit.modules.committee.entity.CommitteeEntity;
import io.hmit.modules.committee.service.CommitteeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 委员会管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Service
public class CommitteeServiceImpl extends CrudServiceImpl<CommitteeDao, CommitteeEntity, CommitteeDTO> implements CommitteeService {
@Override
public QueryWrapper<CommitteeEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
QueryWrapper<CommitteeEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
return wrapper;
}
}
\ No newline at end of file
package io.hmit.modules.job.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import javax.sql.DataSource;
import java.util.Properties;
/**
* 定时任务配置
*
* @author zsh 408538940@qq.com
*/
@Configuration
public class ScheduleConfig {
@Bean
public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource) {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setDataSource(dataSource);
//quartz参数
Properties prop = new Properties();
prop.put("org.quartz.scheduler.instanceName", "hmitScheduler");
prop.put("org.quartz.scheduler.instanceId", "AUTO");
//线程池配置
prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
prop.put("org.quartz.threadPool.threadCount", "20");
prop.put("org.quartz.threadPool.threadPriority", "5");
//JobStore配置
prop.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX");
//集群配置
prop.put("org.quartz.jobStore.isClustered", "true");
prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
prop.put("org.quartz.jobStore.misfireThreshold", "12000");
prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
//PostgreSQL数据库,需要打开此注释
//prop.put("org.quartz.jobStore.driverDelegateClass", "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate");
factory.setQuartzProperties(prop);
factory.setSchedulerName("hmitScheduler");
//延时启动
factory.setStartupDelay(30);
factory.setApplicationContextSchedulerContextKey("applicationContextKey");
//可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
factory.setOverwriteExistingJobs(true);
//设置自动启动,默认为true
factory.setAutoStartup(true);
return factory;
}
}
package io.hmit.modules.job.controller;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.Result;
import io.hmit.modules.job.dto.ScheduleJobLogDTO;
import io.hmit.modules.job.service.ScheduleJobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;
/**
* 定时任务日志
*
* @author zsh 408538940@qq.com
*/
@RestController
@RequestMapping("/sys/scheduleLog")
@Api(tags = "定时任务日志")
public class ScheduleJobLogController {
@Autowired
private ScheduleJobLogService scheduleJobLogService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"),
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "jobId", value = "jobId", paramType = "query", dataType = "String")
})
@RequiresPermissions("sys:schedule:log")
public Result<PageData<ScheduleJobLogDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params) {
PageData<ScheduleJobLogDTO> page = scheduleJobLogService.page(params);
return new Result<PageData<ScheduleJobLogDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("sys:schedule:log")
public Result<ScheduleJobLogDTO> info(@PathVariable("id") Long id) {
ScheduleJobLogDTO log = scheduleJobLogService.get(id);
return new Result<ScheduleJobLogDTO>().ok(log);
}
}
\ No newline at end of file
package io.hmit.modules.job.dao;
import io.hmit.common.dao.BaseDao;
import io.hmit.modules.job.entity.ScheduleJobEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
/**
* 定时任务
*
* @author zsh 408538940@qq.com
*/
@Mapper
public interface ScheduleJobDao extends BaseDao<ScheduleJobEntity> {
/**
* 批量更新状态
*/
int updateBatch(Map<String, Object> map);
}
package io.hmit.modules.job.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;
/**
* 定时任务
*
* @author zsh 408538940@qq.com
* @since 1.0.0
*/
@Data
@ApiModel(value = "定时任务")
public class ScheduleJobDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
@Null(message = "{id.null}", groups = AddGroup.class)
@NotNull(message = "{id.require}", groups = UpdateGroup.class)
private Long id;
@ApiModelProperty(value = "spring bean名称")
@NotBlank(message = "{schedule.bean.require}", groups = DefaultGroup.class)
private String beanName;
@ApiModelProperty(value = "参数")
private String params;
@ApiModelProperty(value = "cron表达式")
@NotBlank(message = "{schedule.cron.require}", groups = DefaultGroup.class)
private String cronExpression;
@ApiModelProperty(value = "任务状态 0:暂停 1:正常")
@Range(min = 0, max = 1, message = "{schedule.status.range}", groups = DefaultGroup.class)
private Integer status;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Date createDate;
}
package io.hmit.modules.job.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 定时任务日志
*
* @author zsh 408538940@qq.com
* @since 1.0.0
*/
@Data
@ApiModel(value = "定时任务日志")
public class ScheduleJobLogDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "任务id")
private Long jobId;
@ApiModelProperty(value = "spring bean名称")
private String beanName;
@ApiModelProperty(value = "参数")
private String params;
@ApiModelProperty(value = "任务状态 0:失败 1:成功")
private Integer status;
@ApiModelProperty(value = "失败信息")
private String error;
@ApiModelProperty(value = "耗时(单位:毫秒)")
private Integer times;
@ApiModelProperty(value = "创建时间")
private Date createDate;
}
package io.hmit.modules.job.entity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.hmit.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 定时任务
*
* @author zsh 408538940@qq.com
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("schedule_job")
public class ScheduleJobEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* spring bean名称
*/
private String beanName;
/**
* 参数
*/
private String params;
/**
* cron表达式
*/
private String cronExpression;
/**
* 任务状态 0:暂停 1:正常
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 更新者
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updater;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateDate;
}
\ No newline at end of file
package io.hmit.modules.job.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 定时任务日志
*
* @author zsh 408538940@qq.com
*/
@Data
@TableName("schedule_job_log")
public class ScheduleJobLogEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId
private Long id;
/**
* 任务id
*/
private Long jobId;
/**
* spring bean名称
*/
private String beanName;
/**
* 参数
*/
private String params;
/**
* 任务状态 0:失败 1:成功
*/
private Integer status;
/**
* 失败信息
*/
private String error;
/**
* 耗时(单位:毫秒)
*/
private Integer times;
/**
* 创建时间
*/
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.job.init;
import io.hmit.modules.job.dao.ScheduleJobDao;
import io.hmit.modules.job.entity.ScheduleJobEntity;
import io.hmit.modules.job.utils.ScheduleUtils;
import org.quartz.CronTrigger;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 初始化定时任务数据
*
* @author zsh 408538940@qq.com
*/
@Component
public class JobCommandLineRunner implements CommandLineRunner {
@Autowired
private Scheduler scheduler;
@Autowired
private ScheduleJobDao scheduleJobDao;
@Override
public void run(String... args) {
List<ScheduleJobEntity> scheduleJobList = scheduleJobDao.selectList(null);
for (ScheduleJobEntity scheduleJob : scheduleJobList) {
CronTrigger cronTrigger = ScheduleUtils.getCronTrigger(scheduler, scheduleJob.getId());
//如果不存在,则创建
if (cronTrigger == null) {
ScheduleUtils.createScheduleJob(scheduler, scheduleJob);
} else {
ScheduleUtils.updateScheduleJob(scheduler, scheduleJob);
}
}
}
}
\ No newline at end of file
package io.hmit.modules.job.service;
import io.hmit.common.page.PageData;
import io.hmit.common.service.BaseService;
import io.hmit.modules.job.dto.ScheduleJobLogDTO;
import io.hmit.modules.job.entity.ScheduleJobLogEntity;
import java.util.Map;
/**
* 定时任务日志
*
* @author zsh 408538940@qq.com
*/
public interface ScheduleJobLogService extends BaseService<ScheduleJobLogEntity> {
PageData<ScheduleJobLogDTO> page(Map<String, Object> params);
ScheduleJobLogDTO get(Long id);
}
package io.hmit.modules.job.service;
import io.hmit.common.page.PageData;
import io.hmit.common.service.BaseService;
import io.hmit.modules.job.dto.ScheduleJobDTO;
import io.hmit.modules.job.entity.ScheduleJobEntity;
import java.util.Map;
/**
* 定时任务
*
* @author zsh 408538940@qq.com
*/
public interface ScheduleJobService extends BaseService<ScheduleJobEntity> {
PageData<ScheduleJobDTO> page(Map<String, Object> params);
ScheduleJobDTO get(Long id);
/**
* 保存定时任务
*/
void save(ScheduleJobDTO dto);
/**
* 更新定时任务
*/
void update(ScheduleJobDTO dto);
/**
* 批量删除定时任务
*/
void deleteBatch(Long[] ids);
/**
* 批量更新定时任务状态
*/
int updateBatch(Long[] ids, int status);
/**
* 立即执行
*/
void run(Long[] ids);
/**
* 暂停运行
*/
void pause(Long[] ids);
/**
* 恢复运行
*/
void resume(Long[] ids);
}
package io.hmit.modules.job.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.service.impl.BaseServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.modules.job.dao.ScheduleJobLogDao;
import io.hmit.modules.job.dto.ScheduleJobLogDTO;
import io.hmit.modules.job.entity.ScheduleJobLogEntity;
import io.hmit.modules.job.service.ScheduleJobLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class ScheduleJobLogServiceImpl extends BaseServiceImpl<ScheduleJobLogDao, ScheduleJobLogEntity> implements ScheduleJobLogService {
@Override
public PageData<ScheduleJobLogDTO> page(Map<String, Object> params) {
IPage<ScheduleJobLogEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, ScheduleJobLogDTO.class);
}
private QueryWrapper<ScheduleJobLogEntity> getWrapper(Map<String, Object> params) {
String jobId = (String) params.get("jobId");
QueryWrapper<ScheduleJobLogEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(jobId), "job_id", jobId);
return wrapper;
}
@Override
public ScheduleJobLogDTO get(Long id) {
ScheduleJobLogEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, ScheduleJobLogDTO.class);
}
}
\ No newline at end of file
package io.hmit.modules.job.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.service.impl.BaseServiceImpl;
import io.hmit.common.utils.ConvertUtils;
import io.hmit.modules.job.dao.ScheduleJobDao;
import io.hmit.modules.job.dto.ScheduleJobDTO;
import io.hmit.modules.job.entity.ScheduleJobEntity;
import io.hmit.modules.job.service.ScheduleJobService;
import io.hmit.modules.job.utils.ScheduleUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@Service
public class ScheduleJobServiceImpl extends BaseServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService {
@Autowired
private Scheduler scheduler;
@Override
public PageData<ScheduleJobDTO> page(Map<String, Object> params) {
IPage<ScheduleJobEntity> page = baseDao.selectPage(
getPage(params, Constant.CREATE_DATE, false),
getWrapper(params)
);
return getPageData(page, ScheduleJobDTO.class);
}
@Override
public ScheduleJobDTO get(Long id) {
ScheduleJobEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, ScheduleJobDTO.class);
}
private QueryWrapper<ScheduleJobEntity> getWrapper(Map<String, Object> params){
String beanName = (String)params.get("beanName");
QueryWrapper<ScheduleJobEntity> wrapper = new QueryWrapper<>();
wrapper.like(StringUtils.isNotBlank(beanName), "bean_name", beanName);
return wrapper;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(ScheduleJobDTO dto) {
ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class);
entity.setStatus(Constant.ScheduleStatus.NORMAL.getValue());
this.insert(entity);
ScheduleUtils.createScheduleJob(scheduler, entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(ScheduleJobDTO dto) {
ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class);
ScheduleUtils.updateScheduleJob(scheduler, entity);
this.updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteBatch(Long[] ids) {
for(Long id : ids){
ScheduleUtils.deleteScheduleJob(scheduler, id);
}
//删除数据
this.deleteBatchIds(Arrays.asList(ids));
}
@Override
public int updateBatch(Long[] ids, int status){
Map<String, Object> map = new HashMap<>(2);
map.put("ids", ids);
map.put("status", status);
return baseDao.updateBatch(map);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void run(Long[] ids) {
for(Long id : ids){
ScheduleUtils.run(scheduler, this.selectById(id));
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void pause(Long[] ids) {
for(Long id : ids){
ScheduleUtils.pauseJob(scheduler, id);
}
updateBatch(ids, Constant.ScheduleStatus.PAUSE.getValue());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void resume(Long[] ids) {
for(Long id : ids){
ScheduleUtils.resumeJob(scheduler, id);
}
updateBatch(ids, Constant.ScheduleStatus.NORMAL.getValue());
}
}
\ No newline at end of file
package io.hmit.modules.job.task;
/**
* 定时任务接口,所有定时任务都要实现该接口
*
* @author zsh 408538940@qq.com
* @since 1.0.0
*/
public interface ITask {
/**
* 执行定时任务接口
*
* @param params 参数,多参数使用JSON数据
*/
void run(String params);
}
\ No newline at end of file
package io.hmit.modules.job.task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/**
* 测试定时任务(演示Demo,可删除)
* <p>
* testTask为spring bean的名称
*
* @author zsh 408538940@qq.com
*/
@Component("testTask")
public class TestTask implements ITask {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void run(String params) {
logger.debug("TestTask定时任务正在执行,参数为:{}", params);
}
}
\ No newline at end of file
package io.hmit.modules.job.utils;
import io.hmit.common.constant.Constant;
import io.hmit.common.exception.ExceptionUtils;
import io.hmit.common.utils.SpringContextUtils;
import io.hmit.modules.job.entity.ScheduleJobEntity;
import io.hmit.modules.job.entity.ScheduleJobLogEntity;
import io.hmit.modules.job.service.ScheduleJobLogService;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;
import java.lang.reflect.Method;
import java.util.Date;
/**
* 定时任务
*
* @author zsh 408538940@qq.com
*/
public class ScheduleJob extends QuartzJobBean {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
protected void executeInternal(JobExecutionContext context) {
ScheduleJobEntity scheduleJob = (ScheduleJobEntity) context.getMergedJobDataMap().
get(ScheduleUtils.JOB_PARAM_KEY);
//数据库保存执行记录
ScheduleJobLogEntity log = new ScheduleJobLogEntity();
log.setJobId(scheduleJob.getId());
log.setBeanName(scheduleJob.getBeanName());
log.setParams(scheduleJob.getParams());
log.setCreateDate(new Date());
//任务开始时间
long startTime = System.currentTimeMillis();
try {
//执行任务
logger.info("任务准备执行,任务ID:{}", scheduleJob.getId());
Object target = SpringContextUtils.getBean(scheduleJob.getBeanName());
Method method = target.getClass().getDeclaredMethod("run", String.class);
method.invoke(target, scheduleJob.getParams());
//任务执行总时长
long times = System.currentTimeMillis() - startTime;
log.setTimes((int) times);
//任务状态
log.setStatus(Constant.SUCCESS);
logger.info("任务执行完毕,任务ID:{} 总共耗时:{} 毫秒", scheduleJob.getId(), times);
} catch (Exception e) {
logger.error("任务执行失败,任务ID:{}", scheduleJob.getId(), e);
//任务执行总时长
long times = System.currentTimeMillis() - startTime;
log.setTimes((int) times);
//任务状态
log.setStatus(Constant.FAIL);
log.setError(ExceptionUtils.getErrorStackTrace(e));
} finally {
//获取spring bean
ScheduleJobLogService scheduleJobLogService = SpringContextUtils.getBean(ScheduleJobLogService.class);
scheduleJobLogService.insert(log);
}
}
}
\ No newline at end of file
package io.hmit.modules.job.utils;
import io.hmit.common.constant.Constant;
import io.hmit.common.exception.ErrorCode;
import io.hmit.common.exception.HmitException;
import io.hmit.modules.job.entity.ScheduleJobEntity;
import org.quartz.*;
/**
* 定时任务工具类
*
* @author zsh 408538940@qq.com
*/
public class ScheduleUtils {
private final static String JOB_NAME = "TASK_";
/**
* 任务调度参数key
*/
public static final String JOB_PARAM_KEY = "JOB_PARAM_KEY";
/**
* 获取触发器key
*/
public static TriggerKey getTriggerKey(Long jobId) {
return TriggerKey.triggerKey(JOB_NAME + jobId);
}
/**
* 获取jobKey
*/
public static JobKey getJobKey(Long jobId) {
return JobKey.jobKey(JOB_NAME + jobId);
}
/**
* 获取表达式触发器
*/
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId) {
try {
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
/**
* 创建定时任务
*/
public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
//构建job信息
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getId())).build();
//表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
.withMisfireHandlingInstructionDoNothing();
//按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getId())).withSchedule(scheduleBuilder).build();
//放入参数,运行时的方法可以获取
jobDetail.getJobDataMap().put(JOB_PARAM_KEY, scheduleJob);
scheduler.scheduleJob(jobDetail, trigger);
//暂停任务
if (scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()) {
pauseJob(scheduler, scheduleJob.getId());
}
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
/**
* 更新定时任务
*/
public static void updateScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
TriggerKey triggerKey = getTriggerKey(scheduleJob.getId());
//表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression())
.withMisfireHandlingInstructionDoNothing();
CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getId());
//按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
//参数
trigger.getJobDataMap().put(JOB_PARAM_KEY, scheduleJob);
scheduler.rescheduleJob(triggerKey, trigger);
//暂停任务
if (scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()) {
pauseJob(scheduler, scheduleJob.getId());
}
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
/**
* 立即执行任务
*/
public static void run(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
//参数
JobDataMap dataMap = new JobDataMap();
dataMap.put(JOB_PARAM_KEY, scheduleJob);
scheduler.triggerJob(getJobKey(scheduleJob.getId()), dataMap);
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
/**
* 暂停任务
*/
public static void pauseJob(Scheduler scheduler, Long jobId) {
try {
scheduler.pauseJob(getJobKey(jobId));
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
/**
* 恢复任务
*/
public static void resumeJob(Scheduler scheduler, Long jobId) {
try {
scheduler.resumeJob(getJobKey(jobId));
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
/**
* 删除定时任务
*/
public static void deleteScheduleJob(Scheduler scheduler, Long jobId) {
try {
scheduler.deleteJob(getJobKey(jobId));
} catch (SchedulerException e) {
throw new HmitException(ErrorCode.JOB_ERROR, e);
}
}
}
\ No newline at end of file
package io.hmit.modules.meeting.controller;
import io.hmit.common.annotation.LogOperation;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.ExcelUtils;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.modules.meeting.dto.MeetingDTO;
import io.hmit.modules.meeting.excel.MeetingExcel;
import io.hmit.modules.meeting.service.MeetingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@RestController
@RequestMapping("meeting/meeting")
@Api(tags="会议管理")
public class MeetingController {
@Autowired
private MeetingService meetingService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
@RequiresPermissions("meeting:meeting:page")
public Result<PageData<MeetingDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<MeetingDTO> page = meetingService.page(params);
return new Result<PageData<MeetingDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("meeting:meeting:info")
public Result<MeetingDTO> get(@PathVariable("id") Long id){
MeetingDTO data = meetingService.get(id);
return new Result<MeetingDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("meeting:meeting:save")
public Result save(@RequestBody MeetingDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
meetingService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("meeting:meeting:update")
public Result update(@RequestBody MeetingDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
meetingService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("meeting:meeting:delete")
public Result delete(@RequestBody Long[] ids){
//校验数据
AssertUtils.isArrayEmpty(ids, "id");
meetingService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("meeting:meeting:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<MeetingDTO> list = meetingService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, MeetingExcel.class);
}
}
\ No newline at end of file
package io.hmit.modules.meeting.dao;
import io.hmit.common.dao.BaseDao;
import io.hmit.modules.meeting.entity.MeetingEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Mapper
public interface MeetingDao extends BaseDao<MeetingEntity> {
}
\ No newline at end of file
package io.hmit.modules.meeting.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@ApiModel(value = "会议管理")
public class MeetingDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "会议ID")
private Long id;
@ApiModelProperty(value = "会议名称")
private String name;
@ApiModelProperty(value = "发布人")
private String author;
@ApiModelProperty(value = "会议内容")
private String content;
@ApiModelProperty(value = "创建者")
private Long creator;
@ApiModelProperty(value = "创建时间")
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.meeting.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.hmit.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("wl_meeting")
public class MeetingEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 会议名称
*/
private String name;
/**
* 发布人
*/
private String author;
/**
* 会议内容
*/
private String content;
}
\ No newline at end of file
package io.hmit.modules.meeting.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
public class MeetingExcel {
@Excel(name = "会议ID")
private Long id;
@Excel(name = "会议名称")
private String name;
@Excel(name = "发布人")
private String author;
@Excel(name = "会议内容")
private String content;
@Excel(name = "创建者")
private Long creator;
@Excel(name = "创建时间")
private Date createDate;
}
\ No newline at end of file
package io.hmit.modules.meeting.service;
import io.hmit.common.service.CrudService;
import io.hmit.modules.meeting.dto.MeetingDTO;
import io.hmit.modules.meeting.entity.MeetingEntity;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
public interface MeetingService extends CrudService<MeetingEntity, MeetingDTO> {
}
\ No newline at end of file
package io.hmit.modules.meeting.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.modules.meeting.dao.MeetingDao;
import io.hmit.modules.meeting.dto.MeetingDTO;
import io.hmit.modules.meeting.entity.MeetingEntity;
import io.hmit.modules.meeting.service.MeetingService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 会议管理
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Service
public class MeetingServiceImpl extends CrudServiceImpl<MeetingDao, MeetingEntity, MeetingDTO> implements MeetingService {
@Override
public QueryWrapper<MeetingEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
QueryWrapper<MeetingEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
return wrapper;
}
}
\ No newline at end of file
package io.hmit.modules.user.controller;
import io.hmit.common.annotation.LogOperation;
import io.hmit.common.constant.Constant;
import io.hmit.common.page.PageData;
import io.hmit.common.utils.ExcelUtils;
import io.hmit.common.utils.Result;
import io.hmit.common.validator.AssertUtils;
import io.hmit.common.validator.ValidatorUtils;
import io.hmit.common.validator.group.AddGroup;
import io.hmit.common.validator.group.DefaultGroup;
import io.hmit.common.validator.group.UpdateGroup;
import io.hmit.modules.user.dto.UserDTO;
import io.hmit.modules.user.excel.UserExcel;
import io.hmit.modules.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@RestController
@RequestMapping("user/user")
@Api(tags="用户信息表(关注公众号的用户)")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
})
@RequiresPermissions("user:user:page")
public Result<PageData<UserDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<UserDTO> page = userService.page(params);
return new Result<PageData<UserDTO>>().ok(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
@RequiresPermissions("user:user:info")
public Result<UserDTO> get(@PathVariable("id") Long id){
UserDTO data = userService.get(id);
return new Result<UserDTO>().ok(data);
}
@PostMapping
@ApiOperation("保存")
@LogOperation("保存")
@RequiresPermissions("user:user:save")
public Result save(@RequestBody UserDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
userService.save(dto);
return new Result();
}
@PutMapping
@ApiOperation("修改")
@LogOperation("修改")
@RequiresPermissions("user:user:update")
public Result update(@RequestBody UserDTO dto){
//校验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
userService.update(dto);
return new Result();
}
@DeleteMapping
@ApiOperation("删除")
@LogOperation("删除")
@RequiresPermissions("user:user:delete")
public Result delete(@RequestBody Long[] ids){
//校验数据
AssertUtils.isArrayEmpty(ids, "id");
userService.delete(ids);
return new Result();
}
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("user:user:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<UserDTO> list = userService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, UserExcel.class);
}
}
\ No newline at end of file
package io.hmit.modules.user.dao;
import io.hmit.common.dao.BaseDao;
import io.hmit.modules.user.entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Mapper
public interface UserDao extends BaseDao<UserEntity> {
}
\ No newline at end of file
package io.hmit.modules.user.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@ApiModel(value = "用户信息表(关注公众号的用户)")
public class UserDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "用户ID")
private Long id;
@ApiModelProperty(value = "用户名")
private String name;
@ApiModelProperty(value = "性别;1,男;2,女")
private Integer sex;
@ApiModelProperty(value = "手机号")
private String mobile;
@ApiModelProperty(value = "邮箱")
private String email;
@ApiModelProperty(value = "企业名称")
private String company;
@ApiModelProperty(value = "所属职位")
private String position;
@ApiModelProperty(value = "是否会员;1,是;2,否")
private Integer member;
@ApiModelProperty(value = "委员会ID")
private Long committeeId;
@ApiModelProperty(value = "区市ID")
private Long areaId;
@ApiModelProperty(value = "是否审核;0,待审核1,已审核;2,审核未通过")
private Integer ifCheck;
@ApiModelProperty(value = "微信用户openId")
private String openid;
@ApiModelProperty(value = "创建者")
private Long creator;
@ApiModelProperty(value = "创建时间")
private Date createDate;
@ApiModelProperty(value = "更新时间")
private Date updateDate;
}
\ No newline at end of file
package io.hmit.modules.user.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.hmit.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("wl_user")
public class UserEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 用户名
*/
private String name;
/**
* 性别;1,男;2,女
*/
private Integer sex;
/**
* 手机号
*/
private String mobile;
/**
* 邮箱
*/
private String email;
/**
* 企业名称
*/
private String company;
/**
* 所属职位
*/
private String position;
/**
* 是否会员;1,是;2,否
*/
private Integer member;
/**
* 委员会ID
*/
private Long committeeId;
/**
* 区市ID
*/
private Long areaId;
/**
* 是否审核;0,待审核1,已审核;2,审核未通过
*/
private Integer ifCheck;
/**
* 微信用户openId
*/
private String openid;
/**
* 更新时间
*/
private Date updateDate;
}
\ No newline at end of file
package io.hmit.modules.user.excel;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Data
public class UserExcel {
@Excel(name = "用户ID")
private Long id;
@Excel(name = "用户名")
private String name;
@Excel(name = "性别;1,男;2,女")
private Integer sex;
@Excel(name = "手机号")
private String mobile;
@Excel(name = "邮箱")
private String email;
@Excel(name = "企业名称")
private String company;
@Excel(name = "所属职位")
private String position;
@Excel(name = "是否会员;1,是;2,否")
private Integer member;
@Excel(name = "委员会ID")
private Long committeeId;
@Excel(name = "区市ID")
private Long areaId;
@Excel(name = "是否审核;0,待审核1,已审核;2,审核未通过")
private Integer ifCheck;
@Excel(name = "微信用户openId")
private String openid;
@Excel(name = "创建者")
private Long creator;
@Excel(name = "创建时间")
private Date createDate;
@Excel(name = "更新时间")
private Date updateDate;
}
\ No newline at end of file
package io.hmit.modules.user.service;
import io.hmit.common.service.CrudService;
import io.hmit.modules.user.dto.UserDTO;
import io.hmit.modules.user.entity.UserEntity;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
public interface UserService extends CrudService<UserEntity, UserDTO> {
}
\ No newline at end of file
package io.hmit.modules.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.modules.user.dao.UserDao;
import io.hmit.modules.user.dto.UserDTO;
import io.hmit.modules.user.entity.UserEntity;
import io.hmit.modules.user.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 用户信息表(关注公众号的用户)
*
* @author syf syf0412@qq.com
* @since 1.0.0 2020-12-25
*/
@Service
public class UserServiceImpl extends CrudServiceImpl<UserDao, UserEntity, UserDTO> implements UserService {
@Override
public QueryWrapper<UserEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
return wrapper;
}
}
\ No newline at end of file
<?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="io.hmit.modules.area.dao.AreaDao">
<resultMap type="io.hmit.modules.area.entity.AreaEntity" id="areaMap">
<result property="id" column="id"/>
<result property="parentId" column="parent_id"/>
<result property="name" column="name"/>
<result property="sort" column="sort"/>
<result property="creator" column="creator"/>
<result property="createDate" column="create_date"/>
</resultMap>
</mapper>
\ No newline at end of file
<?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="io.hmit.modules.committee.dao.CommitteeDao">
<resultMap type="io.hmit.modules.committee.entity.CommitteeEntity" id="committeeMap">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="sort" column="sort"/>
<result property="creator" column="creator"/>
<result property="createDate" column="create_date"/>
</resultMap>
</mapper>
\ No newline at end of file
<?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="io.hmit.modules.job.dao.ScheduleJobDao">
<!-- 批量更新状态 -->
<update id="updateBatch">
update schedule_job set status = #{status} where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>
\ No newline at end of file
<?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="io.hmit.modules.job.dao.ScheduleJobLogDao">
</mapper>
\ No newline at end of file
<?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="io.hmit.modules.user.dao.UserDao">
<resultMap type="io.hmit.modules.user.entity.UserEntity" id="userMap">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="sex" column="sex"/>
<result property="mobile" column="mobile"/>
<result property="email" column="email"/>
<result property="company" column="company"/>
<result property="position" column="position"/>
<result property="member" column="member"/>
<result property="committeeId" column="committee_id"/>
<result property="areaId" column="area_id"/>
<result property="ifCheck" column="if_check"/>
<result property="openid" column="openid"/>
<result property="creator" column="creator"/>
<result property="createDate" column="create_date"/>
<result property="updateDate" column="update_date"/>
</resultMap>
</mapper>
\ No newline at end of file
<?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="io.hmit.modules.meeting.dao.MeetingDao">
<resultMap type="io.hmit.modules.meeting.entity.MeetingEntity" id="meetingMap">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="author" column="author"/>
<result property="content" column="content"/>
<result property="creator" column="creator"/>
<result property="createDate" column="create_date"/>
</resultMap>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment