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

news/2024/5/18 21:42:54 标签: java, mysql, jdbc, ajax, html
htmledit_views">

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

一、项目简述

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

二、项目运行 

环境配置: Jdk1.8 + Tomcat8.5 + html" title=mysql>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;
	}
}

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


http://www.niftyadmin.cn/n/1554532.html

相关文章

java里的泛型_Java中的泛型

1.什么是泛型&#xff1f;举例说明答&#xff1a;1).泛型是Java SE 1.5的新特性&#xff0c;泛型的本质是参数化类型&#xff0c;也就是说所操作的数据类型被指定为一个参数。2).这种参数类型可以用在类、接口和方法的创建中&#xff0c;分别称为泛型类、泛型接口、泛型方法。3…

Java项目:在线蛋糕商城系统(java+jsp+jdbc+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 主页显示热销商品&#xff1b;所有蛋糕商品展示&#xff0c;可进行商品搜 索&#xff1b;点击商品进入商品详情页&#xff0c;具有立即购买和加入购物 车功能&#xff0c;可…

tomcat连接mysql配置文件_tomcat中主配置文件连接数据库

1》tomcat中&#xff0c;主目录所在位置在/opt/apache-tomcat-6.0.32/webapps/ROOT/下面找到/opt/apache-tomcat-6.0.32/webapps/ROOT/WEB-INF/classes这个目录。下面有连接数据库驱动的配置文件jdbc.properties这个例子是连接RAC的库用于实例级别的负载均衡system.idCDS001#\u…

Java项目:医院门诊收费管理系统(java+html+jdbc+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a;登录&#xff0c;门诊划价&#xff0c;收费&#xff0c;报表&#xff0c;药品管理等等功能。 二、项目运行 运行环境&#xff1a; Jdk1.8 Tomcats . 5 mysql Eclispe (…

Java项目:校园宿舍管理系统(java+jsp+javaweb+mysql+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a;宿舍管理员&#xff0c;最高管理员&#xff0c;学生三个身份&#xff0c;包括学 生管理&#xff0c;宿舍管理员管理&#xff0c;考勤管理&#xff0c;宿舍楼管理&#xff0c;…

java 清华 pdf_清华毕业大佬教你:Java 将 Word 文档转换为 PDF 的完美工具

今天跟大家分享Java 将 Word 文档转换为 PDF 的完美工具的知识。1 Java 将 Word 文档转换为 PDF 的完美工具在日常工作中&#xff0c;PDF格式良好的视觉阅读性和稳定性使其使用越来越广泛。因此我们常会遇到需要将成型的Word文档转换为PDF格式的情况。本文就将通过使用Java程序…

Java项目:在线购书商城系统(java+jsp+mysql+servlert+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a;一个基于JavaWeb的网上书店的设计与实现&#xff0c;归纳 出了几个模块&#xff0c;首先是登录注册模块&#xff0c;图书查找模块&#xff0c;购 物车模块&#xff0c;订单模…

Java项目:网上花店商城系统(java+jsp+servlert+mysql+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 一套完整的网上花店商场系统&#xff0c;系统支持前台会员的注册 登陆系统留言&#xff0c;花朵的品种选择&#xff0c;详情浏览&#xff0c;加入购物 车&#xff0c;购买花…