package com.ygj.yuemum.service.college; import com.ygj.yuemum.dao.college.CollegeBookingDao; import com.ygj.yuemum.dao.college.CollegeTestDao; import com.ygj.yuemum.domain.college.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @Service public class CollegeBookingService { @Autowired private CollegeBookingDao collegeBookingDao; @Autowired private CollegeLearningDetailService collegeLearningDetailService; @Autowired private CollegeCurriculumPracticeService collegeCurriculumPracticeService; @Autowired private CollegeCurriculumExperienceService collegeCurriculumExperienceService; public List getCollegeBookings() { List collegeBookings = collegeBookingDao.getAll(); return collegeBookings; } public CollegeBooking checkBooking(CollegeBooking collegeBooking){ return collegeBookingDao.checkBooking(collegeBooking); } public CollegeBooking checkELearningBooking(CollegeBooking collegeBooking){ return collegeBookingDao.checkELearningBooking(collegeBooking); } public CollegeBooking getCollegeBooking(Integer id) { return collegeBookingDao.selectByPrimaryKey(id); } public int addELearningBooking(CollegeBooking collegeBooking) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); CollegeBooking collegeBooking1 = collegeBookingDao.checkBooking(collegeBooking); if( collegeBooking1 != null) { collegeBooking.setId(collegeBooking1.getId()); int tt = collegeBookingDao.updateByPrimaryKeySelective(collegeBooking); return tt; } else { try { collegeBooking.setDate(sdf.format(new Date())); CollegeLearningDetail collegeLearningDetail = new CollegeLearningDetail(); collegeLearningDetail.setOpen_id(collegeBooking.getOpenid()); collegeLearningDetail.setC_code(collegeBooking.getCollege_code()); collegeLearningDetail.setDate(sdf.format(new Date())); collegeLearningDetail.setStatus(1); collegeLearningDetail.setSys_type("YueLife"); collegeLearningDetail.setRate("0"); collegeLearningDetailService.addCollegeLearningDetail(collegeLearningDetail); collegeBookingDao.insertSelective(collegeBooking); return 1; }catch (Exception ex){ ex.printStackTrace(); return 0; } } } public int addCollegeBooking(CollegeBooking collegeBooking) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); CollegeBooking collegeBooking1 = collegeBookingDao.checkBooking(collegeBooking); if( collegeBooking1 != null) { collegeBooking.setId(collegeBooking1.getId()); int tt = collegeBookingDao.updateByPrimaryKeySelective(collegeBooking); return tt; } else { try { collegeBooking.setDate(sdf.format(new Date())); collegeBooking.setSys_type("YueSuo"); CollegeLearningDetail collegeLearningDetail = new CollegeLearningDetail(); collegeLearningDetail.setOpen_id(collegeBooking.getOpenid()); collegeLearningDetail.setC_code(collegeBooking.getCollege_code()); collegeLearningDetail.setDate(sdf.format(new Date())); collegeLearningDetail.setStatus(1); collegeLearningDetail.setSys_type("YueSuo"); collegeLearningDetailService.addCollegeLearningDetail(collegeLearningDetail); collegeBookingDao.insertSelective(collegeBooking); // pcount if(collegeBooking.getCollege_code().substring(0,1).equals("P")){ collegeCurriculumPracticeService.updatePCountAdd(collegeBooking.getCollege_code()); } if(collegeBooking.getCollege_code().substring(0,1).equals("E")){ collegeCurriculumExperienceService.updatePCountAdd(collegeBooking.getCollege_code()); } return 1; }catch (Exception ex){ ex.printStackTrace(); return 0; } } } public int deleteCollegeBooking(Integer id) { return collegeBookingDao.deleteByPrimaryKey(id); } public int updateCollegeBooking(CollegeBooking collegeBooking) { return collegeBookingDao.updateByPrimaryKeySelective(collegeBooking); } public int bookingCancel(CollegeBooking collegeBooking) { try { CollegeBooking collegeBooking1 = collegeBookingDao.checkBooking(collegeBooking); if( collegeBooking1 == null) { return 0; } collegeBookingDao.bookingCancel(collegeBooking); CollegeLearningDetail collegeLearningDetail = new CollegeLearningDetail(); collegeLearningDetail.setOpen_id(collegeBooking.getOpenid()); collegeLearningDetail.setC_code(collegeBooking.getCollege_code()); collegeLearningDetailService.deleteBookingCancel(collegeLearningDetail); //pcount if(collegeBooking.getCollege_code().substring(0,1).equals("P")){ collegeCurriculumPracticeService.updatePCountCancel(collegeBooking.getCollege_code()); } if(collegeBooking.getCollege_code().substring(0,1).equals("E")){ collegeCurriculumExperienceService.updatePCountCancel(collegeBooking.getCollege_code()); } return 1; }catch (Exception ex) { ex.printStackTrace(); return 0; } } }