Merge branch 'main' of ssh://192.168.1.205:9922/cf_devdept2/cf_imes_server

This commit is contained in:
lym
2024-09-24 17:54:16 +08:00
77 changed files with 2693 additions and 569 deletions
@@ -211,11 +211,12 @@ public interface ErrorCodeConstants {
ErrorCode THE_CURRENT_BRAND_OF_THE_MACHINE_EXISTS = new ErrorCode(1_002_029_008, "当前机台配置的模板中,该品牌已存在,请重新输入品牌名称");
ErrorCode THE_MODEL_OF_THE_MACHINE_DOES_NOT_EXIST = new ErrorCode(1_002_029_009, "该型号的机台不存在,请进行配置");
ErrorCode THE_CURRENT_BRAND = new ErrorCode(1_002_029_010, "品牌ID错误,或品牌不存在");
ErrorCode MACHINE_NUM_ERROR = new ErrorCode(1_002_029_011, "当前模板创建的机台数量已达到最大值,无法继续创建");
ErrorCode MACHINE_NUM_ERROR = new ErrorCode(1_002_029_011, "当前组织该类型的机台创建已达到最大值,无法继续创建");
ErrorCode MACHINE_NAME_ERROR = new ErrorCode(1_002_029_012, "当前机台名称已存在,请重新输入机台名称");
ErrorCode MACHINETEMPLATE_NAME_ERROR = new ErrorCode(1_002_029_013, "当前机台模板的名称已存在,请重新输入机台模板名称");
ErrorCode LABELINGMACHINE_RELATED_DATA_ERROR = new ErrorCode(1_002_029_014, "当前机台关联的贴标机数据有误,请在高级配置中重新配置贴标机或选择其他模板");
ErrorCode DRILLMACHINE_RELATED_DATA_ERROR = new ErrorCode(1_002_029_015, "当前机台关联的钻孔机数据有误,请在钻孔模块中重新配置钻孔机或选择其他模板");
ErrorCode MACHINE_DATA_ERROR = new ErrorCode(1_002_029_016, "当前组织还未进行机台授权,请联系组织管理员在基础管理里对当前组织进行机台授权,或联系客服进行授权");
// ========== 标签模板 1-002-300-000 ==========
@@ -288,6 +289,16 @@ public interface ErrorCodeConstants {
//=========== 断言提示信息 1-002-041-000 ============
ErrorCode ORDER_DATE_ERROR = new ErrorCode(1_002_041_001, "生产单信息不存在,请重新进入或切换生产单");
ErrorCode ORDER_PLATE_ERROR = new ErrorCode(1_002_041_002, "生产单对应的板材数据有异常,请查看板材信息或联系客服");
ErrorCode INSERT_PLATE_DATE_ERROR = new ErrorCode(1_002_041_003, "新增排单的板材数据有误,请重新新增");
ErrorCode ORDER_PLAN_DATE_ERROR = new ErrorCode(1_002_041_004, "排单信息不存在,请重新进入或切换排单");
ErrorCode ORDER_PLAN_OPTIMIZE_ERROR = new ErrorCode(1_002_041_005, "排单的优化数据异常,请将该排单重新优化");
ErrorCode ORDER_PLATE_MODEL_DATE_ERROR = new ErrorCode(1_002_041_006, "生产单对应的板材造型数据为空,请检查板材信息或者联系客服");
ErrorCode ORDER_PLAN_PLATE_ERROR = new ErrorCode(1_002_041_007, "当前排单对应的板材数据有异常,请查看板材信息或联系客服");
ErrorCode ORDER_PLAN_ERROR = new ErrorCode(1_002_041_008, "当前排单对应的生产单数据有异常,请查看生产单信息或联系客服");
ErrorCode ORDER_PLAN_PLATE_MODEL_DATE_ERROR = new ErrorCode(1_002_041_009, "当前排单对应的板材造型数据为空,请检查板材信息或者联系客服");
ErrorCode ORDER_GOODS_DATA_ERROR = new ErrorCode(1_002_041_010, "当前大板数据异常,请检查大板信息或者联系客服");
ErrorCode ORDER_PACK_DATA_ERROR = new ErrorCode(1_002_041_011, "当前包裹数据为空,请重新查看包裹数据或联系客服");
@@ -213,6 +213,103 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-common</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-module-infra-api</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-module-prod-executor-api</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-module-system-api</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-banner</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-data-permission</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-dict</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-error-code</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-ip</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-operatelog</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-organ</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-biz-sms</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-captcha</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-elasticsearch</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-env</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-excel</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-monitor</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-mybatis</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-redis</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-rpc</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-security</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-web</artifactId>
</include>
<include>
<groupId>com.cf.imes</groupId>
<artifactId>cf-spring-boot-starter-mq</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
@@ -1,33 +1,29 @@
package com.cf.imes.module.system.controller.admin.datasource;
import com.cf.imes.framework.es.core.valid.CreateGroup;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.util.*;
import java.io.IOException;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.util.object.BeanUtils;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
import com.cf.imes.framework.excel.core.util.ExcelUtils;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.*;
import com.cf.imes.module.system.controller.admin.datasource.vo.*;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.module.system.service.datasource.DataSourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 系统数据源")
@RestController
@@ -90,9 +86,9 @@ public class DataSourceController {
}
@PostMapping("/create")
@Operation(summary = "新增数据源字段")
@PreAuthorize("@ss.hasPermission('system:data-source:create')")
// @PostMapping("/create")
// @Operation(summary = "新增数据源字段")
// @PreAuthorize("@ss.hasPermission('system:data-source:create')")
public CommonResult<Boolean> createDataSource(@Validated @RequestBody List<DataSourceSaveReqVO> createReqVO) {
dataSourceService.createDataSource(createReqVO);
@@ -111,6 +107,36 @@ public class DataSourceController {
}
@GetMapping("/getKeyNameData")
@Operation(summary = "数据源对应字段数据查询")
@Parameters({
@Parameter(name = "machineId", description = "机台ID", required = true),
@Parameter(name = "planId", description = "排单ID", required = true)
})
//@PreAuthorize("@ss.hasPermission('system:data-source:query')")
public CommonResult<String> getKeyNameData(@RequestParam("machineId") Long machineId,@RequestParam("planId") Long planId) {
String keyNameData = dataSourceService.getKeyNameData(machineId,planId);
return success(keyNameData);
}
@PutMapping("/insertKeyNameData")
@Operation(summary = "保存机台数据源对应的数据源字段")
//@PreAuthorize("@ss.hasPermission('system:data-source:query')")
public CommonResult<Boolean> saveMachineKeyName(@RequestBody List<MachineDataSourceDO> machineDataSourceDOS ) {
return success(dataSourceService.saveMachineKeyName(machineDataSourceDOS));
}
@GetMapping("/export-excel")
@Operation(summary = "导出系统数据源 Excel")
@PreAuthorize("@ss.hasPermission('system:data-source:export')")
@@ -0,0 +1,87 @@
package com.cf.imes.module.system.controller.admin.datasource.dataQuery;
import com.cf.imes.module.system.dal.mysql.machine.MachineMapper;
import com.cf.imes.module.system.dal.mysql.organ.OrganMapper;
import com.cf.imes.module.system.dal.mysql.user.AdminUserMapper;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.List;
import static com.cf.imes.framework.common.util.json.JsonUtils.toJsonString;
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
/**
* @author Administrator
*/
@Configuration
public class DataQuery {
String SEPARATE = "select";
@Resource
private OrganMapper organMapper;
@Resource
private AdminUserMapper userMapper;
@Resource
private MachineMapper machineMapper;
public String dataGetOrgan(String filed) {
// String sql = "select from system_organization where id = #{id} and deleted = false";
//
// sql = sql.replace("#{id}", String.valueOf(getUserOrganId()));
return toJsonString(organMapper.selectOrganDataSource(conversion(filed),getUserOrganId()));
}
public String dataGetUser(String filed, List<String> nameList) {
// String sql = "select from system_users where nickname in (#{nameList}) and deleted = false and organ_id = #{organId}";
//
// sql = sql.replace("#{organId}", getUserOrganId() + "").replace("#{orderIds}", nameList.toString().replaceAll("\\[|\\]", ""));
return toJsonString(userMapper.selectUserDataSource(conversion(filed),getUserOrganId(),nameList));
}
public String dataGetMachine(String filed,Long machineId) {
return toJsonString(machineMapper.selectMachineDataSource(conversion(filed),machineId,getUserOrganId()));
}
// 字符串处理
private String conversion(String filed) {
// 去除字段中的 【 】
return filed.replaceAll("\\[|\\]", "");
// 使用正则表达式在单词后插入字符串
// return sql.replaceAll(SEPARATE + "(\\b)", SEPARATE + " " + toInsert);
}
}
@@ -0,0 +1,26 @@
package com.cf.imes.module.system.controller.admin.datasource.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "数据源字段信息")
public class DataSource {
@Schema(description = "父级ID")
private Integer parentSourceId;
@Schema(description = "数据源ID")
private Long sourceId;
@Schema(description = "数据源字段名称")
private String keyName;
}
@@ -0,0 +1,28 @@
package com.cf.imes.module.system.controller.admin.datasource.vo;
import com.cf.imes.framework.es.core.dal.ESDocument;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MachineDataSourceDO extends ESDocument {
@Schema(description = "机台ID")
private Long machineId;
@Schema(description = "数据源对象")
private List<DataSource> dataSource;
}
@@ -29,7 +29,7 @@ public class MachineAuthController {
@PutMapping("insert-organ-auth")
@Operation(summary = "组织机台授权信息")
@Operation(summary = "组织机台授权信息新")
@PreAuthorize("@ss.hasPermission('machine-auth::update')")
public CommonResult<Boolean> authInsert(@RequestBody MachineOrgAuthReq vo) {
return success(machineService.authInsert(vo));
@@ -3,9 +3,6 @@ package com.cf.imes.module.system.controller.admin.machine.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
/**
* @author Beal
*/
@@ -36,8 +33,8 @@ public class MachineOrgAuthReq {
private Integer sealedgeLimit;
@Schema(description = "授权的机台ID")
private List<Integer> machineAuthIds;
// @Schema(description = "授权的机台ID")
// private List<Integer> machineAuthIds;
}
@@ -11,8 +11,9 @@ import lombok.Data;
public class OrganMachinePage extends PageParam {
@Schema(description = "组织名称")
private String organName;
private Long organId;
@Schema(description = "组织状态(0正常 1停用)")
private Integer status;
@Schema(description = "机台名称")
private String machineName;
}
@@ -6,6 +6,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* @author Beal
*/
@@ -18,6 +20,9 @@ public class OrganMachineResp {
@Schema(description = "组织id")
private Long organId;
@Schema(description = "组织状态(0正常 1停用)")
private Integer status;
@Schema(description = "组织名称")
private String organName;
@@ -41,4 +46,13 @@ public class OrganMachineResp {
@Schema(description = "封边机授权数量")
private Integer sealedgeLimit;
@Schema(description = "操作人")
private String updater;
@Schema(description = "修改时间")
private LocalDateTime updateTime;
}
@@ -4,6 +4,7 @@ import com.cf.imes.framework.common.enums.CommonStatusEnum;
import com.cf.imes.framework.common.validation.InEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@@ -18,6 +19,7 @@ public class TenantPackageSaveReqVO {
@Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP")
@NotEmpty(message = "套餐名不能为空")
@Length(min = 1, max = 30, message = "套餐名长度不能超过30位")
private String name;
@Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@@ -74,5 +74,5 @@ public interface MachineMapper extends BaseMapperX<MachineDO> {
}
List<MachineDO> selectMachineDataSource(@Param("filed") String filed,@Param("machineId") Long machineId,@Param("organId") Long organId);
}
@@ -90,7 +90,7 @@ public interface OrganMapper extends BaseMapperX<OrganizationDO> {
}
List<OrganizationDO> selectTestSQL(@Param("sql") String sql);
List<OrganizationDO> selectOrganDataSource(@Param("filed") String filed,@Param("organId") Long organId);
/**
@@ -1,15 +1,10 @@
package com.cf.imes.module.system.dal.mysql.setting;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.system.controller.admin.machine.vo.MachinePageReqVO;
import com.cf.imes.module.system.dal.dataobject.machinetemplate.MachineTemplateDO;
import com.cf.imes.module.system.dal.dataobject.setting.PackageConfigDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
@Mapper
public interface SettingMapper extends BaseMapperX<PackageConfigDO> {
@@ -23,4 +18,11 @@ public interface SettingMapper extends BaseMapperX<PackageConfigDO> {
.eqIfPresent(PackageConfigDO::getType,type));
}
default int deleteSetting(Integer type,Long userId, Long organId) {
return delete(new LambdaQueryWrapperX<PackageConfigDO>()
.eq(PackageConfigDO::getOrganId, organId)
.eq(PackageConfigDO::getUserId, userId)
.eq(PackageConfigDO::getType,type));
}
}
@@ -182,4 +182,8 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
*/
@Delete("DELETE FROM system_users WHERE id = #{id}")
int physicalDeleteById(@Param("id") Long id);
List<AdminUserDO> selectUserDataSource(@Param("filed") String filed,@Param("organId") Long organId,@Param("nameList") List<String> nameList);
}
@@ -1,13 +1,11 @@
package com.cf.imes.module.system.service.datasource;
import java.util.*;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.system.controller.admin.datasource.vo.*;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO;
import javax.validation.Valid;
import java.util.List;
/**
* 系统数据源 Service 接口
@@ -59,4 +57,9 @@ public interface DataSourceService {
List<DataSourceRespVO> list();
List<DataSourceFiledReqVO> getList(Integer type);
String getKeyNameData(Long machineId,Long planId);
Boolean saveMachineKeyName(List<MachineDataSourceDO> machineDataSourceDOS);
}
@@ -1,28 +1,37 @@
package com.cf.imes.module.system.service.datasource;
import com.alibaba.fastjson.JSON;
import cn.hutool.core.collection.CollectionUtil;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.search.Hit;
import com.cf.imes.framework.common.enums.MachineTypeEnum;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.es.core.service.ESDocumentService;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.executor.api.plan.OrderPlanApi;
import com.cf.imes.module.system.controller.admin.datasource.dataQuery.DataQuery;
import com.cf.imes.module.system.controller.admin.datasource.vo.*;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceFiledDO;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceFiledMapper;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceMapper;
import com.cf.imes.module.system.dal.mysql.machine.MachineMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import com.cf.imes.module.system.controller.admin.datasource.vo.*;
import com.cf.imes.module.system.dal.dataobject.datasource.DataSourceDO;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.system.dal.mysql.datasource.DataSourceMapper;
import javax.annotation.Resource;
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.ES_ERROR_DELETE;
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.PLAN_NOT_ALLOW_DELETE;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
import static com.cf.imes.framework.common.util.object.BeanUtils.toBean;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.DATA_SOURCE_NOT_EXISTS;
/**
* 系统数据源 Service 实现类
@@ -31,6 +40,7 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
*/
@Service
@Validated
@Slf4j
public class DataSourceServiceImpl implements DataSourceService {
@Resource
@@ -39,6 +49,24 @@ public class DataSourceServiceImpl implements DataSourceService {
@Resource
private DataSourceFiledMapper dataSourceFiledMapper;
@Resource
private MachineMapper machineMapper;
@Resource
private ESDocumentService esDocumentService;
@Resource
private ElasticsearchClient elasticsearchClient;
@Resource
private OrderPlanApi orderPlanApi;
@Resource
private DataQuery dataQuery;
String MACHINE_DATA_SOURCE = "imes_machine_data_source";
@Override
public void createDataSource(List<DataSourceSaveReqVO> createReqVO) {
@@ -252,7 +280,7 @@ public class DataSourceServiceImpl implements DataSourceService {
// 校验存在
validateDataSourceExists(updateReqVO.getId());
// 更新
DataSourceDO updateObj = BeanUtils.toBean(updateReqVO, DataSourceDO.class);
DataSourceDO updateObj = toBean(updateReqVO, DataSourceDO.class);
dataSourceMapper.updateById(updateObj);
}
@@ -388,7 +416,7 @@ public class DataSourceServiceImpl implements DataSourceService {
List<DataSourceDO> dataSourceDOS = dataSourceMapper.selectByType();
List<DataSourceFiledReqVO> dataSourceFiledReqVOS = BeanUtils.toBean(dataSourceDOS, DataSourceFiledReqVO.class);
List<DataSourceFiledReqVO> dataSourceFiledReqVOS = toBean(dataSourceDOS, DataSourceFiledReqVO.class);
List<Long> ids = dataSourceDOS.stream().map(DataSourceDO::getId).toList();
@@ -422,7 +450,7 @@ public class DataSourceServiceImpl implements DataSourceService {
// 获取没有key的节点ID
List<Long> ids = parentList.stream()
.filter(f -> f.getKeyName() == null)
// .filter(f -> f.getKeyName() == null)
.map(DataSourceFiledReqVO::getId)
.distinct()
.toList();
@@ -450,6 +478,319 @@ public class DataSourceServiceImpl implements DataSourceService {
}
@Override
public String getKeyNameData(Long machineId,Long planId) {
StringBuilder data = new StringBuilder();
List<Integer> parentSourceId = new ArrayList<>();
List<MachineDataSourceDO> dataSourceDOS = buildMachineDataSourceByMachineId(machineId, MACHINE_DATA_SOURCE);
for (MachineDataSourceDO dataSourceDO : dataSourceDOS) {
parentSourceId.addAll(dataSourceDO.getDataSource().stream().map(DataSource::getParentSourceId).toList());
}
parentSourceId = parentSourceId.stream().distinct().toList();
for (Integer aLong : parentSourceId) {
switch (aLong) {
// 生产单基础信息
// 生产单经销商信息
// 生产单终端客户信息
case 1543, 68, 80 -> {
String machineDataSourceKeyName = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.apiDataGetPlan(planId, machineDataSourceKeyName));
}
// 生产单组织信息
case 61 -> {
String machineDataSourceKeyName1 = getMachineDataSourceKeyName(machineId, aLong);
data.append(dataQuery.dataGetOrgan(machineDataSourceKeyName1));
}
// 生产单业务员信息
// 生产单拆单员信息
case 74, 92 -> {
String machineDataSourceKeyName2 = getMachineDataSourceKeyName(machineId, aLong);
List<String> nameList = orderPlanApi.apiGetOrders(planId, aLong == 74);
data.append(dataQuery.dataGetUser(machineDataSourceKeyName2, nameList));
}
// 排单基础信息
case 98 -> {
String machineDataSourceKeyName3 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.getPlan(planId, machineDataSourceKeyName3));
}
// 排单板材的大板用量信息
case 110 -> {
List<String> machineDataSourceKeyName4 = buildMachineDataSourceByParentSourceId(machineId, aLong, MACHINE_DATA_SOURCE)
.get(0)
.getDataSource()
.stream().map(DataSource::getKeyName).toList();
data.append(orderPlanApi.apiGetEsPlan(planId, machineDataSourceKeyName4));
}
// 排单板材的余料板用量信息
// 物料(商品)板材信息的余料信息
case 119, 822 -> {
String machineDataSourceKeyName5 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.apiGetPlanRemainPlate(planId, machineDataSourceKeyName5));
}
// 排单板件的基础信息
// 排单板件的规格尺寸的成品尺寸信息
// 排单板件的规格尺寸的拆单尺寸信息
// 雕刻机加工概要信息
// 排单钻孔机(大板上下钻)加工信息概要
// 排单钻孔机(小板)加工信息概要
// 板件中板材基础信息
// 板件中的基础信息的成品尺寸
case 140, 204, 209, 446, 552, 657, 846, 907 -> {
String machineDataSourceKeyName6 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.apiGetPlanPlate(planId, machineDataSourceKeyName6));
}
// 排单板件的备注信息
// 排单板件的规格尺寸的开料尺寸信息
// 板件中板材基础信息的备注信息
// 板件中基础信息的开料尺寸
case 141, 213, 853, 908 -> {
List<String> machineDataSourceKeyName7 = buildMachineDataSourceByParentSourceId(machineId, aLong, MACHINE_DATA_SOURCE)
.get(0)
.getDataSource()
.stream().map(DataSource::getKeyName).toList();
data.append(orderPlanApi.apiGetEsPlate(planId, machineDataSourceKeyName7));
}
// 生产单中的房间信息
// 生产单中的柜体信息
// 板件中的基础信息的房间信息
// 板件中的基础信息的柜体信息
case 1544,1545, 881, 889 -> {
String machineDataSourceKeyName8 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.apiGetPlanBodyOrRoom(planId, machineDataSourceKeyName8));
}
// 板件信息的加工组信息
case 897 -> {
String machineDataSourceKeyName9 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.apiGetPlanGroup(planId, machineDataSourceKeyName9));
}
// 物料(商品)的板材信息
// 排单排版信息-大板信息
case 808, 416 -> {
String machineDataSourceKeyName10 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.getGoods(planId, machineDataSourceKeyName10));
}
// 物料(商品)的配件信息
case 809 -> {
String machineDataSourceKeyName11 = getMachineDataSourceKeyName(machineId, aLong);
data.append(orderPlanApi.apiGetPlanParts(planId, machineDataSourceKeyName11));
}
// 物料(商品)的配件备注信息
case 840 -> {
List<String> machineDataSourceKeyName12 = buildMachineDataSourceByParentSourceId(machineId, aLong, MACHINE_DATA_SOURCE)
.get(0)
.getDataSource()
.stream().map(DataSource::getKeyName).toList();
data.append(orderPlanApi.apiGetEsParts(planId, machineDataSourceKeyName12));
}
// 排单信息的生产线信息
case 1483 -> {
Integer machineType = machineMapper.selectById(machineId).getMachineType();
if (machineType.equals(MachineTypeEnum.CUTTING.getType())){
String machineDataSourceKeyName13 = getMachineDataSourceKeyName(machineId, aLong);
data.append(dataQuery.dataGetMachine(machineDataSourceKeyName13,machineId));
}
}
// 排单信息的机台信息
case 1487 -> {
String machineDataSourceKeyName14 = getMachineDataSourceKeyName(machineId, aLong);
data.append(dataQuery.dataGetMachine(machineDataSourceKeyName14,machineId));
}
}
}
return data.toString();
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean saveMachineKeyName(List<MachineDataSourceDO> machineDataSourceDOS) {
Long machineId = machineDataSourceDOS.stream().map(MachineDataSourceDO::getMachineId).distinct().toList().get(0);
/*
* 目前数据源保存有两种方式:
* 1. 每回保存全都传过来,先将机台的原数据源删除,再重新保存
* 2. 传过来的时候将新增的和删除的区分开来,我这边做数据处理
*
* */
// todo 目前先实现第一种:每回保存时传入全部数据,先删除原机台字段信息,再保存
deleteByMachineId(machineId,MACHINE_DATA_SOURCE);
batchSaveMachineDataSource(machineDataSourceDOS);
return Boolean.TRUE;
}
public static List<String> convertToSnakeCase(List<String> camelCaseList) {
List<String> snakeCaseList = new ArrayList<>();
// 字段ID改成数据库的形式
camelCaseList = camelCaseList.stream().map(key -> key.replace("_", "")).toList();
for (String camelCaseStr : camelCaseList) {
StringBuilder snakeCaseStr = new StringBuilder();
for (int i = 0; i < camelCaseStr.length(); i++) {
char c = camelCaseStr.charAt(i);
// 如果字符是大写字母,并且不是第一个字符,则添加下划线
if (Character.isUpperCase(c) && i != 0) {
snakeCaseStr.append('_');
}
// 转换字符为小写
snakeCaseStr.append(Character.toLowerCase(c));
}
snakeCaseList.add(snakeCaseStr.toString());
}
return snakeCaseList;
}
public void batchSaveMachineDataSource(List<MachineDataSourceDO> machineDataSourceDOS) {
try {
BulkResponse bulkResponse = esDocumentService.bulkCreate(MACHINE_DATA_SOURCE, machineDataSourceDOS);
boolean errors = bulkResponse.errors();
if (errors) {
log.error(bulkResponse.items().toString());
throw new ServiceException(500, "未知异常");
}
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
throw new RuntimeException(e);
}
}
private String getMachineDataSourceKeyName(Long machineId, Integer parentSourceId) {
return convertToSnakeCase(buildMachineDataSourceByParentSourceId(machineId, parentSourceId, MACHINE_DATA_SOURCE)
.get(0)
.getDataSource()
.stream().map(DataSource::getKeyName).toList())
.toString();
}
// 根据机台ID和父级ID,查询对应的数据源字段
private List<MachineDataSourceDO> buildMachineDataSourceByParentSourceId(Long machineId,Integer parentSourceId, String index) {
SearchRequest.Builder builder = new SearchRequest.Builder();
builder.index(index);
builder.query(q -> q.bool(b -> b
.must(m->m.term(t->t.field("machineId").value(machineId)))
.must(m->m.match(t->t.field("dataSource.parentSourceId").query(parentSourceId)))));
try {
SearchResponse<MachineDataSourceDO> search = elasticsearchClient.search(builder.build(), MachineDataSourceDO.class);
List<Hit<MachineDataSourceDO>> hits = search.hits().hits();
if (CollectionUtil.isNotEmpty(hits)) {
return hits.stream().map(Hit::source).collect(Collectors.toList());
}
return new ArrayList<>();
} catch (IOException e) {
log.error(e.getMessage());
throw new ServiceException(INTERNAL_SERVER_ERROR);
}
}
// 根据机台ID查询机台对应的数据源字段信息
private List<MachineDataSourceDO> buildMachineDataSourceByMachineId(Long machineId, String index) {
SearchRequest.Builder builder = new SearchRequest.Builder();
builder.index(index);
builder.query(q -> q.term(b -> b.field("machineId").value(machineId)));
try {
SearchResponse<MachineDataSourceDO> search = elasticsearchClient.search(builder.build(), MachineDataSourceDO.class);
List<Hit<MachineDataSourceDO>> hits = search.hits().hits();
if (CollectionUtil.isNotEmpty(hits)) {
return hits.stream().map(Hit::source).collect(Collectors.toList());
}
return new ArrayList<>();
} catch (IOException e) {
log.error(e.getMessage());
throw new ServiceException(INTERNAL_SERVER_ERROR);
}
}
// 根据机台ID删除对应的数据源ES信息
public void deleteByMachineId(Long machineId, String index) {
DeleteByQueryRequest.Builder builder = new DeleteByQueryRequest.Builder();
builder.index(index);
builder.query(q -> q.term(t -> t.field("machineId").value(machineId)));
try {
DeleteByQueryResponse response = elasticsearchClient.deleteByQuery(builder.build());
log.info("Deleted {} documents with planId {}", response.deleted(), machineId);
} catch (IOException e) {
log.error("Error deleting documents with planId {}: {}", machineId, e.getMessage());
throw new ServiceException(ES_ERROR_DELETE);
}
}
private List<Long> conversion(String sourceId) {
return Arrays.stream(sourceId.split(","))
@@ -42,6 +42,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -99,13 +100,19 @@ public class MachineServiceImpl implements MachineService {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
assert loginUser != null;
MachineLimitDO machineLimitDO = machineLimitMapper.selectById(loginUser.getOrganId());
if(machineLimitDO == null){
throw exception(MACHINE_DATA_ERROR);
}
// 校验机台名称是否重复
MachineDO machine = machineMapper.selectMachineName(createReqVO.getName(), createReqVO.getMachineType(), getUserOrganId());
if (machine != null) {
throw exception(MACHINE_NAME_ERROR);
}
// validateMachineNum(createReqVO.getMachineType(), loginUser.getOrganId());
validateMachineNum(createReqVO.getMachineType(), loginUser.getOrganId());
MachineDO machineDO;
MachineTemplateDO machineTemplateDO;
@@ -435,9 +442,9 @@ public class MachineServiceImpl implements MachineService {
@Override
public Boolean authInsert(MachineOrgAuthReq vo) {
OrganizationDO tenant = organMapper.selectById(vo.getOrganId());
MachineLimitDO machineLimit = machineLimitMapper.selectById(vo.getOrganId());
if (tenant != null) {
if (machineLimit != null) {
throw exception(ORGAN_ALREADY_EXISTS);
}
@@ -448,7 +455,7 @@ public class MachineServiceImpl implements MachineService {
.labelLimit(vo.getLabelLimit())
.sawLimit(vo.getSawLimit())
.sealedgeLimit(vo.getSealedgeLimit())
.setting(vo.getMachineAuthIds().toString())
// .setting(vo.getMachineAuthIds().toString())
.build();
machineLimitMapper.insert(machineLimitDO);
@@ -465,6 +472,9 @@ public class MachineServiceImpl implements MachineService {
throw exception(ORGAN_NOT_EXISTS);
}
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
assert loginUser != null;
MachineLimitDO machineLimitDO = MachineLimitDO.builder()
.organId(vo.getOrganId())
.cutLimit(vo.getCutLimit())
@@ -472,9 +482,12 @@ public class MachineServiceImpl implements MachineService {
.labelLimit(vo.getLabelLimit())
.sawLimit(vo.getSawLimit())
.sealedgeLimit(vo.getSealedgeLimit())
.setting(vo.getMachineAuthIds().toString())
// .setting(vo.getMachineAuthIds().toString())
.build();
machineLimitDO.setUpdateTime(LocalDateTime.now());
machineLimitDO.setUpdater(loginUser.getNickname());
machineLimitMapper.updateById(machineLimitDO);
@@ -571,30 +584,18 @@ public class MachineServiceImpl implements MachineService {
// 校验当前组织当前类型的机台是否达到最大创建数量
private void validateMachineNum(Integer machineType, Long organId) {
Integer machineNum = machineMapper.selectByOrganId(machineType, organId).size() + 1;
int machineNum = machineMapper.selectByOrganId(machineType, organId).size() ;
MachineLimitDO machineLimitDO = machineLimitMapper.selectById(organId);
Integer authMachineNum = 0;
switch (machineType) {
case 1:
authMachineNum = machineLimitDO.getCutLimit();
break;
case 2:
authMachineNum = machineLimitDO.getDrillLimit();
break;
case 3:
authMachineNum = machineLimitDO.getSawLimit();
break;
case 4:
authMachineNum = machineLimitDO.getLabelLimit();
break;
case 5:
authMachineNum = machineLimitDO.getSealedgeLimit();
break;
}
Integer authMachineNum = switch (machineType) {
case 1 -> machineLimitDO.getCutLimit();
case 2 -> machineLimitDO.getDrillLimit();
case 3 -> machineLimitDO.getSawLimit();
case 4 -> machineLimitDO.getLabelLimit();
case 5 -> machineLimitDO.getSealedgeLimit();
default -> 0;
};
if (machineNum >= authMachineNum) {
throw exception(MACHINE_NUM_ERROR);
@@ -3,7 +3,6 @@ package com.cf.imes.module.system.service.setting;
import com.cf.imes.framework.common.enums.UserSettingTypeEnum;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.security.core.LoginUser;
import com.cf.imes.module.system.controller.admin.setting.vo.PackageConfigReqVO;
import com.cf.imes.module.system.dal.dataobject.setting.PackageConfigDO;
@@ -16,7 +15,7 @@ import javax.annotation.Resource;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.util.json.JsonUtils.unzipString;
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.*;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.CURRENTLY_NO_CONFIGURATION_AVAILABLE;
@Service
@@ -32,6 +31,9 @@ public class SettingServiceImpl implements SettingService{
public Long insertSetting(PackageConfigReqVO reqVO) {
LoginUser loginUser = getLoginUser();
settingMapper.deleteSetting(reqVO.getType(),loginUser.getId(),loginUser.getOrganId());
PackageConfigDO packageConfigDO = PackageConfigDO.builder()
.userId(loginUser.getId())
.organId(loginUser.getOrganId())
@@ -7,24 +7,28 @@
select sml.*
select distinct
sml.organ_id,
sml.cut_limit,
sml.drill_limit,
sml.label_limit,
sml.saw_limit,
sml.sealedge_limit,
sml.updater,
sml.update_time,
so.name as organName,
so.status
from system_machine_limit sml
left join system_organization so on sml.organ_id = so.id
left join system_machine_template smt on sml.setting like concat(smt.id, '%')
join system_organization so on sml.organ_id = so.id
<where>
sml.deleted = false
and smt.deleted = false
and smt.is_enabled = true
and smt.is_default = false
and so.status = 0
<if test="machinePage.organName !=null">
and so.name like concat('%', #{machinePage.organName},'%')
<if test="machinePage.organId !=null">
and sml.organ_id = #{machinePage.organId}
</if>
<if test="machinePage.machineName !=null">
and smt.name like concat('%', #{machinePage.machineName},'%')
<if test="machinePage.status !=null">
and so.status = #{machinePage.status}
</if>
</where>
@@ -21,9 +21,9 @@
<select id="selectTestSQL" resultType="com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO">
<select id="selectOrganDataSource" resultType="java.util.Map">
${sql}
select ${filed} from system_organization where id = #{organId} and deleted = false
</select>
@@ -38,4 +38,19 @@
ORDER BY
id DESC
</select>
<select id="selectUserDataSource" resultType="java.util.Map">
select ${filed}
from system_users
where organ_id = #{organId}
and deleted = false
and nickname in
<foreach collection="nameList" item="nameList" open="(" close=")" separator=",">
#{nameList}
</foreach>
</select>
</mapper>
@@ -16,4 +16,10 @@
</select>
<select id="selectMachineDataSource" resultType="java.util.Map">
select ${filed} from system_machine where organ_id = #{organId} and deleted = false and id = #{machineId}
</select>
</mapper>