perf(module feed/FeedList): 为数据同步增加了缓存机制
在配料清单部分增加了缓存机制: 所有对数据库的请求通过Map缓存 仅当配方管理出现修改 || 饲喂计划出现增删改操作时通过标志位通知配料清单表下一次请求刷新缓存 减少对数据库的重复请求操作
This commit is contained in:
parent
847055687b
commit
6c67094c0d
@ -10,6 +10,7 @@ import com.zhyc.module.feed.domain.SgFeedPlan;
|
||||
import com.zhyc.module.feed.domain.SgFormulaManagement;
|
||||
import com.zhyc.module.feed.service.ISgFeedPlanService;
|
||||
import com.zhyc.module.feed.service.ISgFormulaManagementService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -46,6 +47,9 @@ public class SgFeedListController extends BaseController {
|
||||
|
||||
private final Map<String, SgFeedList> sgFeedListMap = new HashMap<>();
|
||||
|
||||
public static boolean refresh = true;
|
||||
|
||||
@Autowired
|
||||
public SgFeedListController(ISgFeedListService sgFeedListService, ISgFormulaManagementService sgFormulaManagementService, ISgFeedPlanService sgFeedPlanService) {
|
||||
this.sgFeedListService = sgFeedListService;
|
||||
this.sgFormulaManagementService = sgFormulaManagementService;
|
||||
@ -59,7 +63,14 @@ public class SgFeedListController extends BaseController {
|
||||
@GetMapping("/list")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TableDataInfo list(SgFeedList sgFeedList) {
|
||||
/*
|
||||
刷新缓存
|
||||
当配方管理表出现更新 或 饲喂计划表出现增删改时会将refresh置为true 通知此处进行刷新
|
||||
*/
|
||||
if (refresh) {
|
||||
SyncFeedList();
|
||||
refresh = false;
|
||||
}
|
||||
startPage();
|
||||
List<SgFeedList> list = sgFeedListService.selectSgFeedListList(sgFeedList);
|
||||
// 用 map 中已有的数据替换 list 中的元素
|
||||
@ -164,17 +175,20 @@ public class SgFeedListController extends BaseController {
|
||||
rootPlanQuery.setFormulaId(sgFormulaManagement.getFormulaId());
|
||||
rootPlanQuery.setBatchId(sgFormulaManagement.getBatchId());
|
||||
List<SgFeedPlan> sgFeedPlans = sgFeedPlanService.selectSgFeedPlanList(rootPlanQuery);
|
||||
// 为空则标识当前配方不在饲喂计划中
|
||||
// 为空则标识当前配方不在饲喂计划中 && 不在缓存中设置
|
||||
if (sgFeedPlans.isEmpty()) {
|
||||
isPlan = false;
|
||||
}
|
||||
} else {
|
||||
// rootPlan中存储的是该配方批号的总量
|
||||
SgFeedPlan rootPlan = computePlanTotal(sgFeedPlans);
|
||||
|
||||
// 将计划实体对象设置到配料清单中
|
||||
sgFeedList.setRootPlan(rootPlan);
|
||||
|
||||
// 完整的配料清单对象加入缓存
|
||||
sgFeedListMap.put(sgFormulaManagement.getFormulaId() + "_" + sgFormulaManagement.getBatchId(), sgFeedList);
|
||||
}
|
||||
|
||||
// 不存在则插入
|
||||
if (!isExist && isPlan) {
|
||||
sgFeedListService.insertSgFeedList(sgFeedList);
|
||||
@ -213,6 +227,9 @@ public class SgFeedListController extends BaseController {
|
||||
rootPlan.setPlanNoonSize(planFeedNoonSize);
|
||||
rootPlan.setPlanAfternoonSize(planFeedAfternoonSize);
|
||||
rootPlan.setPlanFeedTotal(planFeedTotalSize);
|
||||
|
||||
// 设置计划日期
|
||||
rootPlan.setPlanDate(sgFeedPlans.get(0).getPlanDate());
|
||||
}
|
||||
return rootPlan;
|
||||
}
|
||||
|
@ -82,6 +82,8 @@ public class SgFeedPlanController extends BaseController {
|
||||
sgFeedPlan.setCreateDate(new Date());
|
||||
// 计算其他字段值
|
||||
setPlan(sgFeedPlan);
|
||||
// 通知配料清单刷新数据
|
||||
SgFeedListController.refresh = true;
|
||||
return toAjax(sgFeedPlanService.insertSgFeedPlan(sgFeedPlan));
|
||||
}
|
||||
|
||||
@ -94,6 +96,8 @@ public class SgFeedPlanController extends BaseController {
|
||||
public AjaxResult edit(@RequestBody SgFeedPlan sgFeedPlan) {
|
||||
// 根据修改后的值重新计算
|
||||
setPlan(sgFeedPlan);
|
||||
// 通知配料清单刷新数据
|
||||
SgFeedListController.refresh = true;
|
||||
return toAjax(sgFeedPlanService.updateSgFeedPlan(sgFeedPlan));
|
||||
}
|
||||
|
||||
@ -104,6 +108,8 @@ public class SgFeedPlanController extends BaseController {
|
||||
@Log(title = "饲喂计划", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{createDates}")
|
||||
public AjaxResult remove(@PathVariable Date[] createDates) {
|
||||
// 通知配料清单刷新数据
|
||||
SgFeedListController.refresh = true;
|
||||
return toAjax(sgFeedPlanService.deleteSgFeedPlanByCreateDates(createDates));
|
||||
}
|
||||
|
||||
@ -111,7 +117,7 @@ public class SgFeedPlanController extends BaseController {
|
||||
* 设定计划值
|
||||
* 用于添加和修改
|
||||
*/
|
||||
private SgFeedPlan setPlan(SgFeedPlan sgFeedPlan) {
|
||||
private void setPlan(SgFeedPlan sgFeedPlan) {
|
||||
// 根据羊舍ID获取羊只数量
|
||||
int countByFoldId = sgFeedPlanService.getSheepCountByFoldId(sgFeedPlan.getSheepHouseId());
|
||||
sgFeedPlan.setSheepCount(countByFoldId);
|
||||
@ -121,6 +127,5 @@ public class SgFeedPlanController extends BaseController {
|
||||
sgFeedPlan.setPlanMorningSize(sgFeedPlan.getPlanFeedTotal() * (sgFeedPlan.getRatioMorning() / 100));
|
||||
sgFeedPlan.setPlanNoonSize(sgFeedPlan.getPlanFeedTotal() * (sgFeedPlan.getRatioNoon() / 100));
|
||||
sgFeedPlan.setPlanAfternoonSize(sgFeedPlan.getPlanFeedTotal() * (sgFeedPlan.getRatioAfternoon() / 100));
|
||||
return sgFeedPlan;
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +143,9 @@ public class SgFormulaManagementController extends BaseController {
|
||||
sgFormulaListItem.setFormulaId(sgFormulaManagement.getFormulaId());
|
||||
sgFormulaListService.insertSgFormulaList(sgFormulaListItem);
|
||||
}
|
||||
|
||||
// 通知配料清单刷新数据
|
||||
SgFeedListController.refresh = true;
|
||||
return toAjax(sgFormulaManagementService.updateSgFormulaManagement(sgFormulaManagement));
|
||||
}
|
||||
|
||||
@ -167,6 +170,9 @@ public class SgFormulaManagementController extends BaseController {
|
||||
}
|
||||
// 前置检查完毕 执行删除
|
||||
sgFormulaManagement.setBatchId(batchId);
|
||||
|
||||
// 通知配料清单刷新数据
|
||||
SgFeedListController.refresh = true;
|
||||
return toAjax(sgFormulaManagementService.deleteSgFormulaManagement(sgFormulaManagement));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user