parent
d36757c0c7
commit
cf8f3dbda4
9 changed files with 440 additions and 0 deletions
@ -0,0 +1,53 @@ |
||||
package org.springblade.job.processor.oem; |
||||
|
||||
import jakarta.annotation.Resource; |
||||
import lombok.Data; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.desk.basic.feign.IOemCustomerTaskClient; |
||||
import org.springframework.stereotype.Component; |
||||
import tech.powerjob.worker.core.processor.ProcessResult; |
||||
import tech.powerjob.worker.core.processor.TaskContext; |
||||
import tech.powerjob.worker.core.processor.sdk.BasicProcessor; |
||||
|
||||
import java.util.concurrent.CompletableFuture; |
||||
|
||||
/** |
||||
* OEM客户数据同步定时任务 |
||||
* 定期从ERP系统同步客户/供应商数据到本地 |
||||
* |
||||
* @author BladeX |
||||
* @since 2026-04-24 |
||||
*/ |
||||
@Component |
||||
@Data |
||||
@Slf4j |
||||
public class OemCustomerSyncProcessor implements BasicProcessor { |
||||
|
||||
@Resource |
||||
private IOemCustomerTaskClient oemCustomerTaskClient; |
||||
|
||||
@Override |
||||
public ProcessResult process(TaskContext context) throws Exception { |
||||
log.info("========== 开始执行外协厂家管理数据同步定时任务 =========="); |
||||
log.info("任务参数: {}", context.getJobParams()); |
||||
|
||||
CompletableFuture<Void> runFuture = CompletableFuture.runAsync(() -> { |
||||
try { |
||||
oemCustomerTaskClient.syncCustomerFromErp(); |
||||
log.info("外协厂家管理数据同步成功"); |
||||
} catch (Exception e) { |
||||
log.error("外协厂家管理数据同步异常", e); |
||||
} |
||||
}); |
||||
|
||||
runFuture.whenComplete((result, exception) -> { |
||||
if (exception != null) { |
||||
log.error("========== 外协厂家管理数据同步定时任务执行失败 ==========", exception); |
||||
} else { |
||||
log.info("========== 外协厂家管理数据同步定时任务执行完毕 =========="); |
||||
} |
||||
}); |
||||
|
||||
return new ProcessResult(true); |
||||
} |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
package org.springblade.desk.basic.feign; |
||||
|
||||
import org.springblade.core.launch.constant.AppConstant; |
||||
import org.springframework.cloud.openfeign.FeignClient; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
||||
/** |
||||
* OEM客户数据同步Feign客户端 |
||||
*/ |
||||
@FeignClient( |
||||
value = AppConstant.APPLICATION_DESK_NAME |
||||
) |
||||
public interface IOemCustomerTaskClient { |
||||
|
||||
String API_PREFIX = "/feign/client/oem-customer"; |
||||
|
||||
/** |
||||
* 同步外协厂家管理数据 |
||||
*/ |
||||
String SYNC_CUSTOMER_FROM_ERP = API_PREFIX + "/sync-customer-from-erp"; |
||||
|
||||
/** |
||||
* 同步外协厂家管理数据到本地 |
||||
*/ |
||||
@GetMapping(SYNC_CUSTOMER_FROM_ERP) |
||||
void syncCustomerFromErp(); |
||||
} |
||||
@ -0,0 +1,127 @@ |
||||
package org.springblade.desk.basic.pojo.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import io.swagger.v3.oas.annotations.media.Schema; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
|
||||
import java.io.Serial; |
||||
|
||||
/** |
||||
* [外协厂家-客户] 实体类 |
||||
* 对应表: BS_OEM_CUSTOMER |
||||
* |
||||
* @author BladeX |
||||
* @since 2026-04-24 |
||||
*/ |
||||
@Data |
||||
@TableName("BS_OEM_CUSTOMER") |
||||
@Schema(description = "OemCustomer Entity对象") |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class OemCustomer extends BaseEntity { |
||||
|
||||
@Serial |
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 编码 |
||||
*/ |
||||
public static final String COL_OC_CODE = "OC_CODE"; |
||||
/** |
||||
* 名称 |
||||
*/ |
||||
public static final String COL_OC_NAME = "OC_NAME"; |
||||
/** |
||||
* 简称 |
||||
*/ |
||||
public static final String COL_ABBREVIATION = "ABBREVIATION"; |
||||
/** |
||||
* 地区 |
||||
*/ |
||||
public static final String COL_REGION = "REGION"; |
||||
/** |
||||
* 地址 |
||||
*/ |
||||
public static final String COL_ADDRESS = "ADDRESS"; |
||||
/** |
||||
* 资质 |
||||
*/ |
||||
public static final String COL_QUALIFICATION = "QUALIFICATION"; |
||||
/** |
||||
* 当前状态 |
||||
*/ |
||||
public static final String COL_CUR_STATUS = "CUR_STATUS"; |
||||
/** |
||||
* 联系人 |
||||
*/ |
||||
public static final String COL_CONTACT_MAN = "CONTACT_MAN"; |
||||
/** |
||||
* 邮箱 |
||||
*/ |
||||
public static final String COL_EMAIL = "EMAIL"; |
||||
/** |
||||
* 联系电话 |
||||
*/ |
||||
public static final String COL_CONTACT_PHONE = "CONTACT_PHONE"; |
||||
|
||||
/** |
||||
* 编码 |
||||
*/ |
||||
@Schema(description = "编码") |
||||
private String ocCode; |
||||
|
||||
/** |
||||
* 名称 |
||||
*/ |
||||
@Schema(description = "名称") |
||||
private String ocName; |
||||
|
||||
/** |
||||
* 简称 |
||||
*/ |
||||
@Schema(description = "简称") |
||||
private String abbreviation; |
||||
|
||||
/** |
||||
* 地区 |
||||
*/ |
||||
@Schema(description = "地区") |
||||
private String region; |
||||
|
||||
/** |
||||
* 地址 |
||||
*/ |
||||
@Schema(description = "地址") |
||||
private String address; |
||||
|
||||
/** |
||||
* 资质 |
||||
*/ |
||||
@Schema(description = "资质") |
||||
private String qualification; |
||||
|
||||
/** |
||||
* 当前状态 |
||||
*/ |
||||
@Schema(description = "当前状态") |
||||
private Integer curStatus; |
||||
|
||||
/** |
||||
* 联系人 |
||||
*/ |
||||
@Schema(description = "联系人") |
||||
private String contactMan; |
||||
|
||||
/** |
||||
* 邮箱 |
||||
*/ |
||||
@Schema(description = "邮箱") |
||||
private String email; |
||||
|
||||
/** |
||||
* 联系电话 |
||||
*/ |
||||
@Schema(description = "联系电话") |
||||
private String contactPhone; |
||||
} |
||||
@ -0,0 +1,54 @@ |
||||
package org.springblade.desk.basic.controller; |
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||
import io.swagger.v3.oas.annotations.Operation; |
||||
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
import jakarta.annotation.Resource; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.boot.ctrl.BladeController; |
||||
import org.springblade.core.log.annotation.ApiLog; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.desk.basic.constant.BAModuleConst; |
||||
import org.springblade.desk.basic.service.IOemCustomerService; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* [外协厂家-客户] 控制器 |
||||
* |
||||
* @author BladeX |
||||
* @since 2026-04-24 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping(BAModuleConst.CONTROLLER_PREFIX + "/OemCustomer") |
||||
@Data |
||||
@AllArgsConstructor |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@Slf4j |
||||
@Tag(name = "[BA][外协厂家-客户]", description = "[外协厂家-客户]接口") |
||||
public class OemCustomerController extends BladeController { |
||||
|
||||
@Resource |
||||
private IOemCustomerService oemCustomerService; |
||||
|
||||
/** |
||||
* 同步外协厂家管理数据 |
||||
*/ |
||||
@PostMapping("/syncFromErp") |
||||
@ApiOperationSupport(order = 1) |
||||
@Operation(summary = "同步数据", description = "同步外协厂家管理数据到本地") |
||||
@ApiLog("同步外协厂家数据") |
||||
public R syncFromErp() { |
||||
try { |
||||
log.info("手动触发同步外协厂家数据"); |
||||
return oemCustomerService.syncCustomerFromErp(); |
||||
} catch (Exception e) { |
||||
log.error("同步外协厂家数据失败: {}", e.getMessage(), e); |
||||
return R.fail("同步失败: " + e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
package org.springblade.desk.basic.feign; |
||||
|
||||
import io.swagger.v3.oas.annotations.Hidden; |
||||
import jakarta.annotation.Resource; |
||||
import org.springblade.desk.basic.service.IOemCustomerService; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* OEM客户数据同步Feign客户端实现 |
||||
*/ |
||||
@RestController |
||||
@Hidden |
||||
public class OemCustomerTaskClientImpl implements IOemCustomerTaskClient { |
||||
|
||||
@Resource |
||||
private IOemCustomerService oemCustomerService; |
||||
|
||||
@Override |
||||
public void syncCustomerFromErp() { |
||||
oemCustomerService.syncCustomerFromErp(); |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
package org.springblade.desk.basic.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.springblade.desk.basic.pojo.entity.OemCustomer; |
||||
|
||||
/** |
||||
* [外协厂家-客户] Mapper 接口 |
||||
* |
||||
* @author BladeX |
||||
* @since 2026-04-24 |
||||
*/ |
||||
@Mapper |
||||
public interface OemCustomerMapper extends BaseMapper<OemCustomer> { |
||||
|
||||
/** |
||||
* 同步ERP外协厂家管理数据到本地 |
||||
* 从 ERP 数据库视图 V_MES_RB_SPLY 同步数据到 BS_OEM_CUSTOMER 表 |
||||
*/ |
||||
void syncCustomerFromErp(); |
||||
} |
||||
@ -0,0 +1,79 @@ |
||||
<?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="org.springblade.desk.basic.mapper.OemCustomerMapper"> |
||||
|
||||
<!-- 通用查询映射结果 --> |
||||
<resultMap id="oemCustomerResultMap" type="org.springblade.desk.basic.pojo.entity.OemCustomer"> |
||||
<result column="OC_ID" property="id"/> |
||||
<result column="OC_CODE" property="ocCode"/> |
||||
<result column="OC_NAME" property="ocName"/> |
||||
<result column="ABBREVIATION" property="abbreviation"/> |
||||
<result column="REGION" property="region"/> |
||||
<result column="ADDRESS" property="address"/> |
||||
<result column="QUALIFICATION" property="qualification"/> |
||||
<result column="CUR_STATUS" property="curStatus"/> |
||||
<result column="CONTACT_MAN" property="contactMan"/> |
||||
<result column="EMAIL" property="email"/> |
||||
<result column="CONTACT_PHONE" property="contactPhone"/> |
||||
<result column="UPDATE_TIME" property="updateTime"/> |
||||
</resultMap> |
||||
|
||||
<!-- |
||||
同步ERP外协厂家管理数据到本地 |
||||
逻辑说明: |
||||
1. 从 ERP 数据库链接 dba_mgr.V_MES_RB_SPLY@erp_mes_link 获取供应商数据 |
||||
2. 根据供应商编码(oc_code)判断是否存在 |
||||
3. 存在则更新,不存在则插入 |
||||
--> |
||||
<update id="syncCustomerFromErp"> |
||||
MERGE INTO BS_OEM_CUSTOMER target |
||||
USING ( |
||||
SELECT |
||||
a.splycode AS oc_code, |
||||
a.splyname AS oc_name, |
||||
a.splyname AS abbreviation, |
||||
a.province AS region, |
||||
a.splyadd AS address, |
||||
a.producttype AS qualification, |
||||
a.splystat AS cur_status, |
||||
a.linkman AS contact_man, |
||||
a.email AS email, |
||||
a.ctactqumd AS contact_phone, |
||||
SYSDATE AS update_time |
||||
FROM dba_mgr.V_MES_RB_SPLY@erp_mes_link a |
||||
) source |
||||
ON (target.OC_CODE = source.oc_code) |
||||
WHEN MATCHED THEN |
||||
UPDATE SET |
||||
target.OC_NAME = source.oc_name, |
||||
target.ABBREVIATION = source.abbreviation, |
||||
target.REGION = source.region, |
||||
target.ADDRESS = source.address, |
||||
target.QUALIFICATION = source.qualification, |
||||
target.CUR_STATUS = source.cur_status, |
||||
target.CONTACT_MAN = source.contact_man, |
||||
target.EMAIL = source.email, |
||||
target.CONTACT_PHONE = source.contact_phone, |
||||
target.UPDATE_TIME = source.update_time |
||||
WHEN NOT MATCHED THEN |
||||
INSERT (OC_ID, OC_CODE, OC_NAME, ABBREVIATION, REGION, ADDRESS, |
||||
QUALIFICATION, CUR_STATUS, CONTACT_MAN, EMAIL, CONTACT_PHONE, |
||||
IS_DELETED, UPDATE_TIME) |
||||
VALUES ( |
||||
S_BS_OEM_CUSTOMER.NEXTVAL, |
||||
source.oc_code, |
||||
source.oc_name, |
||||
source.abbreviation, |
||||
source.region, |
||||
source.address, |
||||
source.qualification, |
||||
source.cur_status, |
||||
source.contact_man, |
||||
source.email, |
||||
source.contact_phone, |
||||
0, |
||||
source.update_time |
||||
) |
||||
</update> |
||||
|
||||
</mapper> |
||||
@ -0,0 +1,22 @@ |
||||
package org.springblade.desk.basic.service; |
||||
|
||||
import org.springblade.core.mp.base.BaseService; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.desk.basic.pojo.entity.OemCustomer; |
||||
|
||||
/** |
||||
* [外协厂家-客户] 服务类 |
||||
* |
||||
* @author BladeX |
||||
* @since 2026-04-24 |
||||
*/ |
||||
public interface IOemCustomerService extends BaseService<OemCustomer> { |
||||
|
||||
/** |
||||
* 同步外协厂家管理数据 |
||||
* 从ERP系统同步供应商/客户数据到本地数据库 |
||||
* |
||||
* @return 同步结果 |
||||
*/ |
||||
R syncCustomerFromErp(); |
||||
} |
||||
@ -0,0 +1,35 @@ |
||||
package org.springblade.desk.basic.service.impl; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.mp.base.BaseServiceImpl; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.desk.basic.mapper.OemCustomerMapper; |
||||
import org.springblade.desk.basic.pojo.entity.OemCustomer; |
||||
import org.springblade.desk.basic.service.IOemCustomerService; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
/** |
||||
* [外协厂家-客户] 服务实现类 |
||||
* |
||||
* @author BladeX |
||||
* @since 2026-04-24 |
||||
*/ |
||||
@Slf4j |
||||
@Service |
||||
public class OemCustomerServiceImpl extends BaseServiceImpl<OemCustomerMapper, OemCustomer> implements IOemCustomerService { |
||||
|
||||
/** |
||||
* 从ERP系统同步供应商/客户数据到本地数据库 |
||||
*/ |
||||
@Override |
||||
@Transactional(rollbackFor = Exception.class) |
||||
public R syncCustomerFromErp() { |
||||
log.info("开始同步外协厂家管理数据..."); |
||||
|
||||
baseMapper.syncCustomerFromErp(); |
||||
|
||||
log.info("外协厂家管理数据同步完成"); |
||||
return R.success("同步成功"); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue