package wjb.action.base; import java.io.File; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import wjb.action.BaseAction; import wjb.bean.EmployeBean; import wjb.constant.SystemConfigKey; import wjb.constant.WjbConstants; import wjb.model.BaseBussinessLog; import wjb.model.BaseEmploye; import wjb.model.BaseUser; import wjb.model.base.SessionInfo; import wjb.model.easyui.Grid; import wjb.model.easyui.Json; import wjb.service.BussinessLogServiceI; import wjb.service.EmployeServiceI; import wjb.service.UserServiceI; import wjb.utils.ConfigUtil; import wjb.utils.DateUtils; import wjb.utils.ExcelUtil; import wjb.utils.FileUtil; import wjb.utils.HqlFilter; import wjb.utils.MapToBeanUtil; import wjb.utils.SpringContextUtil; import wjb.utils.StringUtil; /** * @描述:员工相关业务 * @说明:暂无 * @版权:Copyright © 2018 wujiangbo. All Rights Reserved. @作者:吴江波(QQ:1134135987) @版本:1.0 * @创建日期:2018年5月22日 @创建时间:下午12:57:20 * @所属包名:wjb.action.base * @类的名称:EmployeAction.java */ @Action(value = "employeAction") @Namespace("/base") public class EmployeAction extends BaseAction<BaseEmploye> { private static final long serialVersionUID = -5142949982453225005L; private static final Logger log = Logger.getLogger(UserAction.class); private File photoContext; // 得到上传的图像文件 private String photoContextFileName; // 得到图像文件的名称 /** * @描述:注入业务逻辑,使当前action调用service.xxx的时候,直接是调用基础业务逻辑 * @说明:如果想调用自己特有的服务方法时,请使用((TServiceI) service).methodName()这种形式强转类型调用 * @作者姓名:吴江波(QQ:1134135987) @创建日期:2018年4月20日 @创建时间:下午11:02:48 * @方法名称:setService * @返回类型:void * @所属包名:wjb.action.base * @方法类名:UserAction * @param service */ @Autowired public void setService(EmployeServiceI service) { this.service = service; } @Autowired public void setServiceLog(BussinessLogServiceI service) { this.serviceLog = service; } // 记录员工操作日志 public void writeLog(String log_context) { SessionInfo sessionInfo = (SessionInfo) this.getSession().getAttribute(ConfigUtil.getSessionInfoName()); if (sessionInfo != null && sessionInfo.getUser() != null) { // 记录操作日志 BaseBussinessLog bussiness_log = new BaseBussinessLog(); bussiness_log.setUpdateUser(sessionInfo.getUser().getUserName()); bussiness_log.setLogDescs(log_context); serviceLog.save(bussiness_log); } } /** * @描述:获取前端采集的图像数据 * @作者:wujiangbo(QQ:1134135987) @时间:2018年8月15日 下午1:03:11 */ public void doNotNeedSecurity_getPhotoBase64Data() { String user_id = this.getRequest().getParameter("user_id");// 用户ID String base64_data = this.getRequest().getParameter("base64");// 图像base64数据 String image_save_path = "D:/2018.jpg"; FileUtil.decoderBase64File(base64_data, image_save_path);// 将前端上传的图像base64数据存到磁盘 BaseEmploye emp = service.getById(user_id); emp.setPhotoContext(WjbConstants.BASE64_HEADER + FileUtil.encodeBase64File(new File(image_save_path))); service.update(emp);// 更新此员工信息 Json json = new Json(); json.setSuccess(true); json.setMsg(StringUtil.getMessage("A000003")); writeJson(json); } // 给某员工赋予登录权限 public void grantLogin() { BaseEmploye emp = service.getById(id); BaseUser user = new BaseUser(); user.setId(StringUtil.getPrimaryKey()); user.setUpdateTime(new Date()); user.setUpdateUser(getCurrentUser().getUserName()); user.setBaseDep(emp.getBaseDep()); user.setLoginName(emp.getUserName()); user.setLoginPass(StringUtil.getPassWord(ConfigUtil.getDefaultLoginPass())); user.setUserNo(emp.getUserNo()); user.setUserName(emp.getUserName()); user.setSex(emp.getSex()); user.setPhotoContext(emp.getPhotoContext()); user.setIp(""); user.setPhone(emp.getPhone()); user.setSign(""); user.setEmail(emp.getEmail()); user.setLinkPhone(emp.getLinkPhone()); user.setLinkAddress(emp.getLinkAddress()); user.setBirthday(emp.getBirthday()); user.setIdCard(emp.getIdCard()); user.setQq(emp.getQq()); user.setPosition(emp.getPosition()); user.setUserState("0");// 0:正常;1:黑名单; ((EmployeServiceI) service).saveUser(user); Json json = new Json(); json.setSuccess(true); json.setMsg(StringUtil.getMessage("A000003")); writeLog("为员工[" + emp.getUserName() + "]赋予登录权限成功"); writeJson(json); } /** * 查找分页后的grid */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void grid() { String emp_state = this.getRequest().getParameter("emp_state"); String user_name = this.getRequest().getParameter("user_name"); String user_no = this.getRequest().getParameter("user_no"); String phone = this.getRequest().getParameter("phone"); String dep_id = this.getRequest().getParameter("dep_id"); String position = this.getRequest().getParameter("position"); String sex = this.getRequest().getParameter("sex"); String email = this.getRequest().getParameter("email"); Grid grid = new Grid(); Map<String, Object> params = new HashMap<String, Object>(); params.put("emp_state", StringUtils.isBlank(emp_state) ? "" : emp_state); params.put("user_name", StringUtils.isBlank(user_name) ? "" : user_name); params.put("user_no", StringUtils.isBlank(user_no) ? "" : user_no); params.put("phone", StringUtils.isBlank(phone) ? "" : phone); params.put("dep_id", StringUtils.isBlank(dep_id) ? "" : dep_id); params.put("position", StringUtils.isBlank(position) ? "" : position); params.put("sex", StringUtils.isBlank(sex) ? "" : sex); params.put("email", StringUtils.isBlank(email) ? "" : email); List<Map> list_data = ((EmployeServiceI) service).findEmployeInfoListBySql(params, page, rows); List<Map> list_size = ((EmployeServiceI) service).findEmployeInfoListCountBySql(params); if (list_data != null && list_data.size() > 0) { grid.setRows(list_data); } else { grid.setRows(new ArrayList<String>()); } if (list_size != null && list_size.size() > 0) { grid.setTotal((long) list_size.size()); } else { grid.setTotal(0L); } writeJson(grid); } /** * 获得一个对象 */ public void doNotNeedSecurity_getUserInfoById() { if (StringUtils.isNotBlank(id)) { writeJson(service.getById(id)); } else { Json j = new Json(); j.setMsg(StringUtil.getMessage("A000005")); writeJson(j); } } /** * 删除一个对象 */ @Override public void delete() { Json json = new Json(); if (!StringUtils.isBlank(id)) { BaseEmploye obj = service.getById(id); service.delete(obj); json.setSuccess(true); json.setMsg(StringUtil.getMessage("A000003")); writeLog("删除员工[" + obj.getUserName() + "]成功"); } writeJson(json); } // 更新 @Override public void update() { Json json = new Json(); try { if (data != null) { BaseEmploye user = service.getById(data.getId()); BeanUtils.copyProperties(data, user, new String[] { "loginPass", "lastLoginTime", "ip", "sign", "photoContext", "baseRoles" }); user.setUpdateUser(getCurrentUser().getUserName()); if (photoContext != null) { // 1、校验员工上传图像的格式 // 获取系统设置的格式限制 String user_photo_type = ((EmployeServiceI) service).getSystemInfoByKey(SystemConfigKey.USER_PHOTO_TYPE); // 获取上传文件格式 String upload_photo_type = StringUtil.getLastString(photoContextFileName, "."); if (StringUtils.isNotBlank(user_photo_type)) { if (!user_photo_type.contains(upload_photo_type)) { json.setMsg(StringUtil.getMessage("A000006") + user_photo_type); writeJson(json); return; } } // 2、校验员工上传图像的大小 // 获取系统设置的大小限制 String user_photo_size_temp = ((EmployeServiceI) service).getSystemInfoByKey(SystemConfigKey.USER_PHOTO_SIZE); if (StringUtils.isNotBlank(user_photo_size_temp)) { long user_photo_size = Long.valueOf(user_photo_size_temp);// 数据库中存的单位是MB user_photo_size = user_photo_size * 1024 * 1024;// 转换成字节 // 获取上传文件大小 long upload_photo_size = FileUtil.getFileSize(photoContext); if (upload_photo_size > user_photo_size) { json.setMsg(StringUtil.getMessage("A000007") + user_photo_size + " 字节"); writeJson(json); return; } } // 设置员工图像 user.setPhotoContext(WjbConstants.BASE64_HEADER + FileUtil.encodeBase64File(photoContext)); } service.update(user); json.setSuccess(true); json.setMsg(StringUtil.getMessage("A000003")); writeLog("更新员工[" + data.getUserName() + "]信息成功"); } } catch (BeansException e) { log.error(e.getLocalizedMessage(), e); json.setMsg(e.getLocalizedMessage()); } catch (Exception e) { log.error(e.getLocalizedMessage(), e); json.setMsg(e.getLocalizedMessage()); } writeJson(json); } // 导出员工信息到Excel @SuppressWarnings({ "rawtypes", "unchecked" }) synchronized public void exportEmployeInfo() { HttpServletResponse response = this.getResponse(); try { String fileName = "员工信息-" + DateUtils.getCurrentTimeString() + ".xlsx"; // 这样设置后,在火狐、360、谷歌、IE中测试成功,无乱码问题 fileName = new String(fileName.getBytes("GB2312"), "ISO_8859_1"); response.setCharacterEncoding(WjbConstants.SYSTEM_CHARACTER_ENCODING); response.setContentType("application/vnd.ms-excel;charset=" + WjbConstants.SYSTEM_CHARACTER_ENCODING); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setLocale(new java.util.Locale("zh", "CN")); OutputStream out = response.getOutputStream(); // 根据条件查询所有员工信息,然后到导出 Map<String, String> params = new HashMap<String, String>(); params.put("user_name", this.getRequest().getParameter("user_name")); params.put("user_no", this.getRequest().getParameter("user_no")); params.put("email", this.getRequest().getParameter("email")); params.put("phone", this.getRequest().getParameter("phone")); params.put("dep_id", this.getRequest().getParameter("dep_id")); params.put("position", this.getRequest().getParameter("position")); params.put("sex", this.getRequest().getParameter("sex")); params.put("emp_state", this.getRequest().getParameter("emp_state")); List<Map> employe_list = ((EmployeServiceI) service).getExportEmployeList(params); List<EmployeBean> emp_list = new ArrayList<EmployeBean>(); if (employe_list != null && employe_list.size() > 0) { EmployeBean emp = null; for (int i = 0; i < employe_list.size(); i++) { Map map = employe_list.get(i); emp = new EmployeBean(); emp_list.add((EmployeBean) MapToBeanUtil.transMap2Bean(map, emp)); } } ExcelUtil<EmployeBean> excelUtil = new ExcelUtil<EmployeBean>(); String[] headers = { "工号", "姓名", "身份证号", "部门", "职位", "员工状态", "生日", "手机号码", "性别", "邮箱", "联系电话", "联系地址", "入职日期", "离职日期", "劳动合同起始日期", "劳动合同终止日期", "QQ号", "微信号", "国籍", "籍贯", "民族", "毕业时间", "毕业学校", "学历", "专业", "血型", "健康状况", "婚姻状况", "政治面貌", "工资卡号", "社保账号", "公积金账号" }; excelUtil.exportExcel("员工信息", headers, emp_list, out, WjbConstants.DATE); out.close(); writeLog("导出员工信息到Excel"); } catch (Exception e) { log.error("导出Excel时发生异常:" + e.getLocalizedMessage(), e); } } // 保存 @Override public void save() { Json json = new Json(); // 首先检测人数是否达到上线 UserServiceI userService = (UserServiceI) SpringContextUtil.getBean("userServiceImpl"); String emp_max_count_str = userService.getSystemInfoByKey(SystemConfigKey.USER_MAX_COUNT, "2");// 类型(1:系统参数;2:资源配置;) // 如果从数据库取出来数据为空,则默认为50人 int emp_max_count = StringUtils.isBlank(emp_max_count_str) ? 50 : Integer.valueOf(emp_max_count_str); List<BaseEmploye> emp_list = service.find();// 当前员工总人数 if (emp_list.size() >= emp_max_count) { json.setMsg(StringUtil.getMessage("YW000023")); writeJson(json); return; } if (data != null) { // 首先检测姓名、工号是否已存在 HqlFilter hqlFilter2 = new HqlFilter(); hqlFilter2.addFilter("QUERY_t#userName_S_EQ", data.getUserName()); BaseEmploye user2 = service.getByFilter(hqlFilter2); if (user2 != null) { json.setMsg(StringUtil.getMessage("A000008")); writeJson(json); return; } HqlFilter hqlFilter3 = new HqlFilter(); hqlFilter3.addFilter("QUERY_t#userNo_S_EQ", data.getUserNo()); BaseEmploye user3 = service.getByFilter(hqlFilter3); if (user3 != null) { json.setMsg(StringUtil.getMessage("A000009")); writeJson(json); return; } data.setUpdateUser(getCurrentUser().getUserName()); service.save(data); json.setSuccess(true); json.setMsg(StringUtil.getMessage("A000003")); writeLog("新增员工[" + data.getUserName() + "]成功"); } writeJson(json); } // 根据员工ID查询员工信息 @SuppressWarnings({ "unchecked", "rawtypes" }) public void doNotNeedSecurity_getUserById() { String user_id = this.getRequest().getParameter("user_id"); if (StringUtils.isNotBlank(user_id)) { List<Map> obj_list = ((EmployeServiceI) service).getEmployeById(user_id); if (obj_list != null && obj_list.size() > 0) { writeJson(obj_list.get(0)); } } else { Json j = new Json(); j.setMsg(StringUtil.getMessage("A000005")); writeJson(j); } } public File getPhotoContext() { return photoContext; } public void setPhotoContext(File photoContext) { this.photoContext = photoContext; } public String getPhotoContextFileName() { return photoContextFileName; } public void setPhotoContextFileName(String photoContextFileName) { this.photoContextFileName = photoContextFileName; } }
最近下载更多
最近浏览更多
WBelong LV8
9月19日
wanxiaoqiao52866414 LV1
7月1日
quartz LV8
7月1日
荣》Cowboy LV12
4月11日
Gin19960217 LV4
1月15日
123456wadff LV3
1月15日
lasttimeapp
2023年11月27日
暂无贡献等级
季明亮
2023年11月21日
暂无贡献等级
微信网友_6657940693880832 LV1
2023年10月9日
haotzy LV3
2023年10月8日