Java项目:在线婚纱摄影预定系统(java+javaweb+SSM+springboot+mysql)

源码获取:博客首页 "资源" 里下载!

一、项目简述

功能: 前后用户的登录注册,婚纱照片分类,查看,摄影师预 订,后台订单管理,图片管理等等。

二、项目运行 

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: Jdbc+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload

作品控制器:

/**
 * 
 * 作品控制器
 *
 */
@Controller
@Scope("prototype")
public class WorksController {

	private static final Logger logger = LoggerFactory.getLogger(WorksController.class);
	private ReturnResult returnResult = new ReturnResult();

	@Resource(name = "worksService")
	private IWorksService worksService;
	
	@Resource(name = "attachmentService")
	private IAttachmentService attachmentService;

	/**
	 * 添加作品
	 * 
	 * @param works
	 * @param HttpServletRequest
	 * @return
	 */
	@RequestMapping(value = "addWorks", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult addWorks(TWorks works, HttpServletRequest request) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {

			Map<String, String> map = OperationFileUtil.multiFileUpload(request,
					request.getServletContext().getRealPath("/") + "uploads\\images\\");
			
			works.setCreatetime(new Date());
			worksService.insert(works);
			//插入附件
			int worksId = works.getId();
			for (Map.Entry<String, String> entry : map.entrySet()) {
				TAttachment attachment = new TAttachment();
				attachment.setWorksid(worksId);
				attachment.setPath(entry.getValue().replace(request.getServletContext().getRealPath("/"), "/"));
				attachment.setStatus("0");
				attachment.setCreatetime(new Date());
				attachmentService.insert(attachment);
			}
			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("新增works失败" + e);
			e.printStackTrace();
		}
		return returnResult;

	}

	/**
	 * 修改works状态
	 * @param works
	 * @return
	 */
	@RequestMapping(value = "updateWorksStatus", method = RequestMethod.GET)
	@ResponseBody
	public ReturnResult updateWorksStatus(TWorks works) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			worksService.updateBySQL("UPDATE t_works SET status=" + works.getStatus() + " WHERE id=" + works.getId());
			
			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("更新works状态失败" + e);
		}
		return returnResult;
	}
	
	/**
	 * 修改works封面
	 * @param works
	 * @return
	 */
	@RequestMapping(value = "updateWorksPath", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult updateWorksPath(TWorks works,HttpServletRequest request) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			Map<String, String> map = OperationFileUtil.multiFileUpload(request,
					request.getServletContext().getRealPath("/") + "uploads\\images\\");
			String filePath = "";
			for (Map.Entry<String, String> entry : map.entrySet()) {
				filePath = entry.getValue();
			}
			filePath = filePath.replace(request.getServletContext().getRealPath("/"), "/").replace("\\", "/");
			worksService.updateBySQL("UPDATE t_works SET path='" + filePath + "' WHERE id=" + works.getId());
			
			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error(" 修改works封面失败" + e);
		}
		return returnResult;
	}
	
	
	/**
	 * 修改works的title和content
	 * @param works
	 * @return
	 */
	@RequestMapping(value = "updateWorks", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult updateWorks(TWorks works) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			worksService.updateBySQL("UPDATE t_works SET title='" + works.getTitle() + "',content='"+works.getContent()+"' WHERE id=" + works.getId());
			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("修改works失败" + e);
		}
		return returnResult;
	}
	/**
	 * 根据id获取Works 的照片
	 * @param Works
	 * @return
	 */
	@RequestMapping(value = "getWorksImgById", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getWorksImgById(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS).setData(worksService.selectBySQL("SELECT path FROM t_attachment WHERE worksId="+id));
		} catch (Exception e) {
			logger.error("根据id获取Works 的照片 失败" + e);
		}
		return returnResult;
	}
	
	/**
	 * 根据id获取Works 
	 * @param Works
	 * @return
	 */
	@RequestMapping(value = "getWorksById")
	@ResponseBody
	public ReturnResult getWorksById(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS).setData(worksService.selectByPrimaryKey(id));
		} catch (Exception e) {
			logger.error("根据id获取Works失败" + e);
		}
		return returnResult;
	}
	/**
	 * 根据id获取Works 用户视图
	 * @param Works
	 * @return
	 */
	@RequestMapping(value = "getWorks")
	@ResponseBody
	public ReturnResult getWorks(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS).setData(worksService.getWorks(id));
		} catch (Exception e) {
			logger.error("根据id获取Works失败" + e);
		}
		return returnResult;
	}
	/**
	 * 根据photographerid获取Works 
	 * @param Works
	 * @return
	 */
	@RequestMapping(value = "getWorksByPhotographerId", method = RequestMethod.GET)
	@ResponseBody
	public ReturnResult getWorksByPhotographerId(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS).setData(worksService.getWorksByPhotographerId(id));
		} catch (Exception e) {
			logger.error("根据photographerid获取Works失败" + e);
		}
		return returnResult;
	}
	
	/**
	 * 分页获取works
	 * @return
	 */
	@RequestMapping(value = "getWorksListByPage", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getWorksListByPage(PageVO page,String photographerId,String spotsId,String status) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			Map<String, Object> resultMap = new HashMap<String, Object>();
			StringBuffer sql = new StringBuffer("SELECT a.*,b.`name` AS photographer,c.`name` AS spots FROM t_works a,t_photographer b,t_spots c WHERE a.photographerId=b.id AND a.spotsId=c.id");
			StringBuffer countSql = new StringBuffer("SELECT COUNT(*) AS total FROM t_works a,t_photographer b,t_spots c WHERE a.photographerId=b.id AND a.spotsId=c.id");
			if(StringUtils.isNotBlank(photographerId)){
				sql.append(" AND b.id="+photographerId);
				countSql.append(" AND b.id="+photographerId);
			}
			if(StringUtils.isNotBlank(spotsId)){
				sql.append(" AND c.id="+spotsId);
				countSql.append(" AND c.id="+spotsId);
			}
			if(StringUtils.isNotBlank(status)){
				sql.append(" AND a.status="+status);
				countSql.append(" AND a.status="+status);
			}
			List<Map<String, Object>> results = worksService.selectPageBySQL(sql.toString(), page.getPage() - 1,
					page.getRows());
			if (!results.isEmpty() && results != null) {
				int total = Integer.valueOf(worksService.selectBySQL(countSql.toString()).get(0).get("total").toString());
				int rows = page.getRows();
				rows = rows == 0 ? 10 : rows;
				resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
				resultMap.put("page", page.getPage());
				resultMap.put("records", total);
				resultMap.put("rows", results);
				returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
			}
		}catch (Exception e) {
			logger.error("分页获取works失败" + e);
		}
		return returnResult;
	}
	/**
	 * 分页获取启用的works
	 * @return
	 */
	@RequestMapping(value = "getWorksListByPageStatus", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getWorksListByPageStatus(String sord,String spotsId) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			String sql = "SELECT * FROM t_works WHERE status=0";
			if(StringUtils.isNotBlank(sord)){
				sql="SELECT * FROM t_works WHERE status=0 ORDER BY id DESC";
			}
			if(StringUtils.isNotBlank(spotsId)){
				sql = "SELECT * FROM t_works WHERE status=0 AND spotsId="+spotsId;
			}
				returnResult.setStatus(ReturnCodeType.SUCCESS).setData(worksService.selectBySQL(sql));
		}catch (Exception e) {
			logger.error("分页获取启用的works失败" + e);
		}
		return returnResult;
	}
}

 摄影师控制器:

/**
 * 
 * 摄影师控制器
 *
 */
@Controller
@Scope("prototype")
public class PhotographerController {

	private static final Logger logger = LoggerFactory.getLogger(PhotographerController.class);
	private ReturnResult returnResult = new ReturnResult();

	@Resource(name = "photographerService")
	private IPhotographerService photographerService;
	@Resource(name = "photographerLabelService")
	IPhotographerLabelService photographerLabelService;
	@Resource(name = "photographerLevelService")
	IPhotographerLevelService photographerLevelService;
	@Resource(name = "photographerSpotsService")
	IPhotographerSpotsService photographerSpotsService;

	/**
	 * 添加摄影师
	 * 
	 * @param photographer
	 * @param HttpServletRequest
	 * @return
	 */
	@RequestMapping(value = "addPhotographer", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult addPhotographer(TPhotographer photographer, HttpServletRequest request, Integer labelId,
			Integer levelId, Integer spotsId) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {

			Map<String, String> map = OperationFileUtil.multiFileUpload(request,
					request.getServletContext().getRealPath("/") + "uploads\\photographer\\");
			String filePath = "";
			for (Map.Entry<String, String> entry : map.entrySet()) {
				filePath = entry.getValue();
			}
			filePath = filePath.replace(request.getServletContext().getRealPath("/"), "/");
			photographer.setHead(filePath);
			photographer.setCreatetime(new Date());
			photographerService.insert(photographer);
			int id = photographer.getId();
			TPhotographerLabel label = new TPhotographerLabel(labelId, id, new Date(), "0");
			photographerLabelService.insert(label);

			TPhotographerLevel level = new TPhotographerLevel(levelId, id, new Date(), "0");
			photographerLevelService.insert(level);

			TPhotographerSpots spots = new TPhotographerSpots(spotsId, id, new Date(), "0");
			photographerSpotsService.insert(spots);

			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("新增photographer失败" + e);
		}
		return returnResult;

	}

	/**
	 * 修改photographer状态
	 * 
	 * @param photographer
	 * @return
	 */
	@RequestMapping(value = "updatePhotographerStatus", method = RequestMethod.GET)
	@ResponseBody
	public ReturnResult updatePhotographerStatus(TPhotographer photographer) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			photographerService.updateBySQL("UPDATE t_photographer SET status=" + photographer.getStatus()
					+ " WHERE id=" + photographer.getId());

			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("更新photographer状态失败" + e);
		}
		return returnResult;
	}

	/**
	 * 修改photographer的name和summary
	 * 
	 * @param photographer
	 * @return
	 */
	@RequestMapping(value = "updatePhotographer", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult updatePhotographer(TPhotographer photographer, Integer labelId, Integer levelId,
			Integer spotsId) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			photographerService.updateBySQL("UPDATE t_photographer SET name='" + photographer.getName() + "',summary='"
					+ photographer.getSummary() + "',status=" + photographer.getStatus() + " WHERE id="
					+ photographer.getId());
			photographerLabelService.updateBySQL("UPDATE t_photographer_label SET labelId=" + labelId
					+ " WHERE photographerId=" + photographer.getId());
			photographerLevelService.updateBySQL("UPDATE t_photographer_level SET levelId=" + levelId
					+ " WHERE photographer=" + photographer.getId());
			photographerSpotsService.updateBySQL("UPDATE t_photographer_spots SET spotsId=" + spotsId
					+ " WHERE photographerId=" + photographer.getId());
			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("修改photographer失败" + e);
			e.printStackTrace();
		}
		return returnResult;
	}

	/**
	 * 根据id获取Photographer
	 * admin
	 * @param Photographer
	 * @return
	 */
	@RequestMapping(value = "getPhotographerById", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getPhotographerById(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS)
					.setData(photographerService.selectBySQL(
							"SELECT a.*,b.labelId,c.levelId,d.spotsId FROM t_photographer a,t_photographer_label b,t_photographer_level c,t_photographer_spots d WHERE a.id ="
									+ id + " AND b.photographerId=" + id + " AND c.photographer=" + id
									+ " AND d.photographerId=" + id + "")
							.get(0));
		} catch (Exception e) {
			logger.error("根据id获取Photographer失败" + e);
		}
		return returnResult;
	}
	/**
	 * 根据id获取Photographer
	 * user
	 * @param Photographer
	 * @return
	 */
	@RequestMapping(value = "getPhotographer")
	@ResponseBody
	public ReturnResult getPhotographer(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS)
			.setData(photographerService.selectBySQL(
					"SELECT a.name,a.head,a.summary,d.`name` AS level,e.`name` AS spots FROM t_photographer a,t_photographer_level b,t_photographer_spots c,t_level d,t_spots e WHERE a.id="+id+" AND b.photographer="+id+" AND c.photographerId="+id+" AND d.id=b.levelId AND e.id = c.spotsId AND a.`status`=0")
					.get(0));
		} catch (Exception e) {
			logger.error("根据id获取Photographer失败" + e);
		}
		return returnResult;
	}

	/**
	 * 分页获取photographer
	 * 
	 * @return
	 */
	@RequestMapping(value = "getPhotographerListByPage", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getPhotographerListByPage(PageVO page, String labelId, String levelId, String spotsId,
			String beforeTime, String afterTime, String status, String name) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			Map<String, Object> resultMap = new HashMap<String, Object>();
			StringBuffer sql = new StringBuffer(
					"SELECT a.*,f.`name` AS label,g.`name` AS level,h.`name` AS spots FROM t_photographer a,t_photographer_label b,t_photographer_level c ,t_photographer_spots d,t_label f,t_level g,t_spots h WHERE a.id=b.photographerId AND a.id = c.photographer AND a.id = d.photographerId AND f.id=b.labelId AND g.id=c.levelId AND h.id= d.spotsId");

			if (StringUtils.isNotBlank(labelId)) {
				sql.append(" AND b.labelId=" + labelId);
				sql.append(" AND f.id=" + labelId);
			}
			if (StringUtils.isNotBlank(levelId)) {
				sql.append(" AND c.levelId=" + levelId);
				sql.append(" AND g.id=" + levelId);
			}
			if (StringUtils.isNotBlank(spotsId)) {
				sql.append(" AND d.spotsId=" + spotsId);
				sql.append(" AND h.id=" + spotsId);
			}

			if (StringUtils.isNotBlank(status)) {
				sql.append(" AND a.status=" + status);
			}
			if (StringUtils.isNotBlank(name)) {
				sql.append(" AND a.name=" + name);
			}

			List<Map<String, Object>> results = photographerService.selectPageBySQL(sql.toString(), page.getPage() - 1,
					page.getRows());
			if (!results.isEmpty() && results != null) {
				int total = photographerService.selectCount(new TPhotographer());
				int rows = page.getRows();
				rows = rows == 0 ? 10 : rows;
				resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
				resultMap.put("page", page.getPage());
				resultMap.put("records", total);
				resultMap.put("rows", results);
				returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
			}
		} catch (Exception e) {
			logger.error("分页获取photographer失败" + e);
		}
		return returnResult;
	}

	/**
	 * 分页获取启用的photographer
	 * 
	 * @return
	 */
	@RequestMapping(value = "getPhotographerListByPageStatus", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getPhotographerListByPageStatus(PageVO page, String labelId, String levelId, String spotsId,
			String start, String end) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			Map<String, Object> resultMap = new HashMap<String, Object>();
			StringBuffer sql = new StringBuffer(
					"SELECT a.*,f.`name` AS label,g.`name` AS level,h.`name` AS spots FROM t_photographer a,t_photographer_label b,t_photographer_level c ,t_photographer_spots d,t_label f,t_level g,t_spots h WHERE a.id=b.photographerId AND a.id = c.photographer AND a.id = d.photographerId AND f.id=b.labelId AND g.id=c.levelId AND h.id= d.spotsId AND a.status=0");

			StringBuffer countSql = new StringBuffer("SELECT COUNT(*) AS total FROM t_photographer a,t_photographer_label b,t_photographer_level c ,t_photographer_spots d,t_label f,t_level g,t_spots h WHERE a.id=b.photographerId AND a.id = c.photographer AND a.id = d.photographerId AND f.id=b.labelId AND g.id=c.levelId AND h.id= d.spotsId AND a.status=0");
			if (StringUtils.isNotBlank(start) && StringUtils.isNotBlank(end)) {
				List<String> list = photographerService.selectByStartEnd(start,end);
				for(String id : list){
					sql.append(" AND a.id!="+id);
					countSql.append(" AND a.id!="+id);
				}
			}
			if (StringUtils.isNotBlank(labelId)) {
				sql.append(" AND b.labelId=" + labelId);
				sql.append(" AND f.id=" + labelId);
				countSql.append(" AND b.labelId=" + labelId);
				countSql.append(" AND f.id=" + labelId);
			}
			if (StringUtils.isNotBlank(levelId)) {
				sql.append(" AND c.levelId=" + levelId);
				sql.append(" AND g.id=" + levelId);
				countSql.append(" AND c.levelId=" + levelId);
				countSql.append(" AND g.id=" + levelId);
			}
			if (StringUtils.isNotBlank(spotsId)) {
				sql.append(" AND d.spotsId=" + spotsId);
				sql.append(" AND h.id=" + spotsId);
				countSql.append(" AND d.spotsId=" + spotsId);
				countSql.append(" AND h.id=" + spotsId);
			}

			List<Map<String, Object>> results = photographerService.selectPageBySQL(sql.toString(), page.getPage() - 1,
					page.getRows());
			if (!results.isEmpty() && results != null) {
				int total = Integer.valueOf( photographerService.selectBySQL(countSql.toString()).get(0).get("total").toString());
				int rows = page.getRows();
				rows = rows == 0 ? 10 : rows;
				resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
				resultMap.put("page", page.getPage());
				resultMap.put("records", total);
				resultMap.put("rows", results);
				returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
			}
		} catch (Exception e) {
			logger.error("分页获取启用的photographer失败" + e);
		}
		return returnResult;
	}

	/**
	 * 获取所有启用的Photographer
	 * 
	 * @param Photographer
	 * @return
	 */
	@RequestMapping(value = "getAllPhotographer", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getAllPhotographer() {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS).setData(photographerService.selectBySQL(
					"SELECT a.id,a.name FROM t_photographer a,t_photographer_label b,t_photographer_level c ,t_photographer_spots d,t_label f,t_level g,t_spots h WHERE a.id=b.photographerId AND a.id = c.photographer AND a.id = d.photographerId AND f.id=b.labelId AND g.id=c.levelId AND h.id= d.spotsId AND a.status=0"));
		} catch (Exception e) {
			logger.error("获取所有启用的Photographer失败" + e);
		}
		return returnResult;
	}

}

预约控制器:

/**
 * 
 * 预约控制器
 */
@Controller
@Scope("prototype")
public class ScheduleController {

	private static final Logger logger = LoggerFactory.getLogger(ScheduleController.class);
	private ReturnResult returnResult = new ReturnResult();

	@Resource(name = "scheduleService")
	private IScheduleService scheduleService;

	/**
	 * 添加预约
	 * 
	 * @param schedule
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "addSchedule", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult addSchedule(TSchedule schedule, HttpSession session,String startdate,String enddate) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			schedule.setStart(DateFormater.stringToDate(startdate));
			schedule.setEnd(DateFormater.stringToDate(enddate));
			schedule.setCreatetime(new Date());
			TUser user = (TUser)session.getAttribute("user");
			schedule.setUserid(user.getId());
			if(scheduleService.insert(schedule)>0){
				returnResult.setStatus(ReturnCodeType.SUCCESS);
			}
		} catch (Exception e) {
			logger.error("新增schedule失败" + e);
		}
		return returnResult;

	}

	/**
	 * 修改schedule状态
	 * @param schedule
	 * @return
	 */
	@RequestMapping(value = "updateScheduleStatus", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult updateScheduleStatus(TSchedule schedule,HttpSession session) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			session.getAttribute("admin");
			scheduleService.updateBySQL("UPDATE t_schedule SET status=" + schedule.getStatus() + " WHERE id=" + schedule.getId());
			
			returnResult.setStatus(ReturnCodeType.SUCCESS);
		} catch (Exception e) {
			logger.error("更新schedule状态失败" + e);
		}
		return returnResult;
	}
	
	/**
	 * 设置摄影师无档期或有预约
	 * @param schedule
	 * @return
	 */
	@RequestMapping(value = "setSchedule", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult setSchedule(Integer photographerId,String createTimeRange,HttpSession session,String status) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			if(photographerId!=null&&StringUtils.isNotBlank(createTimeRange)){
				String start = createTimeRange.split(" - ")[0];
				String end = createTimeRange.split(" - ")[1];
				session.getAttribute("admin");
				TSchedule schedule = new TSchedule();
				schedule.setUserid(1);
				schedule.setCreatetime(new Date());
				schedule.setStatus(status);
				schedule.setStart(DateFormater.stringToDate("yyyy/MM/dd",start));
				schedule.setEnd(DateFormater.stringToDate("yyyy/MM/dd",end));
				schedule.setPhotographerid(photographerId);
				scheduleService.insert(schedule);
				returnResult.setStatus(ReturnCodeType.SUCCESS);
			}
			
		} catch (Exception e) {
			logger.error("更新schedule状态失败" + e);
		}
		return returnResult;
	}
	
	/**
	 * 根据id获取schedule
	 * @param schedule
	 * @return
	 */
	@RequestMapping(value = "getScheduleById", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getScheduleById(Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			returnResult.setStatus(ReturnCodeType.SUCCESS).setData(scheduleService.selectByPrimaryKey(id));
		} catch (Exception e) {
			logger.error("根据id获取schedule失败" + e);
		}
		return returnResult;
	}
	/**
	 * 根据摄影师id获取schedule
	 * @param schedule
	 * @return
	 */
	@RequestMapping(value = "getScheduleByPhotographerId", method = RequestMethod.GET)
	@ResponseBody
	public ScheduleVO getScheduleByPhotographerId(Integer photoer_id,String year,String month) {
		
		return scheduleService.getScheduleByPhotographerId( photoer_id, year, month);
	}
	
	/**
	 * 分页获取schedule
	 * @return
	 */
	@RequestMapping(value = "getScheduleListByPage", method = RequestMethod.POST)
	@ResponseBody
	public ReturnResult getScheduleListByPage(PageVO page,String photographerId,String start,String end) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			Map<String, Object> resultMap = new HashMap<String, Object>();
			StringBuffer sql = new StringBuffer("SELECT a.createTime,a.`status`,a.id,a.`start`,a.`end`,b.`name`,b.tel,c.`name` AS photographer FROM t_schedule a, t_user b ,t_photographer c WHERE a.userId = b.id AND a.photographerId =c.id");
			if(StringUtils.isNotBlank(photographerId)){
				sql.append(" AND a.photographerId="+photographerId);
			}
			if(StringUtils.isNotBlank(start)&&StringUtils.isNotBlank(end)){
				sql.append(" AND a.`start` BETWEEN '"+start+"' AND '"+end+"' OR a.`end` BETWEEN '"+start+"' AND '"+end+"'");
			}
			sql.append(" GROUP BY a.id ORDER BY a.createTime DESC");
			List<Map<String, Object>> results = scheduleService.selectPageBySQL(sql.toString(), page.getPage() - 1,
					page.getRows());
			if (!results.isEmpty() && results != null) {
				int total = scheduleService.selectCount(new TSchedule());
				int rows = page.getRows();
				rows = rows == 0 ? 10 : rows;
				resultMap.put("total", (total % rows != 0 ? (total / rows + 1) : (total / rows)));
				resultMap.put("page", page.getPage());
				resultMap.put("records", total);
				resultMap.put("rows", results);
				returnResult.setStatus(ReturnCodeType.SUCCESS).setData(resultMap);
			}
		}catch (Exception e) {
			logger.error("分页获取schedule失败" + e);
		}
		return returnResult;
	}
	
	/**
	 * 根据用户获取schedule
	 * @param schedule
	 * @return
	 */
	@RequestMapping(value = "getSchedule", method = RequestMethod.GET)
	@ResponseBody
	public ReturnResult getSchedule(HttpSession session) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		TUser user = (TUser) session.getAttribute("user");
		return returnResult.setStatus(ReturnCodeType.SUCCESS).setData(scheduleService.selectBySQL("SELECT DATE_FORMAT(a.`start`,'%Y-%m-%d') AS start,DATE_FORMAT(a.`end`,'%Y-%m-%d') AS end,b.name,a.`status`,a.id,a.photographerId FROM t_schedule a,t_photographer b WHERE a.photographerId = b.id AND a.userId="+user.getId()));
	}
	/**
	 *删除
	 * @param schedule
	 * @return
	 */
	@RequestMapping(value = "deleteSchedule", method = RequestMethod.GET)
	@ResponseBody
	public ReturnResult deleteSchedule(HttpSession session,Integer id) {
		returnResult.setStatus(ReturnCodeType.FAILURE);
		try {
			 session.getAttribute("user");
			return returnResult.setStatus(ReturnCodeType.SUCCESS).setData(scheduleService.deleteByPrimaryKey(id));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return returnResult;
	}
}

源码获取:博客首页 "资源" 里下载!

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

OldWinePot

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值