324 lines
12 KiB
Plaintext
324 lines
12 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
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.jdbc.core.BeanPropertyRowMapper;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
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.weChat.service.WechatService;
|
||
import com.jysoft.weChat.vo.ContentVo;
|
||
import com.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.bizc.IGreenApplyListBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenParkInfoBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenUserInfoBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenVisitorInfoBizc;
|
||
import com.nationalelectric.greenH5.po.GreenApplyList;
|
||
import com.nationalelectric.greenH5.po.GreenEAccount;
|
||
import com.nationalelectric.greenH5.po.GreenLicenseplateApproval;
|
||
import com.nationalelectric.greenH5.po.GreenParkInfo;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.nationalelectric.greenH5.po.GreenVisitorInfo;
|
||
import com.nationalelectric.greenH5.po.Result;
|
||
import com.nationalelectric.greenH5.service.EAccountService;
|
||
import com.nationalelectric.greenH5.utils.AesEncryptUtil;
|
||
import com.nationalelectric.greenH5.utils.Base64Utils;
|
||
import com.nationalelectric.greenH5.utils.DateUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
* @author chenweikang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenParkInfo")
|
||
public class GreenParkInfoController extends GreenBaseController {
|
||
|
||
@Autowired
|
||
private BaseServiceImpl BaseService;
|
||
/**
|
||
* 访客预约service
|
||
*/
|
||
@Resource
|
||
private WechatService wService;
|
||
/**
|
||
* 用户controller
|
||
*/
|
||
@Resource
|
||
private GreenUserInfoController greenUserInfoController;
|
||
/**
|
||
* 用户service
|
||
*/
|
||
@Resource
|
||
private IGreenUserInfoBizc greenuserinfoBizc;
|
||
@Resource
|
||
private IGreenParkInfoBizc greenParkInfoBizc;
|
||
@Resource
|
||
private IGreenVisitorInfoBizc greenvisitorinfoBizc;
|
||
@Resource
|
||
private IGreenApplyListBizc greenApplyListBizc;
|
||
/**
|
||
* HibernateDao逻辑构件
|
||
*/
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
|
||
/**
|
||
* 查询车牌审批记录
|
||
*
|
||
* @param result
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/getMyParkInfoList", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getMyParkInfoList(@RequestBody Result result) {
|
||
try {
|
||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
||
ArrayList<Object> params = new ArrayList<Object>();
|
||
String userId = result.getUserId();
|
||
String page = result.getPage();
|
||
String pageSize = result.getPageSize();
|
||
String sql = "select p.id as parkInfoId, p.carowner_name,p.entry_time,p.leave_time_set,p.leave_time_apply,p.leave_time,p.car_num"
|
||
+ ",al.* from green_park_info p left join green_apply_list al on "
|
||
+ "p.id = al.detail_id where p.carowner_id=? and (al.apply_type='05' or al.apply_type is NULL)";
|
||
params.add(userId);
|
||
if(page.matches("\\d+") && pageSize.matches("\\d+")){
|
||
Integer x = Integer.valueOf(page);
|
||
Integer y = Integer.valueOf(pageSize);
|
||
params.add((x-1)*y);
|
||
params.add(y);
|
||
sql+=" ORDER BY p.gmt_created DESC LIMIT ?,?";
|
||
}
|
||
list = hibernateDao.queryForListWithSql(sql.toString(), params.toArray());
|
||
return new RestResult(Constant.SUCCESS, "查询成功", list);
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "查询失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 提交车辆延期申请
|
||
*
|
||
* @param result
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/saveDelayParkInfo", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult saveDelayParkInfo(@RequestBody GreenParkInfo greenParkInfo) {
|
||
try {
|
||
ArrayList<Object> params = new ArrayList<Object>();
|
||
Long id = greenParkInfo.getId();
|
||
String approvalId = greenParkInfo.getApprovalId();
|
||
String reason = greenParkInfo.getReason();
|
||
String leaveTimeSet = greenParkInfo.getLeaveTimeSet();
|
||
String leaveTimeApply = greenParkInfo.getLeaveTimeApply();
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Date leaveDatSet = sdf.parse(leaveTimeSet);
|
||
Long leaveTimeApplyLong = (long) (Integer.parseInt(leaveTimeApply)*60*60*1000);
|
||
Date leaveDateApply = new Date(leaveDatSet.getTime()+leaveTimeApplyLong);
|
||
String leaveTimeApplytrue = sdf.format(leaveDateApply);
|
||
greenParkInfo = greenParkInfoBizc.get(id);
|
||
greenParkInfo.setLeaveTimeApply(leaveTimeApplytrue);
|
||
greenParkInfo.setReason(reason);
|
||
greenParkInfo.setGmtModified(new Date());
|
||
greenParkInfoBizc.update(greenParkInfo, id);
|
||
//审核记录表里插入记录
|
||
GreenUserInfo greenUserInfo = greenuserinfoBizc.get(greenParkInfo.getCarownerId());
|
||
GreenApplyList apply = new GreenApplyList();
|
||
apply.setUserId(greenParkInfo.getCarownerId());
|
||
apply.setDetailId(id);
|
||
apply.setApplyType("05");
|
||
apply.setApplyTypeName("车辆延期申请");
|
||
String isInner = greenUserInfo.getIsInner();
|
||
if("1".equals(isInner)){//判断车主是内部人员还是外部人员 1 内部人员
|
||
String userLevel = greenUserInfo.getUserLevel();
|
||
if("0".equals(userLevel)||"1".equals(userLevel)){//判断车主的用户级别,0专责 1处长 2 主任
|
||
apply.setFirstApproval(approvalId);
|
||
apply.setFirstStatus("0");
|
||
apply.setCurrentStatus("10");
|
||
}else if("2".equals(userLevel)){
|
||
apply.setCurrentStatus("90");
|
||
}
|
||
|
||
}else{
|
||
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
|
||
String startDate = sdf2.format(new Date());
|
||
String getVisitorSql = "select * from green_visitor_info where user_id=? and visit_start_time>='"+startDate+" 00:00' "
|
||
+ "and visit_start_time<='"+startDate+" 23:59' order by visit_start_time desc";
|
||
params.add(greenParkInfo.getCarownerId());
|
||
List<Map<String, Object>> list = hibernateDao.queryForListWithSql(getVisitorSql.toString(), params.toArray());
|
||
Map<String, Object> map = list.get(0);
|
||
apply.setFirstApproval((String)map.get("visited_person_id"));
|
||
apply.setFirstStatus("0");
|
||
apply.setCurrentStatus("10");
|
||
|
||
}
|
||
apply.setApplyTime(new SimpleDateFormat(DateUtil.Y_M_DH_MI_S).format(new Date()));
|
||
apply.setCreator(greenParkInfo.getCarownerId());
|
||
apply.setGmtCreated(new Date());
|
||
apply.setGmtModified(new Date());
|
||
apply.setIsDeleted("N");
|
||
greenApplyListBizc.add(apply);
|
||
return new RestResult(Constant.SUCCESS, "提交成功");
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "提交失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询车辆延期审批记录
|
||
*
|
||
* @param result
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/getParkInfoApprovalList", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getParkInfoApprovalList(@RequestBody Result result) {
|
||
try {
|
||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
||
ArrayList<Object> params = new ArrayList<Object>();
|
||
String userId = result.getUserId();
|
||
String userLevel = result.getUserLevel();
|
||
String page = result.getPage();
|
||
String pageSize = result.getPageSize();
|
||
String sql = "select p.id as parkInfoId, p.carowner_name,p.carowner_id,p.entry_time,p.leave_time_set,p.leave_time_apply,p.leave_time,p.car_num,p.reason"
|
||
+ ",al.*"
|
||
+ ",user.department_name,user.org_name from green_park_info p left join green_apply_list al on "
|
||
+ "p.id = al.detail_id "
|
||
+ " left join green_user_info user on user.id=p.carowner_id "
|
||
+ "where (al.apply_type='05' or al.apply_type is NULL) ";
|
||
if ("1".equals(result.getTabType())){ // 未审批
|
||
if(!"8".equals(userLevel)){
|
||
sql+= " and al.first_approval = ? and al.first_status = '0' ";
|
||
params.add(userId);
|
||
}else{
|
||
sql+= " and al.current_status = '90' ";
|
||
}
|
||
}else if("2".equals(result.getTabType())){//已审批
|
||
if(!"8".equals(userLevel)){
|
||
sql+= " and al.first_approval = ? and al.first_status <> '0' ";
|
||
params.add(userId);
|
||
}else{
|
||
sql+= " and al.current_status like '9%' and al.current_status not like '%0' ";
|
||
}
|
||
}
|
||
|
||
if(page.matches("\\d+") && pageSize.matches("\\d+")){
|
||
Integer x = Integer.valueOf(page);
|
||
Integer y = Integer.valueOf(pageSize);
|
||
params.add((x-1)*y);
|
||
params.add(y);
|
||
sql+=" ORDER BY p.gmt_created DESC LIMIT ?,?";
|
||
}
|
||
list = hibernateDao.queryForListWithSql(sql.toString(), params.toArray());
|
||
return new RestResult(Constant.SUCCESS, "查询成功", list);
|
||
}catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "查询失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 车辆申请的审批
|
||
*
|
||
* @param GreenLicenseplateApproval
|
||
* @return
|
||
*/
|
||
@SuppressWarnings({ "unchecked", "deprecation", "rawtypes" })
|
||
@Transactional(rollbackFor = Exception.class)
|
||
@RequestMapping(value = "/updateParkInfoApprovalBatch", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult updateParkInfoApprovalBatch(@RequestBody Object requestBody) {
|
||
Result restult = new ObjectMapper().convertValue(requestBody, new TypeReference<Result>() { });
|
||
try {
|
||
// 根据用户id查询该用户具有的权限
|
||
String applyListSql = "SELECT * from GREEN_APPLY_LIST WHERE detail_id = ? ";
|
||
// 执行查询sql
|
||
List<GreenApplyList> list = hibernateDao.queryForListWithSql(applyListSql, new Object[] { restult.getApplyId()}, new BeanPropertyRowMapper(GreenApplyList.class));
|
||
if (list.size() > 0) {
|
||
GreenApplyList greenApplyList = list.get(0);
|
||
|
||
String type = restult.getApplyType();
|
||
String userLevel = restult.getUserLevel();
|
||
// if("1".equals(userLevel)){
|
||
// firstStatus = greenApplyList.getSecondStatus();
|
||
// }else if("2".equals(userLevel)){
|
||
// firstStatus = greenApplyList.getThirdStatus();
|
||
// }else
|
||
String tip = "";
|
||
if("1".equals(type)){//拒绝
|
||
String statusLevel="first_status";
|
||
String current_status="12";
|
||
if("8".equals(userLevel)){
|
||
statusLevel = "ninth_status";
|
||
current_status="92";
|
||
}else{
|
||
statusLevel = "first_status";
|
||
current_status="12";
|
||
}
|
||
String updateSql = "UPDATE GREEN_APPLY_LIST SET "+statusLevel+" = 2,current_status='"+current_status+"' WHERE detail_id = ? ";
|
||
hibernateDao.executeSqlUpdate(updateSql,new Object[]{greenApplyList.getDetailId()});
|
||
tip = "审批未通过";
|
||
}else if("2".equals(type)){//同意
|
||
String statusLevel="first_status";
|
||
String current_status="90";//专责审核同意后需要流转到下一级,所以当前状态应该是待审核
|
||
if("8".equals(userLevel)){//审批中心审批
|
||
statusLevel = "ninth_status";
|
||
current_status="91";
|
||
tip = "审批通过";
|
||
}else{
|
||
statusLevel = "first_status";
|
||
current_status="90";
|
||
}
|
||
String updateSql = "UPDATE GREEN_APPLY_LIST SET "+statusLevel+" = 1,current_status='"+current_status+"' WHERE detail_id = ? ";
|
||
hibernateDao.executeSqlUpdate(updateSql,new Object[]{greenApplyList.getDetailId()});
|
||
|
||
if (!tip.equals("")) {
|
||
// 通知用户
|
||
GreenUserInfo user = getUserInfo(greenApplyList.getUserId());
|
||
if (user != null) {
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
||
data.put("first", new ContentVo("尊敬的用户,您的车辆延期申请审核结果已出", "#173177"));
|
||
data.put("keyword1", new ContentVo(tip, "#black"));
|
||
data.put("keyword2", new ContentVo(greenApplyList.getApplyTime(), "#black"));
|
||
data.put("remark", new ContentVo("感谢您的参与和支持", "#173177"));
|
||
wService.publishMsg(data, user.getWxOpenId(), 2);
|
||
}
|
||
}
|
||
return new RestResult(Constant.SUCCESS, "操作成功!");
|
||
}
|
||
}else{
|
||
return new RestResult(Constant.SUCCESS, "不存在该记录!");
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "处理失败");
|
||
}
|
||
return null;
|
||
}
|
||
}
|