|
@@ -36,18 +36,30 @@ public class InspectPlanService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private BuInspectPlanStoreDao inspectPlanStoreDao;
|
|
private BuInspectPlanStoreDao inspectPlanStoreDao;
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取巡检计划分页列表
|
|
|
|
|
+ * @param page 分页数据
|
|
|
|
|
+ * @param searchBean 查询条件
|
|
|
|
|
+ * @return 巡检计划分页列表
|
|
|
|
|
+ */
|
|
|
public List<BuInspectPlan> getPlanPage(PageControlData page, BuInspectPlanSearchBean searchBean) {
|
|
public List<BuInspectPlan> getPlanPage(PageControlData page, BuInspectPlanSearchBean searchBean) {
|
|
|
return inspectPlanDao.getList(page, searchBean, " order by planId desc");
|
|
return inspectPlanDao.getList(page, searchBean, " order by planId desc");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public BuInspectPlan getPlanDetail(Long id) {
|
|
|
|
|
- return (BuInspectPlan) inspectPlanDao.findById(BuInspectPlan.class, id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据ID获取巡检计划
|
|
|
|
|
+ * @param id 巡检计划ID
|
|
|
|
|
+ * @return 巡检计划
|
|
|
|
|
+ */
|
|
|
public BuInspectPlan getPlanById(Long id) {
|
|
public BuInspectPlan getPlanById(Long id) {
|
|
|
- return getPlanDetail(id);
|
|
|
|
|
|
|
+ return (BuInspectPlan) inspectPlanDao.findById(BuInspectPlan.class, id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据ID获取巡检计划关联指标
|
|
|
|
|
+ * @param planId 巡检计划ID
|
|
|
|
|
+ * @return 巡检计划关联指标
|
|
|
|
|
+ */
|
|
|
public List<BuInspectPlanIndicator> getPlanIndicators(Long planId) {
|
|
public List<BuInspectPlanIndicator> getPlanIndicators(Long planId) {
|
|
|
BuInspectPlanIndicatorSearchBean searchBean = new BuInspectPlanIndicatorSearchBean();
|
|
BuInspectPlanIndicatorSearchBean searchBean = new BuInspectPlanIndicatorSearchBean();
|
|
|
searchBean.setPlanId(planId);
|
|
searchBean.setPlanId(planId);
|
|
@@ -55,6 +67,11 @@ public class InspectPlanService {
|
|
|
return inspectPlanIndicatorDao.getList(searchBean, " order by sort asc, planIndicatorId asc");
|
|
return inspectPlanIndicatorDao.getList(searchBean, " order by sort asc, planIndicatorId asc");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据ID获取巡检计划关联门店
|
|
|
|
|
+ * @param planId 巡检计划ID
|
|
|
|
|
+ * @return 巡检计划关联门店
|
|
|
|
|
+ */
|
|
|
public List<BuInspectPlanStore> getPlanStores(Long planId) {
|
|
public List<BuInspectPlanStore> getPlanStores(Long planId) {
|
|
|
BuInspectPlanStoreSearchBean searchBean = new BuInspectPlanStoreSearchBean();
|
|
BuInspectPlanStoreSearchBean searchBean = new BuInspectPlanStoreSearchBean();
|
|
|
searchBean.setPlanId(planId);
|
|
searchBean.setPlanId(planId);
|
|
@@ -62,6 +79,11 @@ public class InspectPlanService {
|
|
|
return inspectPlanStoreDao.getList(searchBean, " order by planStoreId asc");
|
|
return inspectPlanStoreDao.getList(searchBean, " order by planStoreId asc");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存巡检计划
|
|
|
|
|
+ * @param plan 巡检计划
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
public boolean save(BuInspectPlan plan) {
|
|
public boolean save(BuInspectPlan plan) {
|
|
|
if (!InspectCommonUtils.validPlan(plan)) {
|
|
if (!InspectCommonUtils.validPlan(plan)) {
|
|
|
return false;
|
|
return false;
|
|
@@ -69,10 +91,11 @@ public class InspectPlanService {
|
|
|
return inspectPlanDao.save(plan);
|
|
return inspectPlanDao.save(plan);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public boolean savePlan(BuInspectPlan plan) {
|
|
|
|
|
- return save(plan);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新巡检计划
|
|
|
|
|
+ * @param plan 巡检计划
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
public boolean update(BuInspectPlan plan) {
|
|
public boolean update(BuInspectPlan plan) {
|
|
|
if (!InspectCommonUtils.validPlan(plan) || plan.getPlanId() == null) {
|
|
if (!InspectCommonUtils.validPlan(plan) || plan.getPlanId() == null) {
|
|
|
return false;
|
|
return false;
|
|
@@ -89,10 +112,6 @@ public class InspectPlanService {
|
|
|
return inspectPlanDao.update(plan);
|
|
return inspectPlanDao.update(plan);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public boolean updatePlan(BuInspectPlan plan) {
|
|
|
|
|
- return update(plan);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 发布巡检计划。
|
|
* 发布巡检计划。
|
|
|
* 返回 {success, reason}:success=false 时 reason 为失败原因。
|
|
* 返回 {success, reason}:success=false 时 reason 为失败原因。
|
|
@@ -144,41 +163,73 @@ public class InspectPlanService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Map<String, Object> publishPlan(Long id) {
|
|
|
|
|
- return publish(id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public int changeStatus(Long id, Integer status) {
|
|
|
|
|
- return inspectPlanDao.executeSql(
|
|
|
|
|
- "update bu_inspect_plan set STATUS = :status where PLAN_ID = :id",
|
|
|
|
|
- InspectCommonUtils.with(InspectCommonUtils.params("id", id), "status", status));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public int pausePlan(Long id) {
|
|
|
|
|
- return inspectPlanDao.executeSql(
|
|
|
|
|
- "update bu_inspect_plan set STATUS = 2 where PLAN_ID = :id and STATUS = 1",
|
|
|
|
|
- InspectCommonUtils.params("id", id));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 完成巡检计划
|
|
|
|
|
+ * @param id 巡检计划ID
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
public int finish(Long id) {
|
|
public int finish(Long id) {
|
|
|
return inspectPlanDao.executeSql(
|
|
return inspectPlanDao.executeSql(
|
|
|
"update bu_inspect_plan set STATUS = 3, FINISH_DATE = NOW() where PLAN_ID = :id and STATUS in (1, 2)",
|
|
"update bu_inspect_plan set STATUS = 3, FINISH_DATE = NOW() where PLAN_ID = :id and STATUS in (1, 2)",
|
|
|
InspectCommonUtils.params("id", id));
|
|
InspectCommonUtils.params("id", id));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int finishPlan(Long id) {
|
|
|
|
|
- return finish(id);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除巡检计划。仅草稿状态(0)可删除,返回 {success, reason}。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> delete(Long id) {
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("success", false);
|
|
|
|
|
+ BuInspectPlan plan = getPlanById(id);
|
|
|
|
|
+ if (plan == null) {
|
|
|
|
|
+ result.put("reason", "计划不存在");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ int status = plan.getStatus() == null ? 0 : plan.getStatus();
|
|
|
|
|
+ if (status != 0) {
|
|
|
|
|
+ result.put("reason", "仅草稿状态的计划可删除,当前计划为" + statusName(status) + ",无法删除");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ int rows = inspectPlanDao.executeSql("delete from bu_inspect_plan where PLAN_ID = :id and STATUS = 0",
|
|
|
|
|
+ InspectCommonUtils.params("id", id));
|
|
|
|
|
+ result.put("success", rows > 0);
|
|
|
|
|
+ result.put("reason", rows > 0 ? "删除完成" : "计划不存在或状态已变更,无法删除");
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int delete(Long id) {
|
|
|
|
|
- return inspectPlanDao.executeSql("delete from bu_inspect_plan where PLAN_ID = :id",
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 暂停巡检计划。仅已发布状态(1)可暂停,返回 {success, reason}。
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, Object> pause(Long id) {
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("success", false);
|
|
|
|
|
+ BuInspectPlan plan = getPlanById(id);
|
|
|
|
|
+ if (plan == null) {
|
|
|
|
|
+ result.put("reason", "计划不存在");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ int status = plan.getStatus() == null ? 0 : plan.getStatus();
|
|
|
|
|
+ if (status != 1) {
|
|
|
|
|
+ result.put("reason", "仅已发布的计划可暂停,当前计划为" + statusName(status) + ",无法暂停");
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ int rows = inspectPlanDao.executeSql("update bu_inspect_plan set STATUS = 2 where PLAN_ID = :id and STATUS = 1",
|
|
|
InspectCommonUtils.params("id", id));
|
|
InspectCommonUtils.params("id", id));
|
|
|
|
|
+ result.put("success", rows > 0);
|
|
|
|
|
+ result.put("reason", rows > 0 ? "暂停完成" : "计划状态已变更,无法暂停");
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public int deletePlan(Long id) {
|
|
|
|
|
- return delete(id);
|
|
|
|
|
|
|
+ private String statusName(Integer status) {
|
|
|
|
|
+ switch (status == null ? 0 : status) {
|
|
|
|
|
+ case 1: return "已发布";
|
|
|
|
|
+ case 2: return "已暂停";
|
|
|
|
|
+ case 3: return "已结束";
|
|
|
|
|
+ default: return "草稿";
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public BigDecimal getPlanIndicatorWeightSum(Long planId) {
|
|
public BigDecimal getPlanIndicatorWeightSum(Long planId) {
|
|
|
List<?> rows = inspectPlanIndicatorDao.searchBySql(
|
|
List<?> rows = inspectPlanIndicatorDao.searchBySql(
|
|
|
"select ifnull(sum(WEIGHT), 0) from bu_inspect_plan_indicator "
|
|
"select ifnull(sum(WEIGHT), 0) from bu_inspect_plan_indicator "
|
|
@@ -186,59 +237,23 @@ public class InspectPlanService {
|
|
|
return InspectCommonUtils.firstDecimal(rows);
|
|
return InspectCommonUtils.firstDecimal(rows);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public boolean validPlanIndicatorWeight(Long planId) {
|
|
|
|
|
- return getPlanIndicatorWeightSum(planId).compareTo(new BigDecimal("100")) == 0;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- public List<BuInspectPlanIndicator> getPlanIndicatorPage(PageControlData page, BuInspectPlanIndicatorSearchBean searchBean) {
|
|
|
|
|
- return inspectPlanIndicatorDao.getList(page, searchBean, " order by sort asc, planIndicatorId desc");
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
public boolean savePlanIndicator(BuInspectPlanIndicator planIndicator) {
|
|
public boolean savePlanIndicator(BuInspectPlanIndicator planIndicator) {
|
|
|
return inspectPlanIndicatorDao.save(planIndicator);
|
|
return inspectPlanIndicatorDao.save(planIndicator);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public boolean updatePlanIndicator(BuInspectPlanIndicator planIndicator) {
|
|
|
|
|
- if (planIndicator == null || planIndicator.getPlanIndicatorId() == null) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- BuInspectPlanIndicator old = (BuInspectPlanIndicator) inspectPlanIndicatorDao.findById(
|
|
|
|
|
- BuInspectPlanIndicator.class, planIndicator.getPlanIndicatorId());
|
|
|
|
|
- if (old == null) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- planIndicator.setCreateDate(old.getCreateDate());
|
|
|
|
|
- planIndicator.setUpdateDate(old.getUpdateDate());
|
|
|
|
|
- return inspectPlanIndicatorDao.update(planIndicator);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public int deletePlanIndicator(Long id) {
|
|
public int deletePlanIndicator(Long id) {
|
|
|
return inspectPlanIndicatorDao.executeSql(
|
|
return inspectPlanIndicatorDao.executeSql(
|
|
|
"delete from bu_inspect_plan_indicator where PLAN_INDICATOR_ID = :id",
|
|
"delete from bu_inspect_plan_indicator where PLAN_INDICATOR_ID = :id",
|
|
|
InspectCommonUtils.params("id", id));
|
|
InspectCommonUtils.params("id", id));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<BuInspectPlanStore> getPlanStorePage(PageControlData page, BuInspectPlanStoreSearchBean searchBean) {
|
|
|
|
|
- return inspectPlanStoreDao.getList(page, searchBean, " order by planStoreId desc");
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
public boolean savePlanStore(BuInspectPlanStore planStore) {
|
|
public boolean savePlanStore(BuInspectPlanStore planStore) {
|
|
|
return inspectPlanStoreDao.save(planStore);
|
|
return inspectPlanStoreDao.save(planStore);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public boolean updatePlanStore(BuInspectPlanStore planStore) {
|
|
|
|
|
- if (planStore == null || planStore.getPlanStoreId() == null) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- BuInspectPlanStore old = (BuInspectPlanStore) inspectPlanStoreDao.findById(
|
|
|
|
|
- BuInspectPlanStore.class, planStore.getPlanStoreId());
|
|
|
|
|
- if (old == null) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- planStore.setCreateDate(old.getCreateDate());
|
|
|
|
|
- return inspectPlanStoreDao.update(planStore);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public int deletePlanStore(Long id) {
|
|
public int deletePlanStore(Long id) {
|
|
|
return inspectPlanStoreDao.executeSql(
|
|
return inspectPlanStoreDao.executeSql(
|
|
|
"delete from bu_inspect_plan_store where PLAN_STORE_ID = :id",
|
|
"delete from bu_inspect_plan_store where PLAN_STORE_ID = :id",
|