添加查询标签数据源value接口

This commit is contained in:
yangsb
2024-04-03 16:15:21 +08:00
parent e08dc9324c
commit b0dfc889ff
15 changed files with 123 additions and 9 deletions
@@ -4,6 +4,7 @@ import com.cf.imes.framework.organ.core.aop.OrganIgnore;
import com.cf.imes.module.infra.service.logger.ApiAccessLogService;
/*import com.xxl.job.core.handler.annotation.XxlJob;*/
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -30,11 +31,12 @@ public class AccessLogCleanJob {
*/
private static final Integer DELETE_LIMIT = 100;
/* @XxlJob("accessLogCleanJob")
/* @XxlJob("accessLogCleanJob")*/
@OrganIgnore
/* @Scheduled(cron = "0 0 * * * ?")*/
public void execute() {
Integer count = apiAccessLogService.cleanAccessLog(JOB_CLEAN_RETAIN_DAY, DELETE_LIMIT);
log.info("[execute][定时执行清理访问日志数量 ({}) 个]", count);
}*/
}
}
@@ -4,6 +4,7 @@ import com.cf.imes.framework.organ.core.aop.OrganIgnore;
import com.cf.imes.module.infra.service.logger.ApiErrorLogService;
/*import com.xxl.job.core.handler.annotation.XxlJob;*/
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -30,11 +31,12 @@ public class ErrorLogCleanJob {
*/
private static final Integer DELETE_LIMIT = 100;
/* @XxlJob("errorLogCleanJob")
/*@XxlJob("errorLogCleanJob")*/
@OrganIgnore
/*@Scheduled(cron = "0 0 2 * * ?")*/
public void execute() {
Integer count = apiErrorLogService.cleanErrorLog(JOB_CLEAN_RETAIN_DAY,DELETE_LIMIT);
log.info("[execute][定时执行清理错误日志数量 ({}) 个]", count);
}*/
}
}
@@ -4,6 +4,7 @@ import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.module.executor.controller.admin.plan.vo.*;
import com.cf.imes.module.executor.service.optimizeplan.OptimizePlanService;
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
@@ -16,6 +17,7 @@ import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
/**
* @author there
@@ -86,4 +88,12 @@ public class OptimizePlanController {
return CommonResult.success(optimizePlanParam);
}
@GetMapping("/getLabelDataSourceValue")
@Operation(summary = "获取标签数据源value")
@PreAuthorize("@ss.hasPermission('executor:optimize-plate:create')")
public CommonResult<Map<String,Object>> getLabelDataSourceValue(@Valid GetSourceDataReq req ) {
return CommonResult.success( optimizePlanService.getLabelDataSourceValue(req));
}
}
@@ -0,0 +1,24 @@
package com.cf.imes.module.executor.controller.admin.plan.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author Beal
*/
@Data
@Schema(description = "")
public class GetSourceDataReq {
@Schema(description = "生产单id")
@NotNull(message = "生产单id不能空")
private Long orderId;
@Schema(description = "排单id")
private Long planId;
@Schema(description = "数据源id")
@NotNull(message = "数据源id不能空")
private Long dataSourceId;
}
@@ -17,6 +17,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* 生产单表 order_{N} Mapper
@@ -88,4 +89,5 @@ public interface OrderMapper extends BaseMapperX<OrderDO> {
return selectList(wrapper);
}
Map<String, Object> selectDynamicSqlString(String sql);
}
@@ -1,6 +1,7 @@
package com.cf.imes.module.executor.framework.rpc.config;
import com.cf.imes.module.infra.api.file.FileApi;
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
import com.cf.imes.module.system.api.machine.MachineApi;
import com.cf.imes.module.system.api.user.AdminUserApi;
import com.cf.imes.module.system.api.dict.DictDataApi;
@@ -11,6 +12,6 @@ import org.springframework.context.annotation.Configuration;
* @author there
*/
@Configuration(proxyBeanMethods = false)
@EnableFeignClients(clients = {AdminUserApi.class, MachineApi.class, DictDataApi.class, FileApi.class})
@EnableFeignClients(clients = {AdminUserApi.class, MachineApi.class, DictDataApi.class, FileApi.class, DataSourceApi.class})
public class RpcConfiguration {
}
@@ -3,6 +3,7 @@ package com.cf.imes.module.executor.service.optimizeplan;
import com.cf.imes.module.executor.controller.admin.plan.vo.*;
import java.util.List;
import java.util.Map;
public interface OptimizePlanService {
List<PlateOptimize> getPlateListByPlanId(Long planId);
@@ -16,4 +17,6 @@ public interface OptimizePlanService {
OptimizeParamResVO getOptimizeParam(Long planId);
OptimizeParamRespVO getOptimizePlanParam(Long planId);
Map<String, Object> getLabelDataSourceValue(GetSourceDataReq req);
}
@@ -17,6 +17,7 @@ import com.cf.imes.module.executor.dal.dataobject.remainplaten.OutlineDTO;
import com.cf.imes.module.executor.dal.dataobject.remainplaten.PointDTO;
import com.cf.imes.module.executor.dal.dataobject.remainplaten.RemainPlateDO;
import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper;
import com.cf.imes.module.executor.dal.mysql.order.OrderMapper;
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
import com.cf.imes.module.executor.dal.mysql.plate.PlateMapper;
import com.cf.imes.module.executor.dal.mysql.remainplaten.RemainPlateMapper;
@@ -24,6 +25,7 @@ import com.cf.imes.module.executor.util.RandomUtils;
import com.cf.imes.module.executor.util.RectangleChecker;
import com.cf.imes.module.infra.api.file.FileApi;
import com.cf.imes.module.infra.api.file.dto.FileCreateReqDTO;
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.stereotype.Service;
@@ -61,6 +63,12 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
@Resource
private GoodsMapper goodsMapper;
@Resource
private DataSourceApi dataSourceApi;
@Resource
private OrderMapper orderMapper;
@Override
public List<PlateOptimize> getPlateListByPlanId(Long planId) {
return planMapper.selectPlateListByPlanId(planId);
@@ -226,5 +234,11 @@ public class OptimizePlanServiceImpl implements OptimizePlanService {
return optimizePlanParam;
}
@Override
public Map<String, Object> getLabelDataSourceValue(GetSourceDataReq req) {
String sqlStr = dataSourceApi.getSqlById(req.getDataSourceId()).getCheckedData();
return orderMapper.selectDynamicSqlString(String.format(sqlStr, req.getOrderId()));
}
}
@@ -12,4 +12,8 @@
${ew.customSqlSegment}
group by orderId, p.id
</select>
<select id="selectDynamicSqlString" resultType="java.util.Map">
${sqlStr}
</select>
</mapper>
@@ -0,0 +1,23 @@
package com.cf.imes.module.system.api.dataSource;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Beal
*/
@FeignClient(name = ApiConstants.NAME) // TODO 晨丰:fallbackFactory =
@Tag(name = "RPC 服务 - 数据源")
public interface DataSourceApi {
String PREFIX = ApiConstants.PREFIX + "/dataSource";
@GetMapping(PREFIX + "/getSqlById")
@Operation(summary = "获得数据源sql")
CommonResult<String> getSqlById(@RequestParam(value = "id") Long id);
}
@@ -0,0 +1,29 @@
package com.cf.imes.module.system.api.datasource;
import com.cf.imes.framework.common.exception.ErrorCode;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.module.system.api.dataSource.DataSourceApi;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceMapper;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Objects;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
@RestController
public class DataSourceApiImpl implements DataSourceApi {
@Resource
private DataSourceMapper dataSourceMapper;
@Override
public CommonResult<String> getSqlById(Long id) {
DataSourceDO dataSourceDO = dataSourceMapper.selectById(id);
if(Objects.isNull(dataSourceDO)) {
throw exception(new ErrorCode(2133,"数据源不存在"));
}
return CommonResult.success(dataSourceDO.getSqlStr()) ;
}
}
@@ -19,7 +19,7 @@ public class DataSourcePageReqVO extends PageParam {
private String name;
@Schema(description = "sql")
private String sql;
private String sqlStr;
@Schema(description = "数据源类型", example = "2")
private Integer type;
@@ -24,7 +24,7 @@ public class DataSourceRespVO {
@Schema(description = "sql", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("sql")
private String sql;
private String sqlStr;
@Schema(description = "数据源类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("数据源类型")
@@ -34,7 +34,7 @@ public class DataSourceDO extends BaseDO {
/**
* sql
*/
private String sql;
private String sqlStr;
/**
* 数据源类型
*/
@@ -20,7 +20,7 @@ public interface DataSourceMapper extends BaseMapperX<DataSourceDO> {
default PageResult<DataSourceDO> selectPage(DataSourcePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DataSourceDO>()
.likeIfPresent(DataSourceDO::getName, reqVO.getName())
.eqIfPresent(DataSourceDO::getSql, reqVO.getSql())
.eqIfPresent(DataSourceDO::getSqlStr, reqVO.getSqlStr())
.eqIfPresent(DataSourceDO::getType, reqVO.getType())
.betweenIfPresent(DataSourceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DataSourceDO::getId));