package com.nationalelectric.greenH5; import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; 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.po.GreenApply; import com.nationalelectric.greenH5.po.GreenUserInfo; import com.nationalelectric.greenH5.po.GreenWashCarInfo; import com.nationalelectric.greenH5.utils.DateTimeHelper; import com.nationalelectric.greenH5.utils.DateUtil; import com.sgcc.uap.persistence.IHibernateDao; import com.sgcc.uap.service.validator.ServiceValidatorUtil; /** * 洗车预约 控制层 * * @author Feb * */ @Controller @RequestMapping("/greenWashCar") public class GreenWashCarController extends GreenBaseController { @Autowired private IHibernateDao hibernateDao; @Resource private GreenDictionaryInfoController greenDictionaryInfoController; @Resource private AliasManageController aliasManageController; @Resource private WechatService wService; /** * 根据时间 初始化 数据 * * @return */ @RequestMapping("/initWashCar") public RestResult initWashCar(String applyPlace, String applyDate, String userId) { try { GreenUserInfo userInfo = getUserInfo(userId); if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } // List> placeList = greenDictionaryInfoController.getDictionaryInfo("washcarplace"); // if("".equals(applyPlace)){ // applyPlace = (String) placeList.get(0).get("data_value"); // } // 所有时间段数据 String timeSql = "select id as \"timeId\", wash_car_time as \"time\" from green_wash_car_times where del_flag ='0' order by sort"; List> timeList = hibernateDao.queryForListWithSql(timeSql); // 某天 对应 所有时间段的预约数据 String dateSql = " select apply_time_id as \"apply_time_id\" from green_wash_car_info where apply_place=? and apply_date = ? and del_flag =0 and int_status=0 "; List> list = hibernateDao.queryForListWithSql(dateSql, new Object[] {applyPlace, applyDate }); // 根据 已预约数据 计算剩余可预约数 for (Map map : timeList) { long timeId = Long.valueOf(String.valueOf(map.get("timeId"))); String time = (String) map.get("time"); int count = 1; for (Map clMap : list) { Long cLong = Long.valueOf(String.valueOf(clMap.get("apply_time_id"))); if (cLong.equals(timeId)) { count--; } } if (count < 0) { count=0; //return new RestResult(Constant.FAILED, "数据异常"); } map.put("count", count); } // String commentSql = "SELECT hc.APPLICANT_NAME as userName,hc.comment_content as content, hc.satisfied_level as level FROM GREEN_HAIRCUT_COMMENT hc WHERE hc.TYPE = '2' ORDER BY hc.gmt_created DESC LIMIT 0,10"; // List> comList = hibernateDao.queryForListWithSql(commentSql); // String licensePlateSql = "select distinct licenseplate from green_wash_car_info where user_id='"+userId+"' and del_flag =0 and licenseplate is not null and licenseplate<>'' "; // //String licensePlateSql = "select distinct licenseplate1 from green_licenseplate_approval where user_id='"+userId+"' and is_deleted='N' and licenseplate1_status='1'"; // List> licensePlateList = hibernateDao.queryForListWithSql(licensePlateSql); Map result = new HashMap(); result.put("timeList", timeList); //result.put("comments", comList); // result.put("placeList", placeList); // result.put("licensePlateList", licensePlateList); result.put("deptId", userInfo.getDepartmentId()); // 页面部门下拉框默认显示的部门id return new RestResult(Constant.SUCCESS, "初始化成功", result); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 根据时间 初始化 数据 * * @return */ @RequestMapping("/getPlaceData") public RestResult getPlaceData(String userId) { try { GreenUserInfo userInfo = getUserInfo(userId); if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } List> placeList = greenDictionaryInfoController.getDictionaryInfo("washcarplace"); String licensePlateSql = "select distinct licenseplate from green_wash_car_info where user_id='"+userId+"' and del_flag =0 and licenseplate is not null and licenseplate<>'' "; //String licensePlateSql = "select distinct licenseplate1 from green_licenseplate_approval where user_id='"+userId+"' and is_deleted='N' and licenseplate1_status='1'"; List> licensePlateList = hibernateDao.queryForListWithSql(licensePlateSql); Map result = new HashMap(); //result.put("comments", comList); result.put("placeList", placeList); result.put("licensePlateList", licensePlateList); result.put("deptId", userInfo.getDepartmentId()); // 页面部门下拉框默认显示的部门id return new RestResult(Constant.SUCCESS, "初始化成功", result); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 提交 洗车预约 * * @return */ @RequestMapping("/applyWashCar") @Transactional(rollbackFor = Exception.class) public RestResult applyWashCar(@RequestBody GreenWashCarInfo info) { if (info == null || info.getUserId().equals("") || info.getApplyDate().equals("")) { return new RestResult(Constant.FAILED, "参数有误"); } try { GreenUserInfo userInfo = getUserInfo(info.getUserId()); if (userInfo == null) { return new RestResult(Constant.FAILED, "非法用户"); } if ("".equals(info.getApplyDate())) { info.setApplyDate(DateUtil.now(new SimpleDateFormat("yyyy-MM-dd"))); } //ServiceValidatorUtil.validatorJavaBean(info); String sql = "select count(1) from green_wash_car_info ga where ga.user_id = ? and ga.apply_date = ? and ga.apply_place = ? and ga.apply_time_id = ? and ga.int_status=0"; int c = hibernateDao.queryForIntWithSql(sql, new Object[] { info.getUserId(), info.getApplyDate(),info.getApplyPlace(), info.getApplyTimeId() }); if (c > 0) { return new RestResult(Constant.FAILED, "该时间段已经预约,请重新选择!"); } // 已约数 String ctSql = " select count(1) from green_wash_car_info where apply_date = ? and apply_time_id = ? and apply_place = ? and int_status=0"; int ct = hibernateDao.queryForIntWithSql(ctSql, new Object[]{info.getApplyDate(), info.getApplyTimeId(),info.getApplyPlace()}); if ((1 - ct ) <= 0) { if (ct > 1) { return new RestResult(Constant.FAILED, "数据异常"); } return new RestResult(Constant.FAILED, "当前时段已无余额"); } info.setUserName(userInfo.getRealName()); info.setUpdUser(info.getUserId()); info.setDelFlag(0); info.setCreateTime(new Date()); info.setUpdTime(new Date()); Long id = (Long) hibernateDao.saveObject(info); if (id != null && id != 0) { // 申请记录添加一条记录 GreenApply apply = new GreenApply(); apply.setApplyType(Constant.WASHCAR_APPLY); apply.setApplyTypeName("洗车预约"); apply.setCommentStatus("0"); apply.setDelFlag("0"); apply.setApplyTime(new Date()); apply.setUserId(info.getUserId()); apply.setCurVerifyLevel("0"); apply.setNeedVerifyLevel("0"); apply.setStatus(Constant.APPLY_SUCCESS); apply.setDetailId(id); Long applyId = (Long) hibernateDao.saveObject(apply); if (applyId != null && applyId != 0) { //预约成功后给本人发送预约成功信息 String title="洗车预约"; String text = "您已成功预约洗车,请安排好您的时间。"; String url = "/pages/washcar/washCarReservation?currentTabIndex=1"; aliasManageController.pushToSingle(info.getUserId(), title, text, url); String place = info.getApplyPlace(); Integer moveCar = info.getMoveCar(); List moveCarUserList = new ArrayList(); if("科技楼".equals(place)&&1==moveCar){ List> driverRoleList = greenDictionaryInfoController.getDictionaryInfo("driverRole"); String strRoleIds = ""; for(int i=0;i map = driverRoleList.get(i); if(i!=driverRoleList.size()-1){ strRoleIds+=map.get("data_value").toString()+","; }else{ strRoleIds+=map.get("data_value").toString(); } } String driverSql = "select id,wxopenid,ISC_ID from green_user_info where id in (select user_id from green_user_role_rel where role_id in("+strRoleIds+"))"; List> driverList = hibernateDao.queryForListWithSql(driverSql); for(int i=0;i> roleList = greenDictionaryInfoController.getDictionaryInfo("washCarRole",dataCode); String washCarRole = (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[]{washCarRole}); List> userListEnd = new ArrayList>(); for(int i=0;i params = new ArrayList(); String sql = "select t.wash_car_time as \"wash_car_time\",i.id as \"id\",i.concat_user_name as \"concat_user_name\"," + "i.concat_phone as \"concat_phone\",i.licenseplate as \"licenseplate\",i.endremind as \"endremind\"," + "i.apply_place as \"apply_place\" from green_wash_car_times t " + "left join (SELECT ID,USER_ID,USER_NAME,APPLY_DATE,APPLY_TIME,APPLY_TIME_ID," + "DEPT_ID,DEPT_NAME,CONCAT_USER_NAME,CONCAT_PHONE,to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS \"CREATE_TIME\"," + "UPD_USER,to_char(UPD_TIME,'yyyy-mm-dd hh24:mi:ss') AS \"UPD_TIME\",DEL_FLAG,APPLY_PLACE,LICENSEPLATE," + "STARTREMIND,ENDREMIND,MOVE_CAR,INT_STATUS,IS_PUSH" + " from green_wash_car_info WHERE del_flag=0 and apply_date=? and int_status=0 "; params.add(applyDate); if(applyPlace!=null&&!"".equals(applyPlace)){ sql+=" and apply_place =? "; params.add(applyPlace); } sql+= ") i on t.id= i.apply_time_id where t.del_flag=0 order by t.sort"; List> resultList = hibernateDao.queryForListWithSql(sql,params.toArray()); // 返回结果 return new RestResult(Constant.SUCCESS, "", resultList); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 提醒 * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/remindPickUpCar", method = RequestMethod.POST) public @ResponseBody RestResult remindPickUpCar(@RequestBody GreenWashCarInfo info) { try { String sql = "SELECT ID,USER_ID,USER_NAME,APPLY_DATE,APPLY_TIME,APPLY_TIME_ID," + "DEPT_ID,DEPT_NAME,CONCAT_USER_NAME,CONCAT_PHONE,to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS \"CREATE_TIME\"," + "UPD_USER,to_char(UPD_TIME,'yyyy-mm-dd hh24:mi:ss') AS \"UPD_TIME\",DEL_FLAG,APPLY_PLACE,LICENSEPLATE," + "STARTREMIND,ENDREMIND,MOVE_CAR,INT_STATUS,IS_PUSH" + " from green_wash_car_info where id ="+info.getId()+""; List> list = hibernateDao.queryForListWithSql(sql); Integer endRemind = list.get(0).get("endremind")==null?0:Integer.parseInt( list.get(0).get("endremind").toString()); String upSql = "update green_wash_car_info set endremind="+(endRemind+1)+" where id="+info.getId(); hibernateDao.executeSqlUpdate(upSql); String userId = (String) list.get(0).get("user_id"); Integer moveCae = Integer.parseInt(list.get(0).get("move_car").toString()); String title=""; String text = ""; String url = ""; //aliasManageController.pushToSingle(userId, title, text, url); //GreenUserInfo userInfo = getUserInfo(userId); if("科技楼".equals(list.get(0).get("apply_place").toString())&&1==moveCae){ List> driverRoleList = greenDictionaryInfoController.getDictionaryInfo("driverRole"); String strRoleIds = ""; for(int i=0;i map = driverRoleList.get(i); if(i!=driverRoleList.size()-1){ strRoleIds+=map.get("data_value").toString()+","; }else{ strRoleIds+=map.get("data_value").toString(); } } String driverSql = "select id,wxopenid,ISC_ID from green_user_info where id in (select user_id from green_user_role_rel where role_id in("+strRoleIds+"))"; List> driverList = hibernateDao.queryForListWithSql(driverSql); title = "洗车预约受理"; text = "您好,用户的车已洗好,请及时取车交付。"; url = "/pages/washcar/washCarAccept?applyPlace=科技楼"; aliasManageController.pushToSingleBatch(driverList, title, text, url); }else{ title="洗车预约"; text = "您好,您的车已洗好,请及时取车。"; url = "/pages/washcar/washCarReservation?currentTabIndex=1"; aliasManageController.pushToSingle(userId, title, text, url); } // 返回结果 return new RestResult(Constant.SUCCESS, "已通知取车"); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } /** * 取消 * * @param greenHaircutRemainDTO * @return */ @RequestMapping(value = "/cancleWashCar", method = RequestMethod.POST) public @ResponseBody RestResult cancleWashCar(@RequestBody GreenWashCarInfo info) { try { String sql = "select ID,USER_ID,USER_NAME,APPLY_DATE," + "APPLY_TIME,APPLY_TIME_ID,DEPT_ID,DEPT_NAME,CONCAT_USER_NAME,CONCAT_PHONE," + "to_char(CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS \"CREATE_TIME\",UPD_USER," + "to_char(UPD_TIME,'yyyy-mm-dd hh24:mi:ss') AS \"UPD_TIME\",DEL_FLAG,APPLY_PLACE,LICENSEPLATE,STARTREMIND,ENDREMIND,MOVE_CAR,INT_STATUS," + "IS_PUSH" + " from green_wash_car_info where id =? "; List> list = hibernateDao.queryForListWithSql(sql ,new Object[]{info.getId()}); Integer intStatus = info.getIntStatus(); String upSql = "update green_wash_car_info set int_status=?,is_push = ? where id= ?"; hibernateDao.executeSqlUpdate(upSql,new Object[]{intStatus,null,info.getId()}); // String upApplySql = "update green_apply set del_flag='1' where detail_id=? and apply_type = '09'"; // hibernateDao.executeSqlUpdate(upApplySql,new Object[]{info.getId()}); if(intStatus==1){ String userId = (String) list.get(0).get("user_id"); Integer moveCar =Integer.parseInt(list.get(0).get("move_car").toString()); String applyPlace = list.get(0).get("apply_place").toString(); String title="洗车预约"; String text = "您已成功取消洗车预约。"; String url = "/pages/washcar/washCarReservation?currentTabIndex=1"; aliasManageController.pushToSingle(userId, title, text, url); List moveCarUserList = new ArrayList(); if("科技楼".equals(applyPlace)&&1==moveCar){ List> driverRoleList = greenDictionaryInfoController.getDictionaryInfo("driverRole"); String strRoleIds = ""; for(int i=0;i map = driverRoleList.get(i); if(i!=driverRoleList.size()-1){ strRoleIds+=map.get("data_value").toString()+","; }else{ strRoleIds+=map.get("data_value").toString(); } } String driverSql = "select id,wxopenid,ISC_ID from green_user_info where id in (select user_id from green_user_role_rel where role_id in("+strRoleIds+"))"; List> driverList = hibernateDao.queryForListWithSql(driverSql); for(int i=0;i> roleList = greenDictionaryInfoController.getDictionaryInfo("washCarRole",dataCode); String washCarRole = (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[]{washCarRole}); List> userListEnd = new ArrayList>(); for(int i=0;i> list = hibernateDao.queryForListWithSql(sql ,new Object[]{entity.getUserId()}); return new RestResult(Constant.SUCCESS, "查询成功",list); } catch (Exception e) { e.printStackTrace(); return new RestResult(Constant.FAILED, "查询失败"); } } }