diff --git a/mes/hd/nladmin-system/pom.xml b/mes/hd/nladmin-system/pom.xml index 793e6bc3..99d69a25 100644 --- a/mes/hd/nladmin-system/pom.xml +++ b/mes/hd/nladmin-system/pom.xml @@ -253,6 +253,17 @@ mybatis-plus-generator 3.4.0 + + + commons-configuration + commons-configuration + 1.9 + + + + org.springframework.boot + spring-boot-starter-freemarker + diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/ColumnInfo.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/ColumnInfo.java new file mode 100644 index 00000000..cc23dd56 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/ColumnInfo.java @@ -0,0 +1,98 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.nl.modules.generator.utils.GenUtil; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * 列的数据信息 + * @author Zheng Jie + * @date 2019-01-02 + */ +@Getter +@Setter +@Entity +@NoArgsConstructor +@Table(name = "code_column_config") +public class ColumnInfo implements Serializable { + + @Id + @Column(name = "column_id") + @ApiModelProperty(value = "ID", hidden = true) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ApiModelProperty(value = "表名") + private String tableName; + + @ApiModelProperty(value = "数据库字段名称") + private String columnName; + + @ApiModelProperty(value = "数据库字段类型") + private String columnType; + + @ApiModelProperty(value = "数据库字段键类型") + private String keyType; + + @ApiModelProperty(value = "字段额外的参数") + private String extra; + + @ApiModelProperty(value = "数据库字段描述") + private String remark; + + @ApiModelProperty(value = "是否必填") + private Boolean notNull; + + @ApiModelProperty(value = "是否在列表显示") + private Boolean listShow; + + @ApiModelProperty(value = "是否表单显示") + private Boolean formShow; + + @ApiModelProperty(value = "表单类型") + private String formType; + + @ApiModelProperty(value = "查询 1:模糊 2:精确") + private String queryType; + + @ApiModelProperty(value = "字典名称") + private String dictName; + + @ApiModelProperty(value = "日期注解") + private String dateAnnotation; + + public ColumnInfo(String tableName, String columnName, Boolean notNull, String columnType, String remark, String keyType, String extra) { + this.tableName = tableName; + this.columnName = columnName; + this.columnType = columnType; + this.keyType = keyType; + this.extra = extra; + this.notNull = notNull; + if(GenUtil.PK.equalsIgnoreCase(keyType) && GenUtil.EXTRA.equalsIgnoreCase(extra)){ + this.notNull = false; + } + this.remark = remark; + this.listShow = true; + this.formShow = true; + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/GenConfig.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/GenConfig.java new file mode 100644 index 00000000..454b1e93 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/GenConfig.java @@ -0,0 +1,79 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * 代码生成配置 + * @author Zheng Jie + * @date 2019-01-03 + */ +@Getter +@Setter +@Entity +@NoArgsConstructor +@Table(name = "code_gen_config") +public class GenConfig implements Serializable { + + public GenConfig(String tableName) { + this.tableName = tableName; + } + + @Id + @Column(name = "config_id") + @ApiModelProperty(value = "ID", hidden = true) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotBlank + @ApiModelProperty(value = "表名") + private String tableName; + + @ApiModelProperty(value = "接口名称") + private String apiAlias; + + @NotBlank + @ApiModelProperty(value = "包路径") + private String pack; + + @NotBlank + @ApiModelProperty(value = "模块名") + private String moduleName; + + @NotBlank + @ApiModelProperty(value = "前端文件路径") + private String path; + + @ApiModelProperty(value = "前端文件路径") + private String apiPath; + + @ApiModelProperty(value = "作者") + private String author; + + @ApiModelProperty(value = "表前缀") + private String prefix; + + @ApiModelProperty(value = "是否覆盖") + private Boolean cover = false; +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/vo/TableInfo.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/vo/TableInfo.java new file mode 100644 index 00000000..ddf3388c --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/domain/vo/TableInfo.java @@ -0,0 +1,48 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.domain.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 表的数据信息 + * @author Zheng Jie + * @date 2019-01-02 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TableInfo { + + /** 表名称 */ + private Object tableName; + + /** 创建日期 */ + private Object createTime; + + /** 数据库引擎 */ + private Object engine; + + /** 编码集 */ + private Object coding; + + /** 备注 */ + private Object remark; + + +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/repository/ColumnInfoRepository.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/repository/ColumnInfoRepository.java new file mode 100644 index 00000000..8af5fbb0 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/repository/ColumnInfoRepository.java @@ -0,0 +1,35 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.repository; + +import org.nl.modules.generator.domain.ColumnInfo; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +/** + * @author Zheng Jie + * @date 2019-01-14 + */ +public interface ColumnInfoRepository extends JpaRepository { + + /** + * 查询表信息 + * @param tableName 表格名 + * @return 表信息 + */ + List findByTableNameOrderByIdAsc(String tableName); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/repository/GenConfigRepository.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/repository/GenConfigRepository.java new file mode 100644 index 00000000..c6afcef2 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/repository/GenConfigRepository.java @@ -0,0 +1,33 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.repository; + +import org.nl.modules.generator.domain.GenConfig; +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author Zheng Jie + * @date 2019-01-14 + */ +public interface GenConfigRepository extends JpaRepository { + + /** + * 查询表配置 + * @param tableName 表名 + * @return / + */ + GenConfig findByTableName(String tableName); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/rest/GenConfigController.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/rest/GenConfigController.java new file mode 100644 index 00000000..75ee5b51 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/rest/GenConfigController.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.nl.modules.generator.domain.GenConfig; +import org.nl.modules.generator.service.GenConfigService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +/** + * @author Zheng Jie + * @date 2019-01-14 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/genConfig") +@Api(tags = "系统:代码生成器配置管理") +public class GenConfigController { + + private final GenConfigService genConfigService; + + @ApiOperation("查询") + @GetMapping(value = "/{tableName}") + public ResponseEntity query(@PathVariable String tableName){ + return new ResponseEntity<>(genConfigService.find(tableName), HttpStatus.OK); + } + + @ApiOperation("修改") + @PutMapping + public ResponseEntity update(@Validated @RequestBody GenConfig genConfig){ + return new ResponseEntity<>(genConfigService.update(genConfig.getTableName(), genConfig),HttpStatus.OK); + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/rest/GeneratorController.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/rest/GeneratorController.java new file mode 100644 index 00000000..10238435 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/rest/GeneratorController.java @@ -0,0 +1,108 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.common.utils.PageUtil; +import org.nl.modules.generator.domain.ColumnInfo; +import org.nl.modules.generator.service.GenConfigService; +import org.nl.modules.generator.service.GeneratorService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * @author Zheng Jie + * @date 2019-01-02 + */ +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/generator") +@Api(tags = "系统:代码生成管理") +public class GeneratorController { + + private final GeneratorService generatorService; + private final GenConfigService genConfigService; + + @Value("${generator.enabled}") + private Boolean generatorEnabled; + + @ApiOperation("查询数据库数据") + @GetMapping(value = "/tables/all") + public ResponseEntity queryTables(){ + return new ResponseEntity<>(generatorService.getTables(), HttpStatus.OK); + } + + @ApiOperation("查询数据库数据") + @GetMapping(value = "/tables") + public ResponseEntity queryTables(@RequestParam(defaultValue = "") String name, + @RequestParam(defaultValue = "0")Integer page, + @RequestParam(defaultValue = "10")Integer size){ + int[] startEnd = PageUtil.transToStartEnd(page, size); + return new ResponseEntity<>(generatorService.getTables(name,startEnd), HttpStatus.OK); + } + + @ApiOperation("查询字段数据") + @GetMapping(value = "/columns") + public ResponseEntity queryColumns(@RequestParam String tableName){ + List columnInfos = generatorService.getColumns(tableName); + return new ResponseEntity<>(PageUtil.toPage(columnInfos,columnInfos.size()), HttpStatus.OK); + } + + @ApiOperation("保存字段数据") + @PutMapping + public ResponseEntity save(@RequestBody List columnInfos){ + generatorService.save(columnInfos); + return new ResponseEntity<>(HttpStatus.OK); + } + + @ApiOperation("同步字段数据") + @PostMapping(value = "sync") + public ResponseEntity sync(@RequestBody List tables){ + for (String table : tables) { + generatorService.sync(generatorService.getColumns(table), generatorService.query(table)); + } + return new ResponseEntity<>(HttpStatus.OK); + } + + @ApiOperation("生成代码") + @PostMapping(value = "/{tableName}/{type}") + public ResponseEntity generator(@PathVariable String tableName, @PathVariable Integer type, HttpServletRequest request, HttpServletResponse response){ + if(!generatorEnabled && type == 0){ + throw new BadRequestException("此环境不允许生成代码,请选择预览或者下载查看!"); + } + switch (type){ + // 生成代码 + case 0: generatorService.generator(genConfigService.find(tableName), generatorService.getColumns(tableName)); + break; + // 预览 + case 1: return generatorService.preview(genConfigService.find(tableName), generatorService.getColumns(tableName)); + // 打包 + case 2: generatorService.download(genConfigService.find(tableName), generatorService.getColumns(tableName), request, response); + break; + default: throw new BadRequestException("没有这个选项"); + } + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/GenConfigService.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/GenConfigService.java new file mode 100644 index 00000000..43d9ab31 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/GenConfigService.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.service; + +import org.nl.modules.generator.domain.GenConfig; + +/** + * @author Zheng Jie + * @date 2019-01-14 + */ +public interface GenConfigService { + + /** + * 查询表配置 + * @param tableName 表名 + * @return 表配置 + */ + GenConfig find(String tableName); + + /** + * 更新表配置 + * @param tableName 表名 + * @param genConfig 表配置 + * @return 表配置 + */ + GenConfig update(String tableName, GenConfig genConfig); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/GeneratorService.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/GeneratorService.java new file mode 100644 index 00000000..0e749f38 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/GeneratorService.java @@ -0,0 +1,98 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.service; + +import org.nl.modules.generator.domain.ColumnInfo; +import org.nl.modules.generator.domain.GenConfig; +import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Async; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * @author Zheng Jie + * @date 2019-01-02 + */ +public interface GeneratorService { + + /** + * 查询数据库元数据 + * @param name 表名 + * @param startEnd 分页参数 + * @return / + */ + Object getTables(String name, int[] startEnd); + + /** + * 得到数据表的元数据 + * @param name 表名 + * @return / + */ + List getColumns(String name); + + /** + * 同步表数据 + * @param columnInfos / + * @param columnInfoList / + */ + @Async + void sync(List columnInfos, List columnInfoList); + + /** + * 保持数据 + * @param columnInfos / + */ + void save(List columnInfos); + + /** + * 获取所有table + * @return / + */ + Object getTables(); + + /** + * 代码生成 + * @param genConfig 配置信息 + * @param columns 字段信息 + */ + void generator(GenConfig genConfig, List columns); + + /** + * 预览 + * @param genConfig 配置信息 + * @param columns 字段信息 + * @return / + */ + ResponseEntity preview(GenConfig genConfig, List columns); + + /** + * 打包下载 + * @param genConfig 配置信息 + * @param columns 字段信息 + * @param request / + * @param response / + */ + void download(GenConfig genConfig, List columns, HttpServletRequest request, HttpServletResponse response); + + /** + * 查询数据库的表字段数据数据 + * @param table / + * @return / + */ + List query(String table); +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/impl/GenConfigServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/impl/GenConfigServiceImpl.java new file mode 100644 index 00000000..17951640 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/impl/GenConfigServiceImpl.java @@ -0,0 +1,71 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.service.impl; + +import cn.hutool.core.util.StrUtil; +import lombok.RequiredArgsConstructor; +import org.nl.modules.generator.domain.GenConfig; +import org.nl.modules.generator.repository.GenConfigRepository; +import org.nl.modules.generator.service.GenConfigService; +import org.springframework.stereotype.Service; + +import java.io.File; + +/** + * @author Zheng Jie + * @date 2019-01-14 + */ +@Service +@RequiredArgsConstructor +public class GenConfigServiceImpl implements GenConfigService { + + private final GenConfigRepository genConfigRepository; + + @Override + public GenConfig find(String tableName) { + GenConfig genConfig = genConfigRepository.findByTableName(tableName); + if(genConfig == null){ + return new GenConfig(tableName); + } + return genConfig; + } + + @Override + public GenConfig update(String tableName, GenConfig genConfig) { + // 如果 api 路径为空,则自动生成路径 + if(StrUtil.isEmpty(genConfig.getApiPath())){ + String separator = File.separator; + String[] paths; + String symbol = "\\"; + if (symbol.equals(separator)) { + paths = genConfig.getPath().split("\\\\"); + } else { + paths = genConfig.getPath().split(File.separator); + } + StringBuilder api = new StringBuilder(); + for (String path : paths) { + api.append(path); + api.append(separator); + if ("src".equals(path)) { + api.append("api"); + break; + } + } + genConfig.setApiPath(api.toString()); + } + return genConfigRepository.save(genConfig); + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/impl/GeneratorServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/impl/GeneratorServiceImpl.java new file mode 100644 index 00000000..3fea2a99 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/service/impl/GeneratorServiceImpl.java @@ -0,0 +1,203 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.ZipUtil; +import lombok.RequiredArgsConstructor; +import org.nl.modules.common.exception.BadRequestException; +import org.nl.modules.common.utils.FileUtil; +import org.nl.modules.common.utils.PageUtil; +import org.nl.modules.generator.domain.ColumnInfo; +import org.nl.modules.generator.domain.GenConfig; +import org.nl.modules.generator.domain.vo.TableInfo; +import org.nl.modules.generator.repository.ColumnInfoRepository; +import org.nl.modules.generator.service.GeneratorService; +import org.nl.modules.generator.utils.GenUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author Zheng Jie + * @date 2019-01-02 + */ +@Service +@RequiredArgsConstructor +public class GeneratorServiceImpl implements GeneratorService { + private static final Logger log = LoggerFactory.getLogger(GeneratorServiceImpl.class); + @PersistenceContext + private EntityManager em; + + private final ColumnInfoRepository columnInfoRepository; + + @Override + public Object getTables() { + // 使用预编译防止sql注入 + String sql = "select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables " + + "where table_schema = (select database()) " + + "order by create_time desc"; + Query query = em.createNativeQuery(sql); + return query.getResultList(); + } + + @Override + public Object getTables(String name, int[] startEnd) { + // 使用预编译防止sql注入 + String sql = "select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables " + + "where table_schema = (select database()) " + + "and table_name like ? order by create_time desc"; + Query query = em.createNativeQuery(sql); + query.setFirstResult(startEnd[0]); + query.setMaxResults(startEnd[1] - startEnd[0]); + query.setParameter(1, StrUtil.isNotEmpty(name) ? ("%" + name + "%") : "%%"); + List result = query.getResultList(); + List tableInfos = new ArrayList<>(); + for (Object obj : result) { + Object[] arr = (Object[]) obj; + tableInfos.add(new TableInfo(arr[0], arr[1], arr[2], arr[3], ObjectUtil.isNotEmpty(arr[4]) ? arr[4] : "-")); + } + Query query1 = em.createNativeQuery("SELECT COUNT(*) from information_schema.tables where table_schema = (select database())"); + Object totalElements = query1.getSingleResult(); + return PageUtil.toPage(tableInfos, totalElements); + } + + @Override + public List getColumns(String tableName) { + List columnInfos = columnInfoRepository.findByTableNameOrderByIdAsc(tableName); + if (CollectionUtil.isNotEmpty(columnInfos)) { + return columnInfos; + } else { + columnInfos = query(tableName); + return columnInfoRepository.saveAll(columnInfos); + } + } + + @Override + public List query(String tableName) { + // 使用预编译防止sql注入 + String sql = "select column_name, is_nullable, data_type, column_comment, column_key, extra from information_schema.columns " + + "where table_name = ? and table_schema = (select database()) order by ordinal_position"; + Query query = em.createNativeQuery(sql); + query.setParameter(1, tableName); + List result = query.getResultList(); + List columnInfos = new ArrayList<>(); + for (Object obj : result) { + Object[] arr = (Object[]) obj; + columnInfos.add( + new ColumnInfo( + tableName, + arr[0].toString(), + "NO".equals(arr[1]), + arr[2].toString(), + ObjectUtil.isNotNull(arr[3]) ? arr[3].toString() : null, + ObjectUtil.isNotNull(arr[4]) ? arr[4].toString() : null, + ObjectUtil.isNotNull(arr[5]) ? arr[5].toString() : null) + ); + } + return columnInfos; + } + + @Override + public void sync(List columnInfos, List columnInfoList) { + // 第一种情况,数据库类字段改变或者新增字段 + for (ColumnInfo columnInfo : columnInfoList) { + // 根据字段名称查找 + List columns = columnInfos.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList()); + // 如果能找到,就修改部分可能被字段 + if (CollectionUtil.isNotEmpty(columns)) { + ColumnInfo column = columns.get(0); + column.setColumnType(columnInfo.getColumnType()); + column.setExtra(columnInfo.getExtra()); + column.setKeyType(columnInfo.getKeyType()); + if (StrUtil.isEmpty(column.getRemark())) { + column.setRemark(columnInfo.getRemark()); + } + columnInfoRepository.save(column); + } else { + // 如果找不到,则保存新字段信息 + columnInfoRepository.save(columnInfo); + } + } + // 第二种情况,数据库字段删除了 + for (ColumnInfo columnInfo : columnInfos) { + // 根据字段名称查找 + List columns = columnInfoList.stream().filter(c -> c.getColumnName().equals(columnInfo.getColumnName())).collect(Collectors.toList()); + // 如果找不到,就代表字段被删除了,则需要删除该字段 + if (CollectionUtil.isEmpty(columns)) { + columnInfoRepository.delete(columnInfo); + } + } + } + + @Override + public void save(List columnInfos) { + columnInfoRepository.saveAll(columnInfos); + } + + @Override + public void generator(GenConfig genConfig, List columns) { + if (genConfig.getId() == null) { + throw new BadRequestException("请先配置生成器"); + } + try { + GenUtil.generatorCode(columns, genConfig); + } catch (IOException e) { + log.error(e.getMessage(), e); + throw new BadRequestException("生成失败,请手动处理已生成的文件"); + } + } + + @Override + public ResponseEntity preview(GenConfig genConfig, List columns) { + if (genConfig.getId() == null) { + throw new BadRequestException("请先配置生成器"); + } + List> genList = GenUtil.preview(columns, genConfig); + return new ResponseEntity<>(genList, HttpStatus.OK); + } + + @Override + public void download(GenConfig genConfig, List columns, HttpServletRequest request, HttpServletResponse response) { + if (genConfig.getId() == null) { + throw new BadRequestException("请先配置生成器"); + } + try { + File file = new File(GenUtil.download(columns, genConfig)); + String zipPath = file.getPath() + ".zip"; + ZipUtil.zip(file.getPath(), zipPath); + FileUtil.downloadFile(request, response, new File(zipPath), true); + } catch (IOException e) { + throw new BadRequestException("打包失败"); + } + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/utils/ColUtil.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/utils/ColUtil.java new file mode 100644 index 00000000..ff5a9719 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/utils/ColUtil.java @@ -0,0 +1,56 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.utils; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * sql字段转java + * + * @author Zheng Jie + * @date 2019-01-03 + */ +public class ColUtil { + private static final Logger log = LoggerFactory.getLogger(ColUtil.class); + + /** + * 转换mysql数据类型为java数据类型 + * + * @param type 数据库字段类型 + * @return String + */ + static String cloToJava(String type) { + Configuration config = getConfig(); + assert config != null; + return config.getString(type, "unknowType"); + } + + /** + * 获取配置信息 + */ + public static PropertiesConfiguration getConfig() { + try { + return new PropertiesConfiguration("generator.properties"); + } catch (ConfigurationException e) { + log.error(e.getMessage(), e); + } + return null; + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/utils/GenUtil.java b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/utils/GenUtil.java new file mode 100644 index 00000000..46bcf3bd --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/modules/generator/utils/GenUtil.java @@ -0,0 +1,426 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.generator.utils; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.template.*; +import lombok.extern.slf4j.Slf4j; +import org.nl.modules.common.utils.FileUtil; +import org.nl.modules.common.utils.StringUtils; +import org.nl.modules.generator.domain.ColumnInfo; +import org.nl.modules.generator.domain.GenConfig; +import org.springframework.util.ObjectUtils; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.nl.modules.common.utils.FileUtil.SYS_TEM_DIR; + + +/** + * 代码生成 + * + * @author Zheng Jie + * @date 2019-01-02 + */ +@Slf4j +@SuppressWarnings({"unchecked", "all"}) +public class GenUtil { + + private static final String TIMESTAMP = "Timestamp"; + + private static final String BIGDECIMAL = "BigDecimal"; + + public static final String PK = "PRI"; + + public static final String EXTRA = "auto_increment"; + + /** + * 获取后端代码模板名称 + * + * @return List + */ + private static List getAdminTemplateNames() { + List templateNames = new ArrayList<>(); + // templateNames.add("Entity"); + templateNames.add("Dto"); + // templateNames.add("Mapper"); + templateNames.add("Controller"); + //templateNames.add("QueryCriteria"); + templateNames.add("Service"); + templateNames.add("ServiceImpl"); + // templateNames.add("Repository"); + return templateNames; + } + + /** + * 获取前端代码模板名称 + * + * @return List + */ + private static List getFrontTemplateNames() { + List templateNames = new ArrayList<>(); + templateNames.add("index"); + templateNames.add("api"); + return templateNames; + } + + public static List> preview(List columns, GenConfig genConfig) { + Map genMap = getGenMap(columns, genConfig); + List> genList = new ArrayList<>(); + // 获取后端模版 + List templates = getAdminTemplateNames(); + TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); + for (String templateName : templates) { + Map map = new HashMap<>(1); + Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl"); + map.put("content", template.render(genMap)); + map.put("name", templateName); + genList.add(map); + } + // 获取前端模版 + templates = getFrontTemplateNames(); + for (String templateName : templates) { + Map map = new HashMap<>(1); + Template template = engine.getTemplate("generator/front/" + templateName + ".ftl"); + map.put(templateName, template.render(genMap)); + map.put("content", template.render(genMap)); + map.put("name", templateName); + genList.add(map); + } + return genList; + } + + public static String download(List columns, GenConfig genConfig) throws IOException { + // 拼接的路径:/tmpnladmin-gen-temp/,这个路径在Linux下需要root用户才有权限创建,非root用户会权限错误而失败,更改为: /tmp/nladmin-gen-temp/ + // String tempPath =SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator; + String tempPath = SYS_TEM_DIR + "nladmin-gen-temp" + File.separator + genConfig.getTableName() + File.separator; + Map genMap = getGenMap(columns, genConfig); + TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); + // 生成后端代码 + List templates = getAdminTemplateNames(); + for (String templateName : templates) { + Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl"); + String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), tempPath + "eladmin" + File.separator); + assert filePath != null; + File file = new File(filePath); + // 如果非覆盖生成 + if (!genConfig.getCover() && FileUtil.exist(file)) { + continue; + } + // 生成代码 + genFile(file, template, genMap); + } + // 生成前端代码 + templates = getFrontTemplateNames(); + for (String templateName : templates) { + Template template = engine.getTemplate("generator/front/" + templateName + ".ftl"); + String path = tempPath + "nladmin-web" + File.separator; + String apiPath = path + "src" + File.separator + "api" + File.separator; + String srcPath = path + "src" + File.separator + "views" + File.separator + genMap.get("changeClassName").toString() + File.separator; + String filePath = getFrontFilePath(templateName, apiPath, srcPath, genMap.get("changeClassName").toString()); + assert filePath != null; + File file = new File(filePath); + // 如果非覆盖生成 + if (!genConfig.getCover() && FileUtil.exist(file)) { + continue; + } + // 生成代码 + genFile(file, template, genMap); + } + return tempPath; + } + + public static void generatorCode(List columnInfos, GenConfig genConfig) throws IOException { + Map genMap = getGenMap(columnInfos, genConfig); + TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); + // 生成后端代码 + List templates = getAdminTemplateNames(); + for (String templateName : templates) { + Template template = engine.getTemplate("generator/admin/" + templateName + ".ftl"); + String filePath = getAdminFilePath(templateName, genConfig, genMap.get("className").toString(), System.getProperty("user.dir")); + + assert filePath != null; + File file = new File(filePath); + + // 如果非覆盖生成 + if (!genConfig.getCover() && FileUtil.exist(file)) { + continue; + } + // 生成代码 + genFile(file, template, genMap); + } + + // 生成前端代码 + templates = getFrontTemplateNames(); + for (String templateName : templates) { + Template template = engine.getTemplate("generator/front/" + templateName + ".ftl"); + String filePath = getFrontFilePath(templateName, genConfig.getApiPath(), genConfig.getPath(), genMap.get("changeClassName").toString()); + + assert filePath != null; + File file = new File(filePath); + + // 如果非覆盖生成 + if (!genConfig.getCover() && FileUtil.exist(file)) { + continue; + } + // 生成代码 + genFile(file, template, genMap); + } + } + + // 获取模版数据 + private static Map getGenMap(List columnInfos, GenConfig genConfig) { + // 存储模版字段数据 + Map genMap = new HashMap<>(16); + // 接口别名 + genMap.put("apiAlias", genConfig.getApiAlias()); + // 包名称 + genMap.put("package", genConfig.getPack()); + // 模块名称 + genMap.put("moduleName", genConfig.getModuleName()); + // 作者 + genMap.put("author", genConfig.getAuthor()); + // 创建日期 + genMap.put("date", LocalDate.now().toString()); + // 表名 + genMap.put("tableName", genConfig.getTableName()); + // 大写开头的类名 + String className = StringUtils.toCapitalizeCamelCase(genConfig.getTableName()); + // 小写开头的类名 + String changeClassName = StringUtils.toCamelCase(genConfig.getTableName()); + // 判断是否去除表前缀 + if (StrUtil.isNotEmpty(genConfig.getPrefix())) { + className = StringUtils.toCapitalizeCamelCase(StrUtil.removePrefix(genConfig.getTableName(), genConfig.getPrefix())); + changeClassName = StringUtils.toCamelCase(StrUtil.removePrefix(genConfig.getTableName(), genConfig.getPrefix())); + } + // 保存类名 + genMap.put("className", className); + // 保存小写开头的类名 + genMap.put("changeClassName", changeClassName); + // 存在 Timestamp 字段 + genMap.put("hasTimestamp", false); + // 查询类中存在 Timestamp 字段 + genMap.put("queryHasTimestamp", false); + // 存在 BigDecimal 字段 + genMap.put("hasBigDecimal", false); + // 查询类中存在 BigDecimal 字段 + genMap.put("queryHasBigDecimal", false); + // 是否需要创建查询 + genMap.put("hasQuery", false); + // 自增主键 + genMap.put("auto", false); + // 存在字典 + genMap.put("hasDict", false); + // 存在日期注解 + genMap.put("hasDateAnnotation", false); + // 保存字段信息 + List> columns = new ArrayList<>(); + // 保存查询字段的信息 + List> queryColumns = new ArrayList<>(); + // 存储字典信息 + List dicts = new ArrayList<>(); + // 存储 between 信息 + List> betweens = new ArrayList<>(); + // 存储不为空的字段信息 + List> isNotNullColumns = new ArrayList<>(); + + for (ColumnInfo column : columnInfos) { + Map listMap = new HashMap<>(16); + // 字段描述 + listMap.put("remark", column.getRemark()); + // 字段类型 + listMap.put("columnKey", column.getKeyType()); + // 主键类型 + String colType = ColUtil.cloToJava(column.getColumnType()); + // 小写开头的字段名 + //String changeColumnName = StringUtils.toCamelCase(column.getColumnName()); + String changeColumnName = column.getColumnName(); + // 大写开头的字段名 + String capitalColumnName = StringUtils.toCapitalizeCamelCase(column.getColumnName()); + if (PK.equals(column.getKeyType())) { + // 存储主键类型 + genMap.put("pkColumnType", colType); + // 存储小写开头的字段名 + genMap.put("pkChangeColName", changeColumnName); + // 存储大写开头的字段名 + genMap.put("pkCapitalColName", capitalColumnName); + } + // 是否存在 Timestamp 类型的字段 + if (TIMESTAMP.equals(colType)) { + genMap.put("hasTimestamp", true); + } + // 是否存在 BigDecimal 类型的字段 + if (BIGDECIMAL.equals(colType)) { + genMap.put("hasBigDecimal", true); + } + // 主键是否自增 + if (EXTRA.equals(column.getExtra())) { + genMap.put("auto", true); + } + // 主键存在字典 + if (StrUtil.isNotEmpty(column.getDictName())) { + genMap.put("hasDict", true); + dicts.add(column.getDictName()); + } + + // 存储字段类型 + listMap.put("columnType", colType); + // 存储字原始段名称 + listMap.put("columnName", column.getColumnName()); + // 不为空 + listMap.put("istNotNull", column.getNotNull()); + // 字段列表显示 + listMap.put("columnShow", column.getListShow()); + // 表单显示 + listMap.put("formShow", column.getFormShow()); + // 表单组件类型 + listMap.put("formType", StrUtil.isNotEmpty(column.getFormType()) ? column.getFormType() : "Input"); + // 小写开头的字段名称 + listMap.put("changeColumnName", changeColumnName); + //大写开头的字段名称 + listMap.put("capitalColumnName", capitalColumnName); + // 字典名称 + listMap.put("dictName", column.getDictName()); + // 日期注解 + listMap.put("dateAnnotation", column.getDateAnnotation()); + if (StrUtil.isNotEmpty(column.getDateAnnotation())) { + genMap.put("hasDateAnnotation", true); + } + // 添加非空字段信息 + if (column.getNotNull()) { + isNotNullColumns.add(listMap); + } + // 判断是否有查询,如有则把查询的字段set进columnQuery + if (!StrUtil.isEmpty(column.getQueryType())) { + // 查询类型 + listMap.put("queryType", column.getQueryType()); + // 是否存在查询 + genMap.put("hasQuery", true); + if (TIMESTAMP.equals(colType)) { + // 查询中存储 Timestamp 类型 + genMap.put("queryHasTimestamp", true); + } + if (BIGDECIMAL.equals(colType)) { + // 查询中存储 BigDecimal 类型 + genMap.put("queryHasBigDecimal", true); + } + if ("between".equalsIgnoreCase(column.getQueryType())) { + betweens.add(listMap); + } else { + // 添加到查询列表中 + queryColumns.add(listMap); + } + } + // 添加到字段列表中 + columns.add(listMap); + } + // 保存字段列表 + genMap.put("columns", columns); + // 保存查询列表 + genMap.put("queryColumns", queryColumns); + // 保存字段列表 + genMap.put("dicts", dicts); + // 保存查询列表 + genMap.put("betweens", betweens); + // 保存非空字段信息 + genMap.put("isNotNullColumns", isNotNullColumns); + return genMap; + } + + /** + * 定义后端文件路径以及名称 + */ + private static String getAdminFilePath(String templateName, GenConfig genConfig, String className, String rootPath) { + String projectPath = rootPath + File.separator + genConfig.getModuleName(); + String packagePath = projectPath + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator; + if (!ObjectUtils.isEmpty(genConfig.getPack())) { + packagePath += genConfig.getPack().replace(".", File.separator) + File.separator; + } + + if ("Entity".equals(templateName)) { + return packagePath + "domain" + File.separator + className + ".java"; + } + + if ("Controller".equals(templateName)) { + return packagePath + "rest" + File.separator + className + "Controller.java"; + } + + if ("Service".equals(templateName)) { + return packagePath + "service" + File.separator + className + "Service.java"; + } + + if ("ServiceImpl".equals(templateName)) { + return packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java"; + } + + if ("Dto".equals(templateName)) { + return packagePath + "service" + File.separator + "dto" + File.separator + className + "Dto.java"; + } + + if ("QueryCriteria".equals(templateName)) { + return packagePath + "service" + File.separator + "dto" + File.separator + className + "QueryCriteria.java"; + } + + if ("Mapper".equals(templateName)) { + return packagePath + "service" + File.separator + "mapstruct" + File.separator + className + "Mapper.java"; + } + + if ("Repository".equals(templateName)) { + return packagePath + "repository" + File.separator + className + "Repository.java"; + } + + return null; + } + + /** + * 定义前端文件路径以及名称 + */ + private static String getFrontFilePath(String templateName, String apiPath, String path, String apiName) { + + if ("api".equals(templateName)) { + return apiPath + File.separator + apiName + ".js"; + } + + if ("index".equals(templateName)) { + return path + File.separator + "index.vue"; + } + + return null; + } + + private static void genFile(File file, Template template, Map map) throws IOException { + // 生成目标文件 + Writer writer = null; + try { + FileUtil.touch(file); + writer = new FileWriter(file); + template.render(map, writer); + } catch (TemplateException | IOException e) { + throw new RuntimeException(e); + } finally { + assert writer != null; + writer.close(); + } + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/basedata/master/wql/mdpb.xls b/mes/hd/nladmin-system/src/main/java/org/nl/wms/basedata/master/wql/mdpb.xls index f01aba31..55c259ac 100644 Binary files a/mes/hd/nladmin-system/src/main/java/org/nl/wms/basedata/master/wql/mdpb.xls and b/mes/hd/nladmin-system/src/main/java/org/nl/wms/basedata/master/wql/mdpb.xls differ diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/enums/PointEnum.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/enums/PointEnum.java new file mode 100644 index 00000000..c60294f2 --- /dev/null +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/enums/PointEnum.java @@ -0,0 +1,27 @@ +package org.nl.wms.enums; + +/** + * @Author: lyd + * @Description: 点位枚举 + * @Date: 2023/3/20 + */ +public enum PointEnum { + LOCK_TYPE_OFF("未锁定", "0"), + LOCK_TYPE_ON("锁定", "1"); + + private final String name; + private final String code; + + PointEnum(String name, String code) { + this.name = name; + this.code = code; + } + + public String getName() { + return name; + } + + public String getCode() { + return code; + } +} diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/mps/rest/ProduceWorkorderController.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/mps/rest/ProduceWorkorderController.java index 0d82cd8a..95a768d8 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/mps/rest/ProduceWorkorderController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/mps/rest/ProduceWorkorderController.java @@ -24,7 +24,7 @@ import java.util.Map; **/ @RestController @RequiredArgsConstructor -@Api(tags = "工单管理管理") +@Api(tags = "工单管理") @RequestMapping("/api/produceWorkorder") @Slf4j public class ProduceWorkorderController { diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/PointController.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/PointController.java index 138514f7..81458906 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/PointController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/PointController.java @@ -5,9 +5,9 @@ package org.nl.wms.sch.rest; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; - import lombok.RequiredArgsConstructor; -import org.nl.common.anno.Log; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nl.common.anno.Log; import org.nl.wms.sch.service.PointService; import org.nl.wms.sch.service.dto.PointDto; import org.springframework.data.domain.Pageable; @@ -34,7 +34,7 @@ public class PointController { @GetMapping @Log("查询点位") @ApiOperation("查询点位") - //@PreAuthorize("@el.check('point:list')") + //@SaCheckPermission("point:list") public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { return new ResponseEntity<>(pointService.queryAll(whereJson, page), HttpStatus.OK); } @@ -42,7 +42,7 @@ public class PointController { @PostMapping @Log("新增点位") @ApiOperation("新增点位") - //@PreAuthorize("@el.check('point:add')") + //@SaCheckPermission("point:add") public ResponseEntity create(@Validated @RequestBody PointDto dto) { pointService.create(dto); return new ResponseEntity<>(HttpStatus.CREATED); @@ -51,7 +51,7 @@ public class PointController { @PutMapping @Log("修改点位") @ApiOperation("修改点位") - //@PreAuthorize("@el.check('point:edit')") + //@SaCheckPermission("point:edit") public ResponseEntity update(@Validated @RequestBody PointDto dto) { pointService.update(dto); return new ResponseEntity<>(HttpStatus.NO_CONTENT); @@ -59,7 +59,7 @@ public class PointController { @Log("删除点位") @ApiOperation("删除点位") - //@PreAuthorize("@el.check('point:del')") + //@SaCheckPermission("point:del") @DeleteMapping public ResponseEntity delete(@RequestBody Long[] ids) { pointService.deleteAll(ids); @@ -68,7 +68,7 @@ public class PointController { @PutMapping("/changeActive") @Log("修改点位启用状态") @ApiOperation("修改点位启用状态") - //@PreAuthorize("@el.check('store:edit')") + //@SaCheckPermission("store:edit") public ResponseEntity update(@RequestBody JSONObject json) { pointService.changeActive(json); return new ResponseEntity<>(HttpStatus.NO_CONTENT); @@ -77,24 +77,38 @@ public class PointController { @PostMapping("/getPoint") @Log("查询点位下拉框") @ApiOperation("查询点位下拉框") - //@PreAuthorize("@el.check('materialtype:list')") + //@SaCheckPermission("materialtype:list") public ResponseEntity queryPoint(@RequestBody Map whereJson) { return new ResponseEntity<>(pointService.getPoint(whereJson), HttpStatus.OK); } - @PutMapping("/syncStruct") - @Log("仓位同步") - @ApiOperation("仓位同步") - //@PreAuthorize("@el.check('store:edit')") - public ResponseEntity syncStruct() { - pointService.syncStruct(); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } - @GetMapping("/getEndPoint") + @GetMapping("/selectPoint") @Log("查询点位管理") @ApiOperation("查询点位管理") - //@PreAuthorize("@el.check('Point:list')") - public ResponseEntity getEndPoint(@RequestParam Map whereJson, Pageable page){ - return new ResponseEntity<>(pointService.getEndPoint(whereJson,page),HttpStatus.OK); + //@SaCheckPermission("Point:list") + public ResponseEntity selectPoint(@RequestParam Map whereJson, Pageable page){ + return new ResponseEntity<>(pointService.selectPoint(whereJson,page),HttpStatus.OK); + } + @GetMapping("/getRegion") + @Log("获取区域") + @ApiOperation("获取区域") + public ResponseEntity getRegion(){ + return new ResponseEntity<>(pointService.getRegion(),HttpStatus.OK); + } + + @Log("启动与禁用") + @PostMapping("/changeUsed") + @ApiOperation("启动与禁用") + public ResponseEntity changeUsedOn(@RequestBody JSONObject jsonObject) { + pointService.changeUsed(jsonObject); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("锁定与解锁") + @PostMapping("/changeLock") + @ApiOperation("锁定与解锁") + public ResponseEntity changeLock(@RequestBody JSONObject jsonObject) { + pointService.changeLock(jsonObject); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/RegionController.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/RegionController.java index 8bee5650..8727d465 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/RegionController.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/rest/RegionController.java @@ -63,20 +63,20 @@ public class RegionController { return new ResponseEntity<>(HttpStatus.OK); } - @PostMapping("/getPointStatusSelectById") + @PostMapping("/getPointStatusSelectByCode") @Log("获取点位状态下拉框") @ApiOperation("获取点位状态下拉框") //@SaCheckPermission("region:add") - public ResponseEntity getPointStatusSelectById(@RequestBody Long region_id) { - return new ResponseEntity<>(regionService.getPointStatusSelectById(region_id), HttpStatus.CREATED); + public ResponseEntity getPointStatusSelectByCode(@RequestBody String region_code) { + return new ResponseEntity<>(regionService.getPointStatusSelectByCode(region_code), HttpStatus.CREATED); } - @PostMapping("/getPointTypeSelectById") + @PostMapping("/getPointTypeSelectByCode") @Log("获取点位类型下拉框") @ApiOperation("获取点位类型下拉框") //@SaCheckPermission("region:add") - public ResponseEntity getPointTypeSelectById(@RequestBody Long region_id) { - return new ResponseEntity<>(regionService.getPointTypeSelectById(region_id), HttpStatus.CREATED); + public ResponseEntity getPointTypeSelectByCode(@RequestBody String region_code) { + return new ResponseEntity<>(regionService.getPointTypeSelectByCode(region_code), HttpStatus.CREATED); } } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/PointService.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/PointService.java index 10e37638..80fd4c13 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/PointService.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/PointService.java @@ -36,7 +36,7 @@ public interface PointService { * @param point_id ID * @return Point */ - PointDto findById(Long point_id); + PointDto findById(String point_id); /** * 根据编码查询 @@ -73,10 +73,27 @@ public interface PointService { JSONArray getPoint(Map wherJson); - void syncStruct(); /** * - * 获取终点点位 + * 获取点位 */ - Map getEndPoint(Map whereJson, Pageable page); + Map selectPoint(Map whereJson, Pageable page); + + /** + * + * 获取区域 + */ + JSONArray getRegion(); + + /** + * 改变启用状态 + * @param jsonObject + */ + void changeUsed(JSONObject jsonObject); + + /** + * 改变锁定类型 + * @param jsonObject + */ + void changeLock(JSONObject jsonObject); } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/RegionService.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/RegionService.java index 834c7478..628b71a4 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/RegionService.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/RegionService.java @@ -63,15 +63,15 @@ public interface RegionService { /** * 获取点位状态下拉框 - * @param region_id + * @param region_code * @return */ - JSONArray getPointStatusSelectById(Long region_id); + JSONArray getPointStatusSelectByCode(String region_code); /** * 获取点位类型下拉框 - * @param region_id + * @param region_code * @return */ - JSONArray getPointTypeSelectById(Long region_id); + JSONArray getPointTypeSelectByCode(String region_code); } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/PointDto.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/PointDto.java index cc0334b8..8ad4c2e7 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/PointDto.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/PointDto.java @@ -1,111 +1,137 @@ package org.nl.wms.sch.service.dto; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; -import java.util.Date; - import java.io.Serializable; -import java.util.Date; +import java.math.BigDecimal; +import java.util.List; /** - * @author ldjun * @description / - * @date 2021-12-07 + * @author lyd + * @date 2023-03-17 **/ @Data public class PointDto implements Serializable { - /** 点位标识 */ - /** - * 防止精度丢失 - */ - @JsonSerialize(using = ToStringSerializer.class) - private Long point_id; + /** 点位id */ + private String point_id; - /** - * 点位编码 - */ + /** 点位编码 */ private String point_code; - /** - * 点位名称 - */ + /** 点位名称 */ private String point_name; - /** - * 所属区域 - */ - private String area_type; + /** 生产区域 */ + private String product_area; - /** - * 点位类型 - */ + /** 区域编码 */ + private String region_code; + + /** 区域名称 */ + private String region_name; + + /** 上一区域 */ + private String pre_region_code; + + /** 上一区域 */ + private String next_region_code; + + /** 点位类型 */ private String point_type; - /** - * 点位状态 - */ + /** 点位状态 */ private String point_status; - /** - * 锁定类型 - */ + /** 锁定类型 */ private String lock_type; - /** - * 载具编码 - */ + /** 物料标识 */ + private String material_id; + + /** 物料编码 */ + private String material_code; + + /** 设备编码 */ + private String device_code; + + /** 允许的载具类型 */ + private String can_vehicle_type; + private List can_vehicle_types; + + /** 载具允许最大数量 */ + private BigDecimal vehicle_max_qty; + + /** 载具类型 */ + private String vehicle_type; + + /** 载具编码 */ private String vehicle_code; - /** - * 来源标识 - */ - private Long source_id; + /** 载具数量 */ + private Integer vehicle_qty; - /** - * 备注 - */ + /** 块 */ + private BigDecimal block_num; + + /** 排 */ + private BigDecimal row_num; + + /** 列 */ + private BigDecimal col_num; + + /** 层 */ + private BigDecimal layer_num; + + /** 入库顺序 */ + private BigDecimal in_order_seq; + + /** 出库顺序 */ + private BigDecimal out_order_seq; + + /** 入空载具顺序 */ + private BigDecimal in_empty_seq; + + /** 出空载具顺序 */ + private BigDecimal out_empty_seq; + + /** 点位组编码 */ + private String point_group_code; + + /** 在执行的任务标识 */ + private String task_id; + + /** 位置 */ + private String point_location; + + /** 备注 */ private String remark; - /** - * 是否启用 - */ + /** 来源标识 */ + private String source_id; + + /** 是否启用 */ private String is_used; - /** - * 是否删除 - */ + /** 是否删除 */ private String is_delete; - /** - * 创建人 - */ + /** 创建人 */ private String create_id; - /** - * 创建人姓名 - */ + /** 创建人 */ private String create_name; - /** - * 创建时间 - */ + /** 创建时间 */ private String create_time; - /** - * 修改人 - */ + /** 修改人 */ private String update_id; - /** - * 修改人姓名 - */ + /** 修改人 */ private String update_name; - /** - * 修改时间 - */ + /** 修改时间 */ private String update_time; } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/RegionDto.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/RegionDto.java index f4228023..0ab456c1 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/RegionDto.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/RegionDto.java @@ -41,10 +41,10 @@ public class RegionDto implements Serializable { private String create_time; /** 修改人 */ - private String update_optid; + private String update_id; /** 修改人 */ - private String update_optname; + private String update_name; /** 修改时间 */ private String update_time; diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/TaskDto.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/TaskDto.java index 0dd5c47d..3dc22017 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/TaskDto.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/dto/TaskDto.java @@ -3,6 +3,8 @@ package org.nl.wms.sch.service.dto; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import lombok.Data; + +import java.math.BigDecimal; import java.util.Date; @@ -15,68 +17,122 @@ import java.io.Serializable; **/ @Data public class TaskDto implements Serializable { + private String task_id; + /** 任务编码 */ private String task_code; + /** 任务名称 */ + private String task_name; + + /** 生产区域 */ + private String product_area; + /** 任务类型 */ private String task_type; - /** 任务明细类型 */ - private String taskdtl_type; - - /** 指令状态 */ + /** 任务状态 */ private String task_status; - /** 起始点位 */ - private String start_point_code; + /** 任务执行步骤 */ + private BigDecimal task_step; - /** 下一点位 */ - private String next_point_code; + /** 点位1 */ + private String point_code1; - /** 载具编码 */ + /** 点位2 */ + private String point_code2; + + /** 点位3 */ + private String point_code3; + + /** 点位4 */ + private String point_code4; + + /** 搬运物料信息 */ + private String material_info_id; + + /** 物料信息 */ + private String material_id; + + /** 物料数量 */ + private BigDecimal material_qty; + + /** 载具类型 */ + private String vehicle_type; + + /** 载具数量 */ + private BigDecimal vehicle_qty; + + /** 载具编码1 */ private String vehicle_code; + /** 载具编码2 */ + private String vehicle_code2; + + /** 优先级 */ + private String priority; + /** 处理类 */ private String handle_class; + /** 车号 */ + private String car_no; + + /** 是否自动下发 */ + private String is_auto_issue; + + /** 任务组标识 */ + private String task_group_id; + + /** 任务组顺序号 */ + private BigDecimal sort_seq; + /** 任务完成类型 */ private String finished_type; + /** acs任务类型 */ + private String acs_task_type; + + /** 生成方式 */ + private String create_mode; + + /** 业务表表名 */ + private String table_name; + + /** 业务表表名主键字段 */ + private String table_fk; + + /** 业务表表名主键值 */ + private String table_fk_id; + + /** 生成任务的请求参数 */ + private String request_param; + + /** 下发任务的请求参数 */ + private String response_param; + /** 备注 */ private String remark; /** 是否删除 */ private String is_delete; - /** 创建时间 */ - private String create_time; - - /** 修改时间 */ - private String update_time; - - /** 任务明细标识 */ - /** 防止精度丢失 */ - @JsonSerialize(using= ToStringSerializer.class) - private Long taskdtl_id; - - /** 任务标识 */ - private Long task_id; - - /** 物料编码 */ - private String material_code; - - /** 车号 */ - private String car_no; - /** 创建人 */ private String create_id; - /** 创建人姓名 */ + /** 创建人 */ private String create_name; + /** 创建时间 */ + private String create_time; + /** 修改人 */ private String update_id; - /** 修改人姓名 */ + /** 修改人 */ private String update_name; + + /** 修改时间 */ + private String update_time; } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/PointServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/PointServiceImpl.java index 57b39fd4..85e0da95 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/PointServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/PointServiceImpl.java @@ -17,13 +17,17 @@ import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.WqlUtil; +import org.nl.wms.enums.PointEnum; import org.nl.wms.sch.service.PointService; +import org.nl.wms.sch.service.RegionService; import org.nl.wms.sch.service.dto.PointDto; +import org.nl.wms.sch.service.dto.RegionDto; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -38,18 +42,60 @@ import java.util.Map; @RequiredArgsConstructor @Slf4j public class PointServiceImpl implements PointService { + + private final RegionService regionService; @Override public Map queryAll(Map whereJson, Pageable page) { HashMap map = new HashMap(); map.put("flag", "1"); - map.put("area_type", whereJson.get("area_type")); + map.put("region_code", whereJson.get("region_code")); map.put("ids", whereJson.get("ids")); map.put("lock_type", whereJson.get("lock_type")); map.put("point_status", whereJson.get("point_status")); map.put("is_used", whereJson.get("is_used")); map.put("point_type", whereJson.get("point_type")); + map.put("block_num", whereJson.get("block_num")); + map.put("row_num", whereJson.get("row_num")); + map.put("col_num", whereJson.get("col_num")); + map.put("layer_num", whereJson.get("layer_num")); map.put("name", whereJson.get("name")); JSONObject json = WQL.getWO("QSCH_BASE_POINT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "point_code asc"); + JSONArray content = json.getJSONArray("content"); + JSONArray res = new JSONArray(); + for (int i = 0; i < content.size(); i++) { + JSONObject object = content.getJSONObject(i); + // 可以存放的载具类型 + String[] can_vehicle_types = object.getString("can_vehicle_type").split(","); + object.put("can_vehicle_types", can_vehicle_types); + String region_code = object.getString("region_code"); + String point_status = object.getString("point_status"); + String point_type = object.getString("point_type"); + RegionDto regionDto = regionService.findByCode(region_code); + String point_status_explain = regionDto.getPoint_status_explain(); + String point_type_explain = regionDto.getPoint_type_explain(); + // 获取点位状态名称 + if (!ObjectUtil.isEmpty(point_status)) { + JSONObject statusArr = new JSONObject(); + String[] split = point_status_explain.split(","); + for ( int j = 0; j < split.length; j++) { + String[] status = split[j].split("-"); + statusArr.put(status[0], status[1]); + } + object.put("point_status_name", statusArr.getString(point_status)); + } + // 获取点位类型 + if (!ObjectUtil.isEmpty(point_type)) { + JSONObject typeArr = new JSONObject(); + String[] split = point_type_explain.split(","); + for ( int j = 0; j < split.length; j++) { + String[] types = split[j].split("-"); + typeArr.put(types[0], types[1]); + } + object.put("point_type_name", typeArr.getString(point_type)); + } + res.add(object); + } + json.put("content", res); return json; } @@ -62,7 +108,7 @@ public class PointServiceImpl implements PointService { } @Override - public PointDto findById(Long point_id) { + public PointDto findById(String point_id) { WQLObject wo = WQLObject.getWQLObject("sch_base_point"); JSONObject json = wo.query("point_id =" + point_id + "").uniqueResult(0); if (ObjectUtil.isNotEmpty(json)) { @@ -91,11 +137,15 @@ public class PointServiceImpl implements PointService { if (ObjectUtil.isNotEmpty(byCode)) { throw new BadRequestException("存在相同的点位编码"); } + + String can_vehicle_type = String.join(",", dto.getCan_vehicle_types()); + dto.setCan_vehicle_type(can_vehicle_type); + String currentUserId = SecurityUtils.getCurrentUserId(); String nickName = SecurityUtils.getCurrentNickName(); - dto.setPoint_id(IdUtil.getSnowflake(1, 1).nextId()); + dto.setPoint_id(IdUtil.getSnowflake(1, 1).nextIdStr()); dto.setCreate_id(currentUserId); dto.setCreate_name(nickName); dto.setUpdate_id(currentUserId); @@ -116,17 +166,35 @@ public class PointServiceImpl implements PointService { throw new BadRequestException("被删除或无权限,操作失败!"); } + WQLObject materialBaseTab = WQLObject.getWQLObject("MD_ME_MaterialBase"); + WQLObject pointTab = WQLObject.getWQLObject("SCH_BASE_Point"); + String currentUserId = SecurityUtils.getCurrentUserId(); String nickName = SecurityUtils.getCurrentNickName(); + String can_vehicle_type = String.join(",", dto.getCan_vehicle_types()); + dto.setCan_vehicle_type(can_vehicle_type); - dto.setUpdate_time(DateUtil.now()); + String now = DateUtil.now(); + dto.setUpdate_time(now); dto.setUpdate_id(currentUserId); dto.setUpdate_name(nickName); + String pointStatus = dto.getPoint_status(); - WQLObject wo = WQLObject.getWQLObject("sch_base_point"); + if (ObjectUtil.isNotEmpty(pointStatus) && pointStatus.equals("1")) { // 空位 + dto.setMaterial_id(""); + dto.setVehicle_type(""); + dto.setVehicle_code(""); + dto.setVehicle_qty(0); + } else if (pointStatus.equals("2")) { // 空载具 + dto.setMaterial_id(null); + } else if (pointStatus.equals("3")) { // 有料 + if (ObjectUtil.isEmpty(dto.getMaterial_id())) throw new BadRequestException("物料不能为空"); + JSONObject materialObj = materialBaseTab.query("material_id = '" + dto.getMaterial_id() + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(materialObj)) throw new BadRequestException("未找到该物料"); + } JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto)); - wo.update(json); + pointTab.update(json); } @@ -135,15 +203,13 @@ public class PointServiceImpl implements PointService { public void deleteAll(Long[] ids) { String currentUserId = SecurityUtils.getCurrentUserId(); String nickName = SecurityUtils.getCurrentNickName(); - - WQLObject wo = WQLObject.getWQLObject("sch_base_point"); for (Long point_id : ids) { JSONObject param = new JSONObject(); param.put("point_id", String.valueOf(point_id)); param.put("is_delete", "1"); - param.put("update_optid", currentUserId); - param.put("update_optname", nickName); + param.put("update_id", currentUserId); + param.put("update_name", nickName); param.put("update_time", DateUtil.now()); wo.update(param); } @@ -176,16 +242,16 @@ public class PointServiceImpl implements PointService { is_used = "0"; } json.put("is_used", is_used); - json.put("update_optid", currentUserId); - json.put("update_optname", nickName); + json.put("update_id", currentUserId); + json.put("update_name", nickName); json.put("update_time", DateUtil.now()); WQLObject.getWQLObject("sch_base_point").update(json); //如果启用,则同步更新仓位的状态 json = new JSONObject(); json.put("is_used", is_used); - json.put("update_optid", currentUserId); - json.put("update_optname", nickName); + json.put("update_id", currentUserId); + json.put("update_name", nickName); json.put("update_time", DateUtil.now()); json.put("struct_id", struct_id); WQLObject.getWQLObject("ST_IVT_StructAttr").update(json, " struct_id = '" + struct_id + "'"); @@ -199,69 +265,63 @@ public class PointServiceImpl implements PointService { } @Override - @Transactional(rollbackFor = Exception.class) - public void syncStruct() { - WQLObject.getWQLObject("sch_base_point").delete(" point_type = '01'"); - String currentUserId = SecurityUtils.getCurrentUserId(); - String nickName = SecurityUtils.getCurrentNickName(); - - JSONObject map = new JSONObject(); - map.put("flag", "2"); - JSONArray arrStruct = WQL.getWO("QSCH_BASE_POINT").addParamMap(map).process().getResultJSONArray(0); - WQLObject wo = WQLObject.getWQLObject("sch_base_point"); - for (int i = 0; i < arrStruct.size(); i++) { - JSONObject json = arrStruct.getJSONObject(i); - JSONObject structMap = new JSONObject(); - structMap.put("point_id", json.getString("struct_id")); - structMap.put("point_code", json.getString("struct_code")); - structMap.put("point_name", json.getString("struct_name")); - structMap.put("area_type", json.getString("sect_code")); - structMap.put("source_id", json.getString("struct_id")); - structMap.put("point_type", "01"); - structMap.put("is_used", json.getString("is_used")); - structMap.put("create_id", currentUserId); - structMap.put("create_name", nickName); - structMap.put("create_time", DateUtil.now()); - structMap.put("update_optid", currentUserId); - structMap.put("update_optname", nickName); - structMap.put("update_time", DateUtil.now()); - wo.insert(structMap); - } - } - - @Override - public Map getEndPoint(Map whereJson, Pageable page) { + public Map selectPoint(Map whereJson, Pageable page) { String search = MapUtil.getStr(whereJson, "search"); - //String material_id = MapUtil.getStr(whereJson, "material_id"); - String area_type = MapUtil.getStr(whereJson, "area_type"); - String vehicle_code = MapUtil.getStr(whereJson, "vehicle_code"); - String qty = MapUtil.getStr(whereJson, "qty"); - String loadSeries = "4"; - //根据重量去找最小的级数在哪个范围 - if (StrUtil.isNotEmpty(qty) && Double.valueOf(qty) > 0) { - loadSeries = this.getLoadSeriesByqty(Double.valueOf(qty)); - } + String region_id = MapUtil.getStr(whereJson, "region_id"); - - WQLObject wo_vehicle = WQLObject.getWQLObject("md_pb_storagevehicleinfo"); - String vehicle_type = ""; - if (StrUtil.isNotEmpty(vehicle_code)) { - JSONObject jsonObject = wo_vehicle.query("is_delete = '0' and storagevehicle_code = '" + vehicle_code + "'").uniqueResult(0); - vehicle_type = jsonObject.getString("storagevehicle_type"); - } JSONObject map = new JSONObject(); + map.put("flag", "3"); - map.put("area_type", area_type); - map.put("vehicle_type", vehicle_type); - map.put("loadSeries", loadSeries); - //map.put("material_id",material_id); + map.put("region_id", region_id); if (ObjectUtil.isNotEmpty(search)) { map.put("search", "%" + search + "%"); } - JSONObject json = WQL.getWO("SCH_Point_01").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "struct_code"); + JSONObject json = WQL.getWO("SCH_Point_01").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "point.point_code"); return json; } + @Override + public JSONArray getRegion() { + JSONArray resultJSONArray = WQLObject.getWQLObject("SCH_BASE_Region").query().getResultJSONArray(0); + return resultJSONArray; + } + + /** + * 改变启用状态 + * + * @param jsonObject + */ + @Override + public void changeUsed(JSONObject jsonObject) { + WQLObject wo = WQLObject.getWQLObject("sch_base_Point"); + JSONArray data = jsonObject.getJSONArray("data"); + String used = jsonObject.getString("used"); + for ( int i = 0; i < data.size(); i++ ) { + JSONObject object = data.getJSONObject(i); + if (used.equals("1")) object.put("is_used", 1); + else object.put("is_used", 0); + wo.update(object); + } + } + + /** + * 改变锁定类型 + * + * @param jsonObject + */ + @Override + public void changeLock(JSONObject jsonObject) { + WQLObject wo = WQLObject.getWQLObject("sch_base_Point"); + JSONArray data = jsonObject.getJSONArray("data"); + String lock = jsonObject.getString("lock_type"); + for ( int i = 0; i < data.size(); i++ ) { + JSONObject object = data.getJSONObject(i); + if (lock.equals(PointEnum.LOCK_TYPE_OFF.getCode())) object.put("lock_type", PointEnum.LOCK_TYPE_OFF.getCode()); + else object.put("lock_type", PointEnum.LOCK_TYPE_ON.getCode()); + wo.update(object); + } + } + //根据重量返回最大的 级数 public String getLoadSeriesByqty(Double qty) { JSONArray dictArr = WQLObject.getWQLObject("sys_dict_detail").query("dict_id ='108'", "label").getResultJSONArray(0); diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/RegionServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/RegionServiceImpl.java index fc171747..107866d4 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/RegionServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/RegionServiceImpl.java @@ -77,8 +77,8 @@ public class RegionServiceImpl implements RegionService { dto.setCreate_id(currentUserId); dto.setCreate_name(nickName); - dto.setUpdate_optid(currentUserId); - dto.setUpdate_optname(nickName); + dto.setUpdate_id(currentUserId); + dto.setUpdate_name(nickName); dto.setUpdate_time(now); dto.setCreate_time(now); @@ -97,8 +97,8 @@ public class RegionServiceImpl implements RegionService { String now = DateUtil.now(); dto.setUpdate_time(now); - dto.setUpdate_optid(currentUserId); - dto.setUpdate_optname(nickName); + dto.setUpdate_id(currentUserId); + dto.setUpdate_name(nickName); WQLObject wo = WQLObject.getWQLObject("sch_base_region"); JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto)); @@ -117,11 +117,11 @@ public class RegionServiceImpl implements RegionService { /** * 获取点位状态下拉框 * - * @param region_id + * @param region_code * @return */ @Override - public JSONArray getPointStatusSelectById(Long region_id) { + public JSONArray getPointStatusSelectByCode(String region_code) { /** * label,value */ @@ -143,11 +143,11 @@ public class RegionServiceImpl implements RegionService { /** * 获取点位类型下拉框 * - * @param region_id + * @param region_code * @return */ @Override - public JSONArray getPointTypeSelectById(Long region_id) { + public JSONArray getPointTypeSelectByCode(String region_code) { /** * label,value */ diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/TaskServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/TaskServiceImpl.java index 25970ecb..694bebc7 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/TaskServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/service/impl/TaskServiceImpl.java @@ -1,7 +1,5 @@ - package org.nl.wms.sch.service.impl; - import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.IdUtil; @@ -10,24 +8,24 @@ import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; - import lombok.RequiredArgsConstructor; -import org.nl.common.anno.Log; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nl.common.utils.SecurityUtils; import org.nl.modules.common.exception.BadRequestException; - import org.nl.common.utils.SecurityUtils; import org.nl.modules.wql.WQL; import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.WqlUtil; +import org.nl.wms.basedata.master.service.ClassstandardService; +import org.nl.wms.basedata.master.service.dto.ClassstandardDto; +import org.nl.wms.sch.manage.TaskStatusEnum; import org.nl.wms.sch.service.TaskService; import org.nl.wms.sch.service.dto.TaskDto; - import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -42,6 +40,8 @@ import java.util.Map; @Slf4j public class TaskServiceImpl implements TaskService { + private final ClassstandardService classstandardService; + @Override public Map queryAll(Map form, Pageable page) { @@ -54,6 +54,10 @@ public class TaskServiceImpl implements TaskService { if (StrUtil.isNotEmpty(task_status)) { task_status = task_status.replace("[\"", "").replace("\"]", "").replace("\"", ""); } + String moreTaskStatus = whereJson.getString("more_task_status"); + if (ObjectUtil.isNotEmpty(moreTaskStatus)) { + task_status = moreTaskStatus; + } map.put("task_status", task_status); //处理状态为未完成 if (StrUtil.isNotEmpty(task_status) && task_status.contains("-1")) { @@ -63,20 +67,18 @@ public class TaskServiceImpl implements TaskService { if (StrUtil.isNotEmpty(whereJson.getString("task_code"))) { map.put("task_code", "%" + whereJson.getString("task_code") + "%"); } - if (StrUtil.isNotEmpty(whereJson.getString("start_point_code"))) { - map.put("start_point_code", "%" + whereJson.getString("start_point_code") + "%"); + if (StrUtil.isNotEmpty(whereJson.getString("point_code1"))) { + map.put("point_code1", "%" + whereJson.getString("point_code1") + "%"); } - if (StrUtil.isNotEmpty(whereJson.getString("next_point_code"))) { - map.put("next_point_code", "%" + whereJson.getString("next_point_code") + "%"); + if (StrUtil.isNotEmpty(whereJson.getString("point_code2"))) { + map.put("point_code2", "%" + whereJson.getString("point_code2") + "%"); } if (StrUtil.isNotEmpty(whereJson.getString("vehicle_code"))) { map.put("vehicle_code", "%" + whereJson.getString("vehicle_code") + "%"); } if (StrUtil.isNotEmpty(whereJson.getString("task_type"))) { - map.put("task_type", whereJson.getString("task_type")); - } - if (StrUtil.isNotEmpty(whereJson.getString("taskdtl_type"))) { - map.put("taskdtl_type", whereJson.getString("taskdtl_type")); + ClassstandardDto task_type = classstandardService.findById(whereJson.getString("task_type")); + map.put("task_type", task_type.getClass_code()); } if (StrUtil.isNotEmpty(whereJson.getString("finishTypeList"))) { map.put("finishTypeList", whereJson.getString("finishTypeList")); @@ -128,17 +130,14 @@ public class TaskServiceImpl implements TaskService { public void create(TaskDto dto) { String currentUserId = SecurityUtils.getCurrentUserId(); String nickName = SecurityUtils.getCurrentNickName(); - - - - dto.setTaskdtl_id(IdUtil.getSnowflake(1, 1).nextId()); - dto.setTask_id(dto.getTaskdtl_id()); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.getSnowflake(1, 1).nextIdStr()); dto.setCreate_id(currentUserId); dto.setCreate_name(nickName); dto.setUpdate_id(currentUserId); dto.setUpdate_name(nickName); - dto.setUpdate_time(DateUtil.now()); - dto.setCreate_time(DateUtil.now()); + dto.setUpdate_time(now); + dto.setCreate_time(now); WQLObject wo = WQLObject.getWQLObject("sch_base_task"); JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto)); @@ -169,8 +168,8 @@ public class TaskServiceImpl implements TaskService { @Transactional(rollbackFor = Exception.class) public void deleteAll(String[] ids) { WQLObject wo = WQLObject.getWQLObject("sch_base_task"); - for (String taskdtl_id : ids) { - wo.delete("taskdtl_id = '" + taskdtl_id + "'"); + for (String task_id : ids) { + wo.delete("task_id = '" + task_id + "'"); } } @@ -178,17 +177,25 @@ public class TaskServiceImpl implements TaskService { public void operation(Map map) { String task_id = MapUtil.getStr(map, "task_id"); String method_name = MapUtil.getStr(map, "method_name"); - TaskDto dto = this.findByDtlId(task_id); + JSONObject taskObj = WQLObject.getWQLObject("SCH_BASE_Task").query("task_id = '" + task_id + "'").uniqueResult(0); + if (taskObj.getString("task_status").equals(TaskStatusEnum.FINISHED.getCode())) throw new BadRequestException("任务已完成!"); // 任务处理类 - String processing_class = dto.getHandle_class(); + String processing_class = taskObj.getString("handle_class"); String message = ""; // 根据任务类型获取对应的任务操作类 try { Class clz = Class.forName(processing_class); Object obj = clz.newInstance(); // 调用每个任务类的method_name()强制结束方法 - Method m = obj.getClass().getMethod(method_name, String.class); - JSONObject result = (JSONObject) m.invoke(obj, task_id); + Method m; + JSONObject result; + if (method_name.equals("immediateNotifyAcs")) { // 立即下发不需要参数 + m = obj.getClass().getMethod(method_name); + result = (JSONObject) m.invoke(obj); + } else { + m = obj.getClass().getMethod(method_name, String.class); + result = (JSONObject) m.invoke(obj, task_id); + } if (ObjectUtil.isEmpty(result)) return; JSONArray arr = result.getJSONArray("errArr"); WQLObject wo = WQLObject.getWQLObject("sch_base_task"); @@ -196,7 +203,7 @@ public class TaskServiceImpl implements TaskService { for (int i = 0; i < arr.size(); i++) { JSONObject json = arr.getJSONObject(i); JSONObject param = new JSONObject(); - param.put("taskdtl_id", json.getString("taskdtl_id")); + param.put("task_id", json.getString("task_id")); param.put("remark", json.getString("message")); wo.update(param); } diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallMaterialTask.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallMaterialTask.java index 794e895b..95489190 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallMaterialTask.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/CallMaterialTask.java @@ -327,7 +327,7 @@ public class CallMaterialTask extends AbstractAcsTask { task_status = TaskStatusEnum.START_AND_POINT.getCode(); PointDto startPoint = pointService.findByCode(start_point_code); - start_area = nextPoint.getArea_type(); +// start_area = nextPoint.getArea_type(); //终点点加锁 HashMap lock_map = new HashMap(); lock_map.put("lock_type", "01"); @@ -368,7 +368,7 @@ public class CallMaterialTask extends AbstractAcsTask { taskObj.put("start_area", start_area); taskObj.put("request_param", form.toJSONString()); taskObj.put("next_point_code", next_point_code); - taskObj.put("next_area", nextPoint.getArea_type()); +// taskObj.put("next_area", nextPoint.getArea_type()); taskObj.put("vehicle_code", vehicle_code); taskObj.put("handle_class", THIS_CLASS); taskObj.put("is_auto_issue", "1"); diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendMaterialTask.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendMaterialTask.java index 65f0808d..de736085 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendMaterialTask.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/tasks/SendMaterialTask.java @@ -348,10 +348,10 @@ public class SendMaterialTask extends AbstractAcsTask { taskObj.put("acs_task_type", "1"); taskObj.put("task_status", task_status); taskObj.put("start_point_code", start_point_code); - taskObj.put("start_area", startPoint.getArea_type()); +// taskObj.put("start_area", startPoint.getArea_type()); taskObj.put("request_param", form.toJSONString()); taskObj.put("next_point_code", next_point_code); - taskObj.put("next_area", nextPoint.getArea_type()); +// taskObj.put("next_area", nextPoint.getArea_type()); taskObj.put("vehicle_code", vehicle_code); taskObj.put("handle_class", THIS_CLASS); taskObj.put("is_auto_issue", "1"); diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_BASE_POINT.wql b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_BASE_POINT.wql index 302f9cab..ac375e59 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_BASE_POINT.wql +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_BASE_POINT.wql @@ -14,11 +14,15 @@ ## 表字段对应输入参数 ################################################# 输入.flag TYPEAS s_string - 输入.area_type TYPEAS s_string + 输入.region_code TYPEAS s_string 输入.lock_type TYPEAS s_string 输入.name TYPEAS s_string 输入.point_type TYPEAS s_string 输入.point_status TYPEAS s_string + 输入.block_num TYPEAS s_string + 输入.row_num TYPEAS s_string + 输入.col_num TYPEAS s_string + 输入.layer_num TYPEAS s_string 输入.is_used TYPEAS s_string 输入.ids TYPEAS f_string @@ -48,45 +52,25 @@ IF 输入.flag = "1" PAGEQUERY SELECT - point.point_id, - point.point_code, - point.point_name, - point.area_type, - point.point_type, - point.point_status, - point.lock_type, - d2.label as area_type_name, - d1.label as point_type_name, - d4.label as point_status_name, + point.*, d3.label as lock_type_name, - point.vehicle_code, - point.source_id, - point.remark, - point.taskdtl_type, - point.taskdtl_id, - point.task_code, - point.inv_type, - point.inv_id, - point.inv_code, - point.is_used, - point.is_delete, - point.create_name, - point.create_time, - point.update_optname, - point.update_time + region.region_name, + r2.region_name as pre_region_name, + r3.region_name as next_region_name, + ma.material_name, + ma.material_code, + ma.material_spec FROM sch_base_point point - LEFT JOIN sys_dict_detail d1 ON point.point_type = d1.value and d1.name='sch_point_type' - LEFT JOIN sys_dict_detail d2 ON point.area_type = d2.value and d2.name='sch_area_type' - LEFT JOIN sys_dict_detail d3 ON point.lock_type = d3.value and d3.name='d_lock_type' - LEFT JOIN sys_dict_detail d4 ON point.point_status = d4.value and d4.name='sch_point_status' + LEFT JOIN SCH_BASE_Region region ON point.region_code = region.region_code + LEFT JOIN SCH_BASE_Region r2 ON point.pre_region_code = r2.region_code + LEFT JOIN SCH_BASE_Region r3 ON point.next_region_code = r3.region_code + LEFT JOIN sys_dict d3 ON point.lock_type = d3.value and d3.code='d_lock_type' + LEFT JOIN md_me_materialbase ma ON ma.material_id = point.material_id WHERE point.is_delete = '0' - OPTION 输入.area_type <> "" - point.area_type = 输入.area_type - ENDOPTION - OPTION 输入.ids <> "" - point.area_type in (输入.ids) + OPTION 输入.region_code <> "" + point.region_code = 输入.region_code ENDOPTION OPTION 输入.point_type <> "" point.point_type = 输入.point_type @@ -103,6 +87,18 @@ OPTION 输入.is_used <> "" point.is_used = 输入.is_used ENDOPTION + OPTION 输入.block_num <> "" + point.block_num = 输入.block_num + ENDOPTION + OPTION 输入.row_num <> "" + point.row_num = 输入.row_num + ENDOPTION + OPTION 输入.col_num <> "" + point.col_num = 输入.col_num + ENDOPTION + OPTION 输入.layer_num <> "" + point.layer_num = 输入.layer_num + ENDOPTION OPTION 输入.name <> "" ( point.point_code like "%" 输入.name "%" or point.point_name like "%" 输入.name "%" ) ENDOPTION @@ -113,11 +109,11 @@ IF 输入.flag = "2" QUERY SELECT - struct.*,sect.sect_code + struct.*,region.region_code FROM ST_IVT_StructAttr struct left join - ST_IVT_SectAttr sect on struct.sect_id = sect.sect_id + SCH_BASE_Region region on struct.region_code = region.region_code WHERE struct.is_delete = '0' ENDSELECT diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_TASK_01.wql b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_TASK_01.wql index 217c78ec..26bc0fff 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_TASK_01.wql +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/QSCH_TASK_01.wql @@ -17,14 +17,13 @@ 输入.task_status TYPEAS s_string 输入.finished_type TYPEAS s_string 输入.task_type TYPEAS s_string - 输入.start_point_code TYPEAS s_string - 输入.next_point_code TYPEAS s_string + 输入.point_code1 TYPEAS s_string + 输入.point_code2 TYPEAS s_string 输入.task_code TYPEAS s_string 输入.vehicle_code TYPEAS s_string 输入.begin_time TYPEAS s_string 输入.end_time TYPEAS s_string 输入.unFinish TYPEAS s_string - 输入.taskdtl_type TYPEAS s_string [临时表] --这边列出来的临时表就会在运行期动态创建 @@ -50,29 +49,34 @@ IF 输入.flag = "1" PAGEQUERY - SELECT + SELECT task.*, - p1.point_name AS start_point_name, - d1.label AS start_area_name, - p2.point_name AS next_point_name, - d2.label AS next_area_name, - d3.label AS task_type_name, - d4.label AS taskdtl_type_name + md.class_name task_type_name, + dict.label task_status_name, + reg1.region_code as point1_region_name, + reg2.region_code as point2_region_name, + reg3.region_code as point3_region_name, + reg4.region_code as point4_region_name FROM sch_base_task task - LEFT JOIN sch_base_point p1 ON task.start_point_code = p1.point_code - LEFT JOIN sys_dict_detail d1 ON d1.`value` = p1.area_type AND d1.`name` = 'sch_area_type' - LEFT JOIN sch_base_point p2 ON task.next_point_code = p2.point_code - LEFT JOIN sys_dict_detail d2 ON d2.`value` = p2.area_type AND d2.`name` = 'sch_area_type' - LEFT JOIN sys_dict_detail d3 ON d3.`value` = task.task_type AND d3.`name` = 'SCH_TASK_TYPE' - LEFT JOIN sys_dict_detail d4 ON d4.`value` = task.taskdtl_type AND d4.`name` = 'SCH_TASK_TYPE_DTL' + LEFT JOIN md_pb_classstandard md ON task.task_type = md.class_code + LEFT JOIN sys_dict_detail dict ON dict.`value` = task.task_status AND dict.`name` = 'task_status' + LEFT JOIN SCH_BASE_Region reg1 ON reg1.region_code = ( + SELECT p1.region_code FROM SCH_BASE_Point p1 WHERE p1.point_code = task.point_code1 + ) + LEFT JOIN SCH_BASE_Region reg2 ON reg2.region_code = ( + SELECT p2.region_code FROM SCH_BASE_Point p2 WHERE p2.point_code = task.point_code2 + ) + LEFT JOIN SCH_BASE_Region reg3 ON reg3.region_code = ( + SELECT p3.region_code FROM SCH_BASE_Point p3 WHERE p3.point_code = task.point_code3 + ) + LEFT JOIN SCH_BASE_Region reg4 ON reg4.region_code = ( + SELECT p4.region_code FROM SCH_BASE_Point p4 WHERE p4.point_code = task.point_code4 + ) WHERE task.is_delete = '0' OPTION 输入.task_type <> "" task.task_type = 输入.task_type - ENDOPTION - OPTION 输入.taskdtl_type <> "" - task.taskdtl_type = 输入.taskdtl_type ENDOPTION OPTION 输入.finished_type <> "" task.finished_type = 输入.finished_type @@ -84,7 +88,7 @@ task.create_time <= 输入.end_time ENDOPTION OPTION 输入.unFinish <> "" - task.task_status <> '07' + task.task_status <> '7' ENDOPTION OPTION 输入.task_status <> "" find_in_set( task.task_status, 输入.task_status) @@ -95,11 +99,8 @@ OPTION 输入.task_code <> "" (task.task_code like 输入.task_code) ENDOPTION - OPTION 输入.start_point_code <> "" - (task.start_point_code like 输入.start_point_code) - ENDOPTION - OPTION 输入.next_point_code <> "" - (task.next_point_code like 输入.next_point_code) + OPTION 输入.point_code <> "" + (task.point_code1 like 输入.point_code1) ENDOPTION OPTION 输入.begin_time <> "" task.create_time >= 输入.begin_time diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/sch.xls b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/sch.xls index bd0ab2de..f39438d2 100644 Binary files a/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/sch.xls and b/mes/hd/nladmin-system/src/main/java/org/nl/wms/sch/wql/sch.xls differ diff --git a/mes/hd/nladmin-system/src/main/resources/template/generator/admin/Dto.ftl b/mes/hd/nladmin-system/src/main/resources/template/generator/admin/Dto.ftl index 9a5cf7d5..edfadda2 100644 --- a/mes/hd/nladmin-system/src/main/resources/template/generator/admin/Dto.ftl +++ b/mes/hd/nladmin-system/src/main/resources/template/generator/admin/Dto.ftl @@ -1,18 +1,16 @@ package ${package}.service.dto; import lombok.Data; -import java.util.Date; - <#if hasTimestamp> -import java.sql.Timestamp; + import java.sql.Timestamp; <#if hasBigDecimal> -import java.math.BigDecimal; + import java.math.BigDecimal; import java.io.Serializable; <#if !auto && pkColumnType = 'Long'> -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; /** @@ -23,18 +21,18 @@ import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @Data public class ${className}Dto implements Serializable { <#if columns??> -<#list columns as column> + <#list columns as column> -<#if column.remark != ''> - /** ${column.remark} */ - -<#if column.columnKey = 'PRI'> -<#if !auto && pkColumnType = 'Long'> - /** 防止精度丢失 */ - @JsonSerialize(using= ToStringSerializer.class) - - - private ${column.columnType} ${column.changeColumnName}; - + <#if column.remark != ''> + /** ${column.remark} */ + + <#if column.columnKey = 'PRI'> + <#if !auto && pkColumnType = 'Long'> + /** 防止精度丢失 */ + @JsonSerialize(using= ToStringSerializer.class) + + + private ${column.columnType} ${column.changeColumnName}; + } diff --git a/mes/qd/src/api/wms/sch/point.js b/mes/qd/src/api/wms/sch/point.js index b41e5141..7a781111 100644 --- a/mes/qd/src/api/wms/sch/point.js +++ b/mes/qd/src/api/wms/sch/point.js @@ -23,14 +23,6 @@ export function edit(data) { data }) } - -export function syncStruct() { - return request({ - url: 'api/point/syncStruct', - method: 'put' - }) -} - export function findPoints(area_type) { return request({ url: 'api/point/area_type/' + area_type @@ -53,4 +45,27 @@ export function getPoint(data) { }) } -export default { add, edit, del, syncStruct, changeActive, findPoints, getPoint } +export function getRegion() { + return request({ + url: '/api/point/getRegion', + method: 'get' + }) +} + +export function changeUsed(data) { + return request({ + url: 'api/point/changeUsed', + method: 'post', + data: data + }) +} + +export function changeLock(data) { + return request({ + url: 'api/point/changeLock', + method: 'post', + data: data + }) +} + +export default { add, edit, del, changeActive, findPoints, getPoint, getRegion, changeUsed, changeLock } diff --git a/mes/qd/src/api/wms/sch/region.js b/mes/qd/src/api/wms/sch/region.js index 6cfc1e99..cfaf0da6 100644 --- a/mes/qd/src/api/wms/sch/region.js +++ b/mes/qd/src/api/wms/sch/region.js @@ -32,21 +32,20 @@ export function changeActive(data) { }) } -export function getPointStatusSelectById(id) { +export function getPointStatusSelectByCode(code) { return request({ - url: 'api/region/getPointStatusSelectById', + url: 'api/region/getPointStatusSelectByCode', method: 'post', - data: id + data: code }) } -export function getPointTypeSelectById(id) { +export function getPointTypeSelectByCode(code) { return request({ - url: 'api/region/getPointTypeSelectById', + url: 'api/region/getPointTypeSelectByCode', method: 'post', - data: id + data: code }) } - -export default { add, edit, del, changeActive, getPointStatusSelectById, getPointTypeSelectById } +export default { add, edit, del, changeActive, getPointStatusSelectByCode, getPointTypeSelectByCode } diff --git a/mes/qd/src/views/wms/sch/point/MaterialDialog.vue b/mes/qd/src/views/wms/sch/point/MaterialDialog.vue new file mode 100644 index 00000000..b5f8400e --- /dev/null +++ b/mes/qd/src/views/wms/sch/point/MaterialDialog.vue @@ -0,0 +1,155 @@ + + + + + diff --git a/mes/qd/src/views/wms/sch/point/ViewDialog.vue b/mes/qd/src/views/wms/sch/point/ViewDialog.vue new file mode 100644 index 00000000..7b4c2be8 --- /dev/null +++ b/mes/qd/src/views/wms/sch/point/ViewDialog.vue @@ -0,0 +1,212 @@ + + + + + diff --git a/mes/qd/src/views/wms/sch/point/WorkOrderDialog.vue b/mes/qd/src/views/wms/sch/point/WorkOrderDialog.vue new file mode 100644 index 00000000..d9141c23 --- /dev/null +++ b/mes/qd/src/views/wms/sch/point/WorkOrderDialog.vue @@ -0,0 +1,158 @@ + + + + + diff --git a/mes/qd/src/views/wms/sch/point/index.vue b/mes/qd/src/views/wms/sch/point/index.vue index 5e5bacae..aeb97cea 100644 --- a/mes/qd/src/views/wms/sch/point/index.vue +++ b/mes/qd/src/views/wms/sch/point/index.vue @@ -7,7 +7,7 @@ :inline="true" class="demo-form-inline" label-position="right" - label-width="80px" + label-width="90px" label-suffix=":" > @@ -19,6 +19,23 @@ @keyup.enter.native="crud.toQuery" /> + + + + + - - - - - - - - - - + + + + + + + + + + + + + - - + /> - - - + /> @@ -112,15 +145,52 @@ - 仓位同步 + 启用 + + + 禁用 + + + 锁定 + + + 解锁 @@ -129,28 +199,84 @@ :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" - width="500px" + width="540px" > - + + + + + + + + + + + + + + + + - + - + - + + + + + + @@ -171,32 +297,60 @@ /> - - - - - - {{ item.label }} - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -216,28 +370,38 @@ @selection-change="crud.selectionChangeHandler" > - - + + + + + + + + + + + - - - + - - - - - + + + + + + + + + + diff --git a/mes/qd/src/views/wms/sch/task/index.vue b/mes/qd/src/views/wms/sch/task/index.vue index eb7928da..79bd8cc1 100644 --- a/mes/qd/src/views/wms/sch/task/index.vue +++ b/mes/qd/src/views/wms/sch/task/index.vue @@ -30,67 +30,22 @@ @keyup.enter.native="crud.toQuery" /> - + - - - - - - - - - - - - - - @@ -112,6 +67,17 @@ + + + - - + + + - - - + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -203,11 +188,11 @@ width="30%" > - + + + + + 取 消 确 定 @@ -221,24 +206,34 @@ import crudTask from '@/api/wms/sch/task' import CRUD, { crud, header, presenter } from '@crud/crud' import rrOperation from '@crud/RR.operation' import crudOperation from '@crud/CRUD.operation' +import udOperation from '@crud/UD.operation' import pagination from '@crud/Pagination' +import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect' +import '@riophae/vue-treeselect/dist/vue-treeselect.css' +import crudClassstandard from '@/api/wms/basedata/master/classstandard' export default { name: 'Task', - dicts: ['SCH_TASK_TYPE', 'SCH_TASK_TYPE_DTL'], + dicts: ['acs_task_type', 'vehicle_type', 'task_finished_type'], components: { - pagination, crudOperation, rrOperation + pagination, crudOperation, rrOperation, Treeselect, udOperation }, mixins: [presenter(), header(), crud()], cruds() { return CRUD({ title: '任务', url: 'api/task', - idField: 'taskdtl_id', - sort: 'taskdtl_id,desc', + idField: 'task_id', + sort: 'task_id,desc', crudMethod: { ...crudTask }, query: { - task_code:'',vehicle_code:'',start_point_code:'',next_point_code:'',task_type:'',taskdtl_type:'',finished_type:'',task_status:"" + task_code: '', + vehicle_code: '', + start_point_code: '', + next_point_code: '', + task_type: '', + finished_type: '', + task_status: '' }, optShow: { add: false, @@ -253,7 +248,6 @@ export default { return { viewDialogVisible: false, fullscreen: false, - taskdtl_id: '', currentComponent: '', openParam: {}, create_time: [], @@ -263,26 +257,65 @@ export default { permission: { }, - rules: {} + rules: {}, + classes1: [] } }, created() { + this.initClass1() crudTask.getTaskStatus().then(data => { this.taskStatusList = data }) crudTask.getFinishType().then(data => { this.finishTypeList = data }) - this.crud.query.task_status = ['-1'] - this.crud.toQuery() + // this.crud.query.task_status = ['-1'] + // this.crud.toQuery() }, methods: { + initClass1() { + const param = { + parent_class_code: 'task_type' + } + crudClassstandard.getClassType(param).then(res => { + const data = res.content + this.buildTree(data) + this.classes1 = data + }) + }, + buildTree(classes) { + classes.forEach(data => { + if (data.children) { + this.buildTree(data.children) + } + if (data.hasChildren && !data.children) { + data.children = null // 重点代码 + } + }) + }, + // 获取子节点数据 + loadChildNodes({ action, parentNode, callback }) { + if (action === LOAD_CHILDREN_OPTIONS) { + crudClassstandard.getClass({ pid: parentNode.id }).then(res => { + parentNode.children = res.content.map(function(obj) { + if (obj.hasChildren) { + obj.children = null + } + return obj + }) + setTimeout(() => { + callback() + }, 100) + }) + } + }, hand(value) { this.crud.toQuery() }, handTaskStatus(value) { + this.crud.query.more_task_status = null if (value) { - this.query.task_status = this.task_status.toString() + this.crud.query.more_task_status = value.toString() } this.crud.toQuery() }, @@ -294,46 +327,28 @@ export default { } return '' }, - formatFinishTypeName(row, column) { - for (const item of this.finishTypeList) { - if (item.code === row.finished_type) { - return item.name - } - } - return '' - }, - beforeHandleCommand(index, row, command) { - return { - 'index': index, - 'row': row, - 'command': command - } - }, - handleCommand(command) { + doOperate(row, command) { let method_name = '' - switch (command.command) { + switch (command) { case 'a':// 完成 method_name = 'forceFinish' break case 'b':// 取消 method_name = 'cancel' break - case 'c':// 拉回 - method_name = 'pullBack' + case 'c':// 下发 + method_name = 'immediateNotifyAcs' break - case 'd':// 重发 - method_name = 'renotifyAcs' - break - case 'e':// 详情 + case 'd':// 详情 method_name = 'view' break } if (method_name === 'view') { - this.view(command.row) + this.view(row) return } const data = { - taskdtl_id: command.row.taskdtl_id, + task_id: row.task_id, method_name: method_name } crudTask.operation(data).then(res => { @@ -344,7 +359,7 @@ export default { }) }, view(row) { - this.taskdtl_id = row.taskdtl_id + this.task_id = row.task_id switch (row.task_type) { case '01':// 入库 this.fullscreen = true