Commit 6da8426b authored by suhuiguang's avatar suhuiguang

1.编辑代码公共分析

parent 995750f8
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.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
......@@ -16,19 +17,19 @@ import java.util.Optional;
@Component
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)));
}
@Override
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()) {
return;
}
for (IBizDataChangeHandleStrategy strategy : strategyBeans.values()) {
for (DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> strategy : strategyBeans.values()) {
dataProcessStrategyHashMap.put(strategy.canHandleBizType(), strategy);
}
}
......
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.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
......@@ -17,20 +17,20 @@ import java.util.Optional;
@Component
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)));
}
@Override
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()) {
return;
}
for (IChangeDataProcessStrategy strategy : strategyBeans.values()) {
for (IEquipChangeDataProcessStrategy strategy : strategyBeans.values()) {
dataProcessStrategyHashMap.put(strategy.canHandleMode(), strategy);
}
}
......
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.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
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.SingleManageEquipEditHandleImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.validation.constraints.NotBlank;
import java.util.Map;
@RestController
@RequestMapping(value = "/data-change")
@Api(tags = "业务数据变化处理控制器")
@RequiredArgsConstructor
public class BizDataChangeController {
private final BizDataChangeServiceImpl bizDataChangeService;
public BizDataChangeController(BizDataChangeServiceImpl bizDataChangeService) {
this.bizDataChangeService = bizDataChangeService;
}
private final SingleManageEquipEditHandleImpl singleManageEquipEditHandle;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/{bizType}/save")
@PostMapping(value = "/v1/singleManageEquipEdit/save")
@ApiOperation(value = "业务数据变更保存--西安专用", httpMethod = "POST")
public ResponseModel<String> save(@RequestParam String applyNo,
@PathVariable String bizType,
@RequestBody RequestChangeData changeData) {
bizDataChangeService.save(applyNo, bizType, changeData);
singleManageEquipEditHandle.doSave(applyNo, changeData);
return ResponseHelper.buildResponse("success");
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/{bizType}/detail")
@ApiOperation(value = "查询可业务变更的字段及默认值", httpMethod = "GET")
public ResponseModel<Map<String, ?>> getDetail(@RequestParam(required = false) String applyNo,
@PathVariable String bizType,
IBizDataChangeHandleStrategy.ModelType model,
@RequestParam(required = false) String bizId) {
return ResponseHelper.buildResponse(bizDataChangeService.queryDetail(applyNo, bizType, model, bizId));
@GetMapping(value = "/v1/singleManageEquipEdit/detail")
@ApiOperation(value = "查询可业务变更的字段及默认值--西安专用", httpMethod = "GET")
public ResponseModel<Map<String, ?>> getDetailV1(@RequestParam(required = false) String applyNo,
@RequestParam(required = false) String bizId) {
return ResponseHelper.buildResponse(singleManageEquipEditHandle.getDetail(applyNo, bizId));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/v2/{bizType}/save")
@ApiOperation(value = "编辑保存", httpMethod = "POST")
@ApiOperation(value = "编辑保存--通用", httpMethod = "POST")
public ResponseModel<String> saveV2(@ApiParam(required = true, value = "单据编号") @RequestParam String applyNo,
@ApiParam(required = true, value = "业务类型")@PathVariable String bizType,
@RequestBody RequestChangeData changeData) {
@ApiParam(required = true, value = "业务类型") @PathVariable String bizType,
@RequestBody RequestChangeData changeData) {
// 基础数据校验
changeData.validated();
bizDataChangeService.save(applyNo, bizType, changeData);
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.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;
......@@ -32,10 +33,9 @@ public class RequestChangeData extends JSONObject {
*/
public static final String changeReasonAttachmentKey = "changeReasonAttachment";
public IBizDataChangeHandleStrategy.ModelType getModelType() {
public DefaultBizDataChangeHandler.ModelType getModelType() {
if (this.containsKey(modelTypeKey)) {
return IBizDataChangeHandleStrategy.ModelType.valueOf(this.getString(modelTypeKey));
return DefaultBizDataChangeHandler.ModelType.valueOf(this.getString(modelTypeKey));
}
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;
public interface IBizDataChangeHandleStrategy {
public interface IBizDataChangeHandleStrategy {
/**
* 可处理的业务类型(使用登记等)
......@@ -28,8 +33,10 @@ public interface IBizDataChangeHandleStrategy {
* @param model @see ModelType
* @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 {
batchEquip,
batchCylinder
}
String DEFAULT_VALUE = "default";
}
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.service.IBizDataChangeHandleStrategy;
import java.util.List;
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 {
*
* @return 可处理的类型
*/
IBizDataChangeHandleStrategy.ModelType canHandleMode();
DefaultBizDataChangeHandler.ModelType canHandleMode();
}
......@@ -3,8 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.service.IChangeDataProcessStrategy;
import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
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 java.util.ArrayList;
......@@ -15,12 +16,12 @@ import java.util.Map;
* 批量维护气瓶-策略实现类
*/
@Component
public class BatchCylinderDataChangeProcessStrategy implements IChangeDataProcessStrategy {
public class BatchCylinderDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
public BatchCylinderDataChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
public BatchCylinderDataEquipChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
this.commonEquipDataProcessService = commonEquipDataProcessService;
}
......@@ -115,7 +116,7 @@ public class BatchCylinderDataChangeProcessStrategy implements IChangeDataProces
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchCylinder;
public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return DefaultBizDataChangeHandler.ModelType.batchCylinder;
}
}
......@@ -3,8 +3,9 @@ package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.service.IChangeDataProcessStrategy;
import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
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 java.util.ArrayList;
......@@ -15,12 +16,12 @@ import java.util.Map;
* 批量维护设备-策略实现类
*/
@Component
public class BatchEquipDataChangeProcessStrategy implements IChangeDataProcessStrategy {
public class BatchEquipDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
public BatchEquipDataChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
public BatchEquipDataEquipChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
this.commonEquipDataProcessService = commonEquipDataProcessService;
}
......@@ -67,7 +68,7 @@ public class BatchEquipDataChangeProcessStrategy implements IChangeDataProcessSt
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchEquip;
public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return DefaultBizDataChangeHandler.ModelType.batchEquip;
}
}
......@@ -4,8 +4,9 @@ import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.service.IChangeDataProcessStrategy;
import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
......@@ -19,7 +20,7 @@ import java.util.Map;
*/
@Component
@RequiredArgsConstructor
public class BatchProjectDataChangeProcessStrategy implements IChangeDataProcessStrategy {
public class BatchProjectDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
......@@ -101,7 +102,7 @@ public class BatchProjectDataChangeProcessStrategy implements IChangeDataProcess
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchProject;
public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return DefaultBizDataChangeHandler.ModelType.batchProject;
}
}
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.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
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 org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -23,13 +24,13 @@ public class BizDataChangeServiceImpl {
public void save(String applyNo,
String bizType,
RequestChangeData changeData) {
IBizDataChangeHandleStrategy.ModelType model = changeData.getModelType();
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
DefaultBizDataChangeHandler.ModelType model = changeData.getModelType();
DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
handleStrategy.doSave(applyNo, model, changeData);
}
public Map<String, ?> queryDetail(String applyNo, String bizType, IBizDataChangeHandleStrategy.ModelType model, String bizId) {
IBizDataChangeHandleStrategy handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
public Map<String, ?> queryDetail(String applyNo, String bizType, DefaultBizDataChangeHandler.ModelType model, String bizId) {
DefaultBizDataChangeHandler<? extends BaseBizChangeEvent> handleStrategy = BizDataHandleStrategyContext.getStrategy(bizType);
return handleStrategy.getDetail(applyNo, model, bizId);
}
......
......@@ -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.JgUseRegistrationEq;
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.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 java.util.ArrayList;
......@@ -22,7 +22,7 @@ import java.util.Map;
* 单个维护设备-策略实现类
*/
@Component
public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrategy {
public class SingleEquipEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final JgUseRegistrationServiceImpl useRegistrationService;
......@@ -32,7 +32,7 @@ public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrat
private final CommonEquipDataProcessService commonEquipDataProcessService;
public SingleEquipChangeProcessStrategy(JgUseRegistrationServiceImpl useRegistrationService, JgUseRegistrationEqMapper jgRelationEquipMapper, CommonEquipDataProcessService commonEquipDataProcessService) {
public SingleEquipEquipChangeProcessStrategy(JgUseRegistrationServiceImpl useRegistrationService, JgUseRegistrationEqMapper jgRelationEquipMapper, CommonEquipDataProcessService commonEquipDataProcessService) {
this.useRegistrationService = useRegistrationService;
this.jgRelationEquipMapper = jgRelationEquipMapper;
this.commonEquipDataProcessService = commonEquipDataProcessService;
......@@ -73,8 +73,8 @@ public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrat
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.singleEquip;
public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return DefaultBizDataChangeHandler.ModelType.singleEquip;
}
}
......@@ -2,7 +2,6 @@ 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.*;
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.publisher.EventPublisher;
import lombok.RequiredArgsConstructor;
......@@ -17,18 +16,12 @@ import java.util.Map;
@Component
@RequiredArgsConstructor
public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStrategy {
public class SingleManageEquipEditHandleImpl {
private final CommonEquipDataProcessService commonEquipDataProcessService;
private final EventPublisher publisher;
@Override
public String canHandleBizType() {
return "singleManageEquipEdit";
}
@Override
public Map<String, ?> getDetail(String applyNo, ModelType model, String bizId) {
public Map<String, ?> getDetail(String applyNo, String bizId) {
return this.getDetailByBizId(bizId);
}
......@@ -50,9 +43,9 @@ public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStra
return commonEquipDataProcessService.cast2UnderCase(re);
}
@Override
@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);
// 记录流水
if (!allChangeColumns.isEmpty()) {
......@@ -63,6 +56,7 @@ public class SingleManageEquipEditHandleImpl implements IBizDataChangeHandleStra
}
}
private List<ChangeDataDto> update(String record, Map<String, Object> changeData) {
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
// 新数据解析
......
......@@ -5,8 +5,9 @@ import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.service.IChangeDataProcessStrategy;
import com.yeejoin.amos.boot.module.jg.biz.dto.RequestChangeData;
import com.yeejoin.amos.boot.module.jg.biz.service.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.jg.biz.service.IEquipChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
......@@ -21,7 +22,7 @@ import java.util.Map;
*/
@Component
@RequiredArgsConstructor
public class SingleProjectDataChangeProcessStrategy implements IChangeDataProcessStrategy {
public class SingleProjectDataEquipChangeProcessStrategy implements IEquipChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
......@@ -74,7 +75,7 @@ public class SingleProjectDataChangeProcessStrategy implements IChangeDataProces
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.singleProject;
public DefaultBizDataChangeHandler.ModelType canHandleMode() {
return DefaultBizDataChangeHandler.ModelType.singleProject;
}
}
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.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
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.ChangeDataEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
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.service.IEquipChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStrategy {
private final EventPublisher publisher;
@RequiredArgsConstructor
public class UseRegisterDataChangeHandleImpl extends DefaultBizDataChangeHandler<BaseBizChangeEvent> {
private final UseRegisterUpdateService useRegisterUpdateService;
public UseRegisterDataChangeHandleImpl(EventPublisher publisher, UseRegisterUpdateService useRegisterUpdateService) {
this.publisher = publisher;
this.useRegisterUpdateService = useRegisterUpdateService;
}
@Override
public String canHandleBizType() {
return "useRegister";
......@@ -45,23 +35,22 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
* @param changeData 前端不支持分组-目前为平铺数据结构
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void doSave(String applyNo, ModelType model, Map<String, Object> changeData) {
public List<ChangeDataDto> bizDataSave(String applyNo, ModelType model, Map<String, Object> changeData) {
List<ChangeDataDto> bizEditColumns = new ArrayList<ChangeDataDto>();
// 单据信息的保存、与设备相关、证相关字段的更新
// 1.根据任务状态进行单据数据的处理
// 1.1 流程中,不更业务相关字段,只更新设备
// 1.2 已完成,更新证相关、批量方式的设备公共字段信息
// 1.1 流程中,更新业务相关字段、更新设备
// 1.2 已完成,更新业务相关字段、证相关、批量方式的设备公共字段信息
// 选择是台套、还是单位办理的方式,进行分类数据的解析
IChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
List<ChangeDataDto> allChangeColumns = dataProcessor.handle(changeData, applyNo);
if (!allChangeColumns.isEmpty()) {
// todo 数据库记录此次流水主键和es的batchId关联
// 更新历史的JSON的数据
this.updateHistoryJson(applyNo);
this.buildLogData(allChangeColumns);
// todo activeMQ 发送数据变更(业务+设备records)消息,已单据维度发送(观察者模式)
// todo activeMQ 异步记录日志--保证可靠
publisher.publish(new ChangeDataEvent(this, allChangeColumns, RequestContext.cloneRequestContext()));
}
// 更新历史的JSON的数据
this.updateHistoryJson(applyNo);
this.buildLogData(bizEditColumns);
return bizEditColumns;
}
@Override
public Boolean beforeCheck(String applyNo, ModelType model, Map<String, Object> changeData) {
return null;
}
private void updateHistoryJson(String applyNo) {
......@@ -77,59 +66,15 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
@Override
public Map<String, ?> getDetail(String applyNo, ModelType model, String bizId) {
IChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
IEquipChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
// 兼容:台套类打开变更详情(使用applyNo) 和 单位办理批量时选择单个设备打开详情(使用record)
// return dataProcessor.getDetail(applyNo, bizId);
return null;
}
// private void updateManagerCertInfo(String applyNo, String record, EquipRegisterChangeDataDto registerChangeDataDto) {
// JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>()
// .eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr, JgUseRegistration::getStatus, JgUseRegistration::getUseRegistrationCode));
// 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);
// }
@Override
protected BaseBizChangeEvent buildEvent(String applyNo, ModelType model, Map<String, Object> changeData) {
return new BaseBizChangeEvent(this, applyNo, RequestContext.cloneRequestContext());
}
}
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