|
@@ -3,27 +3,31 @@ package com.usky.oa.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.oa.domain.OaDocument;
|
|
|
+import com.usky.oa.domain.OaFormDefinition;
|
|
|
import com.usky.oa.domain.OaJbdDocument;
|
|
|
import com.usky.oa.domain.OaQjdDocument;
|
|
|
import com.usky.oa.mapper.OaDocumentMapper;
|
|
|
+import com.usky.oa.mapper.OaFormDefinitionMapper;
|
|
|
import com.usky.oa.mapper.OaJbdDocumentMapper;
|
|
|
import com.usky.oa.mapper.OaQjdDocumentMapper;
|
|
|
import com.usky.oa.service.OaDocumentService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
-import com.usky.oa.service.vo.OaApprovalCountVO;
|
|
|
+import com.usky.oa.service.OaJbdDocumentService;
|
|
|
+import com.usky.oa.service.OaQjdDocumentService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -42,11 +46,23 @@ public class OaDocumentServiceImpl extends AbstractCrudService<OaDocumentMapper,
|
|
|
@Autowired
|
|
|
private OaQjdDocumentMapper oaQjdDocumentMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OaQjdDocumentService oaQjdDocumentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OaJbdDocumentService oaJbdDocumentService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private OaJbdDocumentMapper oaJbdDocumentMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
+ private OaDocumentMapper documentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OaFormDefinitionMapper oaFormDefinitionMapper;
|
|
|
+
|
|
|
+ private static final String TABLE_HEAD = "oa_";
|
|
|
+ private static final String TABLE_SUFFIX = "_document";
|
|
|
|
|
|
// 我的申请
|
|
|
@Override
|
|
@@ -65,6 +81,7 @@ public class OaDocumentServiceImpl extends AbstractCrudService<OaDocumentMapper,
|
|
|
return ToCommonPage(page(new Page<>(pageNum, pageSize), wrapper));
|
|
|
}
|
|
|
|
|
|
+ // 单据详情
|
|
|
@Override
|
|
|
public Object documentDetails(String docNo) {
|
|
|
Object documentDetails = null;
|
|
@@ -82,6 +99,7 @@ public class OaDocumentServiceImpl extends AbstractCrudService<OaDocumentMapper,
|
|
|
return documentDetails;
|
|
|
}
|
|
|
|
|
|
+ // 删除单据
|
|
|
@Override
|
|
|
public void delDocument(String docNo) {
|
|
|
String type = getFormSign(docNo);
|
|
@@ -96,47 +114,95 @@ public class OaDocumentServiceImpl extends AbstractCrudService<OaDocumentMapper,
|
|
|
oaDocumentMapper.delete(Wrappers.lambdaQuery(OaDocument.class).eq(OaDocument::getDocNo, docNo));
|
|
|
}
|
|
|
|
|
|
+ // 新增单据
|
|
|
@Override
|
|
|
- public void addDoc(Object oaDocument) {
|
|
|
+ public void addDoc(JSONObject oaDocument) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<OaFormDefinition> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(OaFormDefinition::getFieldInfo).eq(OaFormDefinition::getId, oaDocument.get("formId"));
|
|
|
+ OaFormDefinition oaFormDefinition = oaFormDefinitionMapper.selectOne(queryWrapper);
|
|
|
+ String sign = oaFormDefinition.getFieldInfo();
|
|
|
|
|
|
+ switch (sign) {
|
|
|
+ case "QJD":
|
|
|
+ oaQjdDocumentService.addQjDocument(JSON.parseObject(oaDocument.toJSONString(), OaQjdDocument.class));
|
|
|
+ break;
|
|
|
+ case "JBD":
|
|
|
+ oaJbdDocumentService.add(oaDocument.toJavaObject(OaJbdDocument.class));
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ // 更新单据
|
|
|
@Override
|
|
|
- public void updateDoc(Object oaDocument) {
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(oaDocument));
|
|
|
- String docNo = jsonObject.get("docNo").toString();
|
|
|
- String type = getFormSign(docNo);
|
|
|
- String tableName = "oa_" + type + "_document";
|
|
|
-
|
|
|
- StringBuilder setClause = new StringBuilder();
|
|
|
- // 假设JSON对象中的键值对即为需要更新的字段和值
|
|
|
- jsonObject.forEach((key, value) -> {
|
|
|
- if (!"docNo".equals(key)) {
|
|
|
- setClause.append(key).append(" = '").append(value.toString()).append("', ");
|
|
|
- }
|
|
|
- });
|
|
|
- setClause.setLength(setClause.length() - 2); // 移除最后的逗号和空格
|
|
|
-
|
|
|
- String sql = "UPDATE " + tableName + " SET " + setClause.toString() + " WHERE docNo = '" + docNo + "'";
|
|
|
- jdbcTemplate.update(sql);
|
|
|
+ public void updateDoc(JSONObject jsonDocument) {
|
|
|
+
|
|
|
+ String username = SecurityUtils.getUsername();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedNow = now.format(formatter);
|
|
|
+
|
|
|
+ Map<String, Object> updateMap = jsonDocument.getInnerMap();
|
|
|
+ String docNo = jsonDocument.get("docNo").toString();
|
|
|
+ HashMap<String, Object> updateHashMap = new HashMap<>(updateMap);
|
|
|
+ String tableName = (TABLE_HEAD + getFormSign(docNo) + TABLE_SUFFIX).toLowerCase();
|
|
|
+ updateHashMap.put("tableName", tableName);
|
|
|
+ updateHashMap.put("updateBy", username);
|
|
|
+ updateHashMap.put("updateTime", formattedNow);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(updateMap.get("docStatus").toString())) {
|
|
|
+ throw new BusinessException("单据状态不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新具体单据表
|
|
|
+ if (!updateMap.containsKey("id")) {
|
|
|
+ throw new BusinessException("更新单据id不能为空!");
|
|
|
+ }
|
|
|
+ documentMapper.updateData(updateHashMap);
|
|
|
+
|
|
|
+ // 更新单据总表
|
|
|
+ oaDocumentMapper.update(null, Wrappers.lambdaUpdate(OaDocument.class)
|
|
|
+ .set(OaDocument::getDocStatus, updateMap.get("docStatus"))
|
|
|
+ .set(OaDocument::getUpdateBy, username)
|
|
|
+ .set(OaDocument::getUpdateTime, now)
|
|
|
+ .eq(OaDocument::getDocNo, docNo));
|
|
|
}
|
|
|
|
|
|
+ // 提交单据
|
|
|
@Override
|
|
|
public void submit(String docNo, Integer status) {
|
|
|
if (status != 1) {
|
|
|
throw new RuntimeException("单据提交异常,请联系管理员!");
|
|
|
}
|
|
|
String formSign = getFormSign(docNo);
|
|
|
+
|
|
|
+ String username = SecurityUtils.getUsername();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+
|
|
|
switch (formSign) {
|
|
|
case "QJD":
|
|
|
- oaQjdDocumentMapper.update(null, Wrappers.lambdaUpdate(OaQjdDocument.class).set(OaQjdDocument::getDocStatus, status).eq(OaQjdDocument::getDocNo, docNo));
|
|
|
+ oaQjdDocumentMapper.update(null, Wrappers.lambdaUpdate(OaQjdDocument.class)
|
|
|
+ .set(OaQjdDocument::getDocStatus, status)
|
|
|
+ .set(OaQjdDocument::getUpdateBy, username)
|
|
|
+ .set(OaQjdDocument::getUpdateTime, now)
|
|
|
+ .eq(OaQjdDocument::getDocNo, docNo));
|
|
|
break;
|
|
|
case "JBD":
|
|
|
- oaJbdDocumentMapper.update(null, Wrappers.lambdaUpdate(OaJbdDocument.class).set(OaJbdDocument::getDocStatus, status).eq(OaJbdDocument::getDocNo, docNo));
|
|
|
+ oaJbdDocumentMapper.update(null, Wrappers.lambdaUpdate(OaJbdDocument.class)
|
|
|
+ .set(OaJbdDocument::getDocStatus, status)
|
|
|
+ .set(OaJbdDocument::getUpdateBy, username)
|
|
|
+ .set(OaJbdDocument::getUpdateTime, now)
|
|
|
+ .eq(OaJbdDocument::getDocNo, docNo));
|
|
|
+ break;
|
|
|
}
|
|
|
- oaDocumentMapper.update(null, Wrappers.lambdaUpdate(OaDocument.class).set(OaDocument::getDocStatus, status).eq(OaDocument::getDocNo, docNo));
|
|
|
+ oaDocumentMapper.update(null, Wrappers.lambdaUpdate(OaDocument.class)
|
|
|
+ .set(OaDocument::getDocStatus, status)
|
|
|
+ .set(OaDocument::getUpdateBy, username)
|
|
|
+ .set(OaDocument::getUpdateTime, now)
|
|
|
+ .eq(OaDocument::getDocNo, docNo));
|
|
|
}
|
|
|
|
|
|
+ // 获取单据类型
|
|
|
private String getFormSign(String docNo) {
|
|
|
if (StringUtils.isBlank(docNo)) {
|
|
|
throw new RuntimeException("单据号不能为空!");
|