| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | |
| | | import com.ruoyi.device.mapper.DeviceLedgerMapper; |
| | | import com.ruoyi.device.pojo.DeviceLedger; |
| | | import com.ruoyi.device.service.IDeviceLedgerService; |
| | | import com.ruoyi.production.mapper.ProductProcessMapper; |
| | | import com.ruoyi.production.pojo.ProductProcess; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.time.ZoneOffset; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | private DeviceLedgerMapper deviceLedgerMapper; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | @Autowired |
| | | private ProductProcessMapper productProcessMapper; |
| | | |
| | | @Override |
| | | public IPage<DeviceLedgerDto> queryPage(Page page, DeviceLedgerDto deviceLedger) { |
| | |
| | | |
| | | @Override |
| | | public AjaxResult saveDeviceLedger(DeviceLedger deviceLedger) { |
| | | AjaxResult processCheckResult = validateProductProcess(deviceLedger.getProductProcessId()); |
| | | if (processCheckResult != null) { |
| | | return processCheckResult; |
| | | } |
| | | LambdaQueryWrapper<DeviceLedger> deviceLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | deviceLedgerLambdaQueryWrapper.eq(DeviceLedger::getDeviceModel,deviceLedger.getDeviceModel()); |
| | | deviceLedgerLambdaQueryWrapper.eq(DeviceLedger::getDeviceName,deviceLedger.getDeviceName()); |
| | | if (this.count(deviceLedgerLambdaQueryWrapper) > 0) { |
| | | return AjaxResult.error("设备型号已存在"); |
| | | return AjaxResult.error("设备名称已存在"); |
| | | } |
| | | boolean save = this.save(deviceLedger); |
| | | if (save){ |
| | |
| | | |
| | | @Override |
| | | public AjaxResult updateDeviceLedger(DeviceLedger deviceLedger) { |
| | | if (ObjectUtils.isNotNull(deviceLedger.getStartRuntimeTime()) && ObjectUtils.isNotNull(deviceLedger.getEndRuntimeTime())){ |
| | | //计算运行时长 |
| | | long start = deviceLedger.getStartRuntimeTime().toEpochSecond(ZoneOffset.UTC) * 1000; |
| | | long end = deviceLedger.getEndRuntimeTime().toEpochSecond(ZoneOffset.UTC) * 1000; |
| | | long diffMillis = Math.abs(end - start); |
| | | double time = diffMillis / (1000.0 * 60 * 60);// 毫秒 -> 秒 -> 分钟 -> 小时 |
| | | deviceLedger.setRuntimeDuration(time+"h"); |
| | | AjaxResult processCheckResult = validateProductProcess(deviceLedger.getProductProcessId()); |
| | | if (processCheckResult != null) { |
| | | return processCheckResult; |
| | | } |
| | | if (this.updateById(deviceLedger)) { |
| | | return AjaxResult.success(); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public DeviceLedger getDetailById(Long id) { |
| | | return deviceLedgerMapper.selectById1(id); |
| | | } |
| | | |
| | | private AjaxResult validateProductProcess(Long productProcessId) { |
| | | if (productProcessId == null) { |
| | | return null; |
| | | } |
| | | ProductProcess productProcess = productProcessMapper.selectById(productProcessId); |
| | | if (productProcess == null) { |
| | | return AjaxResult.error("工序不存在,请重新选择"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void export(HttpServletResponse response, Long[] ids) { |
| | | |
| | | if (ids == null || ids.length == 0) { |