274 lines
11 KiB
Plaintext
274 lines
11 KiB
Plaintext
|
|
package com.nationalelectric.greenH5;
|
|||
|
|
|
|||
|
|
import java.text.SimpleDateFormat;
|
|||
|
|
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.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.nationalelectirc.Constant.ApplyRoleConstant;
|
|||
|
|
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.IGreenOperateLogBizc;
|
|||
|
|
import com.nationalelectric.greenH5.bizc.IGreenStaffCardInfoBizc;
|
|||
|
|
import com.nationalelectric.greenH5.po.GreenApplyList;
|
|||
|
|
import com.nationalelectric.greenH5.po.GreenStaffCardInfo;
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* <b>概述</b>:<br>
|
|||
|
|
* <p>
|
|||
|
|
* <b>功能</b>:<br>
|
|||
|
|
*
|
|||
|
|
* @author dell
|
|||
|
|
*/
|
|||
|
|
@Controller
|
|||
|
|
@RequestMapping("/greenStaffCardInfo")
|
|||
|
|
public class GreenStaffCardInfoController extends GreenBaseController{
|
|||
|
|
/**
|
|||
|
|
* 员工卡service
|
|||
|
|
*/
|
|||
|
|
@Resource
|
|||
|
|
private IGreenStaffCardInfoBizc greenstaffcardinfoBizc;
|
|||
|
|
/**
|
|||
|
|
* 我的申请service
|
|||
|
|
*/
|
|||
|
|
@Resource
|
|||
|
|
private IGreenApplyListBizc greenApplyListBizc;
|
|||
|
|
/**
|
|||
|
|
* 保存图片controller
|
|||
|
|
*/
|
|||
|
|
@Resource
|
|||
|
|
private GreenImageInfoController greenImageInfoController;
|
|||
|
|
/**
|
|||
|
|
* 用户controller
|
|||
|
|
*/
|
|||
|
|
@Resource
|
|||
|
|
private GreenUserInfoController greenUserInfoController;
|
|||
|
|
@Resource
|
|||
|
|
private IGreenOperateLogBizc greenOperateLogBizc;
|
|||
|
|
/**
|
|||
|
|
* HibernateDao逻辑构件
|
|||
|
|
*/
|
|||
|
|
@Autowired
|
|||
|
|
IHibernateDao hibernateDao;
|
|||
|
|
@Autowired
|
|||
|
|
private BaseServiceImpl baseService;
|
|||
|
|
/**
|
|||
|
|
* 保存员工卡申请信息
|
|||
|
|
*
|
|||
|
|
* @param greenStaffCardInfo
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
@Transactional(rollbackFor=Exception.class)
|
|||
|
|
@RequestMapping(value = "/saveStaffCardInfo", method = RequestMethod.POST)
|
|||
|
|
public @ResponseBody RestResult saveStaffCardInfo(@RequestBody Object requestBody) {
|
|||
|
|
|
|||
|
|
GreenStaffCardInfo greenStaffCardInfo = new ObjectMapper().convertValue(requestBody, new TypeReference<GreenStaffCardInfo>() {});
|
|||
|
|
try {
|
|||
|
|
String userId = greenStaffCardInfo.getUserId();
|
|||
|
|
GreenUserInfo info = getUserInfo(userId);
|
|||
|
|
if(info==null){
|
|||
|
|
return new RestResult(Constant.FAILED, "非法用户");
|
|||
|
|
}
|
|||
|
|
//校验
|
|||
|
|
ServiceValidatorUtil.validatorJavaBean(greenStaffCardInfo);
|
|||
|
|
String uuid =greenImageInfoController.saveImage(greenStaffCardInfo.getEntryOrderPic(), userId);
|
|||
|
|
// 入职单/调令照片
|
|||
|
|
boolean flag=baseService.saveImgToIO(uuid+Constant.IMG_SUFFIX, greenStaffCardInfo.getEntryOrderPic());
|
|||
|
|
|
|||
|
|
greenStaffCardInfo.setEntryOrderPic(uuid+Constant.IMG_SUFFIX);
|
|||
|
|
// 申请时间
|
|||
|
|
greenStaffCardInfo.setApplyTime(new SimpleDateFormat(DateUtil.Y_M_DH_MI_S).format(new Date()));
|
|||
|
|
// 创建者
|
|||
|
|
greenStaffCardInfo.setCreator(greenStaffCardInfo.getUserId().toString());
|
|||
|
|
// 修改者
|
|||
|
|
greenStaffCardInfo.setModifier(greenStaffCardInfo.getUserId().toString());
|
|||
|
|
// 创建时间
|
|||
|
|
greenStaffCardInfo.setGmtCreated(new Date());
|
|||
|
|
// 修改时间
|
|||
|
|
greenStaffCardInfo.setGmtModified(new Date());
|
|||
|
|
// 删除标记
|
|||
|
|
greenStaffCardInfo.setIsDeleted("N");
|
|||
|
|
//图片外键
|
|||
|
|
greenStaffCardInfo.setEntryOrderPicData(uuid);
|
|||
|
|
//图片状态
|
|||
|
|
greenStaffCardInfo.setImgStatus(flag?1:0);
|
|||
|
|
|
|||
|
|
String cardno = greenStaffCardInfo.getIdcardNo();
|
|||
|
|
try {
|
|||
|
|
cardno = AesEncryptUtil.encrypt(cardno);
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
}
|
|||
|
|
greenStaffCardInfo.setIdcardNo(cardno);
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 添加访客信息到访客信息表
|
|||
|
|
greenstaffcardinfoBizc.add(greenStaffCardInfo);
|
|||
|
|
|
|||
|
|
// 添加员工卡信息到申请信息list表
|
|||
|
|
GreenApplyList list = new GreenApplyList();
|
|||
|
|
// 申请人id
|
|||
|
|
list.setUserId(greenStaffCardInfo.getUserId());
|
|||
|
|
// 申请事项详情ID
|
|||
|
|
list.setDetailId(greenStaffCardInfo.getId());
|
|||
|
|
// 申请类型
|
|||
|
|
list.setApplyType("03");
|
|||
|
|
// 申请类型名称
|
|||
|
|
list.setApplyTypeName("员工卡");
|
|||
|
|
// 申请详情1(所属部门)
|
|||
|
|
list.setApplyInfo1(greenStaffCardInfo.getDeptName());
|
|||
|
|
// 申请详情2(员工姓名)
|
|||
|
|
list.setApplyInfo2(greenStaffCardInfo.getStaffName());
|
|||
|
|
// 一级审批部门
|
|||
|
|
list.setFirstApproval(ApplyRoleConstant.STAFF_CARD_GENERAL);
|
|||
|
|
// 一级审批状态(默认待审批)
|
|||
|
|
// list.setFirstStatus(Constant.APPROVAL_DOING);
|
|||
|
|
// 二级审批部门
|
|||
|
|
list.setSecondApproval(ApplyRoleConstant.STAFF_CARD_SECURITY);
|
|||
|
|
// 二级审批状态(默认待审批)
|
|||
|
|
// list.setSecondStatus(Constant.APPROVAL_DOING);
|
|||
|
|
// 三级审批部门
|
|||
|
|
list.setThirdApproval(ApplyRoleConstant.STAFF_CARD_MAKE);
|
|||
|
|
// 三级审批状态(默认待制卡)
|
|||
|
|
// list.setThirdStatus(Constant.MAKE_CARD_DOING);
|
|||
|
|
// 申请时间
|
|||
|
|
list.setApplyTime(greenStaffCardInfo.getApplyTime());
|
|||
|
|
// 创建者
|
|||
|
|
list.setCreator(greenStaffCardInfo.getUserId().toString());
|
|||
|
|
// 修改者
|
|||
|
|
list.setModifier(greenStaffCardInfo.getUserId().toString());
|
|||
|
|
// 创建时间
|
|||
|
|
list.setGmtCreated(new Date());
|
|||
|
|
// 修改时间
|
|||
|
|
list.setGmtModified(new Date());
|
|||
|
|
// 删除标识
|
|||
|
|
list.setIsDeleted("N");
|
|||
|
|
|
|||
|
|
// 添加申请到申请list表
|
|||
|
|
greenApplyListBizc.add(list);
|
|||
|
|
/*
|
|||
|
|
final ExecutorService taskExecutorService = Executors.newFixedThreadPool(2);
|
|||
|
|
// 根据角色名称查询员工卡申请审批的用户
|
|||
|
|
String staffAppSql = "SELECT user_name userName FROM GREEN_USER_ROLE_REL WHERE role_name='员工卡申请审批'";
|
|||
|
|
|
|||
|
|
List<GreenUserRoleRel> staffAppList = hibernateDao.queryForListWithSql(staffAppSql, new Object[] {},
|
|||
|
|
new BeanPropertyRowMapper(GreenUserRoleRel.class));
|
|||
|
|
|
|||
|
|
final String msgname = "审批通知";
|
|||
|
|
final String tm = "您有一个【员工卡申请】审批";
|
|||
|
|
|
|||
|
|
for (int i = 0; i < staffAppList.size(); i++) {
|
|||
|
|
|
|||
|
|
final String userName = staffAppList.get(i).getUserName();
|
|||
|
|
taskExecutorService.execute(new Runnable() {
|
|||
|
|
|
|||
|
|
public void run() {
|
|||
|
|
System.out.println(userName);
|
|||
|
|
PushMessageUtil.pushMessage(msgname, tm, userName);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
*/
|
|||
|
|
//greenOperateLogBizc.addLog(Constant.STAFF_CARD, Constant.STAFF, Constant.OPERATE_SUCCESS, "员工卡申请", Constant.LOG_OPERATE, greenStaffCardInfo.getUserId());
|
|||
|
|
|
|||
|
|
return new RestResult(Constant.SUCCESS, "申请成功");
|
|||
|
|
} catch (ServiceValidatorBaseException e) {
|
|||
|
|
//greenOperateLogBizc.addLog(Constant.STAFF_CARD, Constant.STAFF, Constant.OPERATE_FAIL, "员工卡申请", Constant.LOG_ERROR, greenStaffCardInfo.getUserId());
|
|||
|
|
//设置手动回滚
|
|||
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|||
|
|
e.printStackTrace();
|
|||
|
|
return new RestResult(Constant.FAILED,e.getMessage());
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
//greenOperateLogBizc.addLog(Constant.STAFF_CARD, Constant.STAFF, Constant.OPERATE_FAIL, "员工卡申请", Constant.LOG_ERROR, greenStaffCardInfo.getUserId());
|
|||
|
|
//设置手动回滚
|
|||
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|||
|
|
e.printStackTrace();
|
|||
|
|
return new RestResult(Constant.FAILED, "申请失败");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 根据id查询员工卡申请详情
|
|||
|
|
*
|
|||
|
|
* @param id
|
|||
|
|
* @param applyType
|
|||
|
|
* @return
|
|||
|
|
* @throws Exception
|
|||
|
|
*/
|
|||
|
|
@SuppressWarnings("unchecked")
|
|||
|
|
public List<Object> getStaffCardInfo(String id, String applyType,String userId) throws Exception {
|
|||
|
|
// String applyInfoByIdSql = " SELECT sci.*,REPLACE(sci.IDCard_no,SUBSTR(sci.IDCard_no,5,10), '**********') as IDCard_no ,al.detail_id,al.apply_type,al.apply_type_name,al.first_approval,"
|
|||
|
|
// + " al.first_status,al.second_approval,al.second_status,al.first_approve_time,al.second_approve_time,gii1.image_content AS pic1,"
|
|||
|
|
// + " CASE first_status WHEN '0' THEN '待审批' WHEN '1' THEN '已同意' WHEN '2' THEN '已拒绝' WHEN '3' THEN '已取消' END AS first_status_value,"
|
|||
|
|
// + " CASE second_status WHEN '4' THEN '待制卡' WHEN '5' THEN '已完成制卡' END AS second_status_value"
|
|||
|
|
// + " FROM GREEN_STAFF_CARD_INFO sci INNER JOIN GREEN_APPLY_LIST al ON sci.id = al.detail_id"
|
|||
|
|
// + " LEFT JOIN GREEN_IMAGE_INFO gii1 ON sci.entry_order_pic = gii1.id"
|
|||
|
|
// + " WHERE sci.id = ? AND al.apply_type = ?";
|
|||
|
|
// 根据用户id查询该用户具有的权限
|
|||
|
|
List<Map<String, Object>> 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 applyInfoByIdSql = " SELECT sci.*, IDCard_no,"
|
|||
|
|
+ " al.detail_id,al.apply_type,al.apply_type_name,al.first_approval,al.first_status,al.second_approval,al.second_status,"
|
|||
|
|
+ " al.first_approve_time,al.second_approve_time,third_approval,third_status,third_approve_time,sci.entry_order_pic AS pic1,"
|
|||
|
|
+ " CASE first_status WHEN '0' THEN '待审批' WHEN '1' THEN '已同意' WHEN '2' THEN '已拒绝' WHEN '3' THEN '已取消' END AS first_status_value,"
|
|||
|
|
+ " CASE second_status WHEN '0' THEN '待审批' WHEN '1' THEN '已同意' WHEN '2' THEN '已拒绝' WHEN '3' THEN '已取消' END AS second_status_value,"
|
|||
|
|
+ " CASE third_status WHEN '4' THEN '待制卡' WHEN '5' THEN '已完成制卡' END AS third_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,null))) AS status_code"
|
|||
|
|
+ " FROM GREEN_STAFF_CARD_INFO sci INNER JOIN GREEN_APPLY_LIST al ON sci.id = al.detail_id"
|
|||
|
|
// + " LEFT JOIN GREEN_IMAGE_INFO gii1 ON sci.entry_order_pic = gii1.id"
|
|||
|
|
+ " WHERE sci.id = ? AND al.apply_type = ?";
|
|||
|
|
List<Object> list= hibernateDao.queryForListWithSql(applyInfoByIdSql, new Object[] { id, applyType });
|
|||
|
|
|
|||
|
|
for(Object map:list){
|
|||
|
|
Map info=(Map)map;
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
|
|||
|
|
String entryOrderPic=(String)info.get("pic1");
|
|||
|
|
String imgBase=baseService.getImageBase64(entryOrderPic);
|
|||
|
|
info.put("pic1",imgBase);
|
|||
|
|
}
|
|||
|
|
return list;
|
|||
|
|
}
|
|||
|
|
}
|