【同步】BOOT 和 CLOUD 的功能(所有)

master-jdk17
YunaiV 2024-12-27 22:19:09 +08:00
parent c322c53b45
commit e5c036a60d
43 changed files with 338 additions and 95 deletions

View File

@ -1,11 +1,12 @@
package cn.iocoder.yudao.framework.common.pojo;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.util.Assert;
import java.io.Serializable;
import java.util.Objects;
@ -41,7 +42,7 @@ public class CommonResult<T> implements Serializable {
* A CommonResult B
*
* @param result result
* @param <T>
* @param <T>
* @return CommonResult
*/
public static <T> CommonResult<T> error(CommonResult<?> result) {
@ -49,13 +50,21 @@ public class CommonResult<T> implements Serializable {
}
public static <T> CommonResult<T> error(Integer code, String message) {
Assert.isTrue(!GlobalErrorCodeConstants.SUCCESS.getCode().equals(code), "code 必须是错误的!");
Assert.notEquals(GlobalErrorCodeConstants.SUCCESS.getCode(), code, "code 必须是错误的!");
CommonResult<T> result = new CommonResult<>();
result.code = code;
result.msg = message;
return result;
}
public static <T> CommonResult<T> error(ErrorCode errorCode, Object... params) {
Assert.notEquals(GlobalErrorCodeConstants.SUCCESS.getCode(), errorCode.getCode(), "code 必须是错误的!");
CommonResult<T> result = new CommonResult<>();
result.code = errorCode.getCode();
result.msg = ServiceExceptionUtil.doFormat(errorCode.getCode(), errorCode.getMsg(), params);
return result;
}
public static <T> CommonResult<T> error(ErrorCode errorCode) {
return error(errorCode.getCode(), errorCode.getMsg());
}

View File

@ -99,7 +99,8 @@ public class BpmModelController {
return null;
}
byte[] bpmnBytes = modelService.getModelBpmnXML(id);
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes));
BpmSimpleModelNodeVO simpleModel = modelService.getSimpleModel(id);
return success(BpmModelConvert.INSTANCE.buildModel(model, bpmnBytes, simpleModel));
}
@PostMapping("/create")
@ -109,7 +110,6 @@ public class BpmModelController {
return success(modelService.createModel(createRetVO));
}
@PutMapping("/update")
@Operation(summary = "修改模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
@ -143,6 +143,7 @@ public class BpmModelController {
return success(true);
}
@Deprecated
@PutMapping("/update-bpmn")
@Operation(summary = "修改模型的 BPMN")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")
@ -169,6 +170,7 @@ public class BpmModelController {
return success(modelService.getSimpleModel(modelId));
}
@Deprecated
@PostMapping("/simple/update")
@Operation(summary = "保存仿钉钉流程设计模型")
@PreAuthorize("@ss.hasPermission('bpm:model:update')")

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -35,12 +36,15 @@ public class BpmModelRespVO extends BpmModelMetaInfoVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "BPMN XML", requiredMode = Schema.RequiredMode.REQUIRED)
private String bpmnXml;
@Schema(description = "可发起的用户数组")
private List<UserSimpleBaseVO> startUsers;
@Schema(description = "BPMN XML")
private String bpmnXml;
@Schema(description = "仿钉钉流程设计模型对象")
private BpmSimpleModelNodeVO simpleModel;
/**
*
*/

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@ -22,4 +24,11 @@ public class BpmModelSaveReqVO extends BpmModelMetaInfoVO {
@Schema(description = "流程分类", example = "1")
private String category;
@Schema(description = "BPMN XML")
private String bpmnXml;
@Schema(description = "仿钉钉流程设计模型对象")
@Valid
private BpmSimpleModelNodeVO simpleModel;
}

View File

@ -15,6 +15,9 @@ public class BpmTaskPageReqVO extends PageParam {
@Schema(description = "流程任务名", example = "芋道")
private String name;
@Schema(description = "流程分类", example = "1")
private String category;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
@ -58,12 +59,13 @@ public interface BpmModelConvert {
return result;
}
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes) {
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) {
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
}
modelVO.setSimpleModel(simpleModel);
return modelVO;
}

View File

@ -124,12 +124,18 @@ public interface BpmTaskConvert {
}
default BpmTaskRespVO buildTodoTask(Task todoTask, List<Task> childrenTasks,
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting) {
return BeanUtils.toBean(todoTask, BpmTaskRespVO.class)
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting,
BpmFormDO form) {
BpmTaskRespVO bpmTaskRespVO = BeanUtils.toBean(todoTask, BpmTaskRespVO.class)
.setStatus(FlowableUtils.getTaskStatus(todoTask)).setReason(FlowableUtils.getTaskReason(todoTask))
.setButtonsSetting(buttonsSetting)
.setChildren(convertList(childrenTasks, childTask -> BeanUtils.toBean(childTask, BpmTaskRespVO.class)
.setStatus(FlowableUtils.getTaskStatus(childTask))));
if (form != null) {
bpmTaskRespVO.setFormId(form.getId()).setFormName(form.getName())
.setFormConf(form.getConf()).setFormFields(form.getFields());
}
return bpmTaskRespVO;
}
default BpmMessageSendWhenTaskCreatedReqDTO convert(ProcessInstance processInstance, AdminUserRespDTO startUser,

View File

@ -54,13 +54,13 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav
Set<Long> assigneeUserIds = (Set<Long>) execution.getVariable(super.collectionVariable, Set.class);
if (assigneeUserIds == null) {
assigneeUserIds = taskCandidateInvoker.calculateUsersByTask(execution);
execution.setVariable(super.collectionVariable, assigneeUserIds);
if (CollUtil.isEmpty(assigneeUserIds)) {
// 特殊:如果没有处理人的情况下,至少有一个 null 空元素,避免自动通过!
// 这样,保证在 BpmUserTaskActivityBehavior 至少创建出一个 Task 任务
// 用途1审批人为空时2审批类型为自动通过、自动拒绝时
assigneeUserIds = SetUtils.asSet((Long) null);
}
execution.setVariableLocal(super.collectionVariable, assigneeUserIds);
}
return assigneeUserIds.size();
}

View File

@ -43,17 +43,18 @@ public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceB
super.collectionElementVariable = FlowableUtils.formatExecutionCollectionElementVariable(execution.getCurrentActivityId());
// 第二步,获取任务的所有处理人
// 不使用 execution.getVariable 原因:目前依次审批任务回退后 collectionVariable 变量没有清理, 如果重新进入该任务不会重新分配审批人
@SuppressWarnings("unchecked")
Set<Long> assigneeUserIds = (Set<Long>) execution.getVariable(super.collectionVariable, Set.class);
Set<Long> assigneeUserIds = (Set<Long>) execution.getVariableLocal(super.collectionVariable, Set.class);
if (assigneeUserIds == null) {
assigneeUserIds = taskCandidateInvoker.calculateUsersByTask(execution);
execution.setVariable(super.collectionVariable, assigneeUserIds);
if (CollUtil.isEmpty(assigneeUserIds)) {
// 特殊:如果没有处理人的情况下,至少有一个 null 空元素,避免自动通过!
// 这样,保证在 BpmUserTaskActivityBehavior 至少创建出一个 Task 任务
// 用途1审批人为空时2审批类型为自动通过、自动拒绝时
assigneeUserIds = SetUtils.asSet((Long) null);
}
execution.setVariableLocal(super.collectionVariable, assigneeUserIds);
}
return assigneeUserIds.size();
}

View File

@ -18,7 +18,7 @@ import java.util.Set;
* @author jason
*/
@Component
public class BpmTaskCandidateFormSDeptLeaderStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {
public class BpmTaskCandidateFormDeptLeaderStrategy extends AbstractBpmTaskCandidateDeptLeaderStrategy {
@Override
public BpmTaskCandidateStrategyEnum getStrategy() {

View File

@ -4,10 +4,14 @@ import cn.hutool.core.convert.Convert;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateStrategy;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmTaskCandidateStrategyEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -17,6 +21,7 @@ import java.util.Set;
* @author
*/
@Component
@Slf4j
public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrategy {
@Override
@ -38,8 +43,16 @@ public class BpmTaskCandidateExpressionStrategy implements BpmTaskCandidateStrat
@Override
public Set<Long> calculateUsersByActivity(BpmnModel bpmnModel, String activityId, String param,
Long startUserId, String processDefinitionId, Map<String, Object> processVariables) {
Object result = FlowableUtils.getExpressionValue(processVariables, param);
return Convert.toSet(Long.class, result);
Map<String, Object> variables = processVariables == null ? new HashMap<>() : processVariables;
try {
Object result = FlowableUtils.getExpressionValue(variables, param);
return Convert.toSet(Long.class, result);
} catch (FlowableException ex) {
// 预测未运行的节点时候,表达式如果包含 execution 或者不存在的流程变量会抛异常,
log.warn("[calculateUsersByActivity][表达式({}) 变量({}) 解析报错", param, variables, ex);
// 不能预测候选人,返回空列表, 避免流程无法进行
return Sets.newHashSet();
}
}
}

View File

@ -73,7 +73,6 @@ public class BpmnModelUtils {
extensionElement.setName(name);
attributes.forEach((key, value) -> {
ExtensionAttribute extensionAttribute = new ExtensionAttribute(key, value);
extensionAttribute.setNamespace(FLOWABLE_EXTENSIONS_NAMESPACE);
extensionElement.addAttribute(extensionAttribute);
});
element.addExtensionElement(extensionElement);
@ -278,8 +277,8 @@ public class BpmnModelUtils {
}
Map<String, String> fieldsPermission = MapUtil.newHashMap();
extensionElements.forEach(element -> {
String field = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE);
String permission = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE);
String field = element.getAttributeValue(null, FORM_FIELD_PERMISSION_ELEMENT_FIELD_ATTRIBUTE);
String permission = element.getAttributeValue(null, FORM_FIELD_PERMISSION_ELEMENT_PERMISSION_ATTRIBUTE);
if (StrUtil.isNotEmpty(field) && StrUtil.isNotEmpty(permission)) {
fieldsPermission.put(field, permission);
}
@ -321,9 +320,9 @@ public class BpmnModelUtils {
}
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonSettings = Maps.newHashMapWithExpectedSize(extensionElements.size());
extensionElements.forEach(element -> {
String id = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE);
String displayName = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE);
String enable = element.getAttributeValue(FLOWABLE_EXTENSIONS_NAMESPACE, BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE);
String id = element.getAttributeValue(null, BUTTON_SETTING_ELEMENT_ID_ATTRIBUTE);
String displayName = element.getAttributeValue(null, BUTTON_SETTING_ELEMENT_DISPLAY_NAME_ATTRIBUTE);
String enable = element.getAttributeValue(null, BUTTON_SETTING_ELEMENT_ENABLE_ATTRIBUTE);
if (StrUtil.isNotEmpty(id)) {
BpmTaskRespVO.OperationButtonSetting setting = new BpmTaskRespVO.OperationButtonSetting();
buttonSettings.put(Integer.valueOf(id), setting.setDisplayName(displayName).setEnable(Boolean.parseBoolean(enable)));
@ -720,7 +719,7 @@ public class BpmnModelUtils {
&& evalConditionExpress(variables, flow.getConditionExpression()));
if (matchSequenceFlow == null) {
matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(),
flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()));
flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
// 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的
if (matchSequenceFlow == null && gateway.getOutgoingFlows().size() == 1) {
matchSequenceFlow = gateway.getOutgoingFlows().get(0);
@ -742,7 +741,7 @@ public class BpmnModelUtils {
&& evalConditionExpress(variables, flow.getConditionExpression()));
if (CollUtil.isEmpty(matchSequenceFlows)) {
matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(),
flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()));
flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId()));
// 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的
if (CollUtil.isEmpty(matchSequenceFlows) && gateway.getOutgoingFlows().size() == 1) {
matchSequenceFlows = gateway.getOutgoingFlows();

View File

@ -83,7 +83,7 @@ public class SimpleModelUtils {
private static BpmSimpleModelNodeVO buildStartNode() {
return new BpmSimpleModelNodeVO().setId(START_EVENT_NODE_ID)
.setName(BpmSimpleModelNodeType.START_USER_NODE.getName())
.setName(BpmSimpleModelNodeType.START_NODE.getName())
.setType(BpmSimpleModelNodeType.START_NODE.getType());
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.service.definition;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
@ -12,6 +13,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.B
import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
@ -65,7 +67,7 @@ public class BpmModelServiceImpl implements BpmModelService {
public List<Model> getModelList(String name) {
ModelQuery modelQuery = repositoryService.createModelQuery();
if (StrUtil.isNotEmpty(name)) {
modelQuery.modelNameLike(name);
modelQuery.modelNameLike("%" + name + "%");
}
return modelQuery.list();
}
@ -82,26 +84,54 @@ public class BpmModelServiceImpl implements BpmModelService {
throw exception(MODEL_KEY_EXISTS, createReqVO.getKey());
}
// 2.1 创建流程定义
// 2. 创建 Model 对象
createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序
Model model = repositoryService.newModel();
BpmModelConvert.INSTANCE.copyToModel(model, createReqVO);
model.setTenantId(FlowableUtils.getTenantId());
// 2.2 保存流程定义
repositoryService.saveModel(model);
// 3. 保存模型
saveModel(model, createReqVO);
return model.getId();
}
@Override
@Transactional(rollbackFor = Exception.class) // 因为进行多个操作,所以开启事务
public void updateModel(Long userId, @Valid BpmModelSaveReqVO updateReqVO) {
public void updateModel(Long userId, BpmModelSaveReqVO updateReqVO) {
// 1. 校验流程模型存在
Model model = validateModelManager(updateReqVO.getId(), userId);
// 修改流程定义
// 2. 填充 Model 信息
BpmModelConvert.INSTANCE.copyToModel(model, updateReqVO);
// 更新模型
// 3. 保存模型
saveModel(model, updateReqVO);
}
/**
*
*
* @param model
* @param saveReqVO
*/
private void saveModel(Model model, BpmModelSaveReqVO saveReqVO) {
// 1. 保存模型的基础信息
repositoryService.saveModel(model);
// 2. 保存流程图
if (ObjUtil.equals(BpmModelTypeEnum.BPMN.getType(), saveReqVO.getType())
&& StrUtil.isNotEmpty(saveReqVO.getBpmnXml())) {
updateModelBpmnXml(model.getId(), saveReqVO.getBpmnXml());
} else if (ObjUtil.equals(BpmModelTypeEnum.SIMPLE.getType(), saveReqVO.getType())
&& saveReqVO.getSimpleModel() != null) {
// JSON 转换成 bpmnModel
BpmnModel bpmnModel = SimpleModelUtils.buildBpmnModel(model.getKey(), model.getName(),
saveReqVO.getSimpleModel());
// 保存 Bpmn XML
updateModelBpmnXml(model.getId(), BpmnModelUtils.getBpmnXml(bpmnModel));
// 保存 JSON 数据
updateModelSimpleJson(model.getId(), saveReqVO.getSimpleModel());
}
}
@Override
@ -110,7 +140,7 @@ public class BpmModelServiceImpl implements BpmModelService {
// 1.1 校验流程模型存在
List<Model> models = repositoryService.createModelQuery()
.modelTenantId(FlowableUtils.getTenantId()).list();
models.removeIf(model ->!ids.contains(model.getId()));
models.removeIf(model -> !ids.contains(model.getId()));
if (ids.size() != models.size()) {
throw exception(MODEL_NOT_EXISTS);
}
@ -173,7 +203,8 @@ public class BpmModelServiceImpl implements BpmModelService {
String simpleJson = getModelSimpleJson(model.getId());
// 2.1 创建流程定义
String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson, form);
String definitionId = processDefinitionService.createProcessDefinition(model, metaInfo, bpmnBytes, simpleJson,
form);
// 2.2 将老的流程定义进行挂起。也就是说,只有最新部署的流程定义,才可以发起任务。
updateProcessDefinitionSuspended(model.getDeploymentId());
@ -220,7 +251,8 @@ public class BpmModelServiceImpl implements BpmModelService {
// 1.1 校验流程模型存在
Model model = validateModelManager(id, userId);
// 1.2 校验流程定义存在
ProcessDefinition definition = processDefinitionService.getProcessDefinitionByDeploymentId(model.getDeploymentId());
ProcessDefinition definition = processDefinitionService
.getProcessDefinitionByDeploymentId(model.getDeploymentId());
if (definition == null) {
throw exception(PROCESS_DEFINITION_NOT_EXISTS);
}
@ -276,7 +308,8 @@ public class BpmModelServiceImpl implements BpmModelService {
}
return form;
} else {
if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath()) || StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) {
if (StrUtil.isEmpty(metaInfo.getFormCustomCreatePath())
|| StrUtil.isEmpty(metaInfo.getFormCustomViewPath())) {
throw exception(MODEL_DEPLOY_FAIL_FORM_NOT_CONFIG);
}
return null;
@ -323,7 +356,8 @@ public class BpmModelServiceImpl implements BpmModelService {
if (oldDefinition == null) {
return;
}
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(),
SuspensionState.SUSPENDED.getStateCode());
}
private Model getModelByKey(String key) {

View File

@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.common.util.object.PageUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.enums.definition.*;
import cn.iocoder.yudao.module.bpm.enums.task.BpmCommentTypeEnum;
import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum;
@ -20,6 +21,7 @@ import cn.iocoder.yudao.module.bpm.enums.task.BpmTaskStatusEnum;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.service.definition.BpmFormService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
@ -91,6 +93,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
private BpmModelService modelService;
@Resource
private BpmMessageService messageService;
@Resource
private BpmFormService formService;
@Resource
private AdminUserApi adminUserApi;
@ -109,6 +113,9 @@ public class BpmTaskServiceImpl implements BpmTaskService {
if (StrUtil.isNotBlank(pageVO.getName())) {
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
}
if (StrUtil.isNotEmpty(pageVO.getCategory())) {
taskQuery.taskCategory(pageVO.getCategory());
}
if (ArrayUtil.isNotEmpty(pageVO.getCreateTime())) {
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[0]));
taskQuery.taskCreatedBefore(DateUtils.of(pageVO.getCreateTime()[1]));
@ -153,7 +160,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(todoTask.getProcessDefinitionId());
Map<Integer, BpmTaskRespVO.OperationButtonSetting> buttonsSetting = BpmnModelUtils.parseButtonsSetting(
bpmnModel, todoTask.getTaskDefinitionKey());
return BpmTaskConvert.INSTANCE.buildTodoTask(todoTask, childrenTasks, buttonsSetting);
// 4. 任务表单
BpmFormDO taskForm = null;
if (StrUtil.isNotBlank(todoTask.getFormKey())){
taskForm = formService.getForm(NumberUtils.parseLong(todoTask.getFormKey()));
}
return BpmTaskConvert.INSTANCE.buildTodoTask(todoTask, childrenTasks, buttonsSetting, taskForm);
}
@Override
@ -188,6 +201,9 @@ public class BpmTaskServiceImpl implements BpmTaskService {
if (StrUtil.isNotBlank(pageVO.getName())) {
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
}
if (StrUtil.isNotEmpty(pageVO.getCategory())) {
taskQuery.taskCategory(pageVO.getCategory());
}
if (ArrayUtil.isNotEmpty(pageVO.getCreateTime())) {
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[0]));
taskQuery.taskCreatedBefore(DateUtils.of(pageVO.getCreateTime()[1]));
@ -441,7 +457,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
*
*
* @param userId Id
* @param task
* @param task
* @return
*/
private boolean isAddSignUserTask(Long userId, Task task) {
@ -669,7 +685,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
reqVO.getTargetTaskDefinitionKey(), task.getProcessDefinitionId());
// 2. 调用 Flowable 框架的退回逻辑
returnTask(task, targetElement, reqVO);
returnTask(userId, task, targetElement, reqVO);
}
/**
@ -701,11 +717,12 @@ public class BpmTaskServiceImpl implements BpmTaskService {
/**
* 退
*
* @param userId
* @param currentTask 退
* @param targetElement 退
* @param reqVO
*/
public void returnTask(Task currentTask, FlowElement targetElement, BpmTaskReturnReqVO reqVO) {
public void returnTask(Long userId, Task currentTask, FlowElement targetElement, BpmTaskReturnReqVO reqVO) {
// 1. 获得所有需要回撤的任务 taskDefinitionKey用于稍后的 moveActivityIdsToSingleActivityId 回撤
// 1.1 获取所有正常进行的任务节点 Key
List<Task> taskList = taskService.createTaskQuery().processInstanceId(currentTask.getProcessInstanceId()).list();
@ -721,22 +738,29 @@ public class BpmTaskServiceImpl implements BpmTaskService {
if (!returnTaskKeyList.contains(task.getTaskDefinitionKey())) {
return;
}
// 2.1 添加评论
taskService.addComment(task.getId(), currentTask.getProcessInstanceId(), BpmCommentTypeEnum.RETURN.getType(),
BpmCommentTypeEnum.RETURN.formatComment(reqVO.getReason()));
// 2.2 更新 task 状态 + 原因
updateTaskStatusAndReason(task.getId(), BpmTaskStatusEnum.RETURN.getStatus(), reqVO.getReason());
// 判断是否分配给自己任务,因为会签任务,一个节点会有多个任务
if (isAssignUserTask(userId, task)) { // 情况一:自己的任务,进行 RETURN 标记
// 2.1.1 添加评论
taskService.addComment(task.getId(), currentTask.getProcessInstanceId(), BpmCommentTypeEnum.RETURN.getType(),
BpmCommentTypeEnum.RETURN.formatComment(reqVO.getReason()));
// 2.1.2 更新 task 状态 + 原因
updateTaskStatusAndReason(task.getId(), BpmTaskStatusEnum.RETURN.getStatus(), reqVO.getReason());
} else { // 情况二:别人的任务,进行 CANCEL 标记
processTaskCanceled(task.getId());
}
});
// 3. 设置流程变量节点驳回标记:用于驳回到节点,不执行 BpmUserTaskAssignStartUserHandlerTypeEnum 策略。导致自动通过
runtimeService.setVariable(currentTask.getProcessInstanceId(),
String.format(PROCESS_INSTANCE_VARIABLE_RETURN_FLAG, reqVO.getTargetTaskDefinitionKey()), Boolean.TRUE);
// 4. 执行驳回
// 使用 moveExecutionsToSingleActivityId 替换 moveActivityIdsToSingleActivityId 原因:
// 当多实例任务回退的时候有问题。相关 issue: https://github.com/flowable/flowable-engine/issues/3944
List<String> runExecutionIds = convertList(taskList, Task::getExecutionId);
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(currentTask.getProcessInstanceId())
.moveActivityIdsToSingleActivityId(returnTaskKeyList, // 当前要跳转的节点列表( 1 或多)
reqVO.getTargetTaskDefinitionKey()) // targetKey 跳转到的节点(1)
.moveExecutionsToSingleActivityId(runExecutionIds, reqVO.getTargetTaskDefinitionKey())
.changeState();
}
@ -1021,14 +1045,22 @@ public class BpmTaskServiceImpl implements BpmTaskService {
Integer assignEmptyHandlerType = BpmnModelUtils.parseAssignEmptyHandlerType(userTaskElement);
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
/**
* TransactionSynchronizationManager afterCommit afterCompletion
* task
* <a href="https://gitee.com/zhijiantianya/yudao-cloud/issues/IB7V7Q">issue</a>
*/
@Override
public void afterCompletion(int transactionStatus) {
// 特殊情况部分情况下TransactionSynchronizationManager 注册 afterCommit 监听时,不会被调用,但是 afterCompletion 可以
// 例如说:第一个 task 就是配置【自动通过】或者【自动拒绝】时
if (ObjectUtil.notEqual(transactionStatus, TransactionSynchronization.STATUS_COMMITTED)) {
// 回滚情况,直接返回
if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_ROLLED_BACK)) {
return;
}
// 特殊情况:第一个 task 【自动通过】时,第二个任务设置审批人时 transactionStatus 会为 STATUS_UNKNOWN不知道啥原因
if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_UNKNOWN)
&& getTask(task.getId()) == null) {
return;
}
// TODO 芋艿:可以后续优化成 getSelf();
// 特殊情况一:【人工审核】审批人为空,根据配置是否要自动通过、自动拒绝
if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.USER.getType())) {
// 如果有审批人、或者拥有人,则说明不满足情况一,不自动通过、不自动拒绝
@ -1036,19 +1068,19 @@ public class BpmTaskServiceImpl implements BpmTaskService {
return;
}
if (ObjectUtil.equal(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.APPROVE.getType())) {
SpringUtil.getBean(BpmTaskService.class).approveTask(null, new BpmTaskApproveReqVO()
getSelf().approveTask(null, new BpmTaskApproveReqVO()
.setId(task.getId()).setReason(BpmReasonEnum.ASSIGN_EMPTY_APPROVE.getReason()));
} else if (ObjectUtil.equal(assignEmptyHandlerType, BpmUserTaskAssignEmptyHandlerTypeEnum.REJECT.getType())) {
SpringUtil.getBean(BpmTaskService.class).rejectTask(null, new BpmTaskRejectReqVO()
getSelf().rejectTask(null, new BpmTaskRejectReqVO()
.setId(task.getId()).setReason(BpmReasonEnum.ASSIGN_EMPTY_REJECT.getReason()));
}
// 特殊情况二:【自动审核】审批类型为自动通过、不通过
} else {
if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.AUTO_APPROVE.getType())) {
SpringUtil.getBean(BpmTaskService.class).approveTask(null, new BpmTaskApproveReqVO()
getSelf().approveTask(null, new BpmTaskApproveReqVO()
.setId(task.getId()).setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_APPROVE.getReason()));
} else if (ObjectUtil.equal(approveType, BpmUserTaskApproveTypeEnum.AUTO_REJECT.getType())) {
SpringUtil.getBean(BpmTaskService.class).rejectTask(null, new BpmTaskRejectReqVO()
getSelf().rejectTask(null, new BpmTaskRejectReqVO()
.setId(task.getId()).setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_REJECT.getReason()));
}
}
@ -1087,8 +1119,22 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 发送通知。在事务提交时,批量执行操作,所以直接查询会无法查询到 ProcessInstance所以这里是通过监听事务的提交来实现。
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
/**
* TransactionSynchronizationManager afterCommit afterCompletion
* task
* <a href="https://gitee.com/zhijiantianya/yudao-cloud/issues/IB7V7Q">issue</a>
*/
@Override
public void afterCommit() {
public void afterCompletion(int transactionStatus) {
// 回滚情况,直接返回
if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_ROLLED_BACK)) {
return;
}
// 特殊情况:第一个 task 【自动通过】时,第二个任务设置审批人时 transactionStatus 会为 STATUS_UNKNOWN不知道啥原因
if (ObjectUtil.equal(transactionStatus, TransactionSynchronization.STATUS_UNKNOWN)
&& getTask(task.getId()) == null) {
return;
}
if (StrUtil.isEmpty(task.getAssignee())) {
log.error("[processTaskAssigned][taskId({}) 没有分配到负责人]", task.getId());
return;

View File

@ -60,12 +60,13 @@ public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO
// Backlog: 回款提醒类型
LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
if (CrmReceivablePlanPageReqVO.REMIND_TYPE_NEEDED.equals(pageReqVO.getRemindType())) { // 待回款
// 查询条件:未回款 + 提醒时间 <= 当前时间(反过来即当前时间 >= 提醒时间,已经到达提醒的时间点)
query.isNull(CrmReceivablePlanDO::getReceivableId) // 未回款
.lt(CrmReceivablePlanDO::getReturnTime, beginOfToday) // 已逾期
.lt(CrmReceivablePlanDO::getRemindTime, beginOfToday); // 今天开始提醒
} else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_EXPIRED.equals(pageReqVO.getRemindType())) { // 已逾期
.le(CrmReceivablePlanDO::getRemindTime, beginOfToday); // 今天开始提醒
} else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_EXPIRED.equals(pageReqVO.getRemindType())) { // 已逾期
// 查询条件:未回款 + 回款时间 < 当前时间(反过来即当前时间 > 回款时间,已经过了回款时间点)
query.isNull(CrmReceivablePlanDO::getReceivableId) // 未回款
.ge(CrmReceivablePlanDO::getReturnTime, beginOfToday); // 已逾期
.lt(CrmReceivablePlanDO::getReturnTime, beginOfToday); // 已逾期
} else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_RECEIVED.equals(pageReqVO.getRemindType())) { // 已回款
query.isNotNull(CrmReceivablePlanDO::getReceivableId);
}

View File

@ -270,7 +270,7 @@ public class CrmContractServiceImpl implements CrmContractService {
}
@Override
@LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}",
@LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}}",
success = CRM_CONTRACT_FOLLOW_UP_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
public void updateContractFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent) {

View File

@ -60,7 +60,8 @@ public class CrmPermissionUtils {
}
query.innerJoin(CrmPermissionDO.class, on -> on.eq(CrmPermissionDO::getBizType, bizType)
.eq(CrmPermissionDO::getBizId, bizId)
.in(CrmPermissionDO::getLevel, CrmPermissionLevelEnum.READ.getLevel(), CrmPermissionLevelEnum.WRITE.getLevel()));
.in(CrmPermissionDO::getLevel, CrmPermissionLevelEnum.READ.getLevel(), CrmPermissionLevelEnum.WRITE.getLevel())
.eq(CrmPermissionDO::getUserId,userId));
query.ne(ownerUserIdField, userId);
}
// 场景三:下属负责的数据(下属是负责人)

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.erp.controller.admin.finance.vo.payment;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
@ -11,6 +12,7 @@ import java.util.List;
@Schema(description = "管理后台 - ERP 付款单 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ErpFinancePaymentRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23752")

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.erp.controller.admin.finance.vo.receipt;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
@ -11,6 +12,7 @@ import java.util.List;
@Schema(description = "管理后台 - ERP 收款单 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ErpFinanceReceiptRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23752")

View File

@ -15,8 +15,8 @@ import java.util.Arrays;
@AllArgsConstructor
public enum ProductCommentAuditStatusEnum implements IntArrayValuable {
NONE(1, "待审核"),
APPROVE(2, "审批通过"),
NONE(0, "待审核"),
APPROVE(1, "审批通过"),
REJECT(2, "审批不通过"),;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductCommentAuditStatusEnum::getStatus).toArray();

View File

@ -48,4 +48,9 @@ public class AppProductSpuRespVO {
@Schema(description = "商品销量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer salesCount;
// ========== 物流相关字段 =========
@Schema(description = "配送方式数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private List<Integer> deliveryTypes;
}

View File

@ -78,7 +78,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Transactional(rollbackFor = Exception.class)
public void updateSpu(ProductSpuSaveReqVO updateReqVO) {
// 校验 SPU 是否存在
validateSpuExists(updateReqVO.getId());
ProductSpuDO spu = validateSpuExists(updateReqVO.getId());
// 校验分类、品牌
validateCategory(updateReqVO.getCategoryId());
brandService.validateProductBrand(updateReqVO.getBrandId());
@ -87,7 +87,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
// 更新 SPU
ProductSpuDO updateObj = BeanUtils.toBean(updateReqVO, ProductSpuDO.class);
ProductSpuDO updateObj = BeanUtils.toBean(updateReqVO, ProductSpuDO.class).setStatus(spu.getStatus());
initSpuFromSkus(updateObj, skuSaveReqList);
productSpuMapper.updateById(updateObj);
// 批量更新 SKU
@ -176,10 +176,12 @@ public class ProductSpuServiceImpl implements ProductSpuService {
productSkuService.deleteSkuBySpuId(id);
}
private void validateSpuExists(Long id) {
if (productSpuMapper.selectById(id) == null) {
private ProductSpuDO validateSpuExists(Long id) {
ProductSpuDO spuDO = productSpuMapper.selectById(id);
if (spuDO == null) {
throw exception(SPU_NOT_EXISTS);
}
return spuDO;
}
@Override

View File

@ -152,7 +152,7 @@ public class CouponServiceImpl implements CouponService {
findAndThen(userCouponIdsMap, userId, couponIds::addAll);
}
} catch (Exception e) {
log.error("[takeCouponsByAdmin][coupon({}) 优惠券发放失败]", entry, e);
log.error("[takeCouponsByAdmin][coupon({}) 优惠券发放失败 userId({})]", entry, userId, e);
}
}
return couponIds;
@ -270,7 +270,7 @@ public class CouponServiceImpl implements CouponService {
}
// 校验剩余数量
if (ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TIME_LIMIT_COUNT_MAX) // 非不限制
&& couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
&& couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
}
// 校验"固定日期"的有效期类型是否过期

View File

@ -93,6 +93,7 @@ public interface ErrorCodeConstants {
ErrorCode BROKERAGE_BIND_OVERRIDE = new ErrorCode(1_011_007_006, "已绑定了推广人");
ErrorCode BROKERAGE_BIND_LOOP = new ErrorCode(1_011_007_007, "下级不能绑定自己的上级");
ErrorCode BROKERAGE_USER_LEVEL_NOT_SUPPORT = new ErrorCode(1_011_007_008, "目前只支持 level 小于等于 2");
ErrorCode BROKERAGE_CREATE_USER_EXISTS = new ErrorCode(1_011_007_009, "分销用户已存在");
// ========== 分销提现 模块 1-011-008-000 ==========
ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1_011_008_000, "佣金提现记录不存在");

View File

@ -47,6 +47,13 @@ public class BrokerageUserController {
@Resource
private MemberUserApi memberUserApi;
@PostMapping("/create")
@Operation(summary = "创建分销用户")
@PreAuthorize("@ss.hasPermission('trade:brokerage-user:create')")
public CommonResult<Long> createBrokerageUser(@Valid @RequestBody BrokerageUserCreateReqVO createReqVO) {
return success(brokerageUserService.createBrokerageUser(createReqVO));
}
@PutMapping("/update-bind-user")
@Operation(summary = "修改推广员")
@PreAuthorize("@ss.hasPermission('trade:brokerage-user:update-bind-user')")

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@Schema(description = "管理后台 - 分销用户创建 Request VO")
@Data
public class BrokerageUserCreateReqVO {
@Schema(description = "分销用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "分销用户编号不能为空")
private Long userId;
@Schema(description = "推广员编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4587")
private Long bindUserId;
}

View File

@ -20,7 +20,7 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 售后日志")
@Tag(name = "用户 App - 售后日志")
@RestController
@RequestMapping("/trade/after-sale-log")
@Validated

View File

@ -59,6 +59,9 @@ public interface BrokerageUserConvert {
}
default BrokerageUserRespVO copyTo(MemberUserRespDTO source, BrokerageUserRespVO target) {
if (target == null) {
return null;
}
Optional.ofNullable(source).ifPresent(
user -> target.setNickname(user.getNickname()).setAvatar(user.getAvatar()));
return target;

View File

@ -27,7 +27,7 @@ import java.util.Map;
*
* @author
*/
@TableName("trade_order")
@TableName(value = "trade_order", autoResultMap = true)
@KeySequence("trade_order_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)

View File

@ -79,7 +79,7 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
TradeConfigDO memberConfig = tradeConfigService.getTradeConfig();
// 0 未启用分销功能
if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) {
log.warn("[addBrokerage][增加佣金失败brokerageEnabled 未配置userId({})", userId);
log.error("[addBrokerage][增加佣金失败brokerageEnabled 未配置userId({}) bizType({}) list({})", userId, bizType, list);
return;
}

View File

@ -1,12 +1,14 @@
package cn.iocoder.yudao.module.trade.service.brokerage;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
/**
@ -107,6 +109,14 @@ public interface BrokerageUserService {
*/
boolean bindBrokerageUser(@NotNull Long userId, @NotNull Long bindUserId);
/**
*
*
* @param createReqVO
* @return
*/
Long createBrokerageUser(@Valid BrokerageUserCreateReqVO createReqVO);
/**
*
*

View File

@ -8,9 +8,11 @@ import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.BrokerageUserPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO;
@ -28,6 +30,7 @@ import cn.iocoder.yudao.module.trade.service.config.TradeConfigService;
import com.baomidou.mybatisplus.core.metadata.IPage;
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;
@ -110,7 +113,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
if (brokerageUserDO == null) {
throw exception(BROKERAGE_USER_NOT_EXISTS);
}
return brokerageUserDO;
}
@ -202,6 +204,24 @@ public class BrokerageUserServiceImpl implements BrokerageUserService {
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long createBrokerageUser(BrokerageUserCreateReqVO createReqVO) {
// 1.1 校验分销用户是否已存在
BrokerageUserDO brokerageUser = brokerageUserMapper.selectById(createReqVO.getUserId());
if (brokerageUser != null) {
throw exception(BROKERAGE_CREATE_USER_EXISTS);
}
// 1.2 校验是否能绑定用户
brokerageUser = BeanUtils.toBean(createReqVO, BrokerageUserDO.class).setId(createReqVO.getUserId())
.setBrokerageTime(LocalDateTime.now());
validateCanBindUser(brokerageUser, createReqVO.getBindUserId());
// 2. 创建分销人
brokerageUserMapper.insert(brokerageUser);
return brokerageUser.getId();
}
/**
*
*

View File

@ -55,7 +55,7 @@ public class CartServiceImpl implements CartService {
cartMapper.updateById(new CartDO().setId(cart.getId()).setSelected(true)
.setCount(cart.getCount() + count));
return cart.getId();
// 情况二:不存在,则进行插入
// 情况二:不存在,则进行插入
} else {
cart = new CartDO().setUserId(userId).setSelected(true)
.setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count);
@ -121,7 +121,7 @@ public class CartServiceImpl implements CartService {
}
// 批量标记删除
cartMapper.deleteBatchIds(ids);
cartMapper.deleteByIds(convertSet(carts, CartDO::getId));
}
@Override

View File

@ -329,7 +329,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
/**
*
*
* @param order
* @param order
* @param payOrderId
* @return
*/
@ -688,8 +688,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
List<TradeOrderItemDO> updateItems = new ArrayList<>();
for (int i = 0; i < orderOrderItems.size(); i++) {
TradeOrderItemDO item = orderOrderItems.get(i);
updateItems.add(new TradeOrderItemDO().setId(item.getId()).setAdjustPrice(item.getAdjustPrice() + dividePrices.get(i))
.setPayPrice((item.getPayPrice() - item.getAdjustPrice()) + dividePrices.get(i)));
updateItems.add(new TradeOrderItemDO().setId(item.getId())
.setAdjustPrice(item.getAdjustPrice() + dividePrices.get(i))
.setPayPrice(item.getPayPrice() + dividePrices.get(i)));
}
tradeOrderItemMapper.updateBatch(updateItems);
@ -747,7 +748,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
}
DeliveryPickUpStoreDO deliveryPickUpStore = pickUpStoreService.getDeliveryPickUpStore(order.getPickUpStoreId());
if (deliveryPickUpStore == null
|| !CollUtil.contains(deliveryPickUpStore.getVerifyUserIds(), userId)) {
|| !CollUtil.contains(deliveryPickUpStore.getVerifyUserIds(), userId)) {
throw exception(ORDER_PICK_UP_FAIL_NOT_VERIFY_USER);
}

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@ -19,6 +20,7 @@ import java.util.List;
* @author
*/
@Component
@Slf4j
public class TradeCouponOrderHandler implements TradeOrderHandler {
@Resource
@ -46,11 +48,15 @@ public class TradeCouponOrderHandler implements TradeOrderHandler {
return;
}
// 赠送优惠券
List<Long> couponIds = couponApi.takeCouponsByAdmin(order.getGiveCouponTemplateCounts(), order.getUserId()).getCheckedData();
if (CollUtil.isEmpty(couponIds)) {
return;
try {
List<Long> couponIds = couponApi.takeCouponsByAdmin(order.getGiveCouponTemplateCounts(), order.getUserId()).getCheckedData();
if (CollUtil.isEmpty(couponIds)) {
return;
}
orderUpdateService.updateOrderGiveCouponIds(order.getUserId(), order.getId(), couponIds);
} catch (Exception e) {
log.error("[afterPayOrder][order({}) 赠送优惠券({})失败,需要手工补偿]", order.getId(), order.getGiveCouponTemplateCounts(), e);
}
orderUpdateService.updateOrderGiveCouponIds(order.getUserId(), order.getId(), couponIds);
}
@Override

View File

@ -122,9 +122,13 @@ public class TradeDeliveryPriceCalculator implements TradePriceCalculator {
*/
private boolean isGlobalExpressFree(TradePriceCalculateRespBO result) {
TradeConfigDO config = tradeConfigService.getTradeConfig();
return config == null
|| Boolean.TRUE.equals(config.getDeliveryExpressFreeEnabled()) // 开启包邮
|| result.getPrice().getPayPrice() >= config.getDeliveryExpressFreePrice(); // 满足包邮的价格
// 情况一:交易中心配置不存在默认不包邮
if (config == null) {
return false;
}
// 情况二:开启了全局包邮 && 满足包邮金额
return Boolean.TRUE.equals(config.getDeliveryExpressFreeEnabled()) &&
result.getPrice().getPayPrice() >= config.getDeliveryExpressFreePrice();
}
private void calculateDeliveryPrice(List<OrderItem> selectedSkus,

View File

@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@Tag(name = "管理后台 - 签到记录")
@Tag(name = "用户 App - 签到记录")
@RestController
@RequestMapping("/member/sign-in/record")
@Validated

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.member.service.point;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.controller.admin.point.vo.recrod.MemberPointRecordPageReqVO;
import cn.iocoder.yudao.module.member.controller.app.point.vo.AppMemberPointRecordPageReqVO;
@ -11,6 +10,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.point.MemberPointRecordMapper;
import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.util.List;
import java.util.Set;
@ -75,7 +74,9 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
int totalPoint = userPoint + point; // 用户变动后的积分
if (totalPoint < 0) {
throw exception(USER_POINT_NOT_ENOUGH);
log.error("[createPointRecord][userId({}) point({}) bizType({}) bizId({}) {}]", userId, point, bizType, bizId,
USER_POINT_NOT_ENOUGH);
return;
}
// 2. 更新用户积分

View File

@ -111,6 +111,7 @@ public interface ErrorCodeConstants {
ErrorCode TENANT_PACKAGE_NOT_EXISTS = new ErrorCode(1_002_016_000, "租户套餐不存在");
ErrorCode TENANT_PACKAGE_USED = new ErrorCode(1_002_016_001, "租户正在使用该套餐,请给租户重新设置套餐后再尝试删除");
ErrorCode TENANT_PACKAGE_DISABLE = new ErrorCode(1_002_016_002, "名字为【{}】的租户套餐已被禁用");
ErrorCode TENANT_PACKAGE_NAME_DUPLICATE = new ErrorCode(1_002_016_003, "已经存在该名字的租户套餐");
// ========== 社交用户 1-002-018-000 ==========
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}");

View File

@ -29,4 +29,8 @@ public interface TenantPackageMapper extends BaseMapperX<TenantPackageDO> {
default List<TenantPackageDO> selectListByStatus(Integer status) {
return selectList(TenantPackageDO::getStatus, status);
}
default TenantPackageDO selectByName(String name) {
return selectOne(TenantPackageDO::getName, name);
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.service.tenant;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
@ -10,6 +11,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO;
import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantPackageMapper;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.google.common.annotations.VisibleForTesting;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -19,6 +21,7 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.TENANT_PACKAGE_NAME_DUPLICATE;
/**
* Service
@ -38,6 +41,8 @@ public class TenantPackageServiceImpl implements TenantPackageService {
@Override
public Long createTenantPackage(TenantPackageSaveReqVO createReqVO) {
// 校验套餐名是否重复
validateTenantPackageNameUnique(null, createReqVO.getName());
// 插入
TenantPackageDO tenantPackage = BeanUtils.toBean(createReqVO, TenantPackageDO.class);
tenantPackageMapper.insert(tenantPackage);
@ -50,6 +55,8 @@ public class TenantPackageServiceImpl implements TenantPackageService {
public void updateTenantPackage(TenantPackageSaveReqVO updateReqVO) {
// 校验存在
TenantPackageDO tenantPackage = validateTenantPackageExists(updateReqVO.getId());
// 校验套餐名是否重复
validateTenantPackageNameUnique(updateReqVO.getId(), updateReqVO.getName());
// 更新
TenantPackageDO updateObj = BeanUtils.toBean(updateReqVO, TenantPackageDO.class);
tenantPackageMapper.updateById(updateObj);
@ -111,4 +118,23 @@ public class TenantPackageServiceImpl implements TenantPackageService {
return tenantPackageMapper.selectListByStatus(status);
}
@VisibleForTesting
void validateTenantPackageNameUnique(Long id, String name) {
if (StrUtil.isBlank(name)) {
return;
}
TenantPackageDO tenantPackage = tenantPackageMapper.selectByName(name);
if (tenantPackage == null) {
return;
}
// 如果 id 为空,说明不用比较是否为相同 id 的用户
if (id == null) {
throw exception(TENANT_PACKAGE_NAME_DUPLICATE);
}
if (!tenantPackage.getId().equals(id)) {
throw exception(TENANT_PACKAGE_NAME_DUPLICATE);
}
}
}