Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
guojunyun
2025-09-21 20:58:56 +08:00
105 changed files with 2612 additions and 206 deletions

View File

@@ -15,6 +15,10 @@ public interface ErrorCodeConstants {
ErrorCode TEMPLATE_INSTANCE_DATA_NOT_EXISTS = new ErrorCode(1_027_000_508, "实例字段值不存在");
ErrorCode TEMPLATE_INSTANCE_ITEM_NOT_EXISTS = new ErrorCode(1_027_000_509, "实例条款值不存在");
ErrorCode PARAMS_IS_NULL_OR_ERR = new ErrorCode(1_027_000_510, "参数为空");
ErrorCode DEPARTMENT_INSTANCE_RELATIVITY_NOT_EXISTS = new ErrorCode(1_027_000_511, "部门与实例关联不存在");
ErrorCode ILLEGAL_OPERATION_TYPE = new ErrorCode(1_027_000_511, "非法操作类型");
ErrorCode OPERATION_FAIL= new ErrorCode(1_027_000_512, "操作失败");
//Illegal operation type
}

View File

@@ -0,0 +1,120 @@
package cn.iocoder.yudao.module.base.controller.admin.templtp;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityPageReqVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityRespVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativitySaveReqVO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.DepartmentInstanceRelativityDO;
import cn.iocoder.yudao.module.base.service.tmpltp.DepartmentInstanceRelativityService;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import cn.iocoder.yudao.framework.business.interceptor.BusinessControllerMarker;
import cn.iocoder.yudao.framework.business.annotation.FileUploadController;
import cn.iocoder.yudao.framework.business.controller.AbstractFileUploadController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.vo.BatchDeleteReqVO;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 部门与实例关联")
@RestController
@RequestMapping("/bse/department-instance-relativity")
@Validated
@FileUploadController(source = "bse.departmentinstancerelativity")
public class DepartmentInstanceRelativityController extends AbstractFileUploadController implements BusinessControllerMarker{
static {
FileUploadController annotation = DepartmentInstanceRelativityController.class.getAnnotation(FileUploadController.class);
if (annotation != null) {
setFileUploadInfo(annotation);
}
}
@Resource
private DepartmentInstanceRelativityService departmentInstanceRelativityService;
@PostMapping("/create")
@Operation(summary = "创建部门与实例关联")
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:create')")
public CommonResult<DepartmentInstanceRelativityRespVO> createDepartmentInstanceRelativity(@Valid @RequestBody DepartmentInstanceRelativitySaveReqVO createReqVO) {
return success(departmentInstanceRelativityService.createDepartmentInstanceRelativity(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新部门与实例关联")
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:update')")
public CommonResult<Boolean> updateDepartmentInstanceRelativity(@Valid @RequestBody DepartmentInstanceRelativitySaveReqVO updateReqVO) {
departmentInstanceRelativityService.updateDepartmentInstanceRelativity(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除部门与实例关联")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:delete')")
public CommonResult<Boolean> deleteDepartmentInstanceRelativity(@RequestParam("id") String id) {
departmentInstanceRelativityService.deleteDepartmentInstanceRelativity(id);
return success(true);
}
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除部门与实例关联")
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:delete')")
public CommonResult<Boolean> deleteDepartmentInstanceRelativityList(@RequestBody BatchDeleteReqVO req) {
departmentInstanceRelativityService.deleteDepartmentInstanceRelativityListByIds(req.getIds());
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得部门与实例关联")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:query')")
public CommonResult<DepartmentInstanceRelativityRespVO> getDepartmentInstanceRelativity(@RequestParam("id") String id) {
DepartmentInstanceRelativityDO departmentInstanceRelativity = departmentInstanceRelativityService.getDepartmentInstanceRelativity(id);
return success(BeanUtils.toBean(departmentInstanceRelativity, DepartmentInstanceRelativityRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得部门与实例关联分页")
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:query')")
public CommonResult<PageResult<DepartmentInstanceRelativityRespVO>> getDepartmentInstanceRelativityPage(@Valid DepartmentInstanceRelativityPageReqVO pageReqVO) {
PageResult<DepartmentInstanceRelativityDO> pageResult = departmentInstanceRelativityService.getDepartmentInstanceRelativityPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, DepartmentInstanceRelativityRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出部门与实例关联 Excel")
@PreAuthorize("@ss.hasPermission('bse:department-instance-relativity:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportDepartmentInstanceRelativityExcel(@Valid DepartmentInstanceRelativityPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<DepartmentInstanceRelativityDO> list = departmentInstanceRelativityService.getDepartmentInstanceRelativityPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "部门与实例关联.xls", "数据", DepartmentInstanceRelativityRespVO.class,
BeanUtils.toBean(list, DepartmentInstanceRelativityRespVO.class));
}
}

View File

@@ -108,4 +108,5 @@ public class TemplateInstanceDataController implements BusinessControllerMarker
BeanUtils.toBean(list, TemplateInstanceDataRespVO.class));
}
}

View File

@@ -143,4 +143,29 @@ public class TmplTpController extends AbstractFileUploadController implements Bu
return success(true);
}
//表单预览
// @GetMapping("/preview")
// @Operation(summary = "表单预览",description = "传入模版分类的id")
// @PreAuthorize("@ss.hasPermission('bse:tmpl-tp:query')")
// public CommonResult< List<TmplFldRespVO>> preview(@Valid @RequestParam("id") Long id) {
// List<TmplFldRespVO> field = tmplTpService.getField(id);
// return success(field);
// }
// 字段编辑新增或者删除
@PostMapping("/field-edit")
@Operation(summary = "字段编辑新增或者删除")
@PreAuthorize("@ss.hasPermission('bse:tmpl-tp:update')")
public CommonResult<Boolean> fieldEdit(@Valid @RequestBody TmplTpEditOrDeleteReqVO reqVO) {
tmplTpService.fieldEdit(reqVO);
return success(true);
}
@PostMapping("/ltm-edit")
@Operation(summary = "条款编辑新增或者删除")
@PreAuthorize("@ss.hasPermission('bse:tmpl-tp:update')")
public CommonResult<Boolean> ltmEdit(@Valid @RequestBody TmplTpEditOrDeleteReqVO reqVO) {
tmplTpService.ltmEdit(reqVO);
return success(true);
}
}

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.base.controller.admin.templtp.vo;
import lombok.*;
import java.time.LocalDate;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 部门与实例关联分页 Request VO")
@Data
public class DepartmentInstanceRelativityPageReqVO extends PageParam {
@Schema(description = "部门主键", example = "2450")
private String companyDepartmentId;
@Schema(description = "模板实例主键", example = "17846")
private String templateInstanceId;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDate[] createTime;
}

View File

@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.base.controller.admin.templtp.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDate;
import java.util.*;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 部门与实例关联 Response VO")
@Data
@ExcelIgnoreUnannotated
public class DepartmentInstanceRelativityRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "4864")
@ExcelProperty("主键")
private String id;
@Schema(description = "部门主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "2450")
@ExcelProperty("部门主键")
private String companyDepartmentId;
@Schema(description = "模板实例主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17846")
@ExcelProperty("模板实例主键")
private String templateInstanceId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDate createTime;
}

View File

@@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.base.controller.admin.templtp.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import jakarta.validation.constraints.*;
@Schema(description = "管理后台 - 部门与实例关联新增/修改 Request VO")
@Data
public class DepartmentInstanceRelativitySaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "4864")
private String id;
@Schema(description = "部门主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "2450")
@NotEmpty(message = "部门主键不能为空")
private String companyDepartmentId;
@Schema(description = "模板实例主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17846")
@NotEmpty(message = "模板实例主键不能为空")
private String templateInstanceId;
}

View File

@@ -14,13 +14,13 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class TemplateInstanceDataPageReqVO extends PageParam {
@Schema(description = "关联实例主键", example = "25824")
private String instanceId;
private String inscId;
@Schema(description = "字段标识;关联字段库")
private String fieldKey;
private String fldKy;
@Schema(description = "用户填写的值")
private String fieldValue;
private String fldVal;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@@ -18,15 +18,15 @@ public class TemplateInstanceDataRespVO {
@Schema(description = "关联实例主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "25824")
@ExcelProperty("关联实例主键")
private String instanceId;
private String inscId;
@Schema(description = "字段标识;关联字段库", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("字段标识;关联字段库")
private String fieldKey;
private String fldKy;
@Schema(description = "用户填写的值", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("用户填写的值")
private String fieldValue;
private String fldVal;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")

View File

@@ -14,14 +14,14 @@ public class TemplateInstanceDataSaveReqVO {
@Schema(description = "关联实例主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "25824")
@NotEmpty(message = "关联实例主键不能为空")
private String instanceId;
private String inscId;
@Schema(description = "字段标识;关联字段库", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "字段标识;关联字段库不能为空")
private String fieldKey;
private String fldKy;
@Schema(description = "用户填写的值", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "用户填写的值不能为空")
private String fieldValue;
private String fldVal;
}

View File

@@ -14,31 +14,31 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class TemplateInstancePageReqVO extends PageParam {
@Schema(description = "分类树主键", example = "7804")
private Long typeId;
private Long tpId;
@Schema(description = "模板名称", example = "王五")
private String name;
@Schema(description = "模板编码")
private String coding;
private String cdg;
@Schema(description = "模板描述")
private String description;
private String dsp;
@Schema(description = "实例文件内容")
private String content;
private String cntt;
@Schema(description = "原始文件内容")
private String originalContent;
private String origCntt;
@Schema(description = "文件类型", example = "1")
private String fileType;
private String fileTp;
@Schema(description = "版本号;如v1.0")
private String version;
private String ver;
@Schema(description = "状态", example = "2")
private String status;
private String sts;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

View File

@@ -18,7 +18,7 @@ public class TemplateInstanceRespVO {
@Schema(description = "分类树主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "7804")
@ExcelProperty("分类树主键")
private Long typeId;
private Long tpId;
@Schema(description = "模板名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@ExcelProperty("模板名称")
@@ -26,31 +26,31 @@ public class TemplateInstanceRespVO {
@Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("模板编码")
private String coding;
private String cdg;
@Schema(description = "模板描述")
@ExcelProperty("模板描述")
private String description;
private String dsp;
@Schema(description = "实例文件内容")
@ExcelProperty("实例文件内容")
private String content;
private String cntt;
@Schema(description = "原始文件内容", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("原始文件内容")
private String originalContent;
private String origCntt;
@Schema(description = "文件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty("文件类型")
private String fileType;
private String fileTp;
@Schema(description = "版本号;如v1.0", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("版本号;如v1.0")
private String version;
private String ver;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("状态")
private String status;
private String sts;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")

View File

@@ -14,7 +14,7 @@ public class TemplateInstanceSaveReqVO {
@Schema(description = "分类树主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "7804")
@NotNull(message = "分类树主键不能为空")
private Long typeId;
private Long tpId;
@Schema(description = "模板名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
@NotEmpty(message = "模板名称不能为空")
@@ -22,28 +22,33 @@ public class TemplateInstanceSaveReqVO {
@Schema(description = "模板编码", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "模板编码不能为空")
private String coding;
private String cdg;
@Schema(description = "模板描述")
private String description;
private String dsp;
@Schema(description = "实例文件内容")
private String content;
private String cntt;
@Schema(description = "原始文件内容", requiredMode = Schema.RequiredMode.REQUIRED)
// @NotEmpty(message = "原始文件内容不能为空")
private String originalContent;
private String origCntt;
@Schema(description = "文件类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotEmpty(message = "文件类型不能为空")
private String fileType;
private String fileTp;
@Schema(description = "版本号;如v1.0", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "版本号;如v1.0不能为空")
private String version;
private String ver;
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotEmpty(message = "状态不能为空")
private String status;
private String sts;
@Schema(description = "使用部门编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotEmpty(message = "使用部门编号不能为空")
private List<Long> deptIds;
}

View File

@@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.base.controller.admin.templtp.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import groovyjarjarantlr4.v4.runtime.misc.NotNull;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.NonNull;
import java.util.List;
@Schema(description = "管理后台 - 模板编辑字段新增/删除 Request VO")
@Data
public class TmplTpEditOrDeleteReqVO {
@Schema(description = "模版ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20895")
@NotEmpty(message = "模版id不能为空")
private String tpId;
@Schema(description = "操作类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "create or delete")
@NotEmpty(message = "操作类型不能为空")
private String type;
@Schema(description = "变更的ids", requiredMode = Schema.RequiredMode.REQUIRED, example = "[20895,23231]")
@NotEmpty(message = "变更的ids不能为空")
private List<String> ids;
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.base.dal.dataobject.tmpltp;
import lombok.*;
import java.util.*;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BusinessBaseDO;
/**
* 部门与实例关联 DO
*
* @author 后台管理
*/
@TableName("bse_dept_insc_rel")
@KeySequence("bse_dept_insc_rel_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class DepartmentInstanceRelativityDO extends BusinessBaseDO {
/**
* 主键
*/
@TableId(type = IdType.INPUT)
private String id;
/**
* 部门主键
*/
@TableField("CPN_DEPT_ID")
private String companyDepartmentId;
/**
* 模板实例主键
*/
@TableField("TMPL_INSC_ID")
private String templateInstanceId;
}

View File

@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.base.dal.dataobject.tmpltp;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BusinessBaseDO;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
@@ -22,7 +23,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class TemplateInstanceDO extends BaseDO {
public class TemplateInstanceDO extends BusinessBaseDO {
@@ -34,7 +35,7 @@ public class TemplateInstanceDO extends BaseDO {
/**
* 分类树主键
*/
private Long typeId;
private Long tpId;
/**
* 模板名称
*/
@@ -42,50 +43,50 @@ public class TemplateInstanceDO extends BaseDO {
/**
* 模板编码
*/
private String coding;
private String cdg;
/**
* 模板描述
*/
private String description;
private String dsp;
/**
* 实例文件内容
*/
private String content;
private String cntt;
/**
* 原始文件内容
*/
private String originalContent;
private String origCntt;
/**
* 文件类型
*/
private String fileType;
private String fileTp;
/**
* 版本号;如v1.0
*/
private String version;
private String ver;
/**
* 状态
*/
private String status;
/**
* 公司编号
*/
private Long companyId;
/**
* 公司名称
*/
private String companyName;
/**
* 部门编号
*/
private Long deptId;
/**
* 部门名称
*/
private String deptName;
/**
* 岗位编号
*/
private Long postId;
private String sts;
// /**
// * 公司编号
// */
// private Long companyId;
// /**
// * 公司名称
// */
// private String companyName;
// /**
// * 部门编号
// */
// private Long deptId;
// /**
// * 部门名称
// */
// private String deptName;
// /**
// * 岗位编号
// */
// private Long postId;
}

View File

@@ -35,16 +35,16 @@ public class TemplateInstanceDataDO extends BusinessBaseDO {
* 关联实例主键
*/
@TableField("INSC_ID")
private String instanceId;
private String inscId;
/**
* 字段标识;关联字段库
*/
@TableField("FLD_KY")
private String fieldKey;
private String fldKy;
/**
* 用户填写的值
*/
@TableField("FLD_VAL")
private String fieldValue;
private String fldVal;
}

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.base.dal.mysql.tmpltp;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityPageReqVO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.DepartmentInstanceRelativityDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 部门与实例关联 Mapper
*
* @author 后台管理
*/
@Mapper
public interface DepartmentInstanceRelativityMapper extends BaseMapperX<DepartmentInstanceRelativityDO> {
default PageResult<DepartmentInstanceRelativityDO> selectPage(DepartmentInstanceRelativityPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<DepartmentInstanceRelativityDO>()
.eqIfPresent(DepartmentInstanceRelativityDO::getCompanyDepartmentId, reqVO.getCompanyDepartmentId())
.eqIfPresent(DepartmentInstanceRelativityDO::getTemplateInstanceId, reqVO.getTemplateInstanceId())
.betweenIfPresent(DepartmentInstanceRelativityDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DepartmentInstanceRelativityDO::getId));
}
}

View File

@@ -21,9 +21,9 @@ public interface TemplateInstanceDataMapper extends BaseMapperX<TemplateInstance
default PageResult<TemplateInstanceDataDO> selectPage(TemplateInstanceDataPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TemplateInstanceDataDO>()
.eqIfPresent(TemplateInstanceDataDO::getInstanceId, reqVO.getInstanceId())
.eqIfPresent(TemplateInstanceDataDO::getFieldKey, reqVO.getFieldKey())
.eqIfPresent(TemplateInstanceDataDO::getFieldValue, reqVO.getFieldValue())
.eqIfPresent(TemplateInstanceDataDO::getInscId, reqVO.getInscId())
.eqIfPresent(TemplateInstanceDataDO::getFldKy, reqVO.getFldKy())
.eqIfPresent(TemplateInstanceDataDO::getFldVal, reqVO.getFldVal())
.betweenIfPresent(TemplateInstanceDataDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(TemplateInstanceDataDO::getId));
}

View File

@@ -21,15 +21,15 @@ public interface TemplateInstanceMapper extends BaseMapperX<TemplateInstanceDO>
default PageResult<TemplateInstanceDO> selectPage(TemplateInstancePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TemplateInstanceDO>()
.eqIfPresent(TemplateInstanceDO::getTypeId, reqVO.getTypeId())
.eqIfPresent(TemplateInstanceDO::getTpId, reqVO.getTpId())
.likeIfPresent(TemplateInstanceDO::getName, reqVO.getName())
.eqIfPresent(TemplateInstanceDO::getCoding, reqVO.getCoding())
.eqIfPresent(TemplateInstanceDO::getDescription, reqVO.getDescription())
.eqIfPresent(TemplateInstanceDO::getContent, reqVO.getContent())
.eqIfPresent(TemplateInstanceDO::getOriginalContent, reqVO.getOriginalContent())
.eqIfPresent(TemplateInstanceDO::getFileType, reqVO.getFileType())
.eqIfPresent(TemplateInstanceDO::getVersion, reqVO.getVersion())
.eqIfPresent(TemplateInstanceDO::getStatus, reqVO.getStatus())
.eqIfPresent(TemplateInstanceDO::getCdg, reqVO.getCdg())
.eqIfPresent(TemplateInstanceDO::getDsp, reqVO.getDsp())
.eqIfPresent(TemplateInstanceDO::getCntt, reqVO.getCntt())
.eqIfPresent(TemplateInstanceDO::getOrigCntt, reqVO.getOrigCntt())
.eqIfPresent(TemplateInstanceDO::getFileTp, reqVO.getFileTp())
.eqIfPresent(TemplateInstanceDO::getVer, reqVO.getVer())
.eqIfPresent(TemplateInstanceDO::getSts, reqVO.getSts())
.betweenIfPresent(TemplateInstanceDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(TemplateInstanceDO::getId));
}

View File

@@ -0,0 +1,65 @@
package cn.iocoder.yudao.module.base.service.tmpltp;
import java.util.*;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityPageReqVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityRespVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativitySaveReqVO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.DepartmentInstanceRelativityDO;
import jakarta.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 部门与实例关联 Service 接口
*
* @author 后台管理
*/
public interface DepartmentInstanceRelativityService {
/**
* 创建部门与实例关联
*
* @param createReqVO 创建信息
* @return 编号
*/
DepartmentInstanceRelativityRespVO createDepartmentInstanceRelativity(@Valid DepartmentInstanceRelativitySaveReqVO createReqVO);
/**
* 更新部门与实例关联
*
* @param updateReqVO 更新信息
*/
void updateDepartmentInstanceRelativity(@Valid DepartmentInstanceRelativitySaveReqVO updateReqVO);
/**
* 删除部门与实例关联
*
* @param id 编号
*/
void deleteDepartmentInstanceRelativity(String id);
/**
* 批量删除部门与实例关联
*
* @param ids 编号
*/
void deleteDepartmentInstanceRelativityListByIds(List<Long> ids);
/**
* 获得部门与实例关联
*
* @param id 编号
* @return 部门与实例关联
*/
DepartmentInstanceRelativityDO getDepartmentInstanceRelativity(String id);
/**
* 获得部门与实例关联分页
*
* @param pageReqVO 分页查询
* @return 部门与实例关联分页
*/
PageResult<DepartmentInstanceRelativityDO> getDepartmentInstanceRelativityPage(DepartmentInstanceRelativityPageReqVO pageReqVO);
}

View File

@@ -0,0 +1,97 @@
package cn.iocoder.yudao.module.base.service.tmpltp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityPageReqVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativityRespVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.DepartmentInstanceRelativitySaveReqVO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.DepartmentInstanceRelativityDO;
import cn.iocoder.yudao.module.base.dal.mysql.tmpltp.DepartmentInstanceRelativityMapper;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.tmpltp.enums.ErrorCodeConstants.DEPARTMENT_INSTANCE_RELATIVITY_NOT_EXISTS;
/**
* 部门与实例关联 Service 实现类
*
* @author 后台管理
*/
@Service
@Validated
public class DepartmentInstanceRelativityServiceImpl implements DepartmentInstanceRelativityService {
@Resource
private DepartmentInstanceRelativityMapper departmentInstanceRelativityMapper;
@Override
public DepartmentInstanceRelativityRespVO createDepartmentInstanceRelativity(DepartmentInstanceRelativitySaveReqVO createReqVO) {
// 插入
DepartmentInstanceRelativityDO departmentInstanceRelativity = BeanUtils.toBean(createReqVO, DepartmentInstanceRelativityDO.class);
departmentInstanceRelativityMapper.insert(departmentInstanceRelativity);
// 返回
return BeanUtils.toBean(departmentInstanceRelativity, DepartmentInstanceRelativityRespVO.class);
}
@Override
public void updateDepartmentInstanceRelativity(DepartmentInstanceRelativitySaveReqVO updateReqVO) {
// 校验存在
validateDepartmentInstanceRelativityExists(updateReqVO.getId());
// 更新
DepartmentInstanceRelativityDO updateObj = BeanUtils.toBean(updateReqVO, DepartmentInstanceRelativityDO.class);
departmentInstanceRelativityMapper.updateById(updateObj);
}
@Override
public void deleteDepartmentInstanceRelativity(String id) {
// 校验存在
validateDepartmentInstanceRelativityExists(id);
// 删除
departmentInstanceRelativityMapper.deleteById(id);
}
@Override
public void deleteDepartmentInstanceRelativityListByIds(List<Long> ids) {
// 校验存在
validateDepartmentInstanceRelativityExists(ids);
// 删除
departmentInstanceRelativityMapper.deleteByIds(ids);
}
private void validateDepartmentInstanceRelativityExists(List<Long> ids) {
List<DepartmentInstanceRelativityDO> list = departmentInstanceRelativityMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(DEPARTMENT_INSTANCE_RELATIVITY_NOT_EXISTS);
}
}
private void validateDepartmentInstanceRelativityExists(String id) {
if (departmentInstanceRelativityMapper.selectById(id) == null) {
throw exception(DEPARTMENT_INSTANCE_RELATIVITY_NOT_EXISTS);
}
}
@Override
public DepartmentInstanceRelativityDO getDepartmentInstanceRelativity(String id) {
return departmentInstanceRelativityMapper.selectById(id);
}
@Override
public PageResult<DepartmentInstanceRelativityDO> getDepartmentInstanceRelativityPage(DepartmentInstanceRelativityPageReqVO pageReqVO) {
return departmentInstanceRelativityMapper.selectPage(pageReqVO);
}
}

View File

@@ -63,4 +63,21 @@ public interface TemplateInstanceDataService {
*/
PageResult<TemplateInstanceDataDO> getTemplateInstanceDataPage(TemplateInstanceDataPageReqVO pageReqVO);
/**
* 设置实例字段值
*
* @param pageReqVOS 保存参数
* @return 布尔类型
*/
boolean setTemplateInstanceData(List<TemplateInstanceDataDO> pageReqVOS);
/**
* 清空实例字段值
*
* @param instanceId ids
* @return 布尔类型
*/
boolean clearTemplateInstanceData(String instanceId,List<Long> valIds);
}

View File

@@ -6,8 +6,12 @@ import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TemplateInstance
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TemplateInstanceDataSaveReqVO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.TemplateInstanceDataDO;
import cn.iocoder.yudao.module.base.dal.mysql.tmpltp.TemplateInstanceDataMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.*;
@@ -18,6 +22,10 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.base.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.tmpltp.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.tmpltp.enums.ErrorCodeConstants.TEMPLATE_INSTANCE_DATA_NOT_EXISTS;
/**
@@ -89,4 +97,27 @@ public class TemplateInstanceDataServiceImpl implements TemplateInstanceDataServ
return templateInstanceDataMapper.selectPage(pageReqVO);
}
@Override
@Transactional
public boolean setTemplateInstanceData(List<TemplateInstanceDataDO> pageReqVOS) {
if (CollUtil.isEmpty(pageReqVOS)) {
throw exception(PARAMS_IS_NULL_OR_ERR);
}
return templateInstanceDataMapper.insertBatch(pageReqVOS);
}
@Override
@Transactional
public boolean clearTemplateInstanceData(String instanceId, List<Long> valIds) {
if (CollUtil.isEmpty(valIds)|| instanceId.isEmpty()) {
throw exception(PARAMS_IS_NULL_OR_ERR);
}
int update = templateInstanceDataMapper.update(new LambdaUpdateWrapper<TemplateInstanceDataDO>().eq(TemplateInstanceDataDO::getInscId, instanceId).in(TemplateInstanceDataDO::getFldKy).set(TemplateInstanceDataDO::getFldVal, ""));
if (valIds.size()!= update){
throw exception(OPERATION_FAIL);
}
return true;
}
}

View File

@@ -6,12 +6,15 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TemplateInstancePageReqVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TemplateInstanceRespVO;
import cn.iocoder.yudao.module.base.controller.admin.templtp.vo.TemplateInstanceSaveReqVO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.DepartmentInstanceRelativityDO;
import cn.iocoder.yudao.module.base.dal.dataobject.tmpltp.TemplateInstanceDO;
import cn.iocoder.yudao.module.base.dal.mysql.tmpltp.DepartmentInstanceRelativityMapper;
import cn.iocoder.yudao.module.base.dal.mysql.tmpltp.TemplateInstanceMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -29,13 +32,25 @@ public class TemplateInstanceServiceImpl implements TemplateInstanceService {
@Resource
private TemplateInstanceMapper templateInstanceMapper;
@Resource
private DepartmentInstanceRelativityMapper departmentInstanceRelativityMapper;
@Override
public TemplateInstanceRespVO createTemplateInstance(TemplateInstanceSaveReqVO createReqVO) {
// 插入
TemplateInstanceDO templateInstance = BeanUtils.toBean(createReqVO, TemplateInstanceDO.class);
templateInstanceMapper.insert(templateInstance);
// 返回
//构建使用部门
List<DepartmentInstanceRelativityDO> departmentInstanceRelativityDOS = new ArrayList<>();
createReqVO.getDeptIds().forEach(deptId ->{
DepartmentInstanceRelativityDO departmentInstanceRelativityDO = new DepartmentInstanceRelativityDO();
departmentInstanceRelativityDO.setTemplateInstanceId(String.valueOf(templateInstance.getId()));
departmentInstanceRelativityDO.setCompanyId(deptId);
departmentInstanceRelativityDOS.add(departmentInstanceRelativityDO);
});
departmentInstanceRelativityMapper.insertBatch(departmentInstanceRelativityDOS);
// 插入使用范围
return BeanUtils.toBean(templateInstance, TemplateInstanceRespVO.class);
}
@@ -48,7 +63,7 @@ public class TemplateInstanceServiceImpl implements TemplateInstanceService {
// String originalContent = templateInstanceDO.getOriginalContent();
// 更新
TemplateInstanceDO updateObj = BeanUtils.toBean(updateReqVO, TemplateInstanceDO.class);
updateObj.setOriginalContent(null); //重新赋值,防止原始文件被更改
updateObj.setOrigCntt(null); //重新赋值,防止原始文件被更改
templateInstanceMapper.updateById(updateObj);
}

View File

@@ -15,7 +15,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
*
* @author 后台管理
*/
public interface TmplTpService extends IService<TmplTpDO> {
public interface TmplTpService extends IService<TmplTpDO> {
/**
* 创建模板分类
@@ -40,10 +40,10 @@ public interface TmplTpService extends IService<TmplTpDO> {
void deleteTmplTp(List<Long> ids);
/**
* 批量删除模板分类
*
* @param ids 编号
*/
* 批量删除模板分类
*
* @param ids 编号
*/
void deleteTmplTpListByIds(List<Long> ids);
/**
@@ -62,9 +62,48 @@ public interface TmplTpService extends IService<TmplTpDO> {
*/
PageResult<TmplTpDO> getTmplTpPage(TmplTpPageReqVO pageReqVO);
/**
* 获得字段回显
*
* @param id 编号
* @return 模板分类
*/
List<TmplFldRespVO> getField(Long id);
List<TmplFldRespVO> getField(Long id);
List<TmplItmRespVO> getClause(Long id);
/**
* 获得条款回显
*
* @param id 编号
* @return 模板分类
*/
List<TmplItmRespVO> getClause(Long id);
/**
* 树结构
*
* @return 模板分类
*/
List<TmplTpTreeVO> buildTree();
/**
* 更新模板分类状态
*
* @param id 编号
* @param status 状态
*/
void updateStatus(Long id, String status);
/**
* 字段编辑
*
* @param reqVO 状态
*/
void fieldEdit(TmplTpEditOrDeleteReqVO reqVO);
/**
* 条款编辑
*
* @param reqVO 状态
*/
void ltmEdit(TmplTpEditOrDeleteReqVO reqVO);
}

View File

@@ -93,6 +93,9 @@ public class TmplTpServiceImpl extends ServiceImpl<TmplTpMapper, TmplTpDO> imple
// }
// 删除
baseMapper.deleteByIds(ids);
//删除对应的关联信息
tmplFldRelMapper.delete(Wrappers.<TmplFldRelDO>lambdaQuery().in(TmplFldRelDO::getTmplTpId, ids));
tmplItmRelMapper.delete(Wrappers.<TmplItmRelDO>lambdaQuery().in(TmplItmRelDO::getTmplTpId, ids));
}
@Override
@@ -189,6 +192,7 @@ public class TmplTpServiceImpl extends ServiceImpl<TmplTpMapper, TmplTpDO> imple
baseMapper.update(Wrappers.<TmplTpDO>lambdaUpdate().set(TmplTpDO::getSts, status).eq(TmplTpDO::getId, id));
}
private boolean validateStatusUpdate(Long id, String status) {
TmplTpDO tmplTpDO = baseMapper.getTmplTpById(id);
String currentSts = tmplTpDO.getSts();
@@ -205,19 +209,60 @@ public class TmplTpServiceImpl extends ServiceImpl<TmplTpMapper, TmplTpDO> imple
return currentStatus.isTransitionAllowed(status);
}
private boolean validateStatusCanDelete(List<Long> ids) {
Set<String> sts = listByIds(ids).stream().map(TmplTpDO::getSts).collect(Collectors.toSet());
List<Boolean> result = new ArrayList<>();
sts.forEach(status -> {
StatusEnum currentStatus = StatusEnum.fromCode(status);
boolean transitionAllowed = false;
if (currentStatus != null) {
transitionAllowed = currentStatus.isTransitionAllowed(status);
} else {
result.add(false);
}
result.add(transitionAllowed);
});
return !result.contains(false);
// private boolean validateStatusCanDelete(List<Long> ids) {
// Set<String> sts = listByIds(ids).stream().map(TmplTpDO::getSts).collect(Collectors.toSet());
// List<Boolean> result = new ArrayList<>();
// sts.forEach(status -> {
// StatusEnum currentStatus = StatusEnum.fromCode(status);
// boolean transitionAllowed = false;
// if (currentStatus != null) {
// transitionAllowed = currentStatus.isTransitionAllowed(status);
// } else {
// result.add(false);
// }
// result.add(transitionAllowed);
// });
// return !result.contains(false);
// }
@Override
public void fieldEdit(TmplTpEditOrDeleteReqVO reqVO) {
if ("create".equals(reqVO.getType())) {
List<TmplFldRelDO> tmplFldRelDOS = new ArrayList<>();
reqVO.getIds().forEach(id -> {
TmplFldRelDO tmplFldRelDO = new TmplFldRelDO();
tmplFldRelDO.setTmplTpId(reqVO.getTpId());
tmplFldRelDO.setTpFldId(id);
tmplFldRelDOS.add(tmplFldRelDO);
});
tmplFldRelMapper.insertBatch(tmplFldRelDOS);
}else if ("delete".equals(reqVO.getType())) {
tmplFldRelMapper.delete(Wrappers.<TmplFldRelDO>lambdaQuery()
.eq(TmplFldRelDO::getTmplTpId, reqVO.getTpId())
.in(TmplFldRelDO::getTpFldId, reqVO.getIds()));
}else {
throw exception(ILLEGAL_OPERATION_TYPE);
}
}
@Override
public void ltmEdit(TmplTpEditOrDeleteReqVO reqVO) {
if ("create".equals(reqVO.getType())) {
List<TmplItmRelDO> tmplItmRelDOS = new ArrayList<>();
reqVO.getIds().forEach(id -> {
TmplItmRelDO tmplItmRelDO = new TmplItmRelDO();
tmplItmRelDO.setTmplTpId(reqVO.getTpId());
tmplItmRelDO.setItmFldId(id);
tmplItmRelDOS.add(tmplItmRelDO);
});
tmplItmRelMapper.insertBatch(tmplItmRelDOS);
}else if ("delete".equals(reqVO.getType())) {
tmplItmRelMapper.delete(Wrappers.<TmplItmRelDO>lambdaQuery()
.eq(TmplItmRelDO::getTmplTpId, reqVO.getTpId())
.in(TmplItmRelDO::getItmFldId, reqVO.getIds()));
}else {
throw exception(ILLEGAL_OPERATION_TYPE);
}
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.base.dal.mysql.tmpltp.DepartmentInstanceRelativityMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@@ -18,6 +18,8 @@
INNER JOIN BSE_TMPL_TP tp ON rel.TMPL_TP_ID = tp.ID
AND tp.tenant_id = 1
WHERE itm.DELETED = 0
AND rel.DELETED = 0
AND tp.DELETED = 0
AND tp.id = #{id}
</select>

View File

@@ -35,46 +35,49 @@ public class ErpConfig {
* 调用ERP接口获取公司数据
*/
public JSONArray fetchDataFromERP(String funcnr, Map<String, Object> req) {
// 构建完整URL
String url = "http://" + erpAddress + "/api/rfc/get";
// 构建请求参数
JSONObject requestBody = new JSONObject();
requestBody.put("sapsys", sapsys);
requestBody.put("funcnr", funcnr); // 获取枚举值
if (req != null) {
requestBody.put("req", req);
}
try {
// 构建完整URL
String url = "http://" + erpAddress + "/api/rfc/get";
// 构建请求参数
JSONObject requestBody = new JSONObject();
requestBody.put("sapsys", sapsys);
requestBody.put("funcnr", funcnr); // 获取枚举值
if (req != null) {
requestBody.put("req", req);
}
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 创建HTTP请求实体
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers);
// 创建HTTP请求实体
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers);
// 发送POST请求
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
// 发送POST请求
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
// 解析响应结果
String responseBody = response.getBody();
if (responseBody == null) {
log.warn("ERP接口返回空响应");
return null;
}
// 解析响应结果
String responseBody = response.getBody();
if (responseBody.isEmpty()) {
log.warn("无所选条件的查询数据"+req);
}
JSONObject jsonResponse = JSON.parseObject(responseBody);
if (jsonResponse == null) {
log.warn("ERP接口响应无法解析为JSON");
return null;
}
JSONObject jsonResponse = JSON.parseObject(responseBody);
if (jsonResponse == null) {
log.warn("ERP接口响应无法解析为JSON");
}
// 正确获取E_DATA数组
JSONObject dataObject = jsonResponse.getJSONObject("data");
if (dataObject != null && "S".equals(dataObject.getString("E_FLAG"))) {
return dataObject.getJSONArray("E_DATA");
} else {
log.warn("ERP接口调用失败或返回错误标志");
// 正确获取E_DATA数组
JSONObject dataObject = jsonResponse.getJSONObject("data");
if (dataObject != null && "S".equals(dataObject.getString("E_FLAG"))) {
return dataObject.getJSONArray("E_DATA");
} else {
log.warn("ERP接口调用失败或返回错误标志");
return null;
}
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
return null;
}
}
@@ -91,11 +94,29 @@ public class ErpConfig {
// 提取有效的 BUKRS 编号
List<String> existingNumbers = new ArrayList<>();
if (dataArray != null) {
// 将dataKey按"-"分割成多个部分
String[] keyParts = dataKey.split("-");
existingNumbers = dataArray.stream()
.filter(Objects::nonNull)
.map(dataJson -> ((JSONObject) dataJson).getString(dataKey))
.filter(Objects::nonNull)
.map(String::trim) // 去除字符串首尾空格
.map(dataJson -> {
JSONObject jsonObject = (JSONObject) dataJson;
// 根据每个部分逐级获取值并拼接
StringBuilder sb = new StringBuilder();
for (String part : keyParts) {
String value = jsonObject.getString(part);
if (value != null) {
if (sb.length() > 0) {
sb.append("-");
}
sb.append(value.trim());
} else {
// 如果某一部分为空,则整个值视为无效
return null;
}
}
return sb.toString();
})
.filter(Objects::nonNull) // 过滤掉无效值
.collect(Collectors.toList());
}
@@ -121,4 +142,26 @@ public class ErpConfig {
// 使用 Redis 更新缓存数据
redisTemplate.opsForValue().set(key, allnumbers);
}
public List<String> getRedisCache(String key) {
// 使用 Redis 更新缓存数据
return (List<String>)redisTemplate.opsForValue().get("erp"+key);
}
public Map<String, String> numbersMap(String key) {
// 使用 Redis 获取缓存数据
Map<String, String> result = (Map<String, String>) redisTemplate.opsForValue().get(key);
return result;
}
// public void updateRedisCache(String key, List<String> allnumbers) {
// // 使用 Redis 更新缓存数据
// redisTemplate.opsForValue().set(key, allnumbers);
// }
//
// public List<String> getRedisCache(String key) {
// // 使用 Redis 更新缓存数据
// return (List<String>)redisTemplate.opsForValue().get("erp"+key);
// }
}

View File

@@ -14,7 +14,7 @@ public class OftenEnum {
//接口编号枚举
public enum FuncnrEnum {
公司代码("001", "BUKRS", ""),
工厂信息("002", "", ""),
工厂信息("002", "WERKS", ""),
客商信息("003", "PARTNER", "DATUM"),
成本中心("004", "", ""),
内部订单("005", "", ""),
@@ -22,11 +22,11 @@ public class OftenEnum {
采购组织("007", "", ""),
销售组织("008", "", ""),
合同信息("009", "", ""),
资产卡片("010", "", ""),
资产卡片("010", "ANLN1-BUKRS", "ERDAT"),
库存信息("011", "", ""),
辅组编码("012", "", ""),
生产订单("013", "", ""),
BOM清单("014", "", ""),
BOM清单("014", "MATNR-STLAL-WERKS", ""),
工艺路线("015", "", ""),
生产版本("016", "", ""),
生产投料("017", "", ""),

View File

@@ -101,4 +101,11 @@ public class ErpAssetController {
BeanUtils.toBean(list, ErpAssetRespVO.class));
}
@PostMapping("/getErpAssetTask")
@Operation(summary = "定时获得erp更新资产卡片")
@PreAuthorize("@ss.hasPermission('sply:erp-asset:query')")
public void getErpCompanyTask() {
erpAssetService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpBomController {
BeanUtils.toBean(list, ErpBomRespVO.class));
}
@PostMapping("/getErpBomTask")
@Operation(summary = "定时获得erp更新物料清单(BOM)")
@PreAuthorize("@ss.hasPermission('sply:erp-bom:query')")
public void getErpBomTask() {
erpBomService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,10 @@ public class ErpContractController {
BeanUtils.toBean(list, ErpContractRespVO.class));
}
@PostMapping("/getErpContractTask")
@Operation(summary = "定时获得erp更新合同")
@PreAuthorize("@ss.hasPermission('sply:erp-contract:query')")
public void getErpContractTask() {
erpContractService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,12 @@ public class ErpCostcenterController {
BeanUtils.toBean(list, ErpCostcenterRespVO.class));
}
@PostMapping("/getErpCostcenterTask")
@Operation(summary = "定时获得erp更新成本中心")
@PreAuthorize("@ss.hasPermission('sply:erp-costcenter:query')")
public void getErpCostcenterTask() {
erpCostcenterService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpFactoryController {
BeanUtils.toBean(list, ErpFactoryRespVO.class));
}
@PostMapping("/getErpFactoryTask")
@Operation(summary = "定时获得erp工厂数据")
@PreAuthorize("@ss.hasPermission('sply:erp-factory:create')")
public void getErpFactoryTask() {
erpFactoryService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpInternalOrderController {
BeanUtils.toBean(list, ErpInternalOrderRespVO.class));
}
@PostMapping("/getErpInternalOrderTask")
@Operation(summary = "定时获得erp更新内部订单数据")
@PreAuthorize("@ss.hasPermission('sply:erp-internal-order:create')")
public void getErpInternalOrderTask() {
erpInternalOrderService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpProcessController {
BeanUtils.toBean(list, ErpProcessRespVO.class));
}
@PostMapping("/getErpProcessTask")
@Operation(summary = "定时获得erp更新工艺路线")
@PreAuthorize("@ss.hasPermission('sply:erp-process:create')")
public void getErpProcessTask() {
erpProcessService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpProductiveOrderController {
BeanUtils.toBean(list, ErpProductiveOrderRespVO.class));
}
@PostMapping("/getErpProductiveOrderTask")
@Operation(summary = "定时获得erp更新生产订单")
@PreAuthorize("@ss.hasPermission('sply:erp-productive-order:create')")
public void getErpProductiveOrderTask() {
erpProductiveOrderService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpProductiveVersionController {
BeanUtils.toBean(list, ErpProductiveVersionRespVO.class));
}
@PostMapping("/getErpProductiveVersionTask")
@Operation(summary = "定时获得erp更新生产版本")
@PreAuthorize("@ss.hasPermission('sply:erp-productive-version:create')")
public void getErpProductiveVersionTask() {
erpProductiveVersionService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpPurchaseOrganizationController {
BeanUtils.toBean(list, ErpPurchaseOrganizationRespVO.class));
}
@PostMapping("/getErpPurchaseOrganizationTask")
@Operation(summary = "定时获得erp更新采购组织")
@PreAuthorize("@ss.hasPermission('sply:erp-purchase-organization:create')")
public void getErpPurchaseOrganizationTask() {
erpPurchaseOrganizationService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpSalesOrganizationController {
BeanUtils.toBean(list, ErpSalesOrganizationRespVO.class));
}
@PostMapping("/getErpSalesOrganizationTask")
@Operation(summary = "定时获得erp更新销售组织")
@PreAuthorize("@ss.hasPermission('sply:erp-sales-organization:create')")
public void getErpSalesOrganizationTask() {
erpSalesOrganizationService.callErpRfcInterface();
}
}

View File

@@ -101,4 +101,11 @@ public class ErpWarehouseController {
BeanUtils.toBean(list, ErpWarehouseRespVO.class));
}
@PostMapping("/getErpWarehouseTask")
@Operation(summary = "定时获得erp更新库位")
@PreAuthorize("@ss.hasPermission('sply:erp-warehouse:create')")
public void getErpWarehouseTask() {
erpWarehouseService.callErpRfcInterface();
}
}

View File

@@ -54,8 +54,7 @@ public class ErpAssetPageReqVO extends PageParam {
private LocalDateTime[] depreciationStartDate;
@Schema(description = "计划年使用期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] planYearDate;
private String planYearDate;
@Schema(description = "成本中心编码")
private String costcenterNumber;

View File

@@ -67,7 +67,7 @@ public class ErpAssetRespVO {
@Schema(description = "计划年使用期")
@ExcelProperty("计划年使用期")
private LocalDateTime planYearDate;
private String planYearDate;
@Schema(description = "成本中心编码")
@ExcelProperty("成本中心编码")

View File

@@ -56,7 +56,7 @@ public class ErpAssetSaveReqVO {
private LocalDateTime depreciationStartDate;
@Schema(description = "计划年使用期")
private LocalDateTime planYearDate;
private String planYearDate;
@Schema(description = "成本中心编码")
private String costcenterNumber;

View File

@@ -11,7 +11,7 @@ import java.math.BigDecimal;
public class ErpBomPageReqVO extends PageParam {
@Schema(description = "工厂编码")
private BigDecimal factoryNumber;
private String factoryNumber;
@Schema(description = "顶层物料编码")
private String upMaterial;

View File

@@ -18,7 +18,7 @@ public class ErpBomRespVO {
@Schema(description = "工厂编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("工厂编码")
private BigDecimal factoryNumber;
private String factoryNumber;
@Schema(description = "顶层物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("顶层物料编码")

View File

@@ -16,7 +16,7 @@ public class ErpBomSaveReqVO {
@Schema(description = "工厂编码", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "工厂编码不能为空")
private BigDecimal factoryNumber;
private String factoryNumber;
@Schema(description = "顶层物料编码", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "顶层物料编码不能为空")

View File

@@ -14,7 +14,7 @@ import java.time.LocalDateTime;
@TableName("sply_erp_ast")
@KeySequence("sply_erp_ast_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -22,7 +22,7 @@ import java.time.LocalDateTime;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpAssetDO extends BaseDO {
public class ErpAssetDO{
@@ -95,7 +95,7 @@ public class ErpAssetDO extends BaseDO {
* 计划年使用期
*/
@TableField("PLN_YR_DT")
private LocalDateTime planYearDate;
private String planYearDate;
/**
* 成本中心编码
*/

View File

@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import java.math.BigDecimal;
import java.util.List;
/**
* ERP物料清单(BOM) DO
*
@@ -13,7 +15,7 @@ import java.math.BigDecimal;
@TableName("sply_erp_bm")
@KeySequence("sply_erp_bm_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,9 +23,7 @@ import java.math.BigDecimal;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpBomDO extends BaseDO {
public class ErpBomDO {
/**
* 主键
@@ -34,7 +34,7 @@ public class ErpBomDO extends BaseDO {
* 工厂编码
*/
@TableField("FACT_NUM")
private BigDecimal factoryNumber;
private String factoryNumber;
/**
* 顶层物料编码
*/
@@ -61,4 +61,7 @@ public class ErpBomDO extends BaseDO {
@TableField("UNT")
private String unit;
@TableField(fill = FieldFill.INSERT)
private List<ErpBomDetailDO> erpBomDetailDOList;
}

View File

@@ -13,7 +13,7 @@ import java.math.BigDecimal;
@TableName("sply_erp_bm_dtl")
@KeySequence("sply_erp_bm_dtl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpBomDetailDO extends BaseDO {
public class ErpBomDetailDO {

View File

@@ -13,7 +13,7 @@ import java.time.LocalDateTime;
@TableName("sply_erp_cctr")
@KeySequence("sply_erp_cctr_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,7 +21,7 @@ import java.time.LocalDateTime;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpCostcenterDO extends BaseDO {
public class ErpCostcenterDO {

View File

@@ -11,7 +11,7 @@ import lombok.*;
@TableName("sply_erp_fact")
@KeySequence("sply_erp_fact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -19,7 +19,7 @@ import lombok.*;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpFactoryDO extends BaseDO {
public class ErpFactoryDO {
@@ -42,6 +42,6 @@ public class ErpFactoryDO extends BaseDO {
* 公司编号
*/
@TableField("CPN_ID")
private Long companyId;
private String companyId;
}

View File

@@ -11,7 +11,7 @@ import lombok.*;
@TableName("sply_erp_intl_ord")
@KeySequence("sply_erp_intl_ord_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -19,7 +19,7 @@ import lombok.*;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpInternalOrderDO extends BaseDO {
public class ErpInternalOrderDO {

View File

@@ -13,7 +13,7 @@ import java.math.BigDecimal;
@TableName("sply_erp_prcs")
@KeySequence("sply_erp_prcs_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpProcessDO extends BaseDO {
public class ErpProcessDO {

View File

@@ -13,7 +13,7 @@ import java.math.BigDecimal;
@TableName("sply_erp_prcs_dtl")
@KeySequence("sply_erp_prcs_dtl_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpProcessDetailDO extends BaseDO {
public class ErpProcessDetailDO {

View File

@@ -13,7 +13,7 @@ import java.time.LocalDateTime;
@TableName("sply_erp_pdtv_ord")
@KeySequence("sply_erp_pdtv_ord_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,7 +21,7 @@ import java.time.LocalDateTime;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpProductiveOrderDO extends BaseDO {
public class ErpProductiveOrderDO{

View File

@@ -13,7 +13,7 @@ import java.math.BigDecimal;
@TableName("sply_erp_pdtv_ver")
@KeySequence("sply_erp_pdtv_ver_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -21,7 +21,7 @@ import java.math.BigDecimal;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpProductiveVersionDO extends BaseDO {
public class ErpProductiveVersionDO {

View File

@@ -11,7 +11,7 @@ import lombok.*;
@TableName("sply_erp_prch_orgz")
@KeySequence("sply_erp_prch_orgz_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -19,7 +19,7 @@ import lombok.*;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpPurchaseOrganizationDO extends BaseDO {
public class ErpPurchaseOrganizationDO {

View File

@@ -11,7 +11,7 @@ import lombok.*;
@TableName("sply_erp_sale_orgz")
@KeySequence("sply_erp_sale_orgz_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@@ -19,7 +19,7 @@ import lombok.*;
/**
* 支持业务基类继承isBusiness=true 时继承 BusinessBaseDO否则继承 BaseDO
*/
public class ErpSalesOrganizationDO extends BaseDO {
public class ErpSalesOrganizationDO {

View File

@@ -29,7 +29,7 @@ public interface ErpAssetMapper extends BaseMapperX<ErpAssetDO> {
.eqIfPresent(ErpAssetDO::getAssetDescription, reqVO.getAssetDescription())
.eqIfPresent(ErpAssetDO::getAssetDescriptionAttach, reqVO.getAssetDescriptionAttach())
.betweenIfPresent(ErpAssetDO::getDepreciationStartDate, reqVO.getDepreciationStartDate())
.betweenIfPresent(ErpAssetDO::getPlanYearDate, reqVO.getPlanYearDate())
.eqIfPresent(ErpAssetDO::getPlanYearDate, reqVO.getPlanYearDate())
.eqIfPresent(ErpAssetDO::getCostcenterNumber, reqVO.getCostcenterNumber())
.eqIfPresent(ErpAssetDO::getDutyCostcenterNumber, reqVO.getDutyCostcenterNumber())
.orderByDesc(ErpAssetDO::getId));

View File

@@ -5,7 +5,11 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* ERP工厂 Mapper
@@ -22,4 +26,6 @@ public interface ErpFactoryMapper extends BaseMapperX<ErpFactoryDO> {
.orderByDesc(ErpFactoryDO::getId));
}
void updateBatch(@Param("toUpdate") List<ErpFactoryDO> toUpdate);
}

View File

@@ -61,4 +61,5 @@ public interface ErpAssetService {
*/
PageResult<ErpAssetDO> getErpAssetPage(ErpAssetPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpAssetSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpAssetDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpAssetMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_ASSET_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP资产卡片 Service 实现类
@@ -29,6 +41,9 @@ public class ErpAssetServiceImpl implements ErpAssetService {
@Resource
private ErpAssetMapper erpAssetMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpAssetRespVO createErpAsset(ErpAssetSaveReqVO createReqVO) {
// 插入
@@ -56,12 +71,12 @@ public class ErpAssetServiceImpl implements ErpAssetService {
}
@Override
public void deleteErpAssetListByIds(List<Long> ids) {
public void deleteErpAssetListByIds(List<Long> ids) {
// 校验存在
validateErpAssetExists(ids);
// 删除
erpAssetMapper.deleteByIds(ids);
}
}
private void validateErpAssetExists(List<Long> ids) {
List<ErpAssetDO> list = erpAssetMapper.selectByIds(ids);
@@ -86,4 +101,128 @@ public class ErpAssetServiceImpl implements ErpAssetService {
return erpAssetMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpAssetTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.资产卡片;
String funcnr = funcnrEnum.getFuncnr();
// 构建req参数
Map<String, Object> req = new HashMap<>();
List<Map<String, String>> datumList = new ArrayList<>();
Map<String, String> datumEntry = new HashMap<>();
datumEntry.put("sign", "I");
datumEntry.put("option", "EQ");
datumEntry.put("low", LocalDate.now().toString());
datumList.add(datumEntry);
req.put(funcnrEnum.getDatekey(), datumList);
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
for (String number : redisCache) {
req.put("BUKRS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL, funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String, List<String>> numbers = erpConfig.numbers(dataArray, key, funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpAssetDO> toUpdate = new ArrayList<>();
List<ErpAssetDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
ErpAssetDO DO = new ErpAssetDO();
DO.setCompanyNumber(dataJson.getString("BUKRS"));
DO.setMainAssetNumber(dataJson.getString("ANLN1"));
if (!dataJson.getString("ERDAT").equals("0000-00-00")) {
DO.setRecordCreateDate(LocalDateTime.parse(dataJson.getString("ERDAT") + "T00:00:00"));
}
DO.setUpdateUserName(dataJson.getString("ERNAM"));
DO.setAssetTypeNumber(dataJson.getString("ANLKL"));
DO.setAssetTypeName(dataJson.getString("TXK20"));
if (!dataJson.getString("AKTIV").equals("0000-00-00")) {
DO.setAssetDate(LocalDateTime.parse(dataJson.getString("AKTIV") + "T00:00:00"));
}
DO.setUom(dataJson.getString("MEINS"));
DO.setQuantity(dataJson.getBigDecimal("MENGE"));
DO.setAssetDescription(dataJson.getString("TXT50"));
DO.setAssetDescriptionAttach(dataJson.getString("TXA50"));
if (!dataJson.getString("AFABG").equals("0000-00-00")) {
DO.setDepreciationStartDate(LocalDateTime.parse(dataJson.getString("AFABG") + "T00:00:00"));
}
DO.setPlanYearDate(dataJson.getString("NDJAR"));
DO.setCostcenterNumber(dataJson.getString("KOSTL"));
DO.setDutyCostcenterNumber(dataJson.getString("KOSTLV"));
if (comnumbers.contains(DO.getMainAssetNumber()+"-"+DO.getCompanyNumber())) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert, key, allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpAssetMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpAssetMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key, result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpAssetDO> toUpdate;
private final List<ErpAssetDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpAssetDO> toUpdate, List<ErpAssetDO> toInsert, String key, List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpBomService {
*/
PageResult<ErpBomDO> getErpBomPage(ErpBomPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpBomSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpBomDetailDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpBomMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_BOM_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP物料清单(BOM) Service 实现类
@@ -29,6 +41,9 @@ public class ErpBomServiceImpl implements ErpBomService {
@Resource
private ErpBomMapper erpBomMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpBomRespVO createErpBom(ErpBomSaveReqVO createReqVO) {
// 插入
@@ -56,12 +71,12 @@ public class ErpBomServiceImpl implements ErpBomService {
}
@Override
public void deleteErpBomListByIds(List<Long> ids) {
public void deleteErpBomListByIds(List<Long> ids) {
// 校验存在
validateErpBomExists(ids);
// 删除
erpBomMapper.deleteByIds(ids);
}
}
private void validateErpBomExists(List<Long> ids) {
List<ErpBomDO> list = erpBomMapper.selectByIds(ids);
@@ -86,4 +101,131 @@ public class ErpBomServiceImpl implements ErpBomService {
return erpBomMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpBomTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.BOM清单;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
for (String factoryNumber : redisCache) {
req.put("WERKS", factoryNumber);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL, funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String, String> numbers = erpConfig.numbersMap(key);
Map<String, String> numberDels = erpConfig.numbersMap(key+"del");
List<ErpBomDO> toUpdate = new ArrayList<>();
List<ErpBomDO> toInsert = new ArrayList<>();
List<String> allnumbers = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
ErpBomDO DO = new ErpBomDO();
DO.setFactoryNumber(dataJson.getString("WERKS"));
DO.setUpMaterial(dataJson.getString("MATNR"));
DO.setUseItem(dataJson.getString("STLAL"));
// DO.set(dataJson.getString("STLAN"));数据库无这个字段
DO.setMaterialDescription(dataJson.getString("MAKTX"));
DO.setQuantity(dataJson.getBigDecimal("BMENG"));
DO.setUnit(dataJson.getString("BMEIN"));
String number =DO.getUpMaterial()+"-"+DO.getUseItem()+"-"+DO.getFactoryNumber();
String domId = null;
if (numbers.get(number)!=null) {
// 更新
domId = numbers.get(number);
DO.setId(Long.valueOf(domId));
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
JSONArray dataJsonItem = dataJson.getJSONArray("ITEM");
if (dataJsonItem != null) {
List<ErpBomDetailDO> erpBomDetailDOList =new ArrayList<>();
for (int j = 0; j < dataJsonItem.size(); j++){
JSONObject dataJsonItemJson = dataJsonItem.getJSONObject(j);
ErpBomDetailDO detailDO = new ErpBomDetailDO();
String numberDel = number+dataJsonItemJson.getString("STVKN");
if (numberDels.get( numberDel) != null){
detailDO.setId(Long.valueOf(numberDels.get( numberDel)));
}
detailDO.setBomId(domId);
detailDO.setErpBomId(dataJsonItemJson.getString("STVKN"));
detailDO.setErpBomId(dataJsonItemJson.getString("IDNRK"));
detailDO.setErpBomId(dataJsonItemJson.getString("OJTXP"));
detailDO.setErpBomId(dataJsonItemJson.getString("POSTP"));
detailDO.setErpBomId(dataJsonItemJson.getString("MENGE"));
detailDO.setErpBomId(dataJsonItemJson.getString("MEINS"));
detailDO.setErpBomId(dataJsonItemJson.getString("WLCAT"));
erpBomDetailDOList.add(detailDO);
}
DO.setErpBomDetailDOList(erpBomDetailDOList);
}
}
}
return new ProcessingResult(toUpdate, toInsert, key, allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpBomMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpBomMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key, result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpBomDO> toUpdate;
private final List<ErpBomDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpBomDO> toUpdate, List<ErpBomDO> toInsert, String key, List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpContractService {
*/
PageResult<ErpContractDO> getErpContractPage(ErpContractPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,29 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpContractSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpContractDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpContractDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpContractMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_CONTRACT_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP合同映射 Service 实现类
@@ -29,6 +39,9 @@ public class ErpContractServiceImpl implements ErpContractService {
@Resource
private ErpContractMapper erpContractMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpContractRespVO createErpContract(ErpContractSaveReqVO createReqVO) {
// 插入
@@ -86,4 +99,93 @@ public class ErpContractServiceImpl implements ErpContractService {
return erpContractMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpContractTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.合同信息;
String funcnr = funcnrEnum.getFuncnr();
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, null);
if (dataArray == null || dataArray.isEmpty()) {
return;
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArray,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpContractDO> toUpdate = new ArrayList<>();
List<ErpContractDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("BUKRS").trim();
if (number != null) {
ErpContractDO DO = new ErpContractDO();
// DO.setName(dataJson.getString("BUTXT"));
// DO.setNumber(number);
// DO.setCurrency(dataJson.getString("WAERS"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpContractMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpContractMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpContractDO> toUpdate;
private final List<ErpContractDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpContractDO> toUpdate, List<ErpContractDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpCostcenterService {
*/
PageResult<ErpCostcenterDO> getErpCostcenterPage(ErpCostcenterPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpCostcenterSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCostcenterDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCostcenterDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpCostcenterMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_COSTCENTER_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP成本中心 Service 实现类
@@ -29,6 +41,9 @@ public class ErpCostcenterServiceImpl implements ErpCostcenterService {
@Resource
private ErpCostcenterMapper erpCostcenterMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpCostcenterRespVO createErpCostcenter(ErpCostcenterSaveReqVO createReqVO) {
// 插入
@@ -86,4 +101,110 @@ public class ErpCostcenterServiceImpl implements ErpCostcenterService {
return erpCostcenterMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpCostcenterTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.成本中心;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("BUKRS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpCostcenterDO> toUpdate = new ArrayList<>();
List<ErpCostcenterDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
ErpCostcenterDO DO = new ErpCostcenterDO();
DO.setNumber(dataJson.getString("KOSTL"));
DO.setName(dataJson.getString("KTEX"));
DO.setIsUse(dataJson.getString("DRNAM"));
DO.setScopeNumber(dataJson.getString("FKBER"));
if (!dataJson.getString("AKTIV").equals("0000-00-00")) {
DO.setStartDate(LocalDateTime.parse(dataJson.getString("DATAB") + "T00:00:00"));
}
if (!dataJson.getString("AKTIV").equals("0000-00-00")) {
DO.setStartDate(LocalDateTime.parse(dataJson.getString("DATBI") + "T00:00:00"));
}
DO.setScopeName(dataJson.getString("FKBTX"));
if (comnumbers.contains(dataJson.getString("KOSTL"))) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpCostcenterMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpCostcenterMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpCostcenterDO> toUpdate;
private final List<ErpCostcenterDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpCostcenterDO> toUpdate, List<ErpCostcenterDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpCustomerDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpCustomerMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
@@ -108,6 +109,7 @@ public class ErpCustomerServiceImpl implements ErpCustomerService {
@Override
@Transactional
@XxlJob("getErpCustomerTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.客商信息;
@@ -120,10 +122,8 @@ public class ErpCustomerServiceImpl implements ErpCustomerService {
datumEntry.put("sign", "I");
datumEntry.put("option", "EQ");
datumEntry.put("low", LocalDate.now().toString());
// datumEntry.put("low", "2021-05-17");
datumList.add(datumEntry);
req.put(funcnrEnum.getDatekey(), datumList);
// req.put("BUKRS", "3001");
// 1. 调用ERP接口获取数据
for (OftenEnum.ModeTypeEnum type : OftenEnum.ModeTypeEnum.values()) {
@@ -161,7 +161,7 @@ public class ErpCustomerServiceImpl implements ErpCustomerService {
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("PARTNER").trim();
String number = dataJson.getString(funcnrEnum.getDatakey()).trim();
if (number != null) {
ErpCustomerDO DO = new ErpCustomerDO();
DO.setName(dataJson.getString("NAME_ORG1"));

View File

@@ -61,4 +61,5 @@ public interface ErpFactoryService {
*/
PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactoryRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpFactorySaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpFactoryDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpFactoryMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_FACTORY_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP工厂 Service 实现类
@@ -29,6 +40,9 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
@Resource
private ErpFactoryMapper erpFactoryMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpFactoryRespVO createErpFactory(ErpFactorySaveReqVO createReqVO) {
// 插入
@@ -85,5 +99,110 @@ public class ErpFactoryServiceImpl implements ErpFactoryService {
public PageResult<ErpFactoryDO> getErpFactoryPage(ErpFactoryPageReqVO pageReqVO) {
return erpFactoryMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpFactoryTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.工厂信息;
String funcnr = funcnrEnum.getFuncnr();
// 1. 调用ERP接口获取数据
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
for (String companyNumber : redisCache) {
req.put("BUKRS", companyNumber);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
// 往每个子项中添加BUKRS字段
for (int j = 0; j < dataArray.size(); j++) {
JSONObject item = dataArray.getJSONObject(j);
if (item != null) {
item.put("BUKRS", companyNumber);
}
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpFactoryDO> toUpdate = new ArrayList<>();
List<ErpFactoryDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString(funcnr.getDatakey()).trim();
ErpFactoryDO DO = new ErpFactoryDO();
DO.setName(dataJson.getString("NAME1"));
DO.setNumber(number);
DO.setCompanyId(dataJson.getString("BUKRS"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpFactoryMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpFactoryMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpFactoryDO> toUpdate;
private final List<ErpFactoryDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpFactoryDO> toUpdate, List<ErpFactoryDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpInternalOrderService {
*/
PageResult<ErpInternalOrderDO> getErpInternalOrderPage(ErpInternalOrderPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpInternalOrderSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpInternalOrderDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpInternalOrderDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpInternalOrderMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_INTERNAL_ORDER_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP内部订单 Service 实现类
@@ -29,6 +40,9 @@ public class ErpInternalOrderServiceImpl implements ErpInternalOrderService {
@Resource
private ErpInternalOrderMapper erpInternalOrderMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpInternalOrderRespVO createErpInternalOrder(ErpInternalOrderSaveReqVO createReqVO) {
// 插入
@@ -86,4 +100,104 @@ public class ErpInternalOrderServiceImpl implements ErpInternalOrderService {
return erpInternalOrderMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpInternalOrderTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.内部订单;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("BUKRS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpInternalOrderDO> toUpdate = new ArrayList<>();
List<ErpInternalOrderDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
ErpInternalOrderDO DO = new ErpInternalOrderDO();
DO.setName(dataJson.getString("KTEXT"));
DO.setNumber(dataJson.getString("AUFNR"));
DO.setType(dataJson.getString("AUART"));
DO.setIsOff(dataJson.getString("PHAS3"));
DO.setIsFinish(dataJson.getString("PHAS2"));
if (comnumbers.contains(dataJson.getString("AUFNR"))) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpInternalOrderMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpInternalOrderMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpInternalOrderDO> toUpdate;
private final List<ErpInternalOrderDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpInternalOrderDO> toUpdate, List<ErpInternalOrderDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpMaterialDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpMaterialMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -102,6 +103,7 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
@Override
@Transactional
@XxlJob("getErpMaterialTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.物料数据;
@@ -150,29 +152,27 @@ public class ErpMaterialServiceImpl implements ErpMaterialService {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("MATNR").trim();
if (number != null) {
ErpMaterialDO DO = new ErpMaterialDO();
DO.setDownCenterNumber(number);
DO.setCenterNumber(dataJson.getString("BISMT"));
DO.setCreateDate(LocalDateTime.parse(dataJson.getString("ERSDA")));
DO.setMaterialType(dataJson.getString("MTART"));
DO.setMaterialGroupDate(dataJson.getString("MATKL"));
DO.setExternalMaterialGroupDate(dataJson.getString("EXTWG"));
DO.setUnit(dataJson.getString("MEINS"));
DO.setUnitDescription(dataJson.getString("MSEHT"));
DO.setMaterialTypeDescription(dataJson.getString("MTBEZ"));
DO.setMaterialGroupDescription(dataJson.getString("WGBEZ"));
DO.setExternalMaterialGroupDescription(dataJson.getString("EWBEZ"));
DO.setMaterialName(dataJson.getString("MAKTX"));
DO.setMaterialLengthDescription(dataJson.getString("LDESC"));
ErpMaterialDO DO = new ErpMaterialDO();
DO.setDownCenterNumber(number);
DO.setCenterNumber(dataJson.getString("BISMT"));
DO.setCreateDate(LocalDateTime.parse(dataJson.getString("ERSDA")));
DO.setMaterialType(dataJson.getString("MTART"));
DO.setMaterialGroupDate(dataJson.getString("MATKL"));
DO.setExternalMaterialGroupDate(dataJson.getString("EXTWG"));
DO.setUnit(dataJson.getString("MEINS"));
DO.setUnitDescription(dataJson.getString("MSEHT"));
DO.setMaterialTypeDescription(dataJson.getString("MTBEZ"));
DO.setMaterialGroupDescription(dataJson.getString("WGBEZ"));
DO.setExternalMaterialGroupDescription(dataJson.getString("EWBEZ"));
DO.setMaterialName(dataJson.getString("MAKTX"));
DO.setMaterialLengthDescription(dataJson.getString("LDESC"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpProcessService {
*/
PageResult<ErpProcessDO> getErpProcessPage(ErpProcessPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,29 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProcessSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProcessDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProcessDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProcessMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PROCESS_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP工艺路线 Service 实现类
@@ -29,6 +39,9 @@ public class ErpProcessServiceImpl implements ErpProcessService {
@Resource
private ErpProcessMapper erpProcessMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpProcessRespVO createErpProcess(ErpProcessSaveReqVO createReqVO) {
// 插入
@@ -86,4 +99,93 @@ public class ErpProcessServiceImpl implements ErpProcessService {
return erpProcessMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpProcessTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.公司代码;
String funcnr = funcnrEnum.getFuncnr();
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, null);
if (dataArray == null || dataArray.isEmpty()) {
return;
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArray,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpProcessDO> toUpdate = new ArrayList<>();
List<ErpProcessDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("BUKRS").trim();
if (number != null) {
ErpProcessDO DO = new ErpProcessDO();
// DO.setName(dataJson.getString("BUTXT"));
// DO.setNumber(number);
// DO.setCurrency(dataJson.getString("WAERS"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpProcessMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpProcessMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpProcessDO> toUpdate;
private final List<ErpProcessDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpProcessDO> toUpdate, List<ErpProcessDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpProductiveOrderService {
*/
PageResult<ErpProductiveOrderDO> getErpProductiveOrderPage(ErpProductiveOrderPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,31 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveOrderSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveOrderDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveOrderDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProductiveOrderMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PRODUCTIVE_ORDER_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP生产订单 Service 实现类
@@ -29,6 +41,9 @@ public class ErpProductiveOrderServiceImpl implements ErpProductiveOrderService
@Resource
private ErpProductiveOrderMapper erpProductiveOrderMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpProductiveOrderRespVO createErpProductiveOrder(ErpProductiveOrderSaveReqVO createReqVO) {
// 插入
@@ -86,4 +101,113 @@ public class ErpProductiveOrderServiceImpl implements ErpProductiveOrderService
return erpProductiveOrderMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpProductiveOrderTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.生产订单;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
List<Map<String, String>> datumList = new ArrayList<>();
Map<String, String> datumEntry = new HashMap<>();
// 构建datum参数数组
datumEntry.put("sign", "I");
datumEntry.put("option", "EQ");
datumEntry.put("low", LocalDate.now().toString());
datumList.add(datumEntry);
req.put(funcnrEnum.getDatekey(), datumList);
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("WERKS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpProductiveOrderDO> toUpdate = new ArrayList<>();
List<ErpProductiveOrderDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("BUKRS").trim();
if (number != null) {
ErpProductiveOrderDO DO = new ErpProductiveOrderDO();
// DO.setName(dataJson.getString("BUTXT"));
// DO.setNumber(number);
// DO.setCurrency(dataJson.getString("WAERS"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpProductiveOrderMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpProductiveOrderMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpProductiveOrderDO> toUpdate;
private final List<ErpProductiveOrderDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpProductiveOrderDO> toUpdate, List<ErpProductiveOrderDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpProductiveVersionService {
*/
PageResult<ErpProductiveVersionDO> getErpProductiveVersionPage(ErpProductiveVersionPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpProductiveVersionSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveVersionDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpProductiveVersionDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpProductiveVersionMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PRODUCTIVE_VERSION_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP生产版本 Service 实现类
@@ -29,6 +40,9 @@ public class ErpProductiveVersionServiceImpl implements ErpProductiveVersionServ
@Resource
private ErpProductiveVersionMapper erpProductiveVersionMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpProductiveVersionRespVO createErpProductiveVersion(ErpProductiveVersionSaveReqVO createReqVO) {
// 插入
@@ -86,4 +100,107 @@ public class ErpProductiveVersionServiceImpl implements ErpProductiveVersionServ
return erpProductiveVersionMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpProductiveVersionTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.生产版本;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("WERKS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpProductiveVersionDO> toUpdate = new ArrayList<>();
List<ErpProductiveVersionDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("VERID").trim();
ErpProductiveVersionDO DO = new ErpProductiveVersionDO();
// DO.setFactoryNumber(dataJson.getString("MATNR"));
DO.setMaterialNumber(dataJson.getString("WERKS"));
DO.setProductiveVersionNumber(number);
DO.setProductiveVersionName(dataJson.getString("TEXT1"));
DO.setBomNumber(dataJson.getString("STLAL"));
DO.setBlineGroup(dataJson.getString("PLNNR"));
// DO.setGroupCount(dataJson.getString("ALNAL"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpProductiveVersionMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpProductiveVersionMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpProductiveVersionDO> toUpdate;
private final List<ErpProductiveVersionDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpProductiveVersionDO> toUpdate, List<ErpProductiveVersionDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpPurchaseOrganizationService {
*/
PageResult<ErpPurchaseOrganizationDO> getErpPurchaseOrganizationPage(ErpPurchaseOrganizationPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpPurchaseOrganizationSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpPurchaseOrganizationDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpPurchaseOrganizationDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpPurchaseOrganizationMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_PURCHASE_ORGANIZATION_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP采购组织 Service 实现类
@@ -29,6 +40,9 @@ public class ErpPurchaseOrganizationServiceImpl implements ErpPurchaseOrganizati
@Resource
private ErpPurchaseOrganizationMapper erpPurchaseOrganizationMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpPurchaseOrganizationRespVO createErpPurchaseOrganization(ErpPurchaseOrganizationSaveReqVO createReqVO) {
// 插入
@@ -86,4 +100,101 @@ public class ErpPurchaseOrganizationServiceImpl implements ErpPurchaseOrganizati
return erpPurchaseOrganizationMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpPurchaseOrganizationTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.采购组织;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("WERKS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpPurchaseOrganizationDO> toUpdate = new ArrayList<>();
List<ErpPurchaseOrganizationDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("EKORG").trim();
ErpPurchaseOrganizationDO DO = new ErpPurchaseOrganizationDO();
DO.setName(dataJson.getString("EKOTX"));
DO.setNumber(number);
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpPurchaseOrganizationMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpPurchaseOrganizationMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpPurchaseOrganizationDO> toUpdate;
private final List<ErpPurchaseOrganizationDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpPurchaseOrganizationDO> toUpdate, List<ErpPurchaseOrganizationDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpSalesOrganizationService {
*/
PageResult<ErpSalesOrganizationDO> getErpSalesOrganizationPage(ErpSalesOrganizationPageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpSalesOrganizationSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpSalesOrganizationDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpSalesOrganizationDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpSalesOrganizationMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_SALES_ORGANIZATION_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP销售组织 Service 实现类
@@ -29,6 +40,9 @@ public class ErpSalesOrganizationServiceImpl implements ErpSalesOrganizationServ
@Resource
private ErpSalesOrganizationMapper erpSalesOrganizationMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpSalesOrganizationRespVO createErpSalesOrganization(ErpSalesOrganizationSaveReqVO createReqVO) {
// 插入
@@ -86,4 +100,109 @@ public class ErpSalesOrganizationServiceImpl implements ErpSalesOrganizationServ
return erpSalesOrganizationMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpSalesOrganizationTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.销售组织;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.公司代码.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("BUKRS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
// 往每个子项中添加BUKRS字段
for (int j = 0; j < dataArray.size(); j++) {
JSONObject item = dataArray.getJSONObject(j);
if (item != null) {
item.put("BUKRS", number);
}
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpSalesOrganizationDO> toUpdate = new ArrayList<>();
List<ErpSalesOrganizationDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("VKORG").trim();
ErpSalesOrganizationDO DO = new ErpSalesOrganizationDO();
DO.setName(dataJson.getString("VTEXT"));
DO.setNumber(number);
DO.setCompanyNumber(dataJson.getString("BUKRS"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpSalesOrganizationMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpSalesOrganizationMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpSalesOrganizationDO> toUpdate;
private final List<ErpSalesOrganizationDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpSalesOrganizationDO> toUpdate, List<ErpSalesOrganizationDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -61,4 +61,5 @@ public interface ErpWarehouseService {
*/
PageResult<ErpWarehouseDO> getErpWarehousePage(ErpWarehousePageReqVO pageReqVO);
void callErpRfcInterface();
}

View File

@@ -3,19 +3,30 @@ package cn.iocoder.yudao.module.erp.service.erp;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.common.conf.ErpConfig;
import cn.iocoder.yudao.module.erp.common.enums.OftenEnum;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehousePageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehouseRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.erp.vo.ErpWarehouseSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.erp.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.dal.mysql.erp.ErpWarehouseMapper;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.handler.annotation.XxlJob;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.ERP_WAREHOUSE_NOT_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
* ERP库位 Service 实现类
@@ -29,6 +40,9 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
@Resource
private ErpWarehouseMapper erpWarehouseMapper;
@Resource
private ErpConfig erpConfig;
@Override
public ErpWarehouseRespVO createErpWarehouse(ErpWarehouseSaveReqVO createReqVO) {
// 插入
@@ -86,4 +100,110 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
return erpWarehouseMapper.selectPage(pageReqVO);
}
@Override
@Transactional
@XxlJob("getErpWarehouseTask")
public void callErpRfcInterface() {
try {
OftenEnum.FuncnrEnum funcnrEnum =OftenEnum.FuncnrEnum.库位信息;
String funcnr = funcnrEnum.getFuncnr();
Map<String, Object> req = new HashMap<>();
JSONArray dataArrayALL = new JSONArray();
List<String> redisCache = erpConfig.getRedisCache(OftenEnum.FuncnrEnum.工厂信息.getFuncnr());
if (CollUtil.isEmpty(redisCache)) {
return;
}
// 1. 调用ERP接口获取数据
for (String number : redisCache) {
req.put("WERKS", number);
// 1. 调用ERP接口获取数据
JSONArray dataArray = erpConfig.fetchDataFromERP(funcnr, req);
if (dataArray == null || dataArray.isEmpty()) {
continue;
}
// 往每个子项中添加BUKRS字段
for (int j = 0; j < dataArray.size(); j++) {
JSONObject item = dataArray.getJSONObject(j);
if (item != null) {
item.put("WERKS", number);
}
}
dataArrayALL.addAll(dataArray);
}
// 2. 处理公司数据,区分新增和更新
ProcessingResult result = processData(dataArrayALL,funcnrEnum);
// 3. 批量保存数据
saveData(result);
} catch (Exception e) {
log.error("调用ERP RFC接口失败: {}", e);
throw new RuntimeException("调用ERP RFC接口失败: " + e.getMessage(), e);
}
}
/**
* 处理数据,区分新增和更新
*/
private ProcessingResult processData(JSONArray dataArray, OftenEnum.FuncnrEnum funcnr) {
String key = "erp" + funcnr.getFuncnr();
Map<String,List<String>> numbers = erpConfig.numbers(dataArray, key,funcnr.getDatakey());
List<String> allnumbers = numbers.get("all");
List<String> comnumbers = numbers.get("com");
List<ErpWarehouseDO> toUpdate = new ArrayList<>();
List<ErpWarehouseDO> toInsert = new ArrayList<>();
for (int i = 0; i < dataArray.size(); i++) {
JSONObject dataJson = dataArray.getJSONObject(i);
if (dataJson != null) {
String number = dataJson.getString("LGORT").trim();
ErpWarehouseDO DO = new ErpWarehouseDO();
DO.setName(dataJson.getString("LGOBE"));
DO.setNumber(number);
DO.setFactoryNumber(dataJson.getString("WERKS"));
if (comnumbers.contains(number)) {
// 更新
toUpdate.add(DO);
} else {
// 新增
toInsert.add(DO);
}
}
}
return new ProcessingResult(toUpdate, toInsert,key,allnumbers);
}
/**
* 批量保存数据
*/
private void saveData(ProcessingResult result) {
// 批量新增和更新
if (!result.toInsert.isEmpty()) {
erpWarehouseMapper.insertBatch(result.toInsert);
}
if (!result.toUpdate.isEmpty()) {
erpWarehouseMapper.updateBatch(result.toUpdate);
}
erpConfig.updateRedisCache(result.key,result.allnumbers);
}
/**
* 数据处理结果封装类
*/
private static class ProcessingResult {
private final List<ErpWarehouseDO> toUpdate;
private final List<ErpWarehouseDO> toInsert;
private final String key;
private final List<String> allnumbers;
public ProcessingResult(List<ErpWarehouseDO> toUpdate, List<ErpWarehouseDO> toInsert,String key,List<String> allnumbers) {
this.toUpdate = toUpdate;
this.toInsert = toInsert;
this.key = key;
this.allnumbers = allnumbers;
}
}
}

View File

@@ -8,5 +8,23 @@
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
UPDATE sply_erp_ast
<set>
NAME = CASE
<foreach collection="toUpdate" item="item">
WHEN CPN_NUM = #{item.companyNumber} AND MAIN_AST_NUM = #{item.mainAssetNumber} THEN #{item.name}
</foreach>
END,
CPN_ID = CASE
<foreach collection="toUpdate" item="item">
WHEN CPN_NUM = #{item.companyNumber} AND MAIN_AST_NUM = #{item.mainAssetNumber} THEN #{item.companyId}
</foreach>
END
</set>
WHERE (CPN_NUM, MAIN_AST_NUM) IN
<foreach collection="toUpdate" item="item" open="(" separator="," close=")">
#{item.companyNumber}, #{item.mainAssetNumber}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

View File

@@ -9,4 +9,14 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
<update id="updateBatch">
<foreach collection="toUpdate" item="item" separator=";">
UPDATE sply_erp_fact
<set>
<if test="item.name != null">NAME = #{item.name},</if>
<if test="item.number != null">CPN_ID = #{item.companyId},</if>
</set>
WHERE NUM = #{item.number}
</foreach>
</update>
</mapper>

Some files were not shown because too many files have changed in this diff Show More