maven
2025-08-05 60838d9bc1043bcc6cb171f9a30519e649b118b6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.ruoyi.measuringinstrumentledger.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.equipmentenergyconsumption.pojo.EquipmentEnergyConsumption;
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.measuringinstrumentledger.dto.MeasuringInstrumentLedgerDto;
import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerRecordMapper;
import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedger;
import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedgerRecord;
import com.ruoyi.measuringinstrumentledger.service.MeasuringInstrumentLedgerService;
import com.ruoyi.measuringinstrumentledger.service.impl.MeasuringInstrumentLedgerServiceImpl;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
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 javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
 
/**
 * @author :yys
 * @date : 2025/8/5 9:27
 */
@RestController
@Api(tags = "计量器具台账")
@RequestMapping("/measuringInstrumentLedger")
public class MeasuringInstrumentLedgerController extends BaseController {
 
    @Autowired
    private MeasuringInstrumentLedgerService measuringInstrumentLedgerService;
 
    @Autowired
    private SysUserMapper sysUserMapper;
 
    @Autowired
    private MeasuringInstrumentLedgerRecordMapper measuringInstrumentLedgerRecordMapper;
 
 
    @GetMapping("/listPage")
    @ApiOperation("计量器具台账-分页查询")
    @Log(title = "计量器具台账-分页查询", businessType = BusinessType.OTHER)
    public AjaxResult listPage(Page page, MeasuringInstrumentLedger measuringInstrumentLedger) {
        IPage<MeasuringInstrumentLedger> listPage = measuringInstrumentLedgerService.listPage(page, measuringInstrumentLedger);
        return AjaxResult.success(listPage);
    }
 
 
    @PostMapping("/add")
    @ApiOperation("计量器具台账-新增")
    @Log(title = "计量器具台账-新增", businessType = BusinessType.INSERT)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult add(@RequestBody MeasuringInstrumentLedger measuringInstrumentLedger) throws IOException {
        boolean save = measuringInstrumentLedgerService.add(measuringInstrumentLedger);
        if (save) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
 
    @PostMapping("/update")
    @ApiOperation("计量器具台账-修改")
    @Log(title = "计量器具台账-修改", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult update(@RequestBody MeasuringInstrumentLedger measuringInstrumentLedger) {
        SysUser sysUser = sysUserMapper.selectUserById(measuringInstrumentLedger.getUserId());
        if (sysUser == null) {
            return AjaxResult.error("用户不存在");
        }
        measuringInstrumentLedger.setUserName(sysUser.getUserName());
        boolean update = measuringInstrumentLedgerService.updateById(measuringInstrumentLedger);
        if (update) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
 
    @DeleteMapping("/delete")
    @ApiOperation("计量器具台账-删除")
    @Log(title = "计量器具台账-删除", businessType = BusinessType.DELETE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult delete(@RequestBody List<Long> ids) {
        if(CollectionUtils.isEmpty(ids)) return AjaxResult.error("请选择至少一条数据");
        for (Long id : ids) {
            LambdaQueryWrapper<MeasuringInstrumentLedgerRecord> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId,id);
            List<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecords = measuringInstrumentLedgerRecordMapper.selectList(queryWrapper);
            if(!CollectionUtils.isEmpty(measuringInstrumentLedgerRecords)){
                return AjaxResult.error("请先删除选中计量器具台账下的所有检定记录");
            }
        }
        boolean delete = measuringInstrumentLedgerService.removeBatchByIds(ids);
        if (delete) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
 
    @PostMapping("/verifying")
    @ApiOperation("计量器具台账-检定")
    @Log(title = "计量器具台账-检定", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult verifying(@RequestBody MeasuringInstrumentLedgerDto measuringInstrumentLedger) throws IOException {
        boolean update = measuringInstrumentLedgerService.verifying(measuringInstrumentLedger);
        return update ? AjaxResult.success("检定成功") : AjaxResult.error("检定失败");
    }
 
    /**
     * 导出计量器具台账
     */
    @Log(title = "导出计量器具台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出计量器具台账")
    public void export(HttpServletResponse response) {
        measuringInstrumentLedgerService.export( response);
    }
 
 
}