sinake
2 天以前 49120f2b9db33455756a911e56cfefd7c3120a14
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/SpStatCaseController.java
@@ -48,13 +48,13 @@
import static com.ruoyi.web.controller.project.ServiceReimbursementController.convert;
/**
 * 费用申请主Controller
 * 案例统计
 *
 * @author ruoyi
 * @date 2022-01-24
 */
@Slf4j
@Api("费用申请主")
@Api("案例统计")
@RestController
@RequestMapping("/project/spstatcase")
public class SpStatCaseController extends BaseController {
@@ -63,14 +63,67 @@
    SpstatCaseService spstatCaseService;
    /**
     * 查询费用申请主列表
     * 查询案例统计
     */
    @ApiOperation("查询费用申请主列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody SpStatCaseReq spStatCaseReq) {
    @ApiOperation("查询案例统计")
    @PostMapping("/spStatCaselist")
    public TableDataInfo spStatCaselist(@RequestBody SpStatCaseReq spStatCaseReq) {
        startPage();
        return getDataTable(spstatCaseService.getListBypower(spStatCaseReq));
    }
    /**
     * 导出案例统计
     */
    @ApiOperation("导出案例统计")
    @Log(title = "案例统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SpStatCaseReq spStatCaseReq) {
        List<SpStatCase> list = spstatCaseService.getListBypower(spStatCaseReq);
        ExcelUtil<SpStatCase> util = new ExcelUtil<SpStatCase>(SpStatCase.class);
        return util.exportExcel(list, "案例统计数据");
    }
    /**
     * 导出案例统计(按业务组)
     */
    @ApiOperation("导出案例统计(按业务组)")
    @Log(title = "案例统计", businessType = BusinessType.EXPORT)
    @GetMapping("/exportDept")
    public AjaxResult exportDept(SpStatCaseReq spStatCaseReq) {
        List<SpStatCase> list = spstatCaseService.getListBypower(spStatCaseReq);
        Map<String, SpStatCaseDept> grouped = new LinkedHashMap<String, SpStatCaseDept>();
        for (SpStatCase row : list) {
            String key = StringUtils.isNotEmpty(row.getDeptid()) ? row.getDeptid() : row.getDeptname();
            if (key == null) {
                key = "";
            }
            SpStatCaseDept dept = grouped.get(key);
            if (dept == null) {
                dept = new SpStatCaseDept();
                dept.setDeptname(row.getDeptname() == null ? "未分组" : row.getDeptname());
                dept.setCaseTotal(0);
                dept.setTerminationTotal(0);
                grouped.put(key, dept);
            }
            dept.setCaseTotal(dept.getCaseTotal() + toInt(row.getWorkflowsum()));
            dept.setTerminationTotal(dept.getTerminationTotal() + toInt(row.getTerminationcase()));
        }
        List<SpStatCaseDept> result = new ArrayList<SpStatCaseDept>(grouped.values());
        ExcelUtil<SpStatCaseDept> util = new ExcelUtil<SpStatCaseDept>(SpStatCaseDept.class);
        return util.exportExcel(result, "案例统计(按业务组)");
    }
    private int toInt(String value) {
        if (StringUtils.isEmpty(value)) {
            return 0;
        }
        try {
            return Integer.parseInt(value.trim());
        } catch (NumberFormatException e) {
            return 0;
        }
    }
}