Commit 6da8426b authored by suhuiguang's avatar suhuiguang

1.编辑代码公共分析

parent 995750f8
package com.yeejoin.amos.boot.module.jg.biz.context; package com.yeejoin.amos.boot.module.jg.biz.context;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.event.BaseBizChangeEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
...@@ -16,19 +17,19 @@ import java.util.Optional; ...@@ -16,19 +17,19 @@ import java.util.Optional;
@Component @Component
public class BizDataHandleStrategyContext implements ApplicationContextAware { public class BizDataHandleStrategyContext implements ApplicationContextAware {
private static final Map<String, IBizDataChangeHandleStrategy> dataProcessStrategyHashMap = new HashMap<>(); private static final Map<String, DefaultBizDataChangeHandler<? extends BaseBizChangeEvent>> dataProcessStrategyHashMap = new HashMap<>();
public static IBizDataChangeHandleStrategy getStrategy(String bizType) { public static DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> getStrategy(String bizType) {
return Optional.ofNullable(dataProcessStrategyHashMap.get(bizType)).orElseThrow(() -> new RuntimeException(String.format("not found %s type strategy", bizType))); return Optional.ofNullable(dataProcessStrategyHashMap.get(bizType)).orElseThrow(() -> new RuntimeException(String.format("not found %s type strategy", bizType)));
} }
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, IBizDataChangeHandleStrategy> strategyBeans = applicationContext.getBeansOfType(IBizDataChangeHandleStrategy.class); Map<String, DefaultBizDataChangeHandler> strategyBeans = applicationContext.getBeansOfType(DefaultBizDataChangeHandler.class);
if (strategyBeans.isEmpty()) { if (strategyBeans.isEmpty()) {
return; return;
} }
for (IBizDataChangeHandleStrategy strategy : strategyBeans.values()) { for (DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> strategy : strategyBeans.values()) {
dataProcessStrategyHashMap.put(strategy.canHandleBizType(), strategy); dataProcessStrategyHashMap.put(strategy.canHandleBizType(), strategy);
} }
} }
......
package com.yeejoin.amos.boot.module.jg.biz.context; package com.yeejoin.amos.boot.module.jg.biz.context;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
...@@ -17,20 +17,20 @@ import java.util.Optional; ...@@ -17,20 +17,20 @@ import java.util.Optional;
@Component @Component
public class EquipDataProcessStrategyContext implements ApplicationContextAware { public class EquipDataProcessStrategyContext implements ApplicationContextAware {
private static final Map<IBizDataChangeHandleStrategy.ModelType, IChangeDataProcessStrategy> dataProcessStrategyHashMap = new HashMap<>(); private static final Map<DefaultBizDataChangeHandler.ModelType, IEquipChangeDataProcessStrategy> dataProcessStrategyHashMap = new HashMap<>();
public static IChangeDataProcessStrategy getStrategy(IBizDataChangeHandleStrategy.ModelType modelType) { public static IEquipChangeDataProcessStrategy getStrategy(DefaultBizDataChangeHandler.ModelType modelType) {
return Optional.ofNullable(dataProcessStrategyHashMap.get(modelType)).orElseThrow(() -> new RuntimeException(String.format("not found %s type strategy", modelType))); return Optional.ofNullable(dataProcessStrategyHashMap.get(modelType)).orElseThrow(() -> new RuntimeException(String.format("not found %s type strategy", modelType)));
} }
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, IChangeDataProcessStrategy> strategyBeans = applicationContext.getBeansOfType(IChangeDataProcessStrategy.class); Map<String, IEquipChangeDataProcessStrategy> strategyBeans = applicationContext.getBeansOfType(IEquipChangeDataProcessStrategy.class);
if (strategyBeans.isEmpty()) { if (strategyBeans.isEmpty()) {
return; return;
} }
for (IChangeDataProcessStrategy strategy : strategyBeans.values()) { for (IEquipChangeDataProcessStrategy strategy : strategyBeans.values()) {
dataProcessStrategyHashMap.put(strategy.canHandleMode(), strategy); dataProcessStrategyHashMap.put(strategy.canHandleMode(), strategy);
} }
} }
......
package com.yeejoin.amos.boot.module.jg.biz.controller; package com.yeejoin.amos.boot.module.jg.biz.controller;
import com.yeejoin.amos.boot.module.jg.api.dto.RequestChangeData; import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.BizDataChangeServiceImpl; import com.yeejoin.amos.boot.module.jg.biz.service.impl.BizDataChangeServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.SingleManageEquipEditHandleImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.validation.constraints.NotBlank;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping(value = "/data-change") @RequestMapping(value = "/data-change")
@Api(tags = "业务数据变化处理控制器") @Api(tags = "业务数据变化处理控制器")
@RequiredArgsConstructor
public class BizDataChangeController { public class BizDataChangeController {
private final BizDataChangeServiceImpl bizDataChangeService; private final BizDataChangeServiceImpl bizDataChangeService;
public BizDataChangeController(BizDataChangeServiceImpl bizDataChangeService) { private final SingleManageEquipEditHandleImpl singleManageEquipEditHandle;
this.bizDataChangeService = bizDataChangeService;
}
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/{bizType}/save") @PostMapping(value = "/v1/singleManageEquipEdit/save")
@ApiOperation(value = "业务数据变更保存--西安专用", httpMethod = "POST") @ApiOperation(value = "业务数据变更保存--西安专用", httpMethod = "POST")
public ResponseModel<String> save(@RequestParam String applyNo, public ResponseModel<String> save(@RequestParam String applyNo,
@PathVariable String bizType,
@RequestBody RequestChangeData changeData) { @RequestBody RequestChangeData changeData) {
bizDataChangeService.save(applyNo, bizType, changeData); singleManageEquipEditHandle.doSave(applyNo, changeData);
return ResponseHelper.buildResponse("success"); return ResponseHelper.buildResponse("success");
} }
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/{bizType}/detail") @GetMapping(value = "/v1/singleManageEquipEdit/detail")
@ApiOperation(value = "查询可业务变更的字段及默认值", httpMethod = "GET") @ApiOperation(value = "查询可业务变更的字段及默认值--西安专用", httpMethod = "GET")
public ResponseModel<Map<String, ?>> getDetail(@RequestParam(required = false) String applyNo, public ResponseModel<Map<String, ?>> getDetailV1(@RequestParam(required = false) String applyNo,
@PathVariable String bizType,
IBizDataChangeHandleStrategy.ModelType model,
@RequestParam(required = false) String bizId) { @RequestParam(required = false) String bizId) {
return ResponseHelper.buildResponse(bizDataChangeService.queryDetail(applyNo, bizType, model, bizId)); return ResponseHelper.buildResponse(singleManageEquipEditHandle.getDetail(applyNo, bizId));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/v2/{bizType}/save") @PostMapping(value = "/v2/{bizType}/save")
@ApiOperation(value = "编辑保存", httpMethod = "POST") @ApiOperation(value = "编辑保存--通用", httpMethod = "POST")
public ResponseModel<String> saveV2(@ApiParam(required = true, value = "单据编号") @RequestParam String applyNo, public ResponseModel<String> saveV2(@ApiParam(required = true, value = "单据编号") @RequestParam String applyNo,
@ApiParam(required = true, value = "业务类型")@PathVariable String bizType, @ApiParam(required = true, value = "业务类型") @PathVariable String bizType,
@RequestBody RequestChangeData changeData) { @RequestBody RequestChangeData changeData) {
// 基础数据校验 // 基础数据校验
changeData.validated(); changeData.validated();
bizDataChangeService.save(applyNo, bizType, changeData); bizDataChangeService.save(applyNo, bizType, changeData);
return ResponseHelper.buildResponse("success"); return ResponseHelper.buildResponse("success");
} }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/v2/{bizType}/detail")
@ApiOperation(value = "查询可业务变更的字段及默认值--通用", httpMethod = "GET")
public ResponseModel<Map<String, ?>> getDetailV2(@RequestParam(required = false) String applyNo,
@RequestParam(required = false) String bizId,
@PathVariable String bizType,
DefaultBizDataChangeHandler.ModelType model) {
return ResponseHelper.buildResponse(bizDataChangeService.queryDetail(applyNo, bizType, model, bizId));
}
} }
package com.yeejoin.amos.boot.module.jg.api.dto; package com.yeejoin.amos.boot.module.jg.biz.dto;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
...@@ -32,10 +33,9 @@ public class RequestChangeData extends JSONObject { ...@@ -32,10 +33,9 @@ public class RequestChangeData extends JSONObject {
*/ */
public static final String changeReasonAttachmentKey = "changeReasonAttachment"; public static final String changeReasonAttachmentKey = "changeReasonAttachment";
public DefaultBizDataChangeHandler.ModelType getModelType() {
public IBizDataChangeHandleStrategy.ModelType getModelType() {
if (this.containsKey(modelTypeKey)) { if (this.containsKey(modelTypeKey)) {
return IBizDataChangeHandleStrategy.ModelType.valueOf(this.getString(modelTypeKey)); return DefaultBizDataChangeHandler.ModelType.valueOf(this.getString(modelTypeKey));
} }
return null; return null;
} }
......
package com.yeejoin.amos.boot.module.jg.biz.event;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
import org.typroject.tyboot.core.foundation.context.RequestContextModel;
@Getter
public class BaseBizChangeEvent extends ApplicationEvent {
private final String applyNo;
private final RequestContextModel requestContext;
/**
* Create a new {@code ApplicationEvent}.
*
* @param source the object on which the event initially occurred or with
* which the event is associated (never {@code null})
*/
public BaseBizChangeEvent(Object source, String applyNo, RequestContextModel requestContext) {
super(source);
this.applyNo = applyNo;
this.requestContext = requestContext;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service;
import cn.hutool.extra.spring.SpringUtil;
import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import com.yeejoin.amos.boot.module.jg.biz.context.EquipDataProcessStrategyContext;
import com.yeejoin.amos.boot.module.jg.biz.event.BaseBizChangeEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.List;
import java.util.Map;
public abstract class DefaultBizDataChangeHandler<U extends BaseBizChangeEvent> implements IBizDataChangeHandleStrategy {
@Transactional(rollbackFor = Exception.class)
public void doSave(String applyNo, ModelType model, Map<String, Object> changeData) {
if (beforeCheck(applyNo, model, changeData)) {
IEquipChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
List<ChangeDataDto> allChangeColumns = dataProcessor.handle(changeData, applyNo);
List<ChangeDataDto> bizEditColumns = bizDataSave(applyNo, model, changeData);
allChangeColumns.addAll(bizEditColumns);
// 发送数据变更
publish2OtherBiz(buildEvent(applyNo,model,changeData));
// 异步记录日志
writeLog(allChangeColumns);
}
}
protected abstract U buildEvent(String applyNo, ModelType model, Map<String, Object> changeData);
private void publish2OtherBiz(U event) {
EventPublisher publisher = SpringUtil.getBean(com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher.class);
publisher.publish(event);
}
private void writeLog(List<ChangeDataDto> allChangeColumns) {
EventPublisher publisher = SpringUtil.getBean(com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher.class);
publisher.publish(new ChangeDataEvent(this, allChangeColumns, RequestContext.cloneRequestContext()));
}
}
package com.yeejoin.amos.boot.module.jg.api.service; package com.yeejoin.amos.boot.module.jg.biz.service;
import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import com.yeejoin.amos.boot.module.jg.biz.context.EquipDataProcessStrategyContext;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface IBizDataChangeHandleStrategy { public interface IBizDataChangeHandleStrategy {
...@@ -28,8 +33,10 @@ public interface IBizDataChangeHandleStrategy { ...@@ -28,8 +33,10 @@ public interface IBizDataChangeHandleStrategy {
* @param model @see ModelType * @param model @see ModelType
* @param changeData 变更数据 * @param changeData 变更数据
*/ */
void doSave(String applyNo, ModelType model, Map<String, Object> changeData); List<ChangeDataDto> bizDataSave(String applyNo, ModelType model, Map<String, Object> changeData);
Boolean beforeCheck(String applyNo, ModelType model, Map<String, Object> changeData);
/** /**
* 单据方式:单个处理、批量处理 * 单据方式:单个处理、批量处理
...@@ -41,6 +48,4 @@ public interface IBizDataChangeHandleStrategy { ...@@ -41,6 +48,4 @@ public interface IBizDataChangeHandleStrategy {
batchEquip, batchEquip,
batchCylinder batchCylinder
} }
String DEFAULT_VALUE = "default";
} }
package com.yeejoin.amos.boot.module.jg.biz.service; package com.yeejoin.amos.boot.module.jg.biz.service;
import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto; import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -9,7 +8,7 @@ import java.util.Map; ...@@ -9,7 +8,7 @@ import java.util.Map;
/** /**
* 处理监策略类 * 处理监策略类
*/ */
public interface IChangeDataProcessStrategy { public interface IEquipChangeDataProcessStrategy {
/** /**
* 处理 * 处理
...@@ -21,5 +20,5 @@ public interface IChangeDataProcessStrategy { ...@@ -21,5 +20,5 @@ public interface IChangeDataProcessStrategy {
* *
* @return 可处理的类型 * @return 可处理的类型
*/ */
IBizDataChangeHandleStrategy.ModelType canHandleMode(); DefaultBizDataChangeHandler.ModelType canHandleMode();
} }
...@@ -3,8 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl; ...@@ -3,8 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*; import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -15,12 +16,12 @@ import java.util.Map; ...@@ -15,12 +16,12 @@ import java.util.Map;
* 批量维护气瓶-策略实现类 * 批量维护气瓶-策略实现类
*/ */
@Component @Component
public class BatchCylinderDataChangeProcessStrategy implements IChangeDataProcessStrategy { public class BatchCylinderDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService; private final CommonEquipDataProcessService commonEquipDataProcessService;
public BatchCylinderDataChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) { public BatchCylinderDataEquipChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
this.commonEquipDataProcessService = commonEquipDataProcessService; this.commonEquipDataProcessService = commonEquipDataProcessService;
} }
...@@ -115,7 +116,7 @@ public class BatchCylinderDataChangeProcessStrategy implements IChangeDataProces ...@@ -115,7 +116,7 @@ public class BatchCylinderDataChangeProcessStrategy implements IChangeDataProces
@Override @Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() { public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchCylinder; return DefaultBizDataChangeHandler.ModelType.batchCylinder;
} }
} }
...@@ -3,8 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl; ...@@ -3,8 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*; import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -15,12 +16,12 @@ import java.util.Map; ...@@ -15,12 +16,12 @@ import java.util.Map;
* 批量维护设备-策略实现类 * 批量维护设备-策略实现类
*/ */
@Component @Component
public class BatchEquipDataChangeProcessStrategy implements IChangeDataProcessStrategy { public class BatchEquipDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService; private final CommonEquipDataProcessService commonEquipDataProcessService;
public BatchEquipDataChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) { public BatchEquipDataEquipChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
this.commonEquipDataProcessService = commonEquipDataProcessService; this.commonEquipDataProcessService = commonEquipDataProcessService;
} }
...@@ -67,7 +68,7 @@ public class BatchEquipDataChangeProcessStrategy implements IChangeDataProcessSt ...@@ -67,7 +68,7 @@ public class BatchEquipDataChangeProcessStrategy implements IChangeDataProcessSt
@Override @Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() { public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchEquip; return DefaultBizDataChangeHandler.ModelType.batchEquip;
} }
} }
...@@ -4,8 +4,9 @@ import cn.hutool.core.bean.BeanUtil; ...@@ -4,8 +4,9 @@ import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*; import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
...@@ -19,7 +20,7 @@ import java.util.Map; ...@@ -19,7 +20,7 @@ import java.util.Map;
*/ */
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class BatchProjectDataChangeProcessStrategy implements IChangeDataProcessStrategy { public class BatchProjectDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService; private final CommonEquipDataProcessService commonEquipDataProcessService;
...@@ -101,7 +102,7 @@ public class BatchProjectDataChangeProcessStrategy implements IChangeDataProcess ...@@ -101,7 +102,7 @@ public class BatchProjectDataChangeProcessStrategy implements IChangeDataProcess
} }
@Override @Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() { public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchProject; return DefaultBizDataChangeHandler.ModelType.batchProject;
} }
} }
package com.yeejoin.amos.boot.module.jg.biz.service.impl; package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.jg.api.dto.RequestChangeData; import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.event.BaseBizChangeEvent;
import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.context.BizDataHandleStrategyContext; import com.yeejoin.amos.boot.module.jg.biz.context.BizDataHandleStrategyContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -23,13 +24,13 @@ public class BizDataChangeServiceImpl { ...@@ -23,13 +24,13 @@ public class BizDataChangeServiceImpl {
public void save(String applyNo, public void save(String applyNo,
String bizType, String bizType,
RequestChangeData changeData) { RequestChangeData changeData) {
IBizDataChangeHandleStrategy.ModelType model = changeData.getModelType(); DefaultBizDataChangeHandler.ModelType model = changeData.getModelType();
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType); DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
handleStrategy.doSave(applyNo, model, changeData); handleStrategy.doSave(applyNo, model, changeData);
} }
public Map<String, ?> queryDetail(String applyNo, String bizType, IBizDataChangeHandleStrategy.ModelType model, String bizId) { public Map<String, ?> queryDetail(String applyNo, String bizType, DefaultBizDataChangeHandler.ModelType model, String bizId) {
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType); DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
return handleStrategy.getDetail(applyNo, model, bizId); return handleStrategy.getDetail(applyNo, model, bizId);
} }
......
...@@ -10,8 +10,8 @@ import com.yeejoin.amos.boot.module.jg.api.dto.EquipRegisterChangeDataDto; ...@@ -10,8 +10,8 @@ import com.yeejoin.amos.boot.module.jg.api.dto.EquipRegisterChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistration; import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistration;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationEq; import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationEq;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationEqMapper; import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationEqMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -22,7 +22,7 @@ import java.util.Map; ...@@ -22,7 +22,7 @@ import java.util.Map;
* 单个维护设备-策略实现类 * 单个维护设备-策略实现类
*/ */
@Component @Component
public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrategy { public class SingleEquipEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final JgUseRegistrationServiceImpl useRegistrationService; private final JgUseRegistrationServiceImpl useRegistrationService;
...@@ -32,7 +32,7 @@ public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrat ...@@ -32,7 +32,7 @@ public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrat
private final CommonEquipDataProcessService commonEquipDataProcessService; private final CommonEquipDataProcessService commonEquipDataProcessService;
public SingleEquipChangeProcessStrategy(JgUseRegistrationServiceImpl useRegistrationService, JgUseRegistrationEqMapper jgRelationEquipMapper, CommonEquipDataProcessService commonEquipDataProcessService) { public SingleEquipEquipChangeProcessStrategy(JgUseRegistrationServiceImpl useRegistrationService, JgUseRegistrationEqMapper jgRelationEquipMapper, CommonEquipDataProcessService commonEquipDataProcessService) {
this.useRegistrationService = useRegistrationService; this.useRegistrationService = useRegistrationService;
this.jgRelationEquipMapper = jgRelationEquipMapper; this.jgRelationEquipMapper = jgRelationEquipMapper;
this.commonEquipDataProcessService = commonEquipDataProcessService; this.commonEquipDataProcessService = commonEquipDataProcessService;
...@@ -73,8 +73,8 @@ public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrat ...@@ -73,8 +73,8 @@ public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrat
} }
@Override @Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() { public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.singleEquip; return DefaultBizDataChangeHandler.ModelType.singleEquip;
} }
} }
...@@ -2,7 +2,6 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl; ...@@ -2,7 +2,6 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.yeejoin.amos.boot.module.jg.api.dto.*; import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent; import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher; import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -17,18 +16,12 @@ import java.util.Map; ...@@ -17,18 +16,12 @@ import java.util.Map;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStrategy { public class SingleManageEquipEditHandleImpl {
private final CommonEquipDataProcessService commonEquipDataProcessService; private final CommonEquipDataProcessService commonEquipDataProcessService;
private final EventPublisher publisher; private final EventPublisher publisher;
@Override public Map<String, ?> getDetail(String applyNo, String bizId) {
public String canHandleBizType() {
return "singleManageEquipEdit";
}
@Override
public Map<String, ?> getDetail(String applyNo, ModelType model, String bizId) {
return this.getDetailByBizId(bizId); return this.getDetailByBizId(bizId);
} }
...@@ -50,9 +43,9 @@ public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStra ...@@ -50,9 +43,9 @@ public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStra
return commonEquipDataProcessService.cast2UnderCase(re); return commonEquipDataProcessService.cast2UnderCase(re);
} }
@Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void doSave(String record, ModelType model, Map<String, Object> changeData) { public void doSave(String record, Map<String, Object> changeData) {
List<ChangeDataDto> allChangeColumns = this.update(record, changeData); List<ChangeDataDto> allChangeColumns = this.update(record, changeData);
// 记录流水 // 记录流水
if (!allChangeColumns.isEmpty()) { if (!allChangeColumns.isEmpty()) {
...@@ -63,6 +56,7 @@ public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStra ...@@ -63,6 +56,7 @@ public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStra
} }
} }
private List<ChangeDataDto> update(String record, Map<String, Object> changeData) { private List<ChangeDataDto> update(String record, Map<String, Object> changeData) {
List<ChangeDataDto> allChangeColumns = new ArrayList<>(); List<ChangeDataDto> allChangeColumns = new ArrayList<>();
// 新数据解析 // 新数据解析
......
...@@ -5,8 +5,9 @@ import cn.hutool.core.text.CharSequenceUtil; ...@@ -5,8 +5,9 @@ import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*; import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy; import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
...@@ -21,7 +22,7 @@ import java.util.Map; ...@@ -21,7 +22,7 @@ import java.util.Map;
*/ */
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class SingleProjectDataChangeProcessStrategy implements IChangeDataProcessStrategy { public class SingleProjectDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService; private final CommonEquipDataProcessService commonEquipDataProcessService;
...@@ -74,7 +75,7 @@ public class SingleProjectDataChangeProcessStrategy implements IChangeDataProces ...@@ -74,7 +75,7 @@ public class SingleProjectDataChangeProcessStrategy implements IChangeDataProces
@Override @Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() { public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.singleProject; return DefaultBizDataChangeHandler.ModelType.singleProject;
} }
} }
package com.yeejoin.amos.boot.module.jg.biz.service.impl; package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil; import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.context.EquipDataProcessStrategyContext; import com.yeejoin.amos.boot.module.jg.biz.context.EquipDataProcessStrategyContext;
import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent; import com.yeejoin.amos.boot.module.jg.biz.event.BaseBizChangeEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher; import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy; import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.HashMap; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Service @Service
public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStrategy { @RequiredArgsConstructor
public class UseRegisterDataChangeHandleImpl extends DefaultBizDataChangeHandler<BaseBizChangeEvent> {
private final EventPublisher publisher;
private final UseRegisterUpdateService useRegisterUpdateService; private final UseRegisterUpdateService useRegisterUpdateService;
public UseRegisterDataChangeHandleImpl(EventPublisher publisher, UseRegisterUpdateService useRegisterUpdateService) {
this.publisher = publisher;
this.useRegisterUpdateService = useRegisterUpdateService;
}
@Override @Override
public String canHandleBizType() { public String canHandleBizType() {
return "useRegister"; return "useRegister";
...@@ -45,23 +35,22 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra ...@@ -45,23 +35,22 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
* @param changeData 前端不支持分组-目前为平铺数据结构 * @param changeData 前端不支持分组-目前为平铺数据结构
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) public List<ChangeDataDto> bizDataSave(String applyNo, ModelType model, Map<String, Object> changeData) {
public void doSave(String applyNo, ModelType model, Map<String, Object> changeData) { List<ChangeDataDto> bizEditColumns = new ArrayList<ChangeDataDto>();
// 单据信息的保存、与设备相关、证相关字段的更新
// 1.根据任务状态进行单据数据的处理 // 1.根据任务状态进行单据数据的处理
// 1.1 流程中,不更业务相关字段,只更新设备 // 1.1 流程中,更新业务相关字段、更新设备
// 1.2 已完成,更新证相关、批量方式的设备公共字段信息 // 1.2 已完成,更新业务相关字段、证相关、批量方式的设备公共字段信息
// 选择是台套、还是单位办理的方式,进行分类数据的解析 // 选择是台套、还是单位办理的方式,进行分类数据的解析
IChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
List<ChangeDataDto> allChangeColumns = dataProcessor.handle(changeData, applyNo);
if (!allChangeColumns.isEmpty()) {
// todo 数据库记录此次流水主键和es的batchId关联
// 更新历史的JSON的数据 // 更新历史的JSON的数据
this.updateHistoryJson(applyNo); this.updateHistoryJson(applyNo);
this.buildLogData(allChangeColumns); this.buildLogData(bizEditColumns);
// todo activeMQ 发送数据变更(业务+设备records)消息,已单据维度发送(观察者模式) return bizEditColumns;
// todo activeMQ 异步记录日志--保证可靠
publisher.publish(new ChangeDataEvent(this, allChangeColumns, RequestContext.cloneRequestContext()));
} }
@Override
public Boolean beforeCheck(String applyNo, ModelType model, Map<String, Object> changeData) {
return null;
} }
private void updateHistoryJson(String applyNo) { private void updateHistoryJson(String applyNo) {
...@@ -77,59 +66,15 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra ...@@ -77,59 +66,15 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
@Override @Override
public Map<String, ?> getDetail(String applyNo, ModelType model, String bizId) { public Map<String, ?> getDetail(String applyNo, ModelType model, String bizId) {
IChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model); IEquipChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
// 兼容:台套类打开变更详情(使用applyNo) 和 单位办理批量时选择单个设备打开详情(使用record) // 兼容:台套类打开变更详情(使用applyNo) 和 单位办理批量时选择单个设备打开详情(使用record)
// return dataProcessor.getDetail(applyNo, bizId); // return dataProcessor.getDetail(applyNo, bizId);
return null; return null;
} }
// private void updateManagerCertInfo(String applyNo, String record, EquipRegisterChangeDataDto registerChangeDataDto) { @Override
// JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>() protected BaseBizChangeEvent buildEvent(String applyNo, ModelType model, Map<String, Object> changeData) {
// .eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr, JgUseRegistration::getStatus, JgUseRegistration::getUseRegistrationCode)); return new BaseBizChangeEvent(this, applyNo, RequestContext.cloneRequestContext());
// if (FlowStatusEnum.TO_BE_FINISHED.getName().equals(jgUseRegistration.getStatus())) { }
// LambdaQueryWrapper<JgUseRegistrationManage> queryWrapper = new LambdaQueryWrapper<JgUseRegistrationManage>()
// .eq(JgUseRegistrationManage::getUseRegistrationCode, jgUseRegistration.getUseRegistrationCode())
// .eq(JgUseRegistrationManage::getIsDelete, 0).select(BaseEntity::getSequenceNbr,JgUseRegistrationManage::getVersion);
// JgUseRegistrationManage jgUseRegistrationManage = registrationManageMapper.selectOne(queryWrapper);
// if (jgUseRegistrationManage != null && !StringUtils.equals(jgUseRegistrationManage.getEquDefineCode(), registerChangeDataDto.getEquDefine())) {
// LambdaUpdateWrapper<JgUseRegistrationManage> updateWrapper = new LambdaUpdateWrapper<>();
// updateWrapper.eq(BaseEntity::getSequenceNbr, jgUseRegistrationManage.getSequenceNbr());
// if (StringUtils.isNotEmpty(registerChangeDataDto.getEquDefine())) {
// EquipmentCategory equipmentCategory = getEquipmentCategory(registerChangeDataDto);
// updateWrapper.set(JgUseRegistrationManage::getEquDefineCode, registerChangeDataDto.getEquDefine());
// updateWrapper.set(JgUseRegistrationManage::getEquDefine, equipmentCategory.getName());
// } else {
// updateWrapper.set(JgUseRegistrationManage::getEquDefineCode, null);
// updateWrapper.set(JgUseRegistrationManage::getEquDefine, null);
// }
// updateWrapper.set(JgUseRegistrationManage::getVersion, jgUseRegistrationManage.getVersion() + 1);
// updateWrapper.set(JgUseRegistrationManage::getRecDate, new Date());
// updateWrapper.set(JgUseRegistrationManage::getChangeReason, "设备信息变更");
// registrationManageMapper.update(null, updateWrapper);
// }
// }
// }
// private EquipmentCategory getEquipmentCategory(EquipRegisterChangeDataDto registerChangeDataDto) {
// return equipmentCategoryMapper.selectOne(new LambdaQueryWrapper<EquipmentCategory>().eq(EquipmentCategory::getCode, registerChangeDataDto.getEquDefine()));
// }
// private Map<String, Object> getDetailByBizId(String record) {
// Map<String, Object> re = new HashMap<>();
// // 注册信息(基本信息)构建
// EquipRegisterChangeDataDto equipRegisterChangeDataDto = commonEquipDataProcessService.buildRegisterInfo(record);
// // 制造信息构建
// EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.buildFactoryInfo(record);
// // 设计信息构建
// EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.buildDesignInfo(record);
// // 技术参数构建
// BaseTechParamsFieldDto techParamsFieldDto = commonEquipDataProcessService.buildTechParamInfo(equipRegisterChangeDataDto, record);
// re.putAll(BeanUtil.beanToMap(equipRegisterChangeDataDto));
// re.putAll(BeanUtil.beanToMap(factoryChangeDataDto));
// re.putAll(BeanUtil.beanToMap(designChangeDataDto));
// re.putAll(BeanUtil.beanToMap(techParamsFieldDto));
// commonEquipDataProcessService.castJsonFields(re);
// return commonEquipDataProcessService.cast2UnderCase(re);
// }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment