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 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;
|
|
@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<Map<String, Object>> 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;
|
}
|
|
@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;
|
|
}
|
|
@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<String, Object> 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;
|
}
|
|
@RequestMapping("/getAllowOa.do")
|
public BackMsg getAttachmentAllow(@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);
|
String memo = attachmentOaIfc.getAttachmentAllow(param);
|
if (StringUtils.isBlank(memo)) {
|
msg.setFail("获取不到附件更新内容");
|
return msg;
|
}
|
String[] info = memo.split(";");
|
if (info.length == 9) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("allowViewNums", info[0]);
|
map.put("viewNums",info[1]);
|
map.put("allowDownNums",info[2]);
|
map.put("downNums",info[3]);
|
map.put("type", info[4]);
|
map.put("state", info[5]);
|
map.put("describe", info[6]);
|
map.put("totaViewNums", info[7]);
|
map.put("totaDownNums", info[8]);
|
msg.setOk(map);
|
}
|
} catch (Exception e) {
|
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
return msg;
|
}
|
|
/**
|
* 配置用户结构
|
*
|
* @param list
|
* @return
|
*/
|
private List<Map<String, Object>> Configure(List<Map<String, Object>> list) {
|
List<Map<String, Object>> out = new ArrayList<>();
|
try {
|
String filedId = "ccCode";
|
for (Map<String, Object> 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<Map<String, Object>> similar = list.stream().filter(l -> value.equals(DBHelper.getValue(l, filedId).toLowerCase())).collect(Collectors.toList());
|
//创建一个新map存放相同value
|
Map<String, Object> map = new HashMap<>();
|
map.put(filedId, DBHelper.getValue(m, filedId));
|
map.put("ccName", DBHelper.getValue(m, "ccName"));
|
List<AttachmentOaEntity> oaEntities = new ArrayList<>();
|
boolean check = true;//假设全部选中
|
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
for (Map<String, Object> 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);
|
String star = DBHelper.getValue(map1, "startDate");
|
oaEntity.setStartDate(StringUtils.isBlank(star) ? null : star.split(" ")[0]);
|
String end = DBHelper.getValue(map1, "endDate");
|
oaEntity.setEndDate(StringUtils.isBlank(end) ? null : end.split(" ")[0]);
|
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");
|
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;
|
}
|
|
|
}
|