package com.nationalelectric.greenH5; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; 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.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.nationalelectirc.Constant.ApplyRoleConstant; import com.nationalelectirc.Constant.Constant; import com.nationalelectirc.utils.RestResult; import com.nationalelectric.greenH5.DTO.GreenConstructDTO; import com.nationalelectric.greenH5.DTO.GreenMealTicketApplyDTO; import com.nationalelectric.greenH5.bizc.BaseServiceImpl; import com.nationalelectric.greenH5.bizc.IGreenApplyListBizc; import com.nationalelectric.greenH5.bizc.IGreenConstructInfoBizc; import com.nationalelectric.greenH5.bizc.IGreenConstructPersonInfoBizc; import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc; import com.nationalelectric.greenH5.po.GreenApplyList; import com.nationalelectric.greenH5.po.GreenConstructInfo; import com.nationalelectric.greenH5.po.GreenConstructPersonInfo; import com.nationalelectric.greenH5.po.GreenUserInfo; import com.nationalelectric.greenH5.utils.AesEncryptUtil; 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; /** * 概述
*

* 功能
* * @author dell */ @Controller @RequestMapping("/greenConstructInfo") public class GreenConstructInfoController extends GreenBaseController { /** * 施工申请service */ @Resource private IGreenConstructInfoBizc greenconstructinfoBizc; /** * HibernateDao逻辑构件 */ @Autowired IHibernateDao hibernateDao; /** * 施工申请人员service */ @Resource private IGreenConstructPersonInfoBizc greenconstructpersoninfoBizc; /** * 我的申请列表service */ @Resource private IGreenApplyListBizc greenApplyListBizc; /** * 用户controller */ @Resource private GreenUserInfoController greenUserInfoController; /** * 保存图片controller */ @Resource private GreenImageInfoController greenImageInfoController; @Resource private IGreenOperateLogBizc greenOperateLogBizc; @Autowired private BaseServiceImpl baseService; /** * 保存施工申请 * * @param greenConstructDTO * @return */ @RequestMapping(value = "/saveConstructInfo", method = RequestMethod.POST) @Transactional(rollbackFor = Exception.class) public @ResponseBody RestResult saveConstructInfo(@RequestBody Object requestBody) { GreenConstructDTO greenConstructDTO = new ObjectMapper().convertValue(requestBody, new TypeReference() { }); try { String userId = greenConstructDTO.getUserId(); GreenUserInfo info = getUserInfo(userId); if (info == null) { return new RestResult(Constant.FAILED, "非法用户"); } // 校验 ServiceValidatorUtil.validatorJavaBean(greenConstructDTO); for (GreenConstructPersonInfo greenConstructPersonInfo : greenConstructDTO.getConstructPersonList()) { ServiceValidatorUtil.validatorJavaBean(greenConstructPersonInfo); } // 开始时间 Date startDate = changeDate(greenConstructDTO.getStartTime()); // 结束时间 Date endDate = changeDate(greenConstructDTO.getEndTime()); // 当前时间 Date nowDate = new Date(); if (startDate == null || endDate == null) { /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, * Constant.APPLY, Constant.OPERATE_FAIL, "提交施工申请", * Constant.LOG_OPERATE, greenConstructDTO.getUserId()); */ return new RestResult(Constant.FAILED, "开始时间、结束时间格式有误,请重新输入!"); } // 判断开始时间是否小于当前时间 if (nowDate.getTime() > startDate.getTime()) { /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, * Constant.APPLY, Constant.OPERATE_FAIL, "提交施工申请", * Constant.LOG_OPERATE, greenConstructDTO.getUserId()); */ return new RestResult(Constant.FAILED, "开始时间不能小于当前时间,请重新输入!"); } // 判断结束时间是否小于当前时间 if (nowDate.getTime() > endDate.getTime()) { /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, * Constant.APPLY, Constant.OPERATE_FAIL, "提交施工申请", * Constant.LOG_OPERATE, greenConstructDTO.getUserId()); */ return new RestResult(Constant.FAILED, "结束时间不能小于当前时间,请重新输入!"); } // 判断开始时间是否大于结束时间 if (startDate.getTime() > endDate.getTime()) { /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, * Constant.APPLY, Constant.OPERATE_FAIL, "提交施工申请", * Constant.LOG_OPERATE, greenConstructDTO.getUserId()); */ return new RestResult(Constant.FAILED, "开始时间不能大于结束时间,请重新输入!"); } // 获取施工申请信息 GreenConstructInfo greenConstructInfo = new GreenConstructInfo(); // 申请部门名称 greenConstructInfo.setApplyDeptName(greenConstructDTO.getApplyDeptName()); // 项目负责人 greenConstructInfo.setPrincipal(greenConstructDTO.getPrincipal()); // 联系方式 greenConstructInfo.setContactTel(greenConstructDTO.getContactTel()); // 身份证号,要加密处理 String cardno = greenConstructDTO.getIdcardNo(); try { cardno = AesEncryptUtil.encrypt(cardno); } catch (Exception e) { } greenConstructInfo.setIdcardNo(cardno); // 业务名称 greenConstructInfo.setBusinessName(greenConstructDTO.getBusinessName()); // 业务内容 greenConstructInfo.setBusinessDetail(greenConstructDTO.getBusinessDetail()); // 施工单位 greenConstructInfo.setConstructCompany(greenConstructDTO.getConstructCompany()); // 开始时间 greenConstructInfo.setStartTime(greenConstructDTO.getStartTime()); // 结束时间 greenConstructInfo.setEndTime(greenConstructDTO.getEndTime()); // 实施方案 // greenConstructInfo.setImplementPlan(greenConstructDTO.getImplementPlan()); String p1 = greenImageInfoController.saveImage(greenConstructDTO.getImplementPlan(), userId); greenConstructInfo.setImplementPlanData(p1); baseService.saveImgToIO(p1 + ".jpg", greenConstructDTO.getImplementPlan()); greenConstructInfo.setImplementPlan(p1 + ".jpg"); // 实施发起文件 // greenConstructInfo.setImplementInitiateFile(greenConstructDTO.getImplementInitiateFile()); // greenConstructInfo.setImplementInitiateFile(greenImageInfoController.saveImage(greenConstructDTO.getImplementInitiateFile(),userId)); String p2 = greenImageInfoController.saveImage(greenConstructDTO.getImplementInitiateFile(), userId); greenConstructInfo.setImplementInitiateFileData(p2); greenConstructInfo.setImplementInitiateFile(p2 + ".jpg"); baseService.saveImgToIO(p2 + ".jpg", greenConstructDTO.getImplementInitiateFile()); // 用户id greenConstructInfo.setUserId(greenConstructDTO.getUserId()); // 创建者 greenConstructInfo.setCreator(greenConstructDTO.getUserId().toString()); // 修改者 greenConstructInfo.setModifier(greenConstructDTO.getUserId().toString()); // 创建时间 greenConstructInfo.setGmtCreated(new Date()); // 修改时间 greenConstructInfo.setGmtModified(new Date()); // 删除标记 greenConstructInfo.setIsDeleted("N"); greenConstructInfo.setImgStatus(1); // 添加访客信息到访客信息表 greenconstructinfoBizc.add(greenConstructInfo); // 保存施工人员信息 for (GreenConstructPersonInfo greenConstructPersonInfo : greenConstructDTO.getConstructPersonList()) { // 访客id greenConstructPersonInfo.setConstructId(greenConstructInfo.getId()); // 创建者 greenConstructPersonInfo.setCreator(greenConstructDTO.getUserId().toString()); // 修改者 greenConstructPersonInfo.setModifier(greenConstructDTO.getUserId().toString()); // 创建时间 greenConstructPersonInfo.setGmtCreated(new Date()); // 修改时间 greenConstructPersonInfo.setGmtModified(new Date()); // 删除标记 greenConstructPersonInfo.setIsDeleted("N"); String cardno_1 = greenConstructPersonInfo.getIdcardNo(); try { cardno_1 = AesEncryptUtil.encrypt(cardno_1); } catch (Exception e) { } greenConstructPersonInfo.setIdcardNo(cardno_1); // 执行保存方法 greenconstructpersoninfoBizc.add(greenConstructPersonInfo); } // 下面的操作,不在一个事务里,不能这样操作啦 // baseService.saveConstructImage(greenConstructInfo.getId()); // 添加访客信息到申请信息list表 GreenApplyList list = new GreenApplyList(); // 申请人id list.setUserId(greenConstructDTO.getUserId()); // 申请事项详情ID list.setDetailId(greenConstructInfo.getId()); // 申请类型 list.setApplyType(Constant.CONSTRUCT_APPLY); // 申请类型名称 list.setApplyTypeName("施工申请"); // 申请详情1(申请部门) list.setApplyInfo1(greenConstructDTO.getApplyDeptName()); // 申请详情2(业务名称) list.setApplyInfo2(greenConstructDTO.getBusinessName()); // 一级审批部门 list.setFirstApproval(ApplyRoleConstant.CONSTRUCT_APPROVE_PROJECT); // 一级审批状态 // list.setFirstStatus(Constant.APPROVAL_DOING); // 二级审批部门 list.setSecondApproval(ApplyRoleConstant.CONSTRUCT_APPROVE_DEFEND); // 二级审批状态 // list.setSecondStatus(Constant.APPROVAL_DOING); // 三级审批部门 list.setThirdApproval(ApplyRoleConstant.CONSTRUCT_APPROVE_DIRECTOR); // 三级审批状态 // list.setThirdStatus(Constant.APPROVAL_DOING); // 四级审批部门 list.setFourthApproval(ApplyRoleConstant.CONSTRUCT_APPROVE_GENERAL); // 四级审批状态 // list.setFourthStatus(Constant.APPROVAL_DOING); // 五级审批部门 list.setFifthApproval(ApplyRoleConstant.CONSTRUCT_APPROVE_SECURITY); // 五级审批状态 // list.setFifthStatus(Constant.APPROVAL_DOING); // 申请时间 list.setApplyTime(new SimpleDateFormat(DateUtil.Y_M_DH_MI_S).format(new Date())); // 创建者 list.setCreator(greenConstructDTO.getUserId().toString()); // 修改者 list.setModifier(greenConstructDTO.getUserId().toString()); // 创建时间 list.setGmtCreated(new Date()); // 修改时间 list.setGmtModified(new Date()); // 删除标识 list.setIsDeleted("N"); // 添加申请到申请list表 greenApplyListBizc.add(list); /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, Constant.APPLY, * Constant.OPERATE_SUCCESS, "提交施工申请", Constant.LOG_OPERATE, * greenConstructDTO.getUserId()); */ // 返回结果 return new RestResult(Constant.SUCCESS, "申请成功"); } catch (ServiceValidatorBaseException e) { e.printStackTrace(); /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, Constant.APPLY, * Constant.OPERATE_FAIL, "提交施工申请", Constant.LOG_ERROR, * greenConstructDTO.getUserId()); */ return new RestResult(Constant.FAILED, e.getMessage()); } catch (Exception e) { e.printStackTrace(); /* * greenOperateLogBizc.addLog(Constant.CONSTRUCT, Constant.APPLY, * Constant.OPERATE_FAIL, "提交施工申请", Constant.LOG_ERROR, * greenConstructDTO.getUserId()); */ return new RestResult(Constant.FAILED, "申请失败,请重试"); } } /** * 根据id查询施工申请详情 * * @param id * @param applyType * @return */ @SuppressWarnings({ "unchecked" }) public List> getConstructInfo(String id, String applyType, String userId) throws Exception { List> resultList = new ArrayList>(); List> constructPsersonList = new ArrayList>(); // 根据用户id查询该用户具有的权限 List> queryRoleList = greenUserInfoController.queryRoleById(userId); if (queryRoleList.size() <= 0) { throw new MyException("该角色暂无任何权限,请联系管理员!"); } // 切割查询的权限 String[] userRoleArr = queryRoleList.get(0).get("userRole").toString().split(","); String userRoleStr = ""; for (String value : userRoleArr) { userRoleStr = userRoleStr + "'" + value + "',"; } userRoleStr = "(" + userRoleStr.substring(0, userRoleStr.length() - 1) + ")"; // 查询施工人员信息 String retinueInfoSql = "SELECT * FROM GREEN_CONSTRUCT_PERSON_INFO cpi WHERE cpi.is_deleted = 'N' AND cpi.construct_id = ?"; // 查询施工申请详情 /* * String applyInfoByIdSql = * " SELECT ci.*,al.detail_id,al.apply_type,al.apply_type_name,gii1.image_content AS plan_pic,gii2.image_content AS initiate_file_pic," * + * " al.first_approval,al.first_status,al.first_approve_time,di1.data_value AS first_status_value," * + * " al.second_approval,al.second_status,al.second_approve_time,di2.data_value AS second_status_value," * + * " al.third_approval,al.third_status,al.third_approve_time,di3.data_value AS third_status_value," * + * " al.fourth_approval,al.fourth_status,al.fourth_approve_time,di4.data_value AS fourth_status_value," * + * " al.fifth_approval,al.fifth_status,al.fifth_approve_time,di5.data_value AS fifth_status_value," * + " IF(al.first_approval IN " * +userRoleStr+",al.first_status,IF(al.second_approval IN "+userRoleStr * +",second_status," + " IF(al.third_approval IN " * +userRoleStr+",al.third_status,IF(al.fourth_approval IN"+userRoleStr+ * ",al.fourth_status," + " IF(al.fifth_approval IN " * +userRoleStr+",fifth_status,null))))) AS status_code" + * " FROM GREEN_CONSTRUCT_INFO ci" + * " INNER JOIN GREEN_APPLY_LIST al ON ci.id = al.detail_id" + * " INNER JOIN GREEN_DICTIONARY_INFO di1 ON al.first_status = di1.data_code AND di1.data_type = 'approveStatus'" * + * " INNER JOIN GREEN_DICTIONARY_INFO di2 ON al.second_status = di2.data_code AND di2.data_type = 'approveStatus'" * + * " INNER JOIN GREEN_DICTIONARY_INFO di3 ON al.third_status = di3.data_code AND di3.data_type = 'approveStatus'" * + * " INNER JOIN GREEN_DICTIONARY_INFO di4 ON al.fourth_status = di4.data_code AND di4.data_type = 'approveStatus'" * + * " INNER JOIN GREEN_DICTIONARY_INFO di5 ON al.fifth_status = di5.data_code AND di5.data_type = 'approveStatus'" * + " LEFT JOIN GREEN_IMAGE_INFO gii1 ON ci.implement_plan = gii1.id" + * " LEFT JOIN GREEN_IMAGE_INFO gii2 ON ci.implement_initiate_file = gii2.id" * + " WHERE ci.id = ? AND al.apply_type = ?"; */ String applyInfoByIdSql = " SELECT ci.*,al.detail_id,al.apply_type,al.apply_type_name,ci.implement_plan AS plan_pic,ci.implement_initiate_file AS initiate_file_pic," + " al.first_approval,al.first_status,al.first_approve_time,di1.data_value AS first_status_value," + " al.second_approval,al.second_status,al.second_approve_time,di2.data_value AS second_status_value," + " al.third_approval,al.third_status,al.third_approve_time,di3.data_value AS third_status_value," + " al.fourth_approval,al.fourth_status,al.fourth_approve_time,di4.data_value AS fourth_status_value," + " al.fifth_approval,al.fifth_status,al.fifth_approve_time,di5.data_value AS fifth_status_value," + " IF(al.first_approval IN " + userRoleStr + ",al.first_status,IF(al.second_approval IN " + userRoleStr + ",second_status," + " IF(al.third_approval IN " + userRoleStr + ",al.third_status,IF(al.fourth_approval IN" + userRoleStr + ",al.fourth_status," + " IF(al.fifth_approval IN " + userRoleStr + ",fifth_status,null))))) AS status_code" + " FROM GREEN_CONSTRUCT_INFO ci" + " INNER JOIN GREEN_APPLY_LIST al ON ci.id = al.detail_id" + " INNER JOIN GREEN_DICTIONARY_INFO di1 ON al.first_status = di1.data_code AND di1.data_type = 'approveStatus'" + " INNER JOIN GREEN_DICTIONARY_INFO di2 ON al.second_status = di2.data_code AND di2.data_type = 'approveStatus'" + " INNER JOIN GREEN_DICTIONARY_INFO di3 ON al.third_status = di3.data_code AND di3.data_type = 'approveStatus'" + " INNER JOIN GREEN_DICTIONARY_INFO di4 ON al.fourth_status = di4.data_code AND di4.data_type = 'approveStatus'" + " INNER JOIN GREEN_DICTIONARY_INFO di5 ON al.fifth_status = di5.data_code AND di5.data_type = 'approveStatus'" + " WHERE ci.id = ? AND al.apply_type = ?"; // 执行sql resultList = hibernateDao.queryForListWithSql(applyInfoByIdSql, new Object[] { id, applyType }); // 将实施方案和实施发起文件转成数组 if (resultList.size() > 0) { Map info = resultList.get(0); String pic1name = String.valueOf(info.get("plan_pic")); String pic2name = String.valueOf(info.get("initiate_file_pic")); String pic1Data = baseService.getImageBase64(pic1name); String pic2Data = baseService.getImageBase64(pic2name); info.put("plan_pic", pic1Data); info.put("initiate_file_pic", pic2Data); String cardNo = String.valueOf(info.get("IDCard_no")); try { cardNo = AesEncryptUtil.desEncrypt(cardNo); if (cardNo != null) { cardNo = cardNo.trim(); } } catch (Exception e) { } info.put("IDCard_no", cardNo); for (Map map : resultList) { // 查询施工人员信息 constructPsersonList = hibernateDao.queryForListWithSql(retinueInfoSql, new Object[] { map.get("id") }); for (int i = 0; i < constructPsersonList.size(); i++) { Map m = constructPsersonList.get(i); String cardNo_1 = String.valueOf(m.get("IDCard_no")); try { cardNo_1 = AesEncryptUtil.desEncrypt(cardNo_1); if (cardNo_1 != null) { cardNo_1 = cardNo_1.trim(); } } catch (Exception e) { } m.put("IDCard_no", cardNo_1); } map.put("constructPserson", constructPsersonList); } } return resultList; } /** * 将字符串转成日期格式 * * @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; } } }