package com.yc.action.upload; import com.yc.entity.attachment.AttachmentOAParam; import com.yc.entity.attachment.AttachmentOaEntity; import com.yc.multiData.SpObserver; import com.yc.phoneQRLogin.utils.BackMsg; import com.yc.service.impl.DBHelper; import com.yc.service.upload.AttachmentOaIfc; import com.yc.utils.SessionKey; import jodd.util.StringUtil; import org.apache.commons.lang3.StringUtils; import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Array; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @Author xinyb * @Date 14:43 2022/11/1 **/ @RestController @RequestMapping("/attachmentOa") public class AttachmentOA { @Autowired AttachmentOaIfc attachmentOaIfc; /** * 加载用户权限结构数据 * * @param unid * @param seq * @param keyword * @param request * @param response * @return */ @RequestMapping(value = "/userInfo.do", method = RequestMethod.GET) public BackMsg getAttachmentOAUserInfo(String unid, Integer seq, String keyword, HttpServletRequest request, HttpServletResponse response) { BackMsg msg = new BackMsg(); try { if (StringUtils.isBlank(unid)) { msg.setFail("附件控件唯一unid不能为空"); return msg; } if (seq == null || seq == 0) { msg.setFail("附件标识seq不能为空"); return msg; } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); List> list = attachmentOaIfc.getAttachmentOAUserInfo(unid, seq, keyword); if (list != null && list.size() > 0) { msg.setOk(Configure(list)); } else { if (StringUtils.isNotBlank(keyword)) { msg.setOk(list); return msg; } msg.setFail("获取不到用户信息"); } } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 加载设置了权限的用户 * * @param param * @param request * @return */ @RequestMapping("/oaUser.do") public BackMsg getAttachmentOAUser(@RequestBody AttachmentOAParam param, HttpServletRequest request) { BackMsg msg = new BackMsg(); try { if (StringUtils.isBlank(param.getUnid())) { msg.setFail("附件控件唯一unid不能为空"); return msg; } if (param.getSeq() == null || param.getSeq() == 0) { msg.setFail("附件标识seq不能为空"); return msg; } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); List oaUser = attachmentOaIfc.getAttachmentOAUser(param); msg.setOk(oaUser); } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 批量保存权限设置 * * @param param * @param request * @param response * @return */ @RequestMapping("/setUserOA.do") public BackMsg setAttachmentOAUser(@RequestBody AttachmentOAParam param, HttpServletRequest request, HttpServletResponse response) { BackMsg msg = new BackMsg(); try { if (param == null || StringUtils.isBlank(param.getUnid())) { msg.setFail("参数错误"); return msg; } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); Integer cont = attachmentOaIfc.setAttachmentOAUser(param); msg.setOk("设置成功"); } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 保存单个权限设置人员 * * @param param * @param request * @return */ @RequestMapping("/setUser.do") public BackMsg setAttachmentUser(@RequestBody AttachmentOaEntity param, HttpServletRequest request) { BackMsg msg = new BackMsg(); try { if (param == null || StringUtils.isBlank(param.getUnid())) { msg.setFail("参数错误"); return msg; } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); String demo = attachmentOaIfc.setAttachmentUser(param); msg.setOk(demo); } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 是否有权限显示 ,下载,更新(弃用,前端不需要请求这个接口) * * @param param * @param request * @return */ @RequestMapping("/getOAInfo.do") public BackMsg getAttachmentOAInfo(@RequestBody AttachmentOAParam param, HttpServletRequest request) { BackMsg msg = new BackMsg(); try { if (StringUtils.isBlank(param.getUnid()) || param.getSeq() == null || param.getSeq() == 0) { msg.setFail("附件的参数信息不能为空"); return msg; } if (StringUtils.isBlank(param.getUserCode())) { param.setUserCode((String) request.getSession().getAttribute(SessionKey.HRCODE)); } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); Map info = attachmentOaIfc.getAttachmentOAInfo(param); if (info == null) { msg.setFail("无法找到附件内容,检查附件参数是否正确"); return msg; } msg.setOk(info); } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 执行更新次数操作 * * @param param * @param request * @return */ @RequestMapping("/getAllowOa.do") public BackMsg getAttachmentAllow(@RequestBody AttachmentOAParam param, HttpServletRequest request) { BackMsg msg = new BackMsg(); try { if (StringUtils.isBlank(param.getUnid()) || param.getSeqArray().size() < 1) { msg.setFail("附件的参数信息不能为空"); return msg; } if (StringUtils.isBlank(param.getUserCode())) { param.setUserCode((String) request.getSession().getAttribute(SessionKey.HRCODE)); } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); List> list = new ArrayList<>(); for (Integer seq : param.getSeqArray()) { param.setSeq(seq); String memo = attachmentOaIfc.getAttachmentAllow(param); if (StringUtils.isBlank(memo)) { continue; } String[] info = memo.split(";"); if (info.length == 15) { Map map = new HashMap<>(); map.put("describe", info[0]); map.put("state", info[1]); map.put("allowViewNums", info[2]); map.put("allowDownNums", info[3]); map.put("viewNums", info[4]); map.put("downNums", info[5]); map.put("updateNums", info[6]); map.put("totaViewNums", info[7]); map.put("totaDownNums", info[8]); map.put("totaUpdateNums", info[9]); map.put("fileName", info[10]); map.put("seq",info[11]); map.put("startTime",info[12]); map.put("endTime",info[13]); map.put("dateFlag",info[14]); list.add(map); } } msg.setOk(list); } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 删除附件权限人员 * * @param param * @param request * @return */ @RequestMapping("/deleteAttachmentOa.do") public BackMsg getAttachmentDelete(@RequestBody AttachmentOAParam param, HttpServletRequest request) { BackMsg msg = new BackMsg(); try { if (StringUtils.isBlank(param.getUnid()) || param.getSeq() == null || param.getSeq() == 0) { msg.setFail("附件的参数信息不能为空"); return msg; } if (StringUtils.isBlank(param.getUserCode())) { msg.setFail("删除的用户Code不能为空"); return msg; } String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID); SpObserver.setDBtoInstance("_" + dbId); String demo = attachmentOaIfc.getAttachmentDelete(param); msg.setOk(demo); } catch (Exception e) { msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); } finally { SpObserver.setDBtoInstance(); } return msg; } /** * 配置用户结构 * * @param list * @return */ private List> Configure(List> list) { List> out = new ArrayList<>(); try { String filedId = "ccCode"; for (Map m : list) { String value = DBHelper.getValue(m, filedId).toLowerCase(); if (out.stream().filter(o -> value.equals(o.get(filedId) != null ? o.get(filedId).toString().toLowerCase() : "")).count() == 0) {//等于0表示还没有组装到value值 //获取相同value的集合 List> similar = list.stream().filter(l -> value.equals(DBHelper.getValue(l, filedId).toLowerCase())).collect(Collectors.toList()); //创建一个新map存放相同value Map map = new HashMap<>(); map.put(filedId, DBHelper.getValue(m, filedId)); map.put("ccName", DBHelper.getValue(m, "ccName")); List oaEntities = new ArrayList<>(); boolean check = true;//假设全部选中 SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (Map map1 : similar) { AttachmentOaEntity oaEntity = new AttachmentOaEntity(); oaEntity.setCcCode(DBHelper.getValue(map1, filedId)); oaEntity.setCcName(DBHelper.getValue(map1, "ccName")); oaEntity.setUserCode(DBHelper.getValue(map1, "userCode")); oaEntity.setUserName(DBHelper.getValue(map1, "userName")); oaEntity.setHasView(DBHelper.getValueInt(map1, "hasView") == 1 ? true : false); oaEntity.setHasDownload(DBHelper.getValueInt(map1, "hasDownLoad") == 1 ? true : false); oaEntity.setHasDelete(DBHelper.getValueInt(map1, "hasDelete") == 1 ? true : false); oaEntity.setHasUpdate(DBHelper.getValueInt(map1, "hasUpdate") == 1 ? true : false); oaEntity.setHasAuthor(DBHelper.getValueInt(map1, "hasAuthor") == 1 ? true : false); String star = DBHelper.getValue(map1, "startDate"); oaEntity.setStartDate(StringUtils.isBlank(star) ? null : star.substring(0, 19)); String end = DBHelper.getValue(map1, "endDate"); oaEntity.setEndDate(StringUtils.isBlank(end) ? null : end.substring(0, 19)); String dateFlag = DBHelper.getValue(map1, "dateFlag"); if (StringUtils.isBlank(dateFlag)) { dateFlag = "2"; } oaEntity.setDateFlag(Integer.parseInt(dateFlag)); oaEntity.setAllowViewNums(DBHelper.getValueInt(map1, "allowViewNums")); oaEntity.setAllowDownNums(DBHelper.getValueInt(map1, "allowDownNums")); oaEntity.setAllowUpdateNums(DBHelper.getValueInt(map1, "allowUpdateNums")); oaEntity.setViewNums(DBHelper.getValueInt(map1, "viewNums")); oaEntity.setDownNums(DBHelper.getValueInt(map1, "downNums")); oaEntity.setUpdateNums(DBHelper.getValueInt(map1, "updateNums")); Integer checked = DBHelper.getValueInt(map1, "checked"); if (oaEntity.isHasAuthor()) { oaEntity.setHasView(true); oaEntity.setHasUpdate(true); oaEntity.setHasDelete(true); oaEntity.setHasDownload(true); checked = 1; } oaEntity.setChecked(checked == 1 ? true : false); if (checked == 0) { check = false; } oaEntities.add(oaEntity); } map.put("checked", check); map.put("info", oaEntities); //把相同的value的map组装到out里 out.add(map); } } } catch (Exception e) { throw e; } return out; } }