Merge remote-tracking branch 'origin/main'

This commit is contained in:
ll 2025-08-28 11:13:45 +08:00
commit 3a6dac3130
16 changed files with 139 additions and 27 deletions

View File

@ -1,6 +1,8 @@
package com.zhyc.module.feed.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
@ -63,19 +65,19 @@ public class SgFeedListController extends BaseController {
List<SgFeedList> list = sgFeedListService.selectSgFeedListList(sgFeedList);
// map 中已有的数据替换 list 中的元素
List<SgFeedList> replacedList = new ArrayList<>();
for (SgFeedList item : list) {
String key = item.getFormulaId() + "_" + item.getFormulaBatchId();
// 从缓存中取出完整对象
SgFeedList itemInCache = SgFeedListServiceImpl.getSgFeedListMap().getOrDefault(key, item);
// 将数据库查询的基本信息替换掉缓存中去除的内容 - 前端展示与修改需要
itemInCache.setId(item.getId());
itemInCache.setFormulaBatchId(item.getFormulaBatchId());
itemInCache.setFormulaId(item.getFormulaId());
itemInCache.setZookeeper(item.getZookeeper());
itemInCache.setDeployDate(item.getDeployDate());
// 替换为 map 中的对象
replacedList.add(itemInCache);
}
for (SgFeedList item : list) {
String key = item.getFormulaId() + "_" + item.getFormulaBatchId() + "_" + item.getDeployDate();
// 从缓存中取出完整对象
SgFeedList itemInCache = SgFeedListServiceImpl.getSgFeedListMap().getOrDefault(key, item);
// 将数据库查询的基本信息替换掉缓存中去除的内容 - 前端展示与修改需要
itemInCache.setId(item.getId());
itemInCache.setFormulaBatchId(item.getFormulaBatchId());
itemInCache.setFormulaId(item.getFormulaId());
itemInCache.setZookeeper(item.getZookeeper());
itemInCache.setDeployDate(item.getDeployDate());
// 替换为 map 中的对象
replacedList.add(itemInCache);
}
return getDataTable(replacedList);
}
@ -117,6 +119,7 @@ public class SgFeedListController extends BaseController {
@Log(title = "配料清单", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SgFeedList sgFeedList) {
return toAjax(sgFeedListService.updateSgFeedList(sgFeedList));
}

View File

@ -53,6 +53,8 @@ public class SgFeedList extends BaseEntity
private List<SgFormulaList> formulaList;
private List<SgFeedPlan> planList;
@Override
public String toString() {

View File

@ -60,4 +60,7 @@ public interface SgFeedListMapper
* @return 结果
*/
int deleteSgFeedListByIds(Long[] ids);
// 清空所有
int deleteAll();
}

View File

@ -1,8 +1,6 @@
package com.zhyc.module.feed.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import com.zhyc.module.feed.domain.SgFeedPlan;
import com.zhyc.module.feed.domain.SgFormulaManagement;
@ -32,6 +30,12 @@ public class SgFeedListServiceImpl implements ISgFeedListService {
this.sgFeedListMapper = sgFeedListMapper;
this.sgFormulaManagementService = sgFormulaManagementService;
this.sgFeedPlanService = sgFeedPlanService;
// 构造时将数据库初始数据写入缓存
List<SgFeedList> feedListsFromDataBase = this.selectSgFeedListList(new SgFeedList());
for (SgFeedList sgFeedListItem : feedListsFromDataBase) {
String key = sgFeedListItem.getFormulaId() + "_" + sgFeedListItem.getFormulaBatchId() + "_" + sgFeedListItem.getDeployDate();
sgFeedListMap.put(key, sgFeedListItem);
}
}
/**
@ -100,7 +104,7 @@ public class SgFeedListServiceImpl implements ISgFeedListService {
return sgFeedListMapper.deleteSgFeedListById(id);
}
public void SyncFeedList() {
public void SyncFeedList_old() {
// 清空旧缓存
sgFeedListMap.clear();
// 获取配方管理和现有配料清单内容
@ -153,6 +157,74 @@ public class SgFeedListServiceImpl implements ISgFeedListService {
}
}
public void SyncFeedList() {
HashMap<String, SgFeedList> cacheTemp = new HashMap<>(sgFeedListMap);
// 清空旧缓存
sgFeedListMap.clear();
List<SgFeedPlan> sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(new SgFeedPlan());
List<List<SgFeedPlan>> planGroups = new ArrayList<>();
List<SgFeedPlan> currentFeedPlan = new ArrayList<>();
if (!sgFeedPlans.isEmpty()) {
String currentFormulaId = sgFeedPlans.get(0).getFormulaId();
String currentBatchId = sgFeedPlans.get(0).getBatchId();
Date currentDate = sgFeedPlans.get(0).getPlanDate();
// 对饲喂计划进行分组
for (SgFeedPlan sgFeedPlan : sgFeedPlans) {
if (sgFeedPlan.getBatchId() != null && !sgFeedPlan.getBatchId().equals("0")) {
if (sgFeedPlan.getFormulaId().equals(currentFormulaId) && sgFeedPlan.getBatchId().equals(currentBatchId) && sgFeedPlan.getPlanDate().equals(currentDate)) {
currentFeedPlan.add(sgFeedPlan);
} else {
currentDate = sgFeedPlan.getPlanDate();
currentBatchId = sgFeedPlan.getBatchId();
currentFormulaId = sgFeedPlan.getFormulaId();
planGroups.add(currentFeedPlan);
currentFeedPlan = new ArrayList<>();
// 立即插入否则会丢失该元素
currentFeedPlan.add(sgFeedPlan);
}
}
}
// 插入最后一个列表 - 否则该列表会丢失
planGroups.add(currentFeedPlan);
// 注册数据 - 每一个List为一个清单
for (List<SgFeedPlan> sgFeedPlanList : planGroups) {
SgFeedList sgFeedList = new SgFeedList();
// 计算饲喂总和
SgFeedPlan rootPlan = computePlanTotal(sgFeedPlanList);
sgFeedList.setRootPlan(rootPlan);
sgFeedList.setPlanList(sgFeedPlanList);
// 写入信息
sgFeedList.setFormulaId(sgFeedPlanList.get(0).getFormulaId());
sgFeedList.setFormulaBatchId(sgFeedPlanList.get(0).getBatchId());
sgFeedList.setDeployDate(sgFeedPlanList.get(0).getPlanDate());
// 写入配方管理信息
SgFormulaManagement formulaManagementQuery = new SgFormulaManagement();
formulaManagementQuery.setFormulaId(sgFeedList.getFormulaId());
formulaManagementQuery.setBatchId(sgFeedList.getFormulaBatchId());
List<SgFormulaManagement> formulaManagements = sgFormulaManagementService.selectSgFormulaManagementList(formulaManagementQuery);
if (!formulaManagements.isEmpty()) {
sgFeedList.setRootFormula(formulaManagements.get(0));
sgFeedList.setFormulaList(formulaManagements.get(0).getSgFormulaList());
}
String cacheKey = sgFeedList.getFormulaId() + "_" + sgFeedList.getFormulaBatchId() + "_" + sgFeedList.getDeployDate();
// 从就缓存中查找如果存在则更新可修改的值
if (cacheTemp.containsKey(cacheKey)) {
SgFeedList cacheItem = cacheTemp.get(cacheKey);
sgFeedList.setZookeeper(cacheItem.getZookeeper());
}
sgFeedListMap.put(cacheKey, sgFeedList);
}
List<SgFeedList> toDataBase = new ArrayList<>(sgFeedListMap.values());
// 清空再写入
this.sgFeedListMapper.deleteAll();
// 处理结果写入数据库
for (SgFeedList recordItem : toDataBase) {
this.insertSgFeedList(recordItem);
}
}
}
/**
* 计算某个配方某个批次的总和值
*
@ -176,7 +248,8 @@ public class SgFeedListServiceImpl implements ISgFeedListService {
planFeedAfternoonSize += sgFeedPlan.getPlanAfternoonSize();
planFeedTotalSize += sgFeedPlan.getPlanFeedTotal();
}
rootPlan.setFormulaId(sgFeedPlans.get(0).getFormulaId());
rootPlan.setBatchId(sgFeedPlans.get(0).getBatchId());
rootPlan.setSheepCount(sheepCountTotal);
rootPlan.setPlanDailySize(sheepDailySize);
rootPlan.setPlanMorningSize(planFeedMorningSize);

View File

@ -119,7 +119,7 @@ public class SgFeedStatisticServiceImpl implements ISgFeedStatisticService {
sgFeedListService.SyncFeedList();
// 从缓存获取完整配方清单
String cacheKey = sgFeedStatistic.getFormulaId() + "_" + sgFeedStatistic.getFormulaBatchId();
String cacheKey = sgFeedStatistic.getFormulaId() + "_" + sgFeedStatistic.getFormulaBatchId() + "_" + sgFeedStatistic.getFeedDate();
SgFeedList sgFeedList = SgFeedListServiceImpl.getSgFeedListMap().get(cacheKey);
if (sgFeedList != null && sgFeedList.getFormulaList() != null) {
@ -148,7 +148,7 @@ public class SgFeedStatisticServiceImpl implements ISgFeedStatisticService {
SgFeedPlan sgFeedPlanQuery = new SgFeedPlan();
sgFeedPlanQuery.setFormulaId(sgFeedStatistic.getFormulaId());
sgFeedPlanQuery.setBatchId(sgFeedStatistic.getFormulaBatchId());
sgFeedPlanQuery.setPlanDate(sgFeedStatistic.getFeedDate());
List<SgFeedPlan> sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(sgFeedPlanQuery);
if (!sgFeedPlans.isEmpty()) {

View File

@ -31,7 +31,7 @@ public class ScBreastRating extends BaseEntity {
*/
private String sheepId;
@Excel(name = "羊只id")
@Excel(name = "管理耳号")
private String manageTags;
/**

View File

@ -27,7 +27,7 @@ public class ScChangeComment extends BaseEntity {
* 羊只id
*/
private String sheepId;
@Excel(name = "管理耳号")
private String manageTags;
/** 羊舍 */

View File

@ -47,6 +47,7 @@ public class WzStockInController extends BaseController
{
startPage();
List<WzStockIn> list = wzStockInService.selectWzStockInList(wzStockIn);
logger.debug(wzStockIn.toString());
return getDataTable(list);
}

View File

@ -35,6 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDewormVo"/>
<where>
<if test="sheepId != null "> and sheep_id = #{sheepId}</if>
<if test="sheepNo != null and sheepNo != ''">and bs.manage_tags like concat('%',#{sheepNo},'%')</if>
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
</where>

View File

@ -34,9 +34,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectHealthList" parameterType="Health" resultMap="HealthResult">
<include refid="selectHealthVo"/>
select s.id, datetime, sheep_id, usage_id, variety, sheep_type, s.gender, month_age, s.parity, breed, technical,
s.comment, s.update_by, s.update_time, s.create_by, s.create_time,
bs.manage_tags sheep_no
from sw_health s
left join bas_sheep bs on s.sheep_id = bs.id
<where>
<if test="datetime != null "> and datetime = #{datetime}</if>
<if test="sheepNo != null and sheepNo != ''">and bs.manage_tags like concat('%',#{sheepNo},'%')</if>
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
</where>
ORDER BY datetime DESC

View File

@ -32,10 +32,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectImmunityList" parameterType="Immunity" resultMap="ImmunityResult">
<include refid="selectImmunityVo"/>
select s.id, datetime, sheep_id, usage_id, variety, sheep_type, s.gender, month_age, s.parity, breed, technical,
s.comment, s.update_by, s.update_time, s.create_by, s.create_time,
bs.manage_tags sheep_no
from sw_immunity s
left join bas_sheep bs on s.sheep_id = bs.id
<where>
<if test="sheepId != null "> and sheep_id = #{sheepId}</if>
<if test="sheepType != null "> and sheep_type = #{sheepType}</if>
<if test="sheepNo != null and sheepNo != ''">and bs.manage_tags like concat('%',#{sheepNo},'%')</if>
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
</where>

View File

@ -44,9 +44,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql>
<select id="selectTreatmentList" parameterType="Treatment" resultMap="TreatmentResult">
<include refid="selectTreatmentVo"/>
select t.id, diag_id, sheep_id, variety, sheep_type, month_age, t.gender, t.parity, breed, lact_day, gest_day, datetime, disease_id, disease_pid, veterinary, usage_id,status, t.comment, t.update_by, t.update_time, t.create_by, t.create_time,
bs.manage_tags,
sd.name disease_name,
sd2.name disease_pname
from sw_treatment t
left join bas_sheep bs on t.sheep_id = bs.id
left join sw_disease sd on t.disease_id = sd.id
left join sw_disease sd2 on t.disease_pid = sd2.id
<where>
<if test="sheepId != null "> and sheep_id = #{sheepId}</if>
<if test="sheepNo != null and sheepNo != ''">and bs.manage_tags like concat('%',#{sheepNo},'%')</if>
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
<if test="diseaseId != null "> and disease_id = #{diseaseId}</if>
<if test="status != null and status !=''"> and status = #{status}</if>

View File

@ -24,6 +24,7 @@
<if test="zookeeper != null and zookeeper != ''"> and zookeeper = #{zookeeper}</if>
<if test="deployDate != null "> and deploy_date = #{deployDate}</if>
</where>
ORDER BY deploy_date ASC, formula_id ASC, formula_batch_id ASC
</select>
<select id="selectSgFeedListById" parameterType="Long" resultMap="SgFeedListResult">
@ -68,4 +69,8 @@
#{id}
</foreach>
</delete>
<delete id="deleteAll">
DELETE FROM sg_feed_list;
</delete>
</mapper>

View File

@ -37,9 +37,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectSgFeedPlanVo"/>
<where>
<if test="formulaId != null and formulaId != ''"> and formula_id = #{formulaId}</if>
<if test="batchId != null and batchId != ''"> and batch_id = #{batchId}</if>
<if test="sheepHouseId != null "> and sheep_house_id = #{sheepHouseId}</if>
<if test="planDate != null "> and plan_date = #{planDate}</if>
</where>
ORDER BY formula_id ASC, plan_date ASC
ORDER BY plan_date ASC, formula_id ASC , batch_id ASC
</select>
<select id="selectSgFeedPlanByCreateDate" parameterType="Date" resultMap="SgFeedPlanResult">

View File

@ -26,7 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectWzMaterialsManagementVo"/>
<where>
<if test="materialName != null and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
<if test="params.beginProductionDate != null and params.beginProductionDate != '' and params.endProductionDate != null and params.endProductionDate != ''"> and production_date between #{params.beginProductionDate} and #{params.endProductionDate}</if>
<if test="params.beginProductionDate != null and params.endProductionDate != null"> and production_date between #{params.beginProductionDate} and #{params.endProductionDate}</if>
<if test="productionDate != null"> and production_date = #{productionDate}</if>
</where>
</select>

View File

@ -41,6 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="businessType != null and businessType != ''"> and business_type = #{businessType}</if>
<if test="repositoryName != null and repositoryName != ''"> and repository_name like concat('%', #{repositoryName}, '%')</if>
<if test="materialName != null and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
<if test="docDate != null"> and doc_date = #{docDate}</if>
</where>
</select>