389 lines
15 KiB
Plaintext
389 lines
15 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
import java.math.BigDecimal;
|
||
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 java.util.UUID;
|
||
import java.util.concurrent.locks.ReentrantLock;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.codehaus.jackson.map.ObjectMapper;
|
||
import org.codehaus.jackson.type.TypeReference;
|
||
import org.springframework.beans.BeanUtils;
|
||
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.GreenFoodOrderDetailDTO;
|
||
import com.nationalelectric.greenH5.DTO.GreenFoodOrderListDTO;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.bizc.IGreenDrugsApplyBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenDrugsDetailBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenFoodOrderDetailBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc;
|
||
import com.nationalelectric.greenH5.enums.OrderStatus;
|
||
import com.nationalelectric.greenH5.enums.PayStatus;
|
||
import com.nationalelectric.greenH5.enums.TakeStatus;
|
||
import com.nationalelectric.greenH5.po.GreenDiningRoom;
|
||
import com.nationalelectric.greenH5.po.GreenDrugsApply;
|
||
import com.nationalelectric.greenH5.po.GreenDrugsDetail;
|
||
import com.nationalelectric.greenH5.po.GreenFoodOrderDetail;
|
||
import com.nationalelectric.greenH5.po.GreenFoodOrderList;
|
||
import com.nationalelectric.greenH5.po.GreenUsecarApply;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.nationalelectric.greenH5.po.GreenWashCarInfo;
|
||
import com.nationalelectric.greenH5.utils.DateTime;
|
||
import com.nationalelectric.greenH5.utils.DateUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
import com.sgcc.uap.service.validator.ServiceValidatorBaseException;
|
||
|
||
import net.sf.json.JSONObject;
|
||
import net.sf.json.JSONArray;
|
||
|
||
|
||
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
* @author chenweikang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenUsecarApply")
|
||
public class GreenUseCarApplyController extends GreenBaseController {
|
||
|
||
|
||
@Resource
|
||
private IHibernateDao hibernateDao;
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
@Resource
|
||
private WechatService wService;
|
||
/**
|
||
* greenfoodorderdetail GreenFoodOrderDetail逻辑构件
|
||
*/
|
||
@Resource
|
||
private IGreenDrugsApplyBizc greenDrugsApplyBizc;
|
||
@Resource
|
||
private IGreenDrugsDetailBizc greenDrugsDetailBizc;
|
||
@Resource
|
||
private IGreenOperateLogBizc greenOperateLogBizc;
|
||
|
||
@Resource
|
||
private AliasManageController aliasManageController;
|
||
|
||
private ReentrantLock lock = new ReentrantLock();
|
||
|
||
/**提交订单*/
|
||
|
||
@SuppressWarnings("deprecation")
|
||
@RequestMapping(value="/submitUseCarApply", method = RequestMethod.POST)
|
||
@Transactional(rollbackFor=Exception.class)
|
||
@ResponseBody
|
||
public RestResult submitUseCarApply(@RequestBody GreenUsecarApply greenUsecarApply){
|
||
|
||
try {
|
||
|
||
String userId = greenUsecarApply.getUserid();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if(info==null){
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
greenUsecarApply.setCreatetime(new Date());
|
||
greenUsecarApply.setCreateby(userId);
|
||
|
||
hibernateDao.saveObject(greenUsecarApply);
|
||
String title="用车申请";
|
||
String text = "您好,您已成功发起用车申请,请等待部门领导审核。";
|
||
String url = "/pages/cars-management/cars-management?currentTabIndex=1";
|
||
aliasManageController.pushToSingle(userId, title, text, url);
|
||
|
||
String role = "12011";
|
||
Long deptId = info.getDepartmentId();
|
||
//查询所有有这个权限的人员
|
||
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 = ? and u.department_id = ?";
|
||
List<Map<String,Object>> userList = hibernateDao.queryForListWithSql(getUserSql, new Object[]{role,deptId});
|
||
title = "用车审核";
|
||
text = "您好,您有新的用车申请需要审核,请注意查看。";
|
||
url = "/pages/cars-management/cars-approval";
|
||
aliasManageController.pushToSingleBatch(userList, title, text, url);
|
||
|
||
return new RestResult(Constant.SUCCESS,"提交成功");
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
//设置手动回滚
|
||
return new RestResult(Constant.FAILED,"提交失败");
|
||
}
|
||
}
|
||
|
||
|
||
/**用户订单列表*/
|
||
@RequestMapping(value="/getMyUsecarApplyList", method = RequestMethod.POST)
|
||
@ResponseBody
|
||
public RestResult getMyUsecarApplyList(@RequestBody GreenUsecarApply greenUsecarApply){
|
||
|
||
String userId = greenUsecarApply.getUserid();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if(info==null){
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
try {
|
||
|
||
StringBuffer sb = new StringBuffer();
|
||
//分页信息
|
||
int pageSize = greenUsecarApply.getPageSize();
|
||
int page = greenUsecarApply.getPage();
|
||
page = (page-1) * pageSize;
|
||
//查询订单
|
||
sb.append(" Select * from green_usecar_apply"
|
||
+ " where isdelete='N' and userid = ? order by createtime desc limit ?,? ");
|
||
List<Map<String,Object>> applyList = hibernateDao.queryForListWithSql(sb.toString()
|
||
,new Object[]{ userId, page, pageSize});
|
||
|
||
return new RestResult(Constant.SUCCESS,"成功",applyList);
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"返回异常");
|
||
}
|
||
}
|
||
@RequestMapping(value="/getUsecarApplyList", method = RequestMethod.POST)
|
||
@ResponseBody
|
||
public RestResult getUsecarApplyList(@RequestBody GreenUsecarApply greenUsecarApply){
|
||
|
||
String userId = greenUsecarApply.getUserid();
|
||
String status = greenUsecarApply.getStatus();
|
||
String approvalStatus = greenUsecarApply.getApprovalStatus();
|
||
String deptid = greenUsecarApply.getDeptid();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if(info==null){
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
try {
|
||
|
||
StringBuffer sb = new StringBuffer();
|
||
//分页信息
|
||
int pageSize = greenUsecarApply.getPageSize();
|
||
int page = greenUsecarApply.getPage();
|
||
page = (page-1) * pageSize;
|
||
//查询订单
|
||
sb.append(" Select * from green_usecar_apply"
|
||
+ " where isdelete='N' ");
|
||
if(status!=null&&!"".equals(status)&&"1".equals(approvalStatus)){
|
||
sb.append(" and status='"+status+"' ");
|
||
}
|
||
if(approvalStatus!=null&&!"".equals(approvalStatus)){
|
||
if("0".equals(approvalStatus)){
|
||
sb.append(" and approval_status='"+approvalStatus+"' ");
|
||
}else if("1".equals(approvalStatus)){
|
||
sb.append(" and approval_status='"+approvalStatus+"' ");
|
||
}else if("3".equals(approvalStatus)){
|
||
sb.append(" and approval_status<>'0' ");
|
||
}
|
||
|
||
}
|
||
System.out.println(approvalStatus);
|
||
System.out.println("0".equals(approvalStatus)||"3".equals(approvalStatus));
|
||
if("0".equals(approvalStatus)||"3".equals(approvalStatus)){
|
||
sb.append(" and deptid = "+deptid+" ");
|
||
}
|
||
sb.append("order by createtime desc limit ?,? ");
|
||
List<Map<String,Object>> applyList = hibernateDao.queryForListWithSql(sb.toString()
|
||
,new Object[]{ page, pageSize});
|
||
|
||
return new RestResult(Constant.SUCCESS,"成功",applyList);
|
||
}catch (ServiceValidatorBaseException e) {
|
||
throw e;
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"返回异常");
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取司机列表
|
||
*
|
||
* @param greenHaircutRemainDTO
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "/getDriverList", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getDriverList(@RequestBody Map<String, Object> map) {
|
||
try {
|
||
String userId = (String) map.get("userId");
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if(info==null){
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
String driverSql = "select u.* from green_user_role_rel r left join green_user_info u "
|
||
+ " on r.user_id=u.id where r.role_id=66 and u.is_deleted='N' ";
|
||
List<Map<String, Object>> list = hibernateDao.queryForListWithSql(driverSql);
|
||
// 返回结果
|
||
return new RestResult(Constant.SUCCESS, "查询成功",list);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "查询失败");
|
||
}
|
||
}
|
||
/**
|
||
* 受理
|
||
*
|
||
* @param greenHaircutRemainDTO
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "/acceptUseCarApply", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult acceptUseCarApply(@RequestBody Map<String, Object> map) {
|
||
try {
|
||
// String userId = (String) map.get("userId");
|
||
// GreenUserInfo info = getUserInfo(userId);
|
||
// if(info==null){
|
||
// return new RestResult(Constant.FAILED, "非法用户");
|
||
// }
|
||
String id = map.get("id").toString();
|
||
//Long id = Long.parseLong((int) +"");
|
||
String assignId = (String) map.get("assignId");
|
||
String assignName = (String)map.get("assignName");
|
||
|
||
String sql = "update green_usecar_apply set assignId = ? ,assignName = ? ,status=1 where id=?";
|
||
hibernateDao.updateWithSql(sql,new Object[]{assignId,assignName,id});
|
||
String getApplyList = "select userId as id from green_usecar_apply where id =?";
|
||
List<Map<String,Object>> userList = hibernateDao.queryForListWithSql(getApplyList,new Object[]{id});
|
||
String title = "用车申请";
|
||
String text = "您好,您的用车申请已受理,请注意查看。";
|
||
String url = "/pages/cars-management/cars-management?currentTabIndex=1";
|
||
aliasManageController.pushToSingle((String)userList.get(0).get("id"), title, text, url);
|
||
// 返回结果
|
||
return new RestResult(Constant.SUCCESS, "受理成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "受理失败");
|
||
}
|
||
}
|
||
/**
|
||
* 用车完毕
|
||
*
|
||
* @param greenHaircutRemainDTO
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "/finishUseCar", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult finishUseCar(@RequestBody Map<String, Object> map) {
|
||
try {
|
||
// String userId = (String) map.get("userId");
|
||
// GreenUserInfo info = getUserInfo(userId);
|
||
// if(info==null){
|
||
// return new RestResult(Constant.FAILED, "非法用户");
|
||
// }
|
||
String id = map.get("id").toString();
|
||
//Long id = Long.parseLong((int) +"");
|
||
String userId = (String) map.get("userId");
|
||
|
||
String sql = "update green_usecar_apply set status=2 where id=?";
|
||
hibernateDao.updateWithSql(sql,new Object[]{id});
|
||
|
||
String getApplyList = "select userId as id from green_usecar_apply where id =?";
|
||
List<Map<String,Object>> userList = hibernateDao.queryForListWithSql(getApplyList,new Object[]{id});
|
||
String title = "用车申请";
|
||
String text = "您好,您此次用车已结束,请对本次服务给与评价。";
|
||
String url = "/pages/cars-management/cars-management?currentTabIndex=1";
|
||
aliasManageController.pushToSingle((String)userList.get(0).get("id"), title, text, url);
|
||
|
||
// GreenUserInfo userInfo = getUserInfo(userId);
|
||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||
// String openIdString = userInfo.getWxOpenId();
|
||
// Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
// dataMap.put("first", new ContentVo("您好!您的用车申请已结束,请及时评价!", "#173177"));
|
||
// dataMap.put("keyword1", new ContentVo(userInfo.getRealName(), "#black"));
|
||
// dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
// dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
// wService.publishMsg(dataMap, openIdString, 5);
|
||
// 返回结果
|
||
return new RestResult(Constant.SUCCESS, "受理成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "受理失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 用车审批
|
||
*
|
||
* @param greenHaircutRemainDTO
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "/approvalUseCarApply", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult approvalUseCarApply(@RequestBody Map<String, Object> map) {
|
||
try {
|
||
String userId = (String) map.get("userId");
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if(info==null){
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
String ids = map.get("ids").toString();
|
||
String approvalStatus = map.get("approvalStatus").toString();
|
||
String approvalReason = map.get("approvalReason")==null?"":map.get("approvalReason").toString();
|
||
|
||
String sql = "update green_usecar_apply set approval_status='"+approvalStatus+"',approval_reason='"+approvalReason+"' where id in("+ids+")";
|
||
hibernateDao.updateWithSql(sql);
|
||
String getApplyList = "select userId as id from green_usecar_apply where id in ("+ids+")";
|
||
List<Map<String,Object>> userList = hibernateDao.queryForListWithSql(getApplyList);
|
||
if("1".equals(approvalStatus)){//同意
|
||
// String title="用车审核";
|
||
// String text = "您好,您已成功发起用车申请,请等待部门领导审核。";
|
||
// String url = "/pages/cars-management/cars-management?currentTabIndex=1";
|
||
// aliasManageController.pushToSingle(userId, title, text, url);
|
||
String title = "用车申请";
|
||
String text = "您好,您的用车申请已通过审核,请注意查看。";
|
||
String url = "/pages/cars-management/cars-management?currentTabIndex=1";
|
||
// aliasManageController.pushToSingleBatch(userList, title, text, url);
|
||
//查询所有有这个权限的人员
|
||
String role = "12012";//用车受理权限
|
||
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<Map<String,Object>> userList2 = hibernateDao.queryForListWithSql(getUserSql, new Object[]{role});
|
||
title = "用车受理";
|
||
text = "您好,您有新的用车申请需要受理,请注意查看。";
|
||
url = "/pages/cars-management-sl/cars-management-sl";
|
||
aliasManageController.pushToSingleBatch(userList2, title, text, url);
|
||
}else{
|
||
String title = "用车申请";
|
||
String text = "您好,您的用车申请被拒绝,请注意查看。";
|
||
String url = "/pages/cars-management/cars-management?currentTabIndex=1";
|
||
// aliasManageController.pushToSingleBatch(userList, title, text, url);
|
||
}
|
||
|
||
// 返回结果
|
||
return new RestResult(Constant.SUCCESS, "审批成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "审批失败");
|
||
}
|
||
}
|
||
}
|