parent
f25b7dcd12
commit
71bf886eed
@ -0,0 +1,9 @@ |
||||
package com.bellmann.common.enums; |
||||
|
||||
public enum PlanStatusEnum { |
||||
INIT,//初始状态
|
||||
WAITING,//等待执行
|
||||
RUNNING,//执行中
|
||||
FINISHED,//结束
|
||||
ERROR;//异常结束
|
||||
} |
@ -0,0 +1,43 @@ |
||||
package com.bellmann.config; |
||||
|
||||
import com.alibaba.fastjson.JSON; |
||||
import org.apache.ibatis.type.BaseTypeHandler; |
||||
import org.apache.ibatis.type.JdbcType; |
||||
import org.apache.ibatis.type.MappedTypes; |
||||
import org.postgresql.util.PGobject; |
||||
|
||||
import java.sql.CallableStatement; |
||||
import java.sql.PreparedStatement; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
|
||||
|
||||
@MappedTypes(Object.class) |
||||
public class JsonTypeHandlerObject<T extends Object> extends BaseTypeHandler<T> { |
||||
|
||||
private static final PGobject jsonObject = new PGobject(); |
||||
|
||||
@Override |
||||
public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException { |
||||
jsonObject.setType("jsonb"); |
||||
jsonObject.setValue(JSON.toJSONString(parameter)); |
||||
ps.setObject(i, jsonObject); |
||||
} |
||||
|
||||
@Override |
||||
public T getNullableResult(ResultSet resultSet, String columnName) throws SQLException { |
||||
return (T) resultSet.getString(columnName); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public T getNullableResult(ResultSet resultSet, int columnIndex) throws SQLException { |
||||
return (T) resultSet.getString(columnIndex); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public T getNullableResult(CallableStatement callableStatement, int columnIndex) throws SQLException { |
||||
return (T) callableStatement.getString(columnIndex); |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
package com.bellmann.controller; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.bellmann.common.result.PageResult; |
||||
import com.bellmann.common.result.Result; |
||||
import com.bellmann.model.form.PlanFilterConfigForm; |
||||
import com.bellmann.model.query.SelectQuery; |
||||
import com.bellmann.model.vo.WorkFlowVO; |
||||
import com.bellmann.service.PlanCollectorService; |
||||
import io.swagger.v3.oas.annotations.Operation; |
||||
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
@Tag(name = "36.工作流管理") |
||||
@RestController |
||||
@RequestMapping("/api/workflow/v1") |
||||
@RequiredArgsConstructor |
||||
public class PlanCollectorController { |
||||
private final PlanCollectorService planCollectorService; |
||||
|
||||
|
||||
@PostMapping("add") |
||||
@Operation(summary = "新增工作流") |
||||
public Result<String> addWorkflow(@RequestBody PlanFilterConfigForm form){ |
||||
boolean result = planCollectorService.addWorkflow(form); |
||||
return Result.judge(result); |
||||
} |
||||
@PostMapping("page") |
||||
@Operation(summary = "工作流分页") |
||||
public PageResult<WorkFlowVO> workflowPage(@RequestBody SelectQuery query){ |
||||
Page<WorkFlowVO> result = planCollectorService.workflowPage(query); |
||||
return PageResult.success(result); |
||||
} |
||||
@DeleteMapping("/{planId}") |
||||
@Operation(summary = "删除工作流") |
||||
public Result<String> removeWorkflow(@PathVariable Long planId){ |
||||
boolean result = planCollectorService.removeWorkflow(planId); |
||||
return Result.judge(result); |
||||
} |
||||
@PutMapping("/status/{planId}/{status}") |
||||
@Operation(summary = "修改工作流状态") |
||||
public Result<String> updateWorkflowStatus(@PathVariable Long planId, @PathVariable Integer status){ |
||||
boolean result = planCollectorService.updateWorkflowStatus(planId,status); |
||||
return Result.judge(result); |
||||
} |
||||
} |
@ -0,0 +1,29 @@ |
||||
package com.bellmann.controller; |
||||
|
||||
|
||||
import com.bellmann.common.result.Result; |
||||
import com.bellmann.model.vo.PlanFilterConfigOption; |
||||
import com.bellmann.service.PlanFilterConfigService; |
||||
import io.swagger.v3.oas.annotations.Operation; |
||||
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Tag(name = "34.工作流配置") |
||||
@RestController |
||||
@RequestMapping("/api/plan_filter_config/v1") |
||||
@RequiredArgsConstructor |
||||
public class PlanFilterConfigController { |
||||
private final PlanFilterConfigService planFilterConfigService; |
||||
|
||||
@GetMapping("option") |
||||
@Operation(summary = "工作流动态配置选项") |
||||
public Result<List<PlanFilterConfigOption>> configOption(){ |
||||
List<PlanFilterConfigOption> list = planFilterConfigService.configOption(); |
||||
return Result.success(list); |
||||
} |
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.bellmann.converter; |
||||
|
||||
import com.bellmann.model.entity.PlanCollector; |
||||
import com.bellmann.model.form.WorkFlowForm; |
||||
import org.mapstruct.Mapper; |
||||
|
||||
|
||||
@Mapper(componentModel = "spring") |
||||
public interface PlanCollectorConverter { |
||||
|
||||
|
||||
PlanCollector form2Entity(WorkFlowForm workFlowForm); |
||||
|
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.bellmann.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.bellmann.model.entity.PlanCollector; |
||||
import com.bellmann.model.vo.WorkFlowVO; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.apache.ibatis.annotations.Param; |
||||
|
||||
@Mapper |
||||
public interface PlanCollectorMapper extends BaseMapper<PlanCollector> { |
||||
Page<WorkFlowVO> workflowPage(Page<WorkFlowVO> page, @Param("column") String selectName, @Param("value") Object selectValue); |
||||
} |
@ -0,0 +1,13 @@ |
||||
package com.bellmann.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.bellmann.model.entity.PlanFilterConfig; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.apache.ibatis.annotations.Param; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Mapper |
||||
public interface PlanFilterConfigMapper extends BaseMapper<PlanFilterConfig> { |
||||
List<PlanFilterConfig> groupByFilterName(@Param("filterName") String filterName); |
||||
} |
@ -0,0 +1,37 @@ |
||||
package com.bellmann.model.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableField; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.bellmann.config.JsonTypeHandlerObject; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Data |
||||
@TableName("itms_plan_collector") |
||||
public class PlanCollector { |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Long planId; |
||||
|
||||
private Date startTime; |
||||
|
||||
private Date endTime; |
||||
|
||||
private Integer planStatus; |
||||
|
||||
private Integer maxConcurrency; |
||||
|
||||
private String planName; |
||||
|
||||
private String planDesc; |
||||
|
||||
private String createUser; |
||||
|
||||
@TableField(value = "plan_filter",typeHandler = JsonTypeHandlerObject.class) |
||||
private Object planFilter; |
||||
|
||||
private Date createTime; |
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.bellmann.model.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
@TableName("itms_plan_filter_config") |
||||
public class PlanFilterConfig { |
||||
|
||||
private String displayName; |
||||
|
||||
private String propertyId; |
||||
|
||||
private String value; |
||||
|
||||
private String propertyIdAndValueSql; |
||||
|
||||
private String filterName; |
||||
|
||||
@TableId(type = IdType.AUTO) |
||||
private Long filterId; |
||||
} |
@ -0,0 +1,14 @@ |
||||
package com.bellmann.model.form; |
||||
|
||||
import lombok.Data; |
||||
import lombok.ToString; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
@ToString |
||||
public class PlanFilterConfigForm { |
||||
private List<PlanFilterForm> planFilterForm; |
||||
|
||||
private WorkFlowForm workFlowForm; |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.bellmann.model.form; |
||||
|
||||
import lombok.Data; |
||||
import lombok.ToString; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
@ToString |
||||
public class PlanFilterForm { |
||||
private String filterName; |
||||
|
||||
|
||||
private List<String> values; |
||||
} |
@ -0,0 +1,24 @@ |
||||
package com.bellmann.model.form; |
||||
|
||||
import lombok.Data; |
||||
import lombok.ToString; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Data |
||||
@ToString |
||||
public class WorkFlowForm { |
||||
|
||||
private Long planId; |
||||
|
||||
|
||||
private Date startTime; |
||||
|
||||
private Date endTime; |
||||
|
||||
private Integer maxConcurrency; |
||||
|
||||
private String planName; |
||||
|
||||
private String planDesc; |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.bellmann.model.vo; |
||||
|
||||
import com.bellmann.common.model.Option; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class PlanFilterConfigOption { |
||||
|
||||
private String displayName; |
||||
|
||||
private String filterName; |
||||
|
||||
private List<Option<String>> options; |
||||
} |
@ -0,0 +1,23 @@ |
||||
package com.bellmann.model.vo; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Data |
||||
public class WorkFlowVO { |
||||
private Long planId; |
||||
@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss") |
||||
private Date startTime; |
||||
@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss") |
||||
private Date endTime; |
||||
@JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss") |
||||
private Date createTime; |
||||
|
||||
private String planName; |
||||
|
||||
private Integer planStatus; |
||||
|
||||
private String createUser; |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.bellmann.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.bellmann.model.form.PlanFilterConfigForm; |
||||
import com.bellmann.model.query.SelectQuery; |
||||
import com.bellmann.model.vo.WorkFlowVO; |
||||
|
||||
public interface PlanCollectorService { |
||||
boolean addWorkflow(PlanFilterConfigForm form); |
||||
|
||||
Page<WorkFlowVO> workflowPage(SelectQuery query); |
||||
|
||||
boolean removeWorkflow(Long planId); |
||||
|
||||
boolean updateWorkflowStatus(Long planId, Integer status); |
||||
} |
@ -0,0 +1,11 @@ |
||||
package com.bellmann.service; |
||||
|
||||
import com.bellmann.model.vo.PlanFilterConfigOption; |
||||
|
||||
import java.util.List; |
||||
|
||||
public interface PlanFilterConfigService { |
||||
List<PlanFilterConfigOption> configOption(); |
||||
|
||||
|
||||
} |
@ -0,0 +1,67 @@ |
||||
package com.bellmann.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.bellmann.common.enums.PlanStatusEnum; |
||||
import com.bellmann.converter.PlanCollectorConverter; |
||||
import com.bellmann.mapper.PlanCollectorMapper; |
||||
import com.bellmann.model.entity.PlanCollector; |
||||
import com.bellmann.model.form.PlanFilterConfigForm; |
||||
import com.bellmann.model.form.PlanFilterForm; |
||||
import com.bellmann.model.form.WorkFlowForm; |
||||
import com.bellmann.model.query.SelectQuery; |
||||
import com.bellmann.model.vo.WorkFlowVO; |
||||
import com.bellmann.security.util.SecurityUtils; |
||||
import com.bellmann.service.PlanCollectorService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class PlanCollectorServiceImpl implements PlanCollectorService { |
||||
private final PlanCollectorConverter planCollectorConverter; |
||||
|
||||
private final PlanCollectorMapper planCollectorMapper; |
||||
@Override |
||||
public boolean addWorkflow(PlanFilterConfigForm form) { |
||||
WorkFlowForm workFlowForm = form.getWorkFlowForm(); |
||||
List<PlanFilterForm> filterFormList = form.getPlanFilterForm(); |
||||
PlanCollector planCollector = planCollectorConverter.form2Entity(workFlowForm); |
||||
planCollector.setPlanFilter(filterFormList); |
||||
planCollector.setCreateUser(SecurityUtils.getUsername()); |
||||
planCollector.setPlanStatus(PlanStatusEnum.INIT.ordinal()); |
||||
planCollector.setCreateTime(new Date()); |
||||
int rows = planCollectorMapper.insert(planCollector); |
||||
return rows>0; |
||||
} |
||||
|
||||
@Override |
||||
public Page<WorkFlowVO> workflowPage(SelectQuery query) { |
||||
int pageNum = query.getPageNum(); |
||||
int pageSize = query.getPageSize(); |
||||
Page<WorkFlowVO> page = new Page<>(pageNum,pageSize); |
||||
return planCollectorMapper.workflowPage(page,query.getSelectName(),query.getSelectValue()); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public boolean removeWorkflow(Long planId) { |
||||
int rows = planCollectorMapper.delete(new LambdaQueryWrapper<PlanCollector>() |
||||
.eq(PlanCollector::getPlanId, planId) |
||||
); |
||||
return rows>0; |
||||
} |
||||
|
||||
@Override |
||||
public boolean updateWorkflowStatus(Long planId, Integer status) { |
||||
int rows = planCollectorMapper.update(null, new LambdaUpdateWrapper<PlanCollector>() |
||||
.eq(PlanCollector::getPlanId, planId) |
||||
.set(PlanCollector::getPlanStatus, status) |
||||
); |
||||
return rows>0; |
||||
} |
||||
} |
@ -0,0 +1,70 @@ |
||||
package com.bellmann.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.bellmann.common.model.Option; |
||||
import com.bellmann.mapper.PlanFilterConfigMapper; |
||||
import com.bellmann.model.entity.PlanFilterConfig; |
||||
import com.bellmann.model.vo.PlanFilterConfigOption; |
||||
import com.bellmann.service.PlanFilterConfigService; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.jdbc.core.JdbcTemplate; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.stream.Collectors; |
||||
|
||||
@Service |
||||
@RequiredArgsConstructor |
||||
public class PlanFilterConfigServiceImpl implements PlanFilterConfigService { |
||||
private final PlanFilterConfigMapper planFilterConfigMapper; |
||||
|
||||
private final JdbcTemplate jdbcTemplate; |
||||
@Override |
||||
public List<PlanFilterConfigOption> configOption() { |
||||
List<PlanFilterConfigOption> list = new ArrayList<>(); |
||||
List<PlanFilterConfig> planFilterConfigs = planFilterConfigMapper.selectList(new LambdaQueryWrapper<>()); |
||||
if (planFilterConfigs.isEmpty()){ |
||||
return list; |
||||
} |
||||
for (PlanFilterConfig planFilterConfig:planFilterConfigs){ |
||||
if (!planFilterConfig.getPropertyIdAndValueSql().isEmpty()){ |
||||
List<Map<String, Object>> maps = jdbcTemplate.queryForList(planFilterConfig.getPropertyIdAndValueSql()); |
||||
// List<Map<String, Object>> maps = SqlRunner.db().selectList(planFilterConfig.getPropertyIdAndValueSql());
|
||||
List<Option<String>> options = maps.stream().map(obj -> { |
||||
String value = obj.get("property_id").toString(); |
||||
String label = obj.get("value").toString(); |
||||
Option<String> option = new Option<>(); |
||||
option.setLabel(label); |
||||
option.setValue(value); |
||||
return option; |
||||
}).collect(Collectors.toList()); |
||||
PlanFilterConfigOption planFilterConfigOption = new PlanFilterConfigOption(); |
||||
planFilterConfigOption.setDisplayName(planFilterConfig.getDisplayName()); |
||||
planFilterConfigOption.setFilterName(planFilterConfig.getFilterName()); |
||||
planFilterConfigOption.setOptions(options); |
||||
list.add(planFilterConfigOption); |
||||
}else { |
||||
List<PlanFilterConfig> filterConfigs = planFilterConfigMapper.groupByFilterName(planFilterConfig.getFilterName()); |
||||
for (PlanFilterConfig config:filterConfigs){ |
||||
List<PlanFilterConfig> planFilterConfigList = planFilterConfigMapper.selectList(new LambdaQueryWrapper<PlanFilterConfig>() |
||||
.eq(PlanFilterConfig::getFilterName, config.getFilterName()) |
||||
); |
||||
List<Option<String>> options = planFilterConfigList.stream().map(obj -> { |
||||
Option<String> option = new Option<>(); |
||||
option.setLabel(obj.getPropertyId()); |
||||
option.setValue(obj.getValue()); |
||||
return option; |
||||
}).collect(Collectors.toList()); |
||||
PlanFilterConfigOption planFilterConfigOption = new PlanFilterConfigOption(); |
||||
planFilterConfigOption.setDisplayName(config.getDisplayName()); |
||||
planFilterConfigOption.setFilterName(config.getFilterName()); |
||||
planFilterConfigOption.setOptions(options); |
||||
list.add(planFilterConfigOption); |
||||
} |
||||
} |
||||
} |
||||
return list; |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
<?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.bellmann.mapper.PlanCollectorMapper"> |
||||
|
||||
<select id="workflowPage" resultType="com.bellmann.model.vo.WorkFlowVO"> |
||||
SELECT |
||||
plan_id, |
||||
start_time, |
||||
end_time, |
||||
plan_name, |
||||
create_time, |
||||
create_user, |
||||
plan_status |
||||
FROM |
||||
itms_plan_collector |
||||
<where> |
||||
<if test="column=='planName' and column!=null and column!=''"> |
||||
and plan_name = #{value} |
||||
</if> |
||||
</where> |
||||
</select> |
||||
</mapper> |
@ -0,0 +1,10 @@ |
||||
<?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.bellmann.mapper.PlanFilterConfigMapper"> |
||||
|
||||
<select id="groupByFilterName" resultType="com.bellmann.model.entity.PlanFilterConfig"> |
||||
SELECT display_name,filter_name from itms_plan_filter_config GROUP BY filter_name,display_name; |
||||
</select> |
||||
</mapper> |
Loading…
Reference in new issue