|
@@ -1,5 +1,6 @@
|
|
|
package com.ruoyi.web.v2.v1.service.impl;
|
|
package com.ruoyi.web.v2.v1.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.ruoyi.app.mapper.PigpenMapper;
|
|
import com.ruoyi.app.mapper.PigpenMapper;
|
|
@@ -18,9 +19,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
@@ -43,7 +43,13 @@ public class JsReportServiceImpl extends ServiceImpl<JsReportMapper, JsReport> i
|
|
|
@Transactional
|
|
@Transactional
|
|
|
@Override
|
|
@Override
|
|
|
public boolean register(List<JsDivideCircle> circles) {
|
|
public boolean register(List<JsDivideCircle> circles) {
|
|
|
|
|
+ //当日是否已提交完工报告检测
|
|
|
|
|
+ boolean doubleReport = checkDuplicatedReport();
|
|
|
|
|
+ if(doubleReport) {
|
|
|
|
|
+ throw new RuntimeException("每日只能提交一次完工报告,本日已有提交记录,请勿重复提交...");
|
|
|
|
|
+ }
|
|
|
//根据提交的分圈登记,计算每个批次的剩余存栏量(每个猪圈的存栏量为0后视为该批次完结),然后决定猪圈状态和待宰栏中的该批次数据状态
|
|
//根据提交的分圈登记,计算每个批次的剩余存栏量(每个猪圈的存栏量为0后视为该批次完结),然后决定猪圈状态和待宰栏中的该批次数据状态
|
|
|
|
|
+ List<Map<String, String>> logList = new ArrayList<>();
|
|
|
for (JsDivideCircle circle : circles) {
|
|
for (JsDivideCircle circle : circles) {
|
|
|
if(ObjectUtils.isEmpty(circle.getAmount()) || circle.getAmount() < 0) {
|
|
if(ObjectUtils.isEmpty(circle.getAmount()) || circle.getAmount() < 0) {
|
|
|
throw new IllegalArgumentException("待宰栏【" + circle.getPigpenName() + "】的猪只数量不能为空,或小于0...");
|
|
throw new IllegalArgumentException("待宰栏【" + circle.getPigpenName() + "】的猪只数量不能为空,或小于0...");
|
|
@@ -67,6 +73,10 @@ public class JsReportServiceImpl extends ServiceImpl<JsReportMapper, JsReport> i
|
|
|
//系统自动插入的数据,分圈时间设置为空
|
|
//系统自动插入的数据,分圈时间设置为空
|
|
|
circle.setDivideTime(null);
|
|
circle.setDivideTime(null);
|
|
|
circle.setCreateTime(new Date());
|
|
circle.setCreateTime(new Date());
|
|
|
|
|
+ //插入猪圈数据前,同时生成日志记录
|
|
|
|
|
+ Map<String, String> logRecord = new HashMap<>();
|
|
|
|
|
+ logRecord.put(circle.getPigpenName(), String.valueOf(circle.getAmount()));
|
|
|
|
|
+ logList.add(logRecord);
|
|
|
jsDivideCircleMapper.insert(circle);
|
|
jsDivideCircleMapper.insert(circle);
|
|
|
}
|
|
}
|
|
|
}else {
|
|
}else {
|
|
@@ -75,6 +85,9 @@ public class JsReportServiceImpl extends ServiceImpl<JsReportMapper, JsReport> i
|
|
|
//系统自动插入的数据,分圈时间设置为空
|
|
//系统自动插入的数据,分圈时间设置为空
|
|
|
circle.setDivideTime(null);
|
|
circle.setDivideTime(null);
|
|
|
circle.setCreateTime(new Date());
|
|
circle.setCreateTime(new Date());
|
|
|
|
|
+ Map<String, String> logRecord = new HashMap<>();
|
|
|
|
|
+ logRecord.put(circle.getPigpenName(), String.valueOf(circle.getAmount()));
|
|
|
|
|
+ logList.add(logRecord);
|
|
|
jsDivideCircleMapper.insert(circle);
|
|
jsDivideCircleMapper.insert(circle);
|
|
|
jsDivideCircleMapper.update(null, new LambdaUpdateWrapper<JsDivideCircle>()
|
|
jsDivideCircleMapper.update(null, new LambdaUpdateWrapper<JsDivideCircle>()
|
|
|
.eq(JsDivideCircle::getSeriesNo, circle.getSeriesNo())
|
|
.eq(JsDivideCircle::getSeriesNo, circle.getSeriesNo())
|
|
@@ -91,10 +104,20 @@ public class JsReportServiceImpl extends ServiceImpl<JsReportMapper, JsReport> i
|
|
|
//保存完工报告记录
|
|
//保存完工报告记录
|
|
|
JsReport jsReport = new JsReport();
|
|
JsReport jsReport = new JsReport();
|
|
|
jsReport.setCreateTime(new Date());
|
|
jsReport.setCreateTime(new Date());
|
|
|
|
|
+ jsReport.setOperationLog(JSONObject.toJSONString(logList));
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
jsReport.setUserName(Optional.ofNullable(loginUser.getUser())
|
|
jsReport.setUserName(Optional.ofNullable(loginUser.getUser())
|
|
|
.map(SysUser::getNickName)
|
|
.map(SysUser::getNickName)
|
|
|
.orElse("系统管理员"));
|
|
.orElse("系统管理员"));
|
|
|
return save(jsReport);
|
|
return save(jsReport);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private boolean checkDuplicatedReport() {
|
|
|
|
|
+ LocalDateTime start = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
|
|
|
|
|
+ LocalDateTime end = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59);
|
|
|
|
|
+ int count = this.count(new LambdaQueryWrapper<JsReport>().between(JsReport::getCreateTime, start,end));
|
|
|
|
|
+ return count > 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|