|
@@ -1,18 +1,35 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.dao.InspectionDao;
|
|
|
+import com.ym.mec.biz.dal.dao.InspectionItemDao;
|
|
|
+import com.ym.mec.biz.dal.dao.MusicGroupDao;
|
|
|
+import com.ym.mec.biz.dal.entity.Inspection;
|
|
|
+import com.ym.mec.biz.dal.entity.InspectionItem;
|
|
|
+import com.ym.mec.biz.dal.entity.School;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
+import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
+import com.ym.mec.util.date.DateUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ym.mec.biz.dal.dao.InspectionItemPlanDao;
|
|
|
import com.ym.mec.biz.dal.entity.InspectionItemPlan;
|
|
|
import com.ym.mec.biz.service.InspectionItemPlanService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
|
|
|
@Service
|
|
|
-public class InspectionItemPlanServiceImpl extends BaseServiceImpl<Long,InspectionItemPlan> implements InspectionItemPlanService {
|
|
|
+public class InspectionItemPlanServiceImpl extends BaseServiceImpl<Long, InspectionItemPlan> implements InspectionItemPlanService {
|
|
|
|
|
|
@Autowired
|
|
|
private InspectionItemPlanDao inspectionItemPlanDao;
|
|
|
+ @Autowired
|
|
|
+ private InspectionItemDao inspectionItemDao;
|
|
|
+ @Autowired
|
|
|
+ private InspectionDao inspectionDao;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, InspectionItemPlan> getDAO() {
|
|
@@ -20,7 +37,81 @@ public class InspectionItemPlanServiceImpl extends BaseServiceImpl<Long,Inspecti
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public InspectionItemPlan add(InspectionItemPlan inspectionItemPlan) {
|
|
|
+ InspectionItem inspectionItem = inspectionItemDao.get(inspectionItemPlan.getItemId());
|
|
|
+ if (inspectionItem == null) {
|
|
|
+ throw new BizException("任务项不存在");
|
|
|
+ }
|
|
|
+ if (!inspectionItem.getUserId().equals(inspectionItemPlan.getUserId())) {
|
|
|
+ throw new BizException("请勿非法操作他人日程");
|
|
|
+ }
|
|
|
+ Date nowDate = new Date();
|
|
|
+ Inspection inspection = inspectionDao.get(inspectionItem.getInspectionId());
|
|
|
+ if (inspection.getMonth().after(inspectionItemPlan.getPlanStart())) {
|
|
|
+ throw new BizException("日程时间不能早于工作周期开始时间");
|
|
|
+ }
|
|
|
+ if (nowDate.after(inspectionItemPlan.getPlanStart())) {
|
|
|
+ throw new BizException("日程时间不能早于当前时间");
|
|
|
+ }
|
|
|
+ Date itemEndTime = DateUtil.getLastTimeWithDay(DateUtil.getLastDayOfMonth(inspection.getMonth()));
|
|
|
+ if (itemEndTime.before(inspectionItemPlan.getPlanEnd())) {
|
|
|
+ throw new BizException("日程时间不能晚于工作周期结束时间");
|
|
|
+ }
|
|
|
+ //获取乐团教学点的GPS信息
|
|
|
+ School school = musicGroupDao.getMusicGroupSchool(inspectionItemPlan.getMusicGroupId());
|
|
|
+
|
|
|
+ inspectionItemPlan.setInspectionId(inspectionItem.getInspectionId());
|
|
|
+ inspectionItemPlan.setSchoolGps(school.getLongitudeLatitude());
|
|
|
+ inspectionItemPlan.setSubmitedGps("");
|
|
|
+ inspectionItemPlan.setMemo("");
|
|
|
+ inspectionItemPlan.setStatus(0);
|
|
|
+ inspectionItemPlan.setCreateTime(nowDate);
|
|
|
+ inspectionItemPlan.setUpdateTime(nowDate);
|
|
|
+ inspectionItemPlanDao.insert(inspectionItemPlan);
|
|
|
+ inspectionItem.setPlannedTimes(inspectionItem.getPlannedTimes() + 1);
|
|
|
+ inspectionItemDao.update(inspectionItem);
|
|
|
+ return inspectionItemPlan;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public InspectionItemPlan updatePlan(InspectionItemPlan inspectionItemPlan) {
|
|
|
+ InspectionItemPlan oldPlan = inspectionItemPlanDao.get(inspectionItemPlan.getId());
|
|
|
+ if (oldPlan.getStatus() > 0) {
|
|
|
+ throw new BizException("日程已完成,不能修改");
|
|
|
+ }
|
|
|
+ InspectionItem inspectionItem = inspectionItemDao.get(inspectionItemPlan.getItemId());
|
|
|
+ if (inspectionItem == null) {
|
|
|
+ throw new BizException("任务项不存在");
|
|
|
+ }
|
|
|
+ if (!inspectionItem.getUserId().equals(inspectionItemPlan.getUserId())) {
|
|
|
+ throw new BizException("请勿非法操作他人日程");
|
|
|
+ }
|
|
|
+ Date nowDate = new Date();
|
|
|
+ Inspection inspection = inspectionDao.get(inspectionItem.getInspectionId());
|
|
|
+ if (inspection.getMonth().after(inspectionItemPlan.getPlanStart())) {
|
|
|
+ throw new BizException("日程时间不能早于工作周期开始时间");
|
|
|
+ }
|
|
|
+ if (nowDate.after(inspectionItemPlan.getPlanStart())) {
|
|
|
+ throw new BizException("日程时间不能早于当前时间");
|
|
|
+ }
|
|
|
+ Date itemEndTime = DateUtil.getLastTimeWithDay(DateUtil.getLastDayOfMonth(inspection.getMonth()));
|
|
|
+ if (itemEndTime.before(inspectionItemPlan.getPlanEnd())) {
|
|
|
+ throw new BizException("日程时间不能晚于工作周期结束时间");
|
|
|
+ }
|
|
|
+ //获取乐团教学点的GPS信息
|
|
|
+ School school = musicGroupDao.getMusicGroupSchool(inspectionItemPlan.getMusicGroupId());
|
|
|
+
|
|
|
+ inspectionItemPlan.setInspectionId(inspectionItem.getInspectionId());
|
|
|
+ inspectionItemPlan.setSchoolGps(school.getLongitudeLatitude());
|
|
|
+ inspectionItemPlan.setSubmitedGps("");
|
|
|
+ inspectionItemPlan.setMemo("");
|
|
|
+ inspectionItemPlan.setStatus(0);
|
|
|
+ inspectionItemPlan.setUpdateTime(nowDate);
|
|
|
+ inspectionItemPlanDao.update(inspectionItemPlan);
|
|
|
+ return inspectionItemPlan;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|