吴羡
10 天以前 647960c44d36b97263fee0325487f9dea8b24307
cnas-manage/src/main/java/com/ruoyi/manage/controller/ClientSatisfactionController.java
@@ -52,7 +52,13 @@
    @Operation(summary = "客户满意度调查新增")
    @PostMapping("/addClientSatisfaction")
    public Result addClientSatisfaction(@RequestBody ClientSatisfaction clientSatisfaction){
        return Result.success(clientSatisfactionService.save(clientSatisfaction));
        Result<?> error = fillAssessment(clientSatisfaction);
        if (error != null) {
            return error;
        }
        clientSatisfactionService.save(clientSatisfaction);
        // 返回保存后的记录(含自增id),前端据此上传新增时暂存的照片
        return Result.success(clientSatisfaction);
    }
    /**
@@ -62,7 +68,35 @@
    @Operation(summary = "客户满意度调查新增")
    @PostMapping("/updateClientSatisfaction")
    public Result updateClientSatisfaction(@RequestBody ClientSatisfaction clientSatisfaction){
        Result<?> error = fillAssessment(clientSatisfaction);
        if (error != null) {
            return error;
        }
        return Result.success(clientSatisfactionService.updateById(clientSatisfaction));
    }
    /**
     * 根据10道题的评分计算总分和满意度评定(80分及以上为满意)
     */
    private Result<?> fillAssessment(ClientSatisfaction clientSatisfaction) {
        Integer[] scores = {clientSatisfaction.getScore1(), clientSatisfaction.getScore2(),
                clientSatisfaction.getScore3(), clientSatisfaction.getScore4(),
                clientSatisfaction.getScore5(), clientSatisfaction.getScore6(),
                clientSatisfaction.getScore7(), clientSatisfaction.getScore8(),
                clientSatisfaction.getScore9(), clientSatisfaction.getScore10()};
        int total = 0;
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] == null) {
                return Result.fail("请完成第" + (i + 1) + "题评分");
            }
            if (scores[i] < 5 || scores[i] > 10) {
                return Result.fail("评分必须在5到10分之间");
            }
            total += scores[i];
        }
        clientSatisfaction.setTotalScore(total);
        clientSatisfaction.setSatisfactionResult(total >= 80 ? 0 : 1);
        return null;
    }
    /**
@@ -88,6 +122,16 @@
    public Result exportWordClientSatisfaction(Integer clientSatisfactionId, HttpServletResponse response){
        clientSatisfactionService.exportWordClientSatisfaction(clientSatisfactionId, response);
        return Result.success();
    }
    /**
     * 客户满意度年度汇总导出
     * @param year 汇总年度
     */
    @Operation(summary = "客户满意度年度汇总导出")
    @GetMapping("/exportAnnualSummary")
    public void exportAnnualSummary(Integer year, HttpServletResponse response){
        clientSatisfactionService.exportAnnualSummary(year, response);
    }
    /**
@@ -136,5 +180,33 @@
    public Result delAnalyseFile(Integer analyseFileId){
        return Result.success(clientSatisfactionAnalyseFileMapper.deleteById(analyseFileId));
    }
    /**
     * 查询满意度附件
     */
    @Operation(summary = "查询满意度附件")
    @GetMapping("/selectAttachments")
    public Result selectAttachments(Integer clientSatisfactionId) {
        return Result.success(clientSatisfactionService.selectAttachments(clientSatisfactionId));
    }
    /**
     * 上传满意度附件
     */
    @Operation(summary = "上传满意度附件")
    @PostMapping("/uploadAttachment")
    public Result uploadAttachment(@RequestParam("clientSatisfactionId") Integer clientSatisfactionId,
                                   @RequestParam("file") MultipartFile file) {
        return Result.success(clientSatisfactionService.uploadAttachment(clientSatisfactionId, file));
    }
    /**
     * 删除满意度附件
     */
    @Operation(summary = "删除满意度附件")
    @DeleteMapping("/deleteAttachment")
    public Result deleteAttachment(Long id) {
        return Result.success(clientSatisfactionService.deleteAttachment(id));
    }
}