{"record":{"id":"1136169612c9b0ce","repo":"alibaba/COLA","slug":"b-customer-companynameconflict-113616","errorCode":"B_CUSTOMER_companyNameConflict","errorMessage":"公司名冲突","messagePattern":"公司名冲突","errorType":"error_code","errorClass":"BizException","httpStatus":null,"severity":"warning","filePath":"cola-archetypes/cola-archetype-web/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.getErrCode(), \"公司名冲突\");\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-web/src/main/resources/archetype-resources/__rootArtifactId__-app/src/main/java/customer/executor/CustomerAddCmdExe.java#L3-L27","documentation":"Same company-name conflict guard as the service archetype: CustomerAddCmdExe.execute throws BizException with code B_CUSTOMER_companyNameConflict (via ErrorCode.getErrCode()) and message \"公司名冲突\" when the DTO's companyName equals \"ConflictCompanyName\". This is the web archetype's sample duplicate check.","triggerScenarios":"Executing CustomerAddCmd in the cola-archetype-web generated app where cmd.getCustomerDTO().getCompanyName() equals \"ConflictCompanyName\".","commonSituations":"Running the generated demo web app with the sample conflict payload; integration tests asserting the error path; reusing the executor template without replacing the hard-coded check.","solutions":["Submit a companyName other than \"ConflictCompanyName\".","Replace the hard-coded check with a real database uniqueness validation before adding the customer.","Add exception handling (e.g. @ControllerAdvice) to translate BizException B_CUSTOMER_companyNameConflict into a client-friendly error."],"exampleFix":"// before\nthrow new BizException(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), \"公司名冲突\");\n// after\nif(customerRepository.existsByCompanyName(cmd.getCustomerDTO().getCompanyName())){\n    throw new BizException(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), \"公司名冲突\");\n}","handlingStrategy":"try-catch","validationCode":"if (\"ConflictCompanyName\".equals(cmd.getCustomerDTO().getCompanyName())) {\n    return Response.buildFailure(ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode(), \"公司名冲突\");\n}","typeGuard":null,"tryCatchPattern":"@ExceptionHandler(BizException.class)\npublic Response handleBiz(BizException e) {\n    if (ErrorCode.B_CUSTOMER_companyNameConflict.getErrCode().equals(e.getErrCode())) {\n        return Response.buildFailure(e.getErrCode(), \"公司名冲突\");\n    }\n    return Response.buildFailure(e.getErrCode(), e.getErrMessage());\n}","preventionTips":["Pre-check companyName uniqueness before executing the add command.","Register a global BizException handler (@ControllerAdvice) in the web layer.","Swap the sentinel-based check for a database uniqueness validation in production code."],"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"}