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);
|
}
|
|
|
}
|