zouyu
2025-11-14 113cd73922b9b67c261c19c744e46eb2822d7b41
src/main/java/com/ruoyi/waterrecord/controller/WaterRecordController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,91 @@
package com.ruoyi.waterrecord.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.waterrecord.pojo.WaterRecord;
import com.ruoyi.waterrecord.service.WaterRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * @author :yys
 * @date : 2025/8/11 10:08
 */
@RestController
@Api(tags = "用水管理")
@RequestMapping("/waterRecord")
public class WaterRecordController extends BaseController {
    @Autowired
    private WaterRecordService waterRecordService;
    @GetMapping("/listPage")
    @Log(title = "用水管理-分页查询", businessType = BusinessType.OTHER)
    public AjaxResult listPage(Page page, WaterRecord waterRecord){
        IPage<WaterRecord> listPage = waterRecordService.listPage(page, waterRecord);
        return AjaxResult.success(listPage);
    }
    @PostMapping("/add")
    @Log(title = "用水管理-新增", businessType = BusinessType.INSERT)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@RequestBody WaterRecord waterRecord){
        boolean save = waterRecordService.save(waterRecord);
        return save ? AjaxResult.success() : AjaxResult.error();
    }
    @PostMapping("/update")
    @Log(title = "用水管理-修改", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult update(@RequestBody WaterRecord waterRecord){
        boolean update = waterRecordService.updateById(waterRecord);
        return update ? AjaxResult.success() : AjaxResult.error();
    }
    @DeleteMapping("/delete")
    @Log(title = "用水管理-删除", businessType = BusinessType.DELETE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult delete(@RequestBody List<Long> ids){
        if(CollectionUtils.isEmpty(ids)) return AjaxResult.error("请选择至少一条数据");
        boolean delete = waterRecordService.removeBatchByIds(ids);
        return delete ? AjaxResult.success() : AjaxResult.error();
    }
    /**
     * å¯¼å…¥ç”¨æ°´ç®¡ç†
     */
    @Log(title = "导入用水管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @ApiOperation("导入用水管理")
    public AjaxResult importData(MultipartFile file) throws Exception {
        return waterRecordService.importData(file);
    }
    /**
     * å¯¼å‡ºç”¨æ°´ç®¡ç†
     */
    @Log(title = "导出用水管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出用水管理")
    public void export(HttpServletResponse response) {
        Page page = new Page(-1,-1);
        WaterRecord waterRecord = new WaterRecord();
        IPage<WaterRecord> listPage = waterRecordService.listPage(page, waterRecord);
        ExcelUtil<WaterRecord> util = new ExcelUtil<WaterRecord>(WaterRecord.class);
        util.exportExcel(response, listPage.getRecords() , "用水管理");
    }
}