{"record":{"id":"38d93dc5f3409886","repo":"alibaba/COLA","slug":"b-customer-companynameconflict","errorCode":"B_CUSTOMER_companyNameConflict","errorMessage":"公司名冲突","messagePattern":"公司名冲突","errorType":"error_code","errorClass":"BizException","httpStatus":null,"severity":"warning","filePath":"cola-archetypes/cola-archetype-service/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/customer/executor/CustomerAddCmdExe.java","lineNumber":21,"sourceCode":"#set( $symbol_escape = '\\' )\n\npackage ${package}.customer.executor;\n\nimport com.alibaba.cola.dto.Response;\nimport com.alibaba.cola.exception.BizException;\nimport ${package}.dto.CustomerAddCmd;\nimport ${package}.dto.data.ErrorCode;\nimport org.springframework.stereotype.Component;\n\n\n@Component\npublic class CustomerAddCmdExe{\n\n    public Response execute(CustomerAddCmd cmd) {\n        //The flow of usecase is defined here.\n        //The core ablility should be implemented in Domain. or sink to Domian gradually\n        if(cmd.getCustomerDTO().getCompanyName().equals(\"ConflictCompanyName\")){\n            throw new BizException(ErrorCode.B_CUSTOMER_companyNameConflict, \"公司名冲突\");\n        }\n        return Response.buildSuccess();\n    }\n\n}\n","sourceCodeStart":3,"sourceCodeEnd":27,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-archetypes/cola-archetype-service/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/customer/executor/CustomerAddCmdExe.java#L3-L27","documentation":"CustomerAddCmdExe.execute rejects a customer creation request whose company name equals the sentinel value \"ConflictCompanyName\", throwing a BizException with error code B_CUSTOMER_companyNameConflict and Chinese message \"公司名冲突\" (company name conflict). It is the sample duplicate/uniqueness guard of the COLA service archetype.","triggerScenarios":"Executing CustomerAddCmd where cmd.getCustomerDTO().getCompanyName() equals \"ConflictCompanyName\" — i.e. a demo/test payload that trips the sample conflict check in the command executor.","commonSituations":"Demo clients or integration tests posting the literal \"ConflictCompanyName\"; developers reusing the archetype executor and forgetting to replace the hard-coded conflict check with real database uniqueness validation.","solutions":["Change the submitted companyName to a non-conflicting value.","Replace the hard-coded \"ConflictCompanyName\" check with a real uniqueness check against persistence (query existing customer by name) before insert.","Handle BizException with code B_CUSTOMER_companyNameConflict in the web layer and return a user-friendly response."],"exampleFix":"// before\nif(cmd.getCustomerDTO().getCompanyName().equals(\"ConflictCompanyName\")){\n    throw new BizException(ErrorCode.B_CUSTOMER_companyNameConflict, \"公司名冲突\");\n}\n// after\nif(customerRepository.existsByCompanyName(cmd.getCustomerDTO().getCompanyName())){\n    throw new BizException(ErrorCode.B_CUSTOMER_companyNameConflict, \"公司名冲突\");\n}","handlingStrategy":"validation","validationCode":"if (\"ConflictCompanyName\".equals(cmd.getCustomerDTO().getCompanyName())) {\n    return Response.buildFailure(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), \"公司名冲突\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return customerAddCmdExe.execute(cmd);\n} catch (BizException e) {\n    if (ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode().equals(e.getErrCode())) {\n        return Response.buildFailure(e.getErrCode(), \"公司名冲突，请更换公司名\");\n    }\n    throw e;\n}","preventionTips":["Check the companyName against the conflict rule (or DB uniqueness) before invoking the executor.","Replace the hard-coded sentinel with a real uniqueness query as soon as you move past the demo.","Return structured failures instead of letting BizException bubble to the client unhandled."],"tags":["business-logic","uniqueness-conflict","cola"],"backgroundTag":"schema-validation-failed","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}