package com.nationalelectric.greenH5; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.http.Consts; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.jysoft.unipush.AliasManage; import com.jysoft.weChat.service.WechatService; import com.jysoft.weChat.vo.ContentVo; import com.nationalelectirc.Constant.Constant; import com.nationalelectirc.utils.RestResult; import com.nationalelectric.greenH5.DTO.GreenHaircutRemainDTO; import com.nationalelectric.greenH5.bizc.IGreenApplyBizc; import com.nationalelectric.greenH5.bizc.IGreenApplyListBizc; import com.nationalelectric.greenH5.bizc.IGreenHaircutInfoBizc; import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc; import com.nationalelectric.greenH5.po.GreenApply; import com.nationalelectric.greenH5.po.GreenApplyList; import com.nationalelectric.greenH5.po.GreenHaircutBalance; import com.nationalelectric.greenH5.po.GreenHaircutBalanceDetail; import com.nationalelectric.greenH5.po.GreenHaircutInfo; import com.nationalelectric.greenH5.po.GreenHaircutRemain; import com.nationalelectric.greenH5.po.GreenHaircutTotal; import com.nationalelectric.greenH5.po.GreenUserInfo; import com.nationalelectric.greenH5.utils.DateUtil; import com.sgcc.uap.persistence.IHibernateDao; import com.sgcc.uap.service.validator.ServiceValidatorBaseException; import com.sgcc.uap.service.validator.ServiceValidatorUtil; import net.sf.json.JSONArray; /** * 概述
*

* 功能
* * @author dell */ @Controller @RequestMapping("/greenHaircutInfo") public class GreenHaircutInfoController extends GreenBaseController { /** * 理发预约service */ @Resource private IGreenHaircutInfoBizc greenhaircutinfoBizc; /** * 我的申请service */ @Resource private IGreenApplyListBizc greenApplyListBizc; @Resource private IGreenApplyBizc greenApplyBizc; /** * HibernateDao逻辑构件 */ @Autowired IHibernateDao hibernateDao; /** * 字典表controller */ @Resource private GreenDictionaryInfoController greenDictionaryInfoController; @Resource private IGreenOperateLogBizc greenOperateLogBizc; @Resource private WechatService wService; @Resource private AliasManageController aliasManageController; /** * 理发预约flag */ private static final String HAIRCUT_FLAG_1 = "1"; // 改约 private static final String HAIRCUT_FLAG_2 = "2"; // 新增 /** * 获取当前用户在指定日期已经预约的预约的时间段 * * @param userId * @param applyDate * @return */ @SuppressWarnings("unchecked") public List> getApplyDateByUser(String userId, String applyDate) { // 记录当前用户在指定日期预约的时间段 List timeList = new ArrayList(); // 查询当前用户在指定日期是否有理发预约记录 String applyTimeSql = " SELECT DISTINCT hi.apply_time_id AS apply_time_id, hi.barber_id " + " FROM GREEN_APPLY al" + " INNER JOIN GREEN_HAIRCUT_INFO hi" + " ON al.detail_id = hi.id" + " WHERE al.status = '8'" //+" AND hi.user_id = ?" + " AND hi.apply_date = ? AND al.apply_type='06' "; // 执行sql List> applyTimeList = hibernateDao.queryForListWithSql(applyTimeSql, new Object[] { applyDate });//userId, // 返回结果 return applyTimeList; } /** * 根据理发店所在地和预约日期查询理发师该日所有时间段的可预约的余额(员工查看的页面) * * @param userId * @param applyDate * @param Barbershop * @param flag(flag值为1则添加已约状态,值为2则不添加已约状态) * @return */ @SuppressWarnings("unchecked") public List> getHaircutRemain(String userId, String applyDate, String flag,String barbershop) { // 获取当前用户在指定日期预约的时间段 List> applyTimeList = getApplyDateByUser(userId, applyDate); String remainByDateSql = " SELECT hr.barber_id as \"barber_id\",bi.barber_name as \"barber_name\"," + " hr.haircut_time_id as \"haircut_time_id\",htm.haircut_time as \"haircut_time\",hr.haircut_remain as \"remain_count\" " + " FROM GREEN_HAIRCUT_REMAIN hr" + " INNER JOIN GREEN_BARBER_INFO bi" + " ON hr.barber_id = bi.id" + " INNER JOIN GREEN_HAIRCUT_TIME_MANAGE htm" + " ON hr.haircut_time_id = htm.id" + " WHERE 1=1 " + " AND hr.barbershop = ? " + " AND hr.haircut_date = ? and bi.barber_status = 0 and bi.is_deleted = 'N' "; List> remainByDateList = hibernateDao.queryForListWithSql(remainByDateSql, new Object[] { barbershop,applyDate }); groupHaircutByBaberId(remainByDateList); // 遍历查询的数据,将每个理发师的时间段余额数据处理成json数组,加到集合中 for (Map map : remainByDateList) { JSONArray json = JSONArray.fromObject(map.get("remain")); // 循环处理将当前用户已预约的时间段状态改为已约(状态值为2) for (int i = 0; i < json.size(); i++) { // 判断当前用户该时间段是否有约 String id = json.getJSONObject(i).get("haircut_time_id").toString(); String bId = map.get("barber_id").toString(); json.getJSONObject(i).put("status", "1"); // 未约 // for (Map obj : applyTimeList) { // String timeId = obj.get("apply_time_id").toString(); // String barberId = obj.get("barber_id").toString(); // if ( id.equals(timeId)) {//barberId.equals(bId) && // json.getJSONObject(i).put("status", "2"); // 已约 // } // } } // 移除不需要的字段 map.remove("remain"); // 将处理好的数据加入到集合中 map.put("haircut_remain", json); } // 返回信息 return remainByDateList; } /** * 根据理发店所在地和预约日期查询理发师、理发类型、理发师该日所有时间段的可预约的余额(员工查看的页面) * * @param userId * @param applyDate * @param Barbershop * @param flag(flag值为1则添加已约状态,值为2则不添加已约状态) * @return */ public List> getHaircutBasicInfo(String userId, String applyDate, String Barbershop, String flag) { // 返回结果map Map resultMap = new HashMap(); // 返回结果list List> resultList = new ArrayList>(); // 查询所有理发类型 //List> dictionaryList = greenDictionaryInfoController.getDictionaryInfo("harircutType"); // 将理发类型放入返回结果中 //resultMap.put("type", dictionaryList); // 根据预约日期查询理发师该日所有时间段的可预约的余额 List> remainByDateList = getHaircutRemain(userId, applyDate, flag,Barbershop); // 将理发时间段余额信息放入返回结果中 resultMap.put("remain", remainByDateList); // 封装返回结果 resultList.add(resultMap); // 返回结果 return resultList; } /** * 根据理发店所在地和预约日期查询理发师、理发类型、理发师该日所有时间段的可预约的余额(员工查看的页面) * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/getHaircutBasicInfo", method = RequestMethod.POST) public @ResponseBody RestResult getHaircutBasicInfo(@RequestBody Object requestBody) { GreenHaircutRemainDTO greenHaircutRemainDTO = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { // 根据用户id获取用户信息 GreenUserInfo userInfo = getUserInfo(greenHaircutRemainDTO.getUserId()); // 判断是否是合法用户 // if (userInfo == null) { // return new RestResult(Constant.FAILED, "非法用户"); // } String hairCutDate = greenHaircutRemainDTO.getHaircutDate(); // 返回结果list List> resultList = getHaircutBasicInfo(greenHaircutRemainDTO.getUserId(), greenHaircutRemainDTO.getHaircutDate(), greenHaircutRemainDTO.getBarbershop(), HAIRCUT_FLAG_1); // 返回结果 return new RestResult(Constant.SUCCESS, "", resultList); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 初始化理发预约时加载理发余额等数据(员工查看的页面) * * @param greenHaircutRemainDTO * @return */ @SuppressWarnings("unchecked") @RequestMapping(value = "/initHaircut", method = RequestMethod.POST) public @ResponseBody RestResult initHaircut(String userId) { try { // 根据用户id获取用户信息 GreenUserInfo userInfo = getUserInfo(userId); // 判断是否是合法用户 if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } // 获取当前日期 String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); // 返回结果list List> resultList = getHaircutBasicInfo(userId, nowDate, userInfo.getOwnerLocation(), HAIRCUT_FLAG_1); // 获取的余额信息是否为空 if (resultList.size() > 0) { // 查询评论 String commentSql = "SELECT * FROM GREEN_HAIRCUT_COMMENT hc WHERE hc.TYPE = '1' ORDER BY hc.gmt_created DESC LIMIT 0,10"; List> commentList = hibernateDao.queryForListWithSql(commentSql); // 查询个人信息,包括个人姓名、电话 String tmp = " SELECT mobile, department_id,real_name FROM green_user_info WHERE id = ? "; Map userMap = hibernateDao.queryForMapWithSql(tmp, new Object[] { userId }); // Map userMap = list.get(0); Object mobile = userMap.get("mobile"); Object realName = userMap.get("real_name"); Object deptIdObj = userMap.get("department_id"); // 查询部门信息,并直接拼接返回 String deptSql = "SELECT gd.id,gd.name FROM GREEN_DEPARTMENT gd WHERE id = ?"; List> deptAllList = hibernateDao.queryForListWithSql(deptSql, new Object[] { deptIdObj }); if (deptIdObj != null) { String deptId = deptIdObj.toString(); for (Map dept : deptAllList) { String id = dept.get("id").toString(); if (deptId.equals(id)) { dept.put("select", 1); } else { dept.put("select", 0); } } } for (Map map : resultList) { map.put("mobile", mobile); map.put("comment", commentList); map.put("department", deptAllList); map.put("realName", realName); } } // 返回结果 return new RestResult(Constant.SUCCESS, "", resultList); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 根据预约日期查询理发师该日所有时间段的可预约的余额(理发店查看的页面) * * @param applyDate * @param Barbershop * @return */ @SuppressWarnings("unchecked") public List> getBasicInfoForBarber(String applyDate, String Barbershop) { // 返回结果map Map resultMap = new HashMap(); // 返回结果list List> resultList = new ArrayList>(); // 根据理发店所在地和预约日期查询理发师该日所有时间段的可预约的余额 String remainByDateSql = "SELECT htm.haircut_time_id AS \"apply_time_id\", m.haircut_time AS \"haircut_time\", hi.apply_person_name AS \"apply_person_name\", hi.apply_person_tel AS \"apply_person_tel\", hi.user_id AS \"user_id\"," + " hi.barber_id AS \"barber_id\",hi.id AS \"id\"," + " (case when hi.countData IS NULL then 0 else hi.countData end) as \"countData\"" + " FROM green_haircut_total htm" + " LEFT JOIN (" + " SELECT hi.apply_time_id, COUNT(*) AS countData, hi.apply_person_name, hi.apply_person_tel, hi.user_id, hi.barber_id,hi.id" + " FROM green_apply al INNER JOIN green_haircut_info hi ON al.detail_id = hi.id AND al.apply_type = '06' AND hi.is_deleted = 'N' and hi.int_status=0 WHERE al.del_flag = '0' AND al. STATUS <> '9' AND hi.barbershop_area = 1 " + " AND hi.apply_date = ? GROUP BY hi.apply_time_id, hi.apply_person_name, hi.apply_person_tel, hi.user_id,hi.barber_id,hi.id) hi ON htm.haircut_time_id = hi.apply_time_id LEFT JOIN green_haircut_time_manage m" + " ON htm.haircut_time_id = m.id WHERE htm.is_deleted = 'N'" + " AND htm.barbershop = ? ORDER BY htm.id"; // 执行sql List> remainByDateList = hibernateDao.queryForListWithSql(remainByDateSql, new Object[] {applyDate ,Barbershop}); // 将理发时间段余额信息放入返回结果中 resultMap.put("remain", remainByDateList); // 根据理发类型统计理发预约数 // String countHaircutSql = " SELECT di.data_value AS type,IF(hi.countData IS NULL,0,hi.countData) countData" // + " FROM GREEN_DICTIONARY_INFO di LEFT JOIN (SELECT hi.haircut_type,COUNT(*) AS countData" // + " FROM GREEN_APPLY al INNER JOIN GREEN_HAIRCUT_INFO hi ON al.detail_id = hi.id AND al.apply_type = '06'" // + " WHERE al.status <> '9' and hi.apply_date = ? AND hi.barbershop_area = '1' " // + " GROUP BY hi.haircut_type) hi" // + " ON di.data_code = hi.haircut_type AND di.data_type = 'harircutType'" // + " WHERE di.data_type = 'harircutType'"; // // 执行sql // List> countHaircutList = hibernateDao.queryForListWithSql(countHaircutSql, // new Object[] { applyDate }); // resultMap.put("kind", countHaircutList); // 封装返回结果 resultList.add(resultMap); // 返回结果 return resultList; } /** * 根据预约日期查询理发师该日所有时间段的可预约的余额(理发店查看的页面) * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/getBasicInfoForBarber", method = RequestMethod.POST) public @ResponseBody RestResult getBasicInfoForBarber(@RequestBody Object requestBody) { GreenHaircutRemainDTO greenHaircutRemainDTO = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { // 根据用户id获取用户信息 GreenUserInfo userInfo = getUserInfo(greenHaircutRemainDTO.getUserId()); // 判断是否是合法用户 if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } String hairCutDate = greenHaircutRemainDTO.getApplyDate(); // 返回结果list List> resultList = getBasicInfoForBarber(greenHaircutRemainDTO.getApplyDate(), userInfo.getOwnerLocation()); // 返回结果 return new RestResult(Constant.SUCCESS, "", resultList); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 初始化理发预约时加载理发余额等数据(理发店查看的页面) * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/initHaircutForBarber", method = RequestMethod.POST) public @ResponseBody RestResult initHaircutForBarber(@RequestBody Object requestBody) { GreenHaircutRemainDTO greenHaircutRemainDTO = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { // 根据用户id获取用户信息 GreenUserInfo userInfo = getUserInfo(greenHaircutRemainDTO.getUserId()); // 判断是否是合法用户 if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } // 获取当前日期 String nowDate = greenHaircutRemainDTO.getApplyDate();//new SimpleDateFormat("yyyy-MM-dd").format(new Date()); String barbershop = greenHaircutRemainDTO.getBarbershop(); // 返回结果list List> resultList = getBasicInfoForBarber(nowDate, barbershop); // 返回结果 return new RestResult(Constant.SUCCESS, "", resultList); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 根据id查询理发预约详情 * * @param id * @return */ @SuppressWarnings("unchecked") public List getHaircutInfo(String id) { String applyInfoByIdSql = " SELECT hi.*,gd.name AS barbershop_area_name,di1.data_value AS haircut_type_name,al.first_status,di2.data_value AS first_status_value,al.first_approve_time" + " FROM GREEN_HAIRCUT_INFO hi" + " INNER JOIN GREEN_APPLY_LIST al ON hi.id = al.detail_id" + " INNER JOIN GREEN_DEPARTMENT gd ON hi.barbershop_area = gd.id" + " INNER JOIN GREEN_DICTIONARY_INFO di1 ON hi.haircut_type = di1.data_code AND di1.data_type = 'harircutType'" + " INNER JOIN GREEN_DICTIONARY_INFO di2 ON al.first_status = di2.data_code AND di2.data_type = 'approveStatus'" + " WHERE hi.id = ? and al.apply_Type = '06' "; return hibernateDao.queryForListWithSql(applyInfoByIdSql, new Object[] { id }); } /** * 根据id查询理发预约详情以及理发师预约余额 * * @param greenHaircutInfo * @return */ @RequestMapping(value = "/getHaircutInfoAndRemain", method = RequestMethod.POST) public @ResponseBody RestResult getHaircutInfoAndRemain(@RequestBody Object requestBody) { GreenHaircutInfo greenHaircutInfo = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { String userId = greenHaircutInfo.getUserId(); GreenUserInfo info = getUserInfo(userId); if (info == null) { return new RestResult(Constant.FAILED, "非法用户"); } // 返回结果list List> resultList = new ArrayList>(); // 返回结果map Map resultMap = new HashMap(); // 根据id查询理发详情 GreenHaircutInfo data = greenhaircutinfoBizc.get(greenHaircutInfo.getId()); // 将理发详情数据加入到返回结果集中 resultMap.put("data", data); // 根据理发店所在地和预约日期查询理发师该日所有时间段的可预约的余额 List> remainByDateList = getHaircutRemain(greenHaircutInfo.getUserId(), data.getApplyDate(), HAIRCUT_FLAG_2,greenHaircutInfo.getBarberId()+""); // 将理发师余额信息加入到返回结果集中 resultMap.put("remain", remainByDateList); // 封装返回结果 resultList.add(resultMap); // 返回结果 return new RestResult(Constant.SUCCESS, "", resultList); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败!"); } } /** * 提交和修改理发预约信息 * * @param greenHaircutInfo * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Transactional(rollbackFor = Exception.class) @RequestMapping(value = "/saveHaircutInfo", method = RequestMethod.POST) public @ResponseBody RestResult saveHaircutInfo(@RequestBody Object requestBody) { GreenHaircutInfo greenHaircutInfo = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { String userId = greenHaircutInfo.getUserId(); GreenUserInfo info = getUserInfo(userId); if (info == null) { throw new MyException("非法用户"); } greenHaircutInfo.setBarbershopArea("1"); // 校验 //ServiceValidatorUtil.validatorJavaBean(greenHaircutInfo); // 格式化日期 SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String nowDate = fmt.format(new Date()); String applyDate = greenHaircutInfo.getApplyDate(); // 查询提交的理发预约时间段是否有余额 String sql = " SELECT * FROM GREEN_HAIRCUT_REMAIN hr" + " WHERE hr.barber_id = ?" + " AND hr.haircut_date = ? AND hr.haircut_time_id = ?"; // 执行sql List queryList = hibernateDao .queryForListWithSql(sql, new Object[] { greenHaircutInfo.getBarberId(), greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId() }, new BeanPropertyRowMapper(GreenHaircutRemain.class)); // 判断查询结果是否为空 if (queryList.size() <= 0) { throw new MyException("您选择的理发师在该时间段繁忙,请电话联系理发室!"); } // 获取理发余额信息 GreenHaircutRemain greenHaircutRemain = queryList.get(0); // 查询指定用户在该时间段是否有预约 String haircutByuserSql = " SELECT * FROM GREEN_HAIRCUT_INFO hi WHERE hi.is_deleted = 'N' AND hi.barbershop_area = '1' AND hi.barber_id = ?" + " AND hi.apply_date = ? AND hi.apply_time_id = ? AND hi.user_id = ? and int_status=0"; // 执行sql List haircutByuserList = hibernateDao.queryForListWithSql(haircutByuserSql, new Object[] { greenHaircutInfo.getBarberId(), greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId(), greenHaircutInfo.getUserId() }, new BeanPropertyRowMapper(GreenHaircutInfo.class)); if (haircutByuserList.size() > 0) { // 新增理发预约 if (greenHaircutInfo.getId() == null) { throw new MyException("该时间段已经预约,请重新选择!"); } else {// 改约 // 判断当前改约和查询到的理发预约是否是同一条数据,如果是预约时间段相同则允许改约,如果不是则提示该时间段已经预约 if (!greenHaircutInfo.getId().equals(haircutByuserList.get(0).getId())) { throw new MyException("该时间段已经预约,请重新选择!"); } } } // 判断提交的理发预约时间段是否有余额 if (greenHaircutInfo.getId() != null) { if (haircutByuserList.size() <= 0 && greenHaircutRemain.getHaircutRemain() <= 0) { throw new MyException("该时间段已无余额,请重新选择!"); } } else { if (greenHaircutRemain.getHaircutRemain() <= 0) { throw new MyException("该时间段已无余额,请重新选择!"); } } // 获取预约时间段 String applyTime = greenHaircutInfo.getApplyTime().substring(0, 5); // 拼接获取预约日期 String applyTimeStr = greenHaircutInfo.getApplyDate() + " " + applyTime; // 判断当前时间是否大于预约时间,如果大于则不能预约 if (applyTimeStr.compareTo(nowDate) < 0) { throw new MyException("该时间段已不能预约,请重新选择!"); } // 判断是新增还是更新操作 if (greenHaircutInfo.getId() == null) { // 保存理发预约信息 save(greenHaircutInfo, HAIRCUT_FLAG_1, null); // 余额减一 String deleteRemainSql = " UPDATE GREEN_HAIRCUT_REMAIN hr SET hr.haircut_remain = (hr.haircut_remain-1) WHERE hr.barber_id = ?" + " AND hr.haircut_date = ? AND hr.haircut_time_id = ? AND hr.haircut_remain = ? "; int result = hibernateDao.executeSqlUpdate(deleteRemainSql, new Object[] { greenHaircutInfo.getBarberId(), greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId(), greenHaircutRemain.getHaircutRemain() }); // 更新出错重试 机制 if (result == 0) { boolean excute = false; // 如果更新失败 循环10次进行更新 for (int i = 0; i < 10; i++) { // 执行sql List repeatQuery = hibernateDao.queryForListWithSql(sql, new Object[] { greenHaircutInfo.getBarbershopArea(), greenHaircutInfo.getBarberId(), greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId() }, new BeanPropertyRowMapper(GreenHaircutRemain.class)); GreenHaircutRemain remain = repeatQuery.get(0); if (remain.getHaircutRemain().longValue() == 0) { throw new MyException("该时间段已不能预约,请重新选择!"); } int repeatResult = hibernateDao.executeSqlUpdate(deleteRemainSql, new Object[] { greenHaircutInfo.getBarbershopArea(), greenHaircutInfo.getBarberId(), greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId(), remain.getHaircutRemain() }); if (repeatResult != 0) { excute = true; break; } } if (!excute) { // 执行10次都没成功 按原来逻辑抛出异常 throw new MyException("该时间段已不能预约,请重新选择!"); } } //预约成功后给本人发送预约成功信息 String title="理发预约"; String text = "您好,您已成功预约理发,请安排好您的时间。"; String url = "/pages/haircut/haircut?currentTabIndex=1"; aliasManageController.pushToSingle(userId, title, text, url); //给理发师发送理发预约受理信息 //字典表查询理发预约受理权限 List> roleList = greenDictionaryInfoController.getDictionaryInfo("haircutRole"); String haircutRole = (String) roleList.get(0).get("data_value"); //查询所有有这个权限的人员 String getUserSql = "SELECT u.id,u.ISC_ID FROM green_user_info u " + " LEFT JOIN green_user_role_rel r ON u.id = r.user_id " + " LEFT JOIN green_role_permission p ON p.role_id = r.role_id " + " WHERE p.permission_id = ?"; List> userList = hibernateDao.queryForListWithSql(getUserSql, new Object[]{haircutRole}); title = "理发预约受理"; text = "您有新的理发预约,请注意查看。"; url = "/pages/haircut-order/haircut-order"; aliasManageController.pushToSingleBatch(userList, title, text, url); } else { update(greenHaircutInfo); //预约修改成功后给本人发送预约成功信息 String title="理发预约修改"; String text = "您已成功修改预约理发,请安排好您的时间。"; String url = "/pages/haircut/haircut?currentTabIndex=1"; aliasManageController.pushToSingle(userId, title, text, url); //给理发师发送理发预约受理信息 //字典表查询理发预约受理权限 List> roleList = greenDictionaryInfoController.getDictionaryInfo("haircutRole"); String haircutRole = (String) roleList.get(0).get("data_value"); //查询所有有这个权限的人员 String getUserSql = "SELECT u.id,u.ISC_ID FROM green_user_info u " + " LEFT JOIN green_user_role_rel r ON u.id = r.user_id " + " LEFT JOIN green_role_permission p ON p.role_id = r.role_id " + " WHERE p.permission_id = ?"; List> userList = hibernateDao.queryForListWithSql(getUserSql, new Object[]{haircutRole}); title = "理发预约受理修改"; text = "您好,用户已修改理发预约,请注意查看最新的预约情况。"; url = "/pages/haircut-order/haircut-order"; aliasManageController.pushToSingleBatch(userList, title, text, url); } return new RestResult(Constant.SUCCESS, "申请成功"); } catch (MyException e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return new RestResult(Constant.FAILED, e.getMessage()); } catch (ServiceValidatorBaseException e) { TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return new RestResult(Constant.FAILED, e.getMessage()); } catch (Exception e) { e.printStackTrace(); TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return new RestResult(Constant.FAILED, "申请失败"); } } /** * 保存理发预约信息 * * @param greenHaircutInfo * @param flag(flag为1新增,flag为2改约) * @param userId(改约时预约人userId) */ public void save(GreenHaircutInfo greenHaircutInfo, String flag, String beforeUserId) { // 获取用户userId String userId = greenHaircutInfo.getUserId(); // 获取理发类型名称 List> typeNameList = greenDictionaryInfoController.getDictionaryInfo("harircutType", greenHaircutInfo.getHaircutType()); String typeName = ""; if (typeNameList.size() > 0) { typeName = typeNameList.get(0).get("data_value"); } // 判断是改约还是新增 if (HAIRCUT_FLAG_1.equals(flag)) { greenHaircutInfo.setUserId(userId); } else if (HAIRCUT_FLAG_2.equals(flag)) { greenHaircutInfo.setId(null); greenHaircutInfo.setUserId(beforeUserId); } greenHaircutInfo.setCreator(userId); greenHaircutInfo.setModifier(userId); greenHaircutInfo.setGmtCreated(new Date()); greenHaircutInfo.setGmtModified(new Date()); greenHaircutInfo.setIsDeleted("N"); // 添加理发预约信息到理发预约信息表 greenhaircutinfoBizc.add(greenHaircutInfo); // 添加理发预约信息到申请信息list表 // GreenApplyList list = new GreenApplyList(); GreenApply greenApply = new GreenApply(); // 判断是改约还是新增 if (HAIRCUT_FLAG_1.equals(flag)) { // 申请人id // list.setUserId(userId); greenApply.setUserId(userId); } else if (HAIRCUT_FLAG_2.equals(flag)) { // 申请人id // list.setUserId(beforeUserId); greenApply.setUserId(beforeUserId); } // 申请事项详情ID greenApply.setId(new Date().getTime()); greenApply.setDetailId(greenHaircutInfo.getId()); greenApply.setApplyType(Constant.HAIRCUT_APPLY); greenApply.setApplyTypeName(Constant.FAULT_REPAIR_APPLY(Constant.HAIRCUT_APPLY)); greenApply.setDelFlag("0"); greenApply.setStatus(Constant.APPLY_SUCCESS); greenApply.setApplyTime(new Date()); greenApply.setNeedVerifyLevel("0"); // 需要审批总等级 0 不需审批 greenApply.setCurVerifyLevel("0"); // 当前审批进度 0 不需审批 greenApply.setRefuseLevel("0"); // 拒绝等级 0 不需审批 greenApply.setInfo1(greenHaircutInfo.getApplyDate() + " " + greenHaircutInfo.getApplyTime()); greenApply.setInfo2(typeName); greenApply.setCommentStatus("0"); // 未评价 hibernateDao.saveObject(greenApply); } /** * 理发改约 * * @param greenHaircutInfo * @return */ @SuppressWarnings("unchecked") public void update(GreenHaircutInfo greenHaircutInfo) { /* * 将该数据状态改为已取消 */ // 根据理发预约详情id查询预约list表信息 try { // String sql = "SELECT * FROM GREEN_APPLY_LIST WHERE detail_id = ? // AND apply_type = '06'"; // List list = hibernateDao.queryForListWithSql(sql, // new Object[] { greenHaircutInfo.getId() }, // new BeanPropertyRowMapper(GreenApplyList.class)); String sql = "SELECT * FROM GREEN_APPLY WHERE detail_id = ? AND apply_type = '06'"; List list = hibernateDao.queryForListWithSql(sql, new Object[] { greenHaircutInfo.getId() }, new BeanPropertyRowMapper(GreenApply.class)); if (list.size() <= 0) { throw new MyException(); } // 获取预约list表信息 GreenApply apply = list.get(0); if (Constant.HAIRCUT_DING == apply.getStatus()) { throw new MyException("理发已经开始,不可改约"); } // 判断预约状态是否为已完成 if (Constant.HAIRCUT_FINISH == apply.getStatus()) { throw new MyException("理发已经结束,不可改约"); } // 判断预约状态是否为已取消 if (Constant.APPROVAL_CANCEL == apply.getStatus()) { throw new MyException("理发已经取消,不可改约"); } // GreenApplyList greenApplyList = list.get(0); // 判断预约状态是否为进行中 if (Constant.HAIRCUT_DING == apply.getStatus()) { throw new MyException("理发已经开始,不可改约"); } // 判断预约状态是否为已完成 if (Constant.HAIRCUT_FINISH == apply.getStatus()) { throw new MyException("理发已经结束,不可改约"); } // 判断预约状态是否为已取消 if (Constant.APPROVAL_CANCEL == apply.getStatus()) { throw new MyException("理发已经取消,不可改约"); } apply.setStatus(Constant.APPROVAL_CANCEL); apply.setUpdTime(new Date()); // 一级审批状态 // greenApplyList.setFirstStatus(Constant.APPROVAL_CANCEL); // 修改者 // greenApplyList.setModifier(greenHaircutInfo.getUserId().toString()); // 修改时间 // greenApplyList.setGmtModified(new Date()); // 更新申请list表 // greenApplyListBizc.update(greenApplyList, // greenApplyList.getId()); greenApplyBizc.update(apply, apply.getId()); /* * 删除详情表原预约数据 */ // 根据id查询理发预约详情 GreenHaircutInfo updateGreenHaircutInfo = greenhaircutinfoBizc.get(greenHaircutInfo.getId()); // 修改者 updateGreenHaircutInfo.setModifier(greenHaircutInfo.getUserId().toString()); // 修改时间 updateGreenHaircutInfo.setGmtModified(new Date()); // 删除标识 updateGreenHaircutInfo.setIsDeleted("Y"); // 执行更新余额的操作 greenhaircutinfoBizc.update(updateGreenHaircutInfo, updateGreenHaircutInfo.getId()); /* * 将改约前的时间段余额加一 */ String deleteRemainSql = " UPDATE GREEN_HAIRCUT_REMAIN hr SET hr.haircut_remain = (hr.haircut_remain+1) WHERE hr.barbershop = ? AND hr.barber_id = ?" + " AND hr.haircut_date = ? AND hr.haircut_time_id = ?"; hibernateDao.executeSqlUpdate(deleteRemainSql, new Object[] { updateGreenHaircutInfo.getBarberId(), updateGreenHaircutInfo.getBarberId(), updateGreenHaircutInfo.getApplyDate(), updateGreenHaircutInfo.getApplyTimeId() }); /* * 新增一条理发预约信息 */ save(greenHaircutInfo, HAIRCUT_FLAG_2, updateGreenHaircutInfo.getUserId()); String deleteRemainSql2 = " UPDATE GREEN_HAIRCUT_REMAIN hr SET hr.haircut_remain = (hr.haircut_remain-1) WHERE hr.barber_id = ?" + " AND hr.haircut_date = ? AND hr.haircut_time_id = ? "; int result = hibernateDao.executeSqlUpdate(deleteRemainSql2, new Object[] { greenHaircutInfo.getBarberId(), greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId() }); addLog(Constant.HAIRCUT, Constant.CHANGE, Constant.OPERATE_SUCCESS, "理发改约", Constant.LOG_OPERATE,greenHaircutInfo.getUserId()); } catch (Exception e) { e.printStackTrace(); addLog(Constant.HAIRCUT, Constant.CHANGE, Constant.OPERATE_FAIL, "理发改约", Constant.LOG_ERROR, greenHaircutInfo.getUserId()); } } /** * 根据理发预约日期和时间段查询理发列表 * * @param haircutDate * @param haircutTime * @return */ @SuppressWarnings("unchecked") @RequestMapping(value = "/getHaircutList", method = RequestMethod.POST) public @ResponseBody RestResult getHaircutList(@RequestBody Object requestBody) { GreenHaircutInfo greenHaircutInfo = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { String userId = greenHaircutInfo.getUserId(); GreenUserInfo info = getUserInfo(userId); if (info == null) { return new RestResult(Constant.FAILED, "非法用户"); } String sql = " SELECT hi.*,di.data_value AS haircut_type_name,al.status FROM GREEN_APPLY al" + " INNER JOIN GREEN_HAIRCUT_INFO hi ON al.detail_id = hi.id AND al.apply_type = '06'" + " INNER JOIN GREEN_DICTIONARY_INFO di ON hi.haircut_type = di.data_code AND di.data_type = 'harircutType'" + " WHERE al.status <> '9' AND hi.barbershop_area = '1' " + " AND hi.apply_date = ? AND hi.apply_time_id = ?"; List> list = hibernateDao.queryForListWithSql(sql, new Object[] { greenHaircutInfo.getApplyDate(), greenHaircutInfo.getApplyTimeId() }); return new RestResult(Constant.SUCCESS, "", list); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败!"); } } /** * 根据理发预约日期和时间段查询理发列表 * * @param haircutDate * @param haircutTime * @return */ @SuppressWarnings("unchecked") @RequestMapping(value = "/getHaircutInfoById", method = RequestMethod.POST) public @ResponseBody RestResult getHaircutInfoById(@RequestBody GreenHaircutInfo greenHaircutInfo) { try { Long id = greenHaircutInfo.getId(); String sql = "select id as \"id\",barbershop_area as \"barbershop_area\",apply_date as \"apply_date\",apply_time as \"apply_time\"," + "apply_time_id as \"apply_time_id\",haircut_type as \"haircut_type\"," + "barber_id as \"barber_id\",barber_name as \"barber_name\",dept_id as \"dept_id\",dept_name as \"dept_name\",apply_person_name as \"apply_person_name\",apply_person_tel as \"apply_person_tel\"," + "user_id as \"user_id\",creator as \"creator\",modifier as \"modifier\",gmt_created as \"gmt_created\",gmt_modified as \"gmt_modified\",is_deleted as \"is_deleted\",int_status as \"int_status\"" + " from green_haircut_info where id = ? "; List> list = hibernateDao.queryForListWithSql(sql, new Object[] {id}); if(list.size()==0){ return new RestResult(Constant.FAILED, "查无该数据"); } return new RestResult(Constant.SUCCESS, "查询成功", list.get(0)); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败!"); } } /** * 向理发师余额表里插入当前日期向后推算三十天的信息 */ @SuppressWarnings({ "unchecked", "rawtypes" }) @RequestMapping(value = "/addHaircutRemain", method = RequestMethod.POST) @Transactional(rollbackFor = Exception.class) public @ResponseBody void addHaircutRemain() { try { // 记录当前日期到后三十天内的所有日期(含当前日期) List nowDateList = new ArrayList(); // 记录添加数据库里的数据集合 List dataList = new ArrayList(); // 记录添加数据库里的数据集合中的每一个对象 List dataObjList = new ArrayList(); // 插入sql // List> queryForListWithSql = // hibernateDao.queryForListWithSql("SELECT * FROM GREEN_SEQ WHERE // table_name = 'GREEN_HAIRCUT_REMAIN'"); // if (queryForListWithSql.isEmpty()) { // throw new Exception("返回异常"); // } // Long seqId = // Long.parseLong(String.valueOf(queryForListWithSql.get(0).get("max_id"))); String insertSql = "INSERT INTO GREEN_HAIRCUT_REMAIN(barbershop,barber_id,haircut_date,haircut_time_id,haircut_remain,remain_status,creator,modifier) VALUE (?,?,?,?,?,?,?,?)"; // 查询理发师余总额记录 String haircutTotalSql = " SELECT * FROM GREEN_HAIRCUT_TOTAL ht WHERE ht.is_deleted = 'N'" + " AND ht.total_status = '0' AND ht.barber_id = ?"; // 查询理发师余额表中的预约日期 String haircutDateSql = " SELECT bi.id AS barber_id,GROUP_CONCAT(DISTINCT hr.haircut_date ORDER BY hr.haircut_date) AS haircut_date" + " FROM GREEN_BARBER_INFO bi LEFT JOIN GREEN_HAIRCUT_REMAIN hr ON bi.id = hr.barber_id GROUP BY bi.id"; // 执行sql List haircutDateList = hibernateDao.queryForListWithSql(haircutDateSql, new BeanPropertyRowMapper(GreenHaircutRemain.class)); for (GreenHaircutRemain greenHaircutRemain : haircutDateList) { // 获取当前日期到后三十天内的所有日期(含当前日期) nowDateList = getNextThirtyDate(); // 获取理发师余额表中的预约日期 String haircutDateStr = greenHaircutRemain.getHaircutDate() == null ? "" : greenHaircutRemain.getHaircutDate(); // 判断从当前日期到向后推算三十天的日期中,理发余额表里缺少哪些日期 nowDateList.removeAll(Arrays.asList(haircutDateStr.split(","))); // 执行sql List haircutTotalList = hibernateDao.queryForListWithSql(haircutTotalSql, new Object[] { greenHaircutRemain.getBarberId() }, new BeanPropertyRowMapper(GreenHaircutTotal.class)); // 循环执行添加操作 for (String nowDateStr : nowDateList) { for (GreenHaircutTotal greenHaircutTotal : haircutTotalList) { // 手动填入主键 // dataObjList.add(seqId); // 理发店所在地 dataObjList.add(greenHaircutTotal.getBarbershop()); // 理发师 dataObjList.add(greenHaircutTotal.getBarberId()); // 理发日期 dataObjList.add(nowDateStr); // 理发时间段 dataObjList.add(greenHaircutTotal.getHaircutTimeId()); // 理发余额 dataObjList.add(greenHaircutTotal.getHaircutTotal()); // 当前状态 0 启用 1 禁用 dataObjList.add("0"); // 创建者 dataObjList.add("admin"); // 修改者 dataObjList.add("admin"); // 将数据对象添加到集合中 dataList.add(dataObjList.toArray()); // 初始化 dataObjList = new ArrayList(); // seqId++; } } } // 向余额表里批量插入数据 hibernateDao.batchUpdateWithSql(insertSql, dataList); // hibernateDao.updateWithSql("update GREEN_SEQ set max_id = ? WHERE // table_name = 'GREEN_HAIRCUT_REMAIN'",new Object[]{ seqId}); // 清除余额表里小于当前日期的数据 String deleteRemainSql = "DELETE FROM GREEN_HAIRCUT_REMAIN WHERE TIMESTAMPDIFF(SECOND,CONCAT(haircut_date),DATE_FORMAT(NOW(),'%Y-%m-%d'))>0"; // 执行sql hibernateDao.executeSqlUpdate(deleteRemainSql); } catch (Exception e) { e.printStackTrace(); // 设置手动回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } /** * 将预约时间小于当前时间的理发预约变为已完成状态 */ @SuppressWarnings({ "unchecked" }) @RequestMapping(value = "/updateHaircutStatus", method = RequestMethod.POST) @Transactional(rollbackFor = Exception.class) public @ResponseBody void updateHaircutStatus() { try { // 更新sql String updateRemainSql = "UPDATE GREEN_APPLY_LIST SET first_status = ?,gmt_modified = ? WHERE id = ?"; // 查询预约时间小于当前时间的理发预约 String sql = " SELECT al.id,CONCAT(hi.apply_date,' ',LEFT(hi.apply_time,5)) AS start_date," + " CONCAT(hi.apply_date,' ',RIGHT(hi.apply_time,5)) AS end_date" + " FROM GREEN_APPLY_LIST al" + " INNER JOIN GREEN_HAIRCUT_INFO hi ON al.detail_id = hi.id" + " WHERE al.apply_type = '06' AND al.first_status NOT IN('3','9')"; // 执行sql List> queryList = hibernateDao.queryForListWithSql(sql); // 修改预约状态 for (Map map : queryList) { // 理发预约开始时间 Date startDate = changeDate(map.get("start_date")); // 理发预约结束时间 Date endDate = changeDate(map.get("end_date")); // 如果时间格式转换有误则跳过该条数据 if (startDate == null || endDate == null) { continue; } else { // 当前时间 Date nowDate = new Date(); // 如果当前时间大于预约的开始时间小于预约结束时间将其状态变为进行中,如果当前时间大于结束时间将其状态变为已完成 if (nowDate.getTime() >= startDate.getTime() && nowDate.getTime() <= endDate.getTime()) { // 更新 hibernateDao.executeSqlUpdate(updateRemainSql, new Object[] { Constant.HAIRCUT_DING, nowDate, map.get("id") }); } else if (nowDate.getTime() >= endDate.getTime()) { // 更新 hibernateDao.executeSqlUpdate(updateRemainSql, new Object[] { Constant.HAIRCUT_FINISH, nowDate, map.get("id") }); } } } } catch (Exception e) { e.printStackTrace(); // 设置手动回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } } /** * 提醒 * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/remindForHairCut", method = RequestMethod.POST) public @ResponseBody RestResult remindForHairCut(@RequestBody GreenHaircutRemainDTO greenHaircutRemainDTO) { try { // 根据用户id获取用户信息 GreenUserInfo userInfo = getUserInfo(greenHaircutRemainDTO.getUserId()); // 判断是否是合法用户 if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm"); String ymd = sdf.format(new Date()).split(" ")[0]; String barbershop = greenHaircutRemainDTO.getBarbershop(); // 返回结果list List> resultList = (List>)( getBasicInfoForBarber(ymd,barbershop).get(0).get("remain")); for(int i=0;inew Date().getTime()&&countData>0){ GreenUserInfo remindUser = getUserInfo((String) resultList.get(i).get("user_id")); String userId = remindUser.getId(); String title = "理发预约提醒"; String text = "您好,您预约的理发即将开始("+startTime+"),请安排好您的时间。"; String url = "/pages/haircut/haircut?currentTabIndex=1"; aliasManageController.pushToSingle(userId,title , text, url); // String openIdString = remindUser.getWxOpenId();//"ovRg7w6EjCMt-awFx7TLKz9lAj4U";// // Map dataMap = new HashMap(); // dataMap.put("first", new ContentVo("您好!您预约的理发即将开始,请安排好您的时间,可根据个人时间安排修改预约信息,后续可参与本次服务的评价", "#173177")); // dataMap.put("keyword1", new ContentVo("理发室", "#black")); // dataMap.put("keyword2", new ContentVo("理发", "#black")); // dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177")); // wService.publishMsg(dataMap, openIdString, 6); return new RestResult(Constant.SUCCESS, "已成功通知下一位"); } } // 返回结果 return new RestResult(Constant.SUCCESS, "今日不需要提醒"); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 取消 * * @param * @return */ @RequestMapping(value = "/cancleHaircut", method = RequestMethod.POST) public @ResponseBody RestResult cancleHaircut(@RequestBody Map map) { try { String id = map.get("id").toString(); String sql = "select * from green_haircut_info where id = ? "; List> list = hibernateDao.queryForListWithSql(sql ,new Object[]{id}); String intStatus = map.get("intStatus").toString(); String upSql = "update green_haircut_info set int_status=? where id=?"; hibernateDao.executeSqlUpdate(upSql,new Object[]{intStatus,id}); //已预约时间段恢复 String remainSql = " UPDATE GREEN_HAIRCUT_REMAIN hr SET hr.haircut_remain = (hr.haircut_remain+1) WHERE hr.barber_id = ?" + " AND hr.haircut_date = ? AND hr.haircut_time_id = ? "; hibernateDao.executeSqlUpdate(remainSql, new Object[] { list.get(0).get("barber_id").toString(), list.get(0).get("apply_date").toString(),list.get(0).get("apply_time_id").toString()}); if("1".equals(intStatus)){ //预约成功后给本人发送预约成功信息 String userId = list.get(0).get("user_id").toString(); String title="理发预约"; String text = "您已成功取消理发预约。"; String url = "/pages/haircut/haircut?currentTabIndex=1"; aliasManageController.pushToSingle(userId, title, text, url); //给理发师发送理发预约受理信息 //字典表查询理发预约受理权限 List> roleList = greenDictionaryInfoController.getDictionaryInfo("haircutRole"); String haircutRole = (String) roleList.get(0).get("data_value"); //查询所有有这个权限的人员 String getUserSql = "SELECT u.id,u.ISC_ID FROM green_user_info u " + " LEFT JOIN green_user_role_rel r ON u.id = r.user_id " + " LEFT JOIN green_role_permission p ON p.role_id = r.role_id " + " WHERE p.permission_id = ?"; List> userList = hibernateDao.queryForListWithSql(getUserSql, new Object[]{haircutRole}); title = "理发预约受理"; text = "您好,用户已取消理发预约,请注意查看。"; url = "/pages/haircut-order/haircut-order"; aliasManageController.pushToSingleBatch(userList, title, text, url); // 返回结果 return new RestResult(Constant.SUCCESS, "已取消"); }else if("2".equals(intStatus)){ return new RestResult(Constant.SUCCESS, "已成功设置"); } return new RestResult(Constant.SUCCESS, "已成功设置"); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "失败,请重试!"); } } /** * 获取当前日期到后三十天内的所有日期(含当前日期) * * @return */ public List getNextThirtyDate() { // 日期list List dateList = new ArrayList(); // 实例化SimpleDateFormat SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 实例化日历类Calendar Calendar calendar = Calendar.getInstance(); // 循环获取后三十天的日期 for (int i = 0; i < 30; i++) { // 添加当前时间 calendar.setTime(new Date()); // 增加一天 calendar.add(Calendar.DATE, i); // 将日期放入集合 dateList.add(sdf.format(calendar.getTime())); } // 返回信息 return dateList; } /** * 将字符串转成日期格式 * * @param dateStr * @return */ public Date changeDate(Object dateStr) { try { Date date = null; SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); if (dateStr != null) { date = sDateFormat.parse(dateStr.toString()); } return date; } catch (Exception e) { return null; } } private void groupHaircutByBaberId(List> remainByDateList) { Map remainMaps = new HashMap(); for (Map map : remainByDateList) { Long baberId = Long.parseLong(map.get("barber_id").toString()); if (remainMaps.containsKey(baberId)) { GreenHaircutBalance greenHaircutBalance = remainMaps.get(baberId); List balanceDetails = greenHaircutBalance.getRemain(); GreenHaircutBalanceDetail nBalanceDetail = new GreenHaircutBalanceDetail(); Long haircutMainLong = Long.parseLong(map.get("remain_count").toString()); nBalanceDetail.setHaircut_time_id(Long.parseLong(map.get("haircut_time_id").toString())); nBalanceDetail.setRemain_count(haircutMainLong); nBalanceDetail.setStatus(haircutMainLong <= 0 ? 1 : 0); nBalanceDetail.setHaircut_time(String.valueOf(map.get("haircut_time"))); balanceDetails.add(nBalanceDetail); } else { GreenHaircutBalance greenHaircutBalance = new GreenHaircutBalance(); String barber_name = (String) map.get("barber_name"); greenHaircutBalance.setBarber_id(baberId); greenHaircutBalance.setBarber_name(barber_name); List balanceDetails = new ArrayList(); GreenHaircutBalanceDetail nBalanceDetail = new GreenHaircutBalanceDetail(); Long haircutMainLong = Long.parseLong(map.get("remain_count").toString()); nBalanceDetail.setHaircut_time_id(Long.parseLong(map.get("haircut_time_id").toString())); nBalanceDetail.setRemain_count(haircutMainLong); nBalanceDetail.setStatus(haircutMainLong <= 0 ? 1 : 0); nBalanceDetail.setHaircut_time((String) (map.get("haircut_time"))); balanceDetails.add(nBalanceDetail); greenHaircutBalance.setRemain(balanceDetails); remainMaps.put(baberId, greenHaircutBalance); } } remainByDateList.clear(); for (Long keySet : remainMaps.keySet()) { Map map = new HashMap(); GreenHaircutBalance greenHaircutBalance = remainMaps.get(keySet); map.put("barber_id", keySet); map.put("barber_name", greenHaircutBalance.getBarber_name()); List arrayList = greenHaircutBalance.getRemain(); Collections.sort(arrayList, new Comparator() { @Override public int compare(Object o1, Object o2) { GreenHaircutBalanceDetail g1 = (GreenHaircutBalanceDetail) o1; GreenHaircutBalanceDetail g2 = (GreenHaircutBalanceDetail) o2; // TODO Auto-generated method stub return g1.getHaircut_time_id().compareTo(g2.getHaircut_time_id()); } }); map.put("remain", arrayList); remainByDateList.add(map); } } }