Commit 045ca186 by HlQ

[add] 添加文件更新接口

[chg] 代码优化
1 parent 4aa3ec52
......@@ -14,8 +14,6 @@
<artifactId>Vion-DevOps</artifactId>
<version>1</version>
<properties>
<pg.version>42.7.3</pg.version>
<lombok.version>1.18.34</lombok.version>
<hutool.version>6.0.0-M13</hutool.version>
<redisson.verion>3.32.0</redisson.verion>
<mapstruct-plus.version>1.4.3</mapstruct-plus.version>
......@@ -30,12 +28,10 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${pg.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
......
......@@ -10,6 +10,7 @@ import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.io.file.FileNameUtil;
import org.dromara.hutool.core.io.file.FileUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.net.url.UrlEncoder;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
......@@ -94,13 +95,23 @@ public class FileController {
return "文件删除成功";
}
@PostMapping("/file/{id}")
@SaCheckPermission(value = "file:update", orRole = "admin")
public String updateFile(@PathVariable Long id, @RequestBody FileInfoDTO dto) {
Assert.notNull(dto.getUpdFlag(), "更新标识符不能为空!");
return fileService.lambdaUpdate()
.eq(FileInfo::getId, id)
.set(ObjUtil.isNotNull(dto.getSourceType()), FileInfo::getSourceType, dto.getSourceType())
.set(ObjUtil.isNotNull(dto.getContractId()), FileInfo::getContractId, dto.getContractId())
.update() ? "修改成功" : "修改失败";
}
@PostMapping("/file/formFileUpload")
@SaCheckPermission(value = "file:form:upload", orRole = "admin")
public String uploadFile(FileInfoDTO dto, @RequestParam(name = "file") MultipartFile infile) throws IOException {
String orgName = infile.getOriginalFilename();
String mainName = FileNameUtil.mainName(orgName);
String fileExt = FileNameUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS"), fileExt);
String filename = FileNameUtil.mainName(infile.getOriginalFilename()) + "_" +
DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS") + "." +
FileNameUtil.extName(infile.getOriginalFilename());
String path = getPath(dto, filename);
File file = FileUtil.touch(path);
infile.transferTo(file);
......@@ -113,12 +124,7 @@ public class FileController {
tempFileInfo.setType(FileNameUtil.extName(file));
tempFileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
tempFileInfo.setUploader(dto.getUploader());
if (fileService.save(tempFileInfo)) {
return path;
} else {
return "文件保存失败";
}
return fileService.save(tempFileInfo) ? path : "文件保存失败";
}
private String getPath(FileInfoDTO dto, String filename) {
......@@ -135,10 +141,9 @@ public class FileController {
@SaCheckPermission(value = "file:upload", orRole = "admin")
public String uploadFile1(FileInfo fileInfo, @RequestParam(name = "files") MultipartFile[] files) throws IOException {
for (MultipartFile infile : files) {
String orgName = infile.getOriginalFilename();
String mainName = FileNameUtil.mainName(orgName);
String fileExt = FileNameUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS"), fileExt);
String filename = FileNameUtil.mainName(infile.getOriginalFilename()) + "_" +
DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS") + "." +
FileNameUtil.extName(infile.getOriginalFilename());
String path = fileUrl + FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
infile.transferTo(file);
......@@ -153,7 +158,6 @@ public class FileController {
tempFileInfo.setType(FileNameUtil.extName(file));
tempFileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
tempFileInfo.setUploader(fileInfo.getUploader());
fileService.save(tempFileInfo);
}
return "文件保存成功";
......
......@@ -52,10 +52,6 @@ public class InspectController {
//审核状态为已完成的时候更新完成时间(0进行中、1待审核、2已完成、3、驳回)
.set(data.getStatus() == 2, Inspect::getFinishDate, new Date())
.update();
if (result) {
return "更新巡检状态成功";
} else {
return "更新巡检状态失败";
}
return result ? "更新巡检状态成功" : "更新巡检状态失败";
}
}
......@@ -85,14 +85,4 @@ public class PaymentController {
}
}
@GetMapping("/openSafe")
public String openSafe(String code) {
// 校验 redis 里查询 code 相关信息
if (true) {
StpUtil.openSafe("payment", 600);
return "认证成功";
}
return "认证失败";
}
}
......@@ -3,11 +3,13 @@ package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.text.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.util.ObjUtil;
import org.springframework.web.bind.annotation.*;
import vion.dto.RoleDTO;
import vion.model.*;
......@@ -50,9 +52,7 @@ public class RoleController {
@PostMapping("/role")
@SaCheckPermission(value = "role:save", orRole = "admin")
public String save(@RequestBody RoleDTO dto) {
if (StrUtil.equals(dto.getCode(), "admin")) {
return "管理员角色编码[admin]已存在,不允许再次创建";
}
Assert.isFalse(StrUtil.equals(dto.getCode(), "admin"), "管理员角色编码[admin]已存在,不允许再次创建");
Role role = converter.convert(dto, Role.class);
return roleService.save(role) ? "创建成功" : "创建失败";
}
......@@ -60,9 +60,7 @@ public class RoleController {
@PostMapping("/role/{id}")
@SaCheckPermission(value = "role:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody RoleDTO dto) {
if (id == 1) {
return "管理员角色不允许修改";
}
Assert.isFalse(ObjUtil.equals(id, 1), "管理员角色不允许修改");
Role role = converter.convert(dto, Role.class);
role.setId(id);
return roleService.updateById(role) ? "更新成功" : "更新失败";
......@@ -71,9 +69,7 @@ public class RoleController {
@DeleteMapping("/role/{id}")
@SaCheckPermission(value = "role:remove", orRole = "admin")
public String remove(@PathVariable Long id) {
if (id == 1) {
return "管理员角色不允许删除";
}
Assert.isFalse(ObjUtil.equals(id, 1), "管理员角色不允许修改");
return roleService.removeById(id) ? "删除成功" : "删除失败";
}
......
......@@ -32,6 +32,8 @@ public class FileInfoDTO extends BaseDTO {
private String sha256;
/** 上传人 */
private String uploader;
/** 标识:storeLog */
/** 标识:storeLog,用于区分项目日志的表单文件的提交存储和其他通用表单的文件存储 */
private String flag;
/** 更新标识,更新接口不传该字段,不允许更新文件:1.项目资料 */
private Integer updFlag;
}
......@@ -40,6 +40,7 @@ import vion.dto.RContractTeamDTO;
import vion.mapper.ContractMapper;
import vion.mapper.SettlementDiffMapper;
import vion.model.*;
import vion.model.Dictionary;
import vion.service.*;
import vion.third.DingMod;
import vion.vo.*;
......@@ -407,8 +408,8 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
Map<String, Object> map = MapUtil.<String, Object>builder()
.put("totalAmount", financialAgeVOList.stream().map(FinancialAgeVO::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add)).build();
// 手动分页 todo hutool 6.0 暂时没有
int[] transToStartEnd = {(dto.getPageNum() - 1 ) * dto.getPageSize(),
(dto.getPageNum() - 1 ) * dto.getPageSize() + dto.getPageSize()};
int[] transToStartEnd = {(dto.getPageNum() - 1) * dto.getPageSize(),
(dto.getPageNum() - 1) * dto.getPageSize() + dto.getPageSize()};
Page<FinancialAgeVO> financialAgeVOPage = Page.<FinancialAgeVO>of(dto.getPageNum(), dto.getPageSize(), financialAgeVOList.size())
.setRecords(CollUtil.sub(financialAgeVOList, transToStartEnd[0], transToStartEnd[1]));
map.put("list", financialAgeVOPage);
......@@ -561,7 +562,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var fileArr = JSONUtil.parseObj(v).getJSONObject("data").getJSONArray("file_1");
var contractNo = JSONUtil.parseObj(v).getJSONObject("data").getStr("serialNo");
return JSONUtil.ofObj().set("contractNo", contractNo).set("fileArr", fileArr);
}).collect(Collectors.toList());
}).toList();
fileList.addAll(fileListR);
}
......@@ -572,6 +573,7 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
var contractId2Sha256Map = fileInfoList.stream().collect(Collectors.groupingBy(FileInfo::getContractId,
Collectors.mapping(FileInfo::getSha256, Collectors.toList())));
List<FileInfo> saveFileInfoList = new ArrayList<>();
for (JSONObject entries : fileList) {
var contractNo = entries.getStr("contractNo");
var fileArr = entries.getJSONArray("fileArr");
......@@ -585,7 +587,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
continue;
}
List<FileInfo> saveFileInfoList = new ArrayList<>();
for (Object o : fileArr) {
var fileObj = JSONUtil.parseObj(o);
var filename = fileObj.getStr("filename");
......@@ -611,8 +612,8 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
fileInfo.setUploader("销帮帮同步");
saveFileInfoList.add(fileInfo);
}
fileService.saveBatch(saveFileInfoList);
}
fileService.saveBatch(saveFileInfoList);
log.info("同步销帮帮合同文件[完成]");
return "销帮帮合同文件同步完成,请核对已同步文件!";
}
......@@ -703,9 +704,9 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd());
if (StrUtil.isNotBlank(dto.getOperator()) && ObjUtil.isNotNull(dto.getAmount())) {
String ope = dto.getOperator();
if (">" .equals(ope)) {
if (">".equals(ope)) {
wrapper.gt(getCol(dto), dto.getAmount());
} else if ("<" .equals(ope)) {
} else if ("<".equals(ope)) {
wrapper.lt(getCol(dto), dto.getAmount());
} else {
wrapper.eq(getCol(dto), dto.getAmount());
......@@ -772,13 +773,197 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
return jsonObj;
}
private static class Result {
public final Set<String> roleCodeList;
public final MPJLambdaWrapper<Contract> wrapper;
private record Result(Set<String> roleCodeList, MPJLambdaWrapper<Contract> wrapper) {
}
/*
* todo
* 1.校验合同数量,以及合同编号
* 2.校验合同金额
* */
public JSONObject ver() {
var contractNoList = this.listObjs(v -> ((Contract) v).getContractNo());
var json = JSONUtil.ofObj()
.set("sortMap", JSONUtil.ofObj()
.set("field", "updateTime")
.set("sort", "desc"))
.set("conditions", JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("attr", "date_3")
.set("symbol", "greaterequal")
.set("value", new String[]{"1715356800"}))
)
.set("corpid", corpId)
.set("formId", 8429903)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var jobO = JSONUtil.parseObj(res.bodyStr());
if (jobO.getInt("code") != 1) {
log.error("获取合同列表失败,错误原因:{}", jobO);
return json;
}
Integer cnt = jobO.getJSONObject("result").getInt("totalCount");
Integer page = jobO.getJSONObject("result").getInt("totalPage");
if (NumberUtil.equals(cnt, 0)) {
log.info("没有需要插入或更新的合同");
return json;
}
var jsonArray = jobO.getJSONObject("result").getJSONArray("list");
// 合同编号
var dataIdSet =
jsonArray.stream().map(v -> JSONUtil.parseObj(v).getJSONObject("data").getStr("serialNo")).collect(Collectors.toSet());
for (int i = 2; i <= page; i++) {
var jsonR = JSONUtil.ofObj()
.set("sortMap", JSONUtil.ofObj()
.set("field", "updateTime")
.set("order", "desc"))
.set("conditions", JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("attr", "date_3")
.set("symbol", "greaterequal")
.set("value", new String[]{"1715356800"}))
)
.set("corpid", corpId)
.set("formId", 8429903)
.set("page", i)
.set("pageSize", 100);
var resR = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
.header("sign", SecureUtil.sha256(jsonR.toString() + token))
.body(jsonR.toString())
.method(Method.POST)
.send();
var jobR = JSONUtil.parseObj(resR.bodyStr());
var jsonArrR = jobR.getJSONObject("result").getJSONArray("list");
var dataIdSetR = jsonArrR.stream().map(v -> JSONUtil.parseObj(v).getJSONObject("data").getStr("serialNo")).collect(Collectors.toSet());
dataIdSet.addAll(dataIdSetR);
}
// 返回销帮帮存在,但项目运维管理平台不存在的合同
var unsyncedList = CollUtil.subtractToList(dataIdSet, contractNoList);
// 返回项目运维管理平台存在,但销帮帮不存在的合同(可能销帮帮对该合同删除了)
var extraList = CollUtil.subtractToList(contractNoList, dataIdSet);
return JSONUtil.ofObj().set("unsynced", unsyncedList).set("extra", extraList);
}
public JSONObject contractDiff(String contractNo) {
var platContract = this.lambdaQuery().eq(Contract::getContractNo, contractNo).one();
var json = JSONUtil.ofObj()
.set("conditions", JSONUtil.ofArray()
.put(JSONUtil.ofObj()
.set("attr", "serialNo")
.set("symbol", "equal")
.set("value", new String[]{contractNo}))
)
.set("corpid", corpId)
.set("formId", 8429903)
.set("pageSize", 100);
var res = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/list")
.header("sign", SecureUtil.sha256(json.toString() + token))
.body(json.toString())
.method(Method.POST)
.send();
var jobO = JSONUtil.parseObj(res.bodyStr());
if (jobO.getInt("code") != 1) {
log.error("获取合同列表失败,错误原因:{}", jobO);
return json;
}
var jsonArray = jobO.getJSONObject("result").getJSONArray("list");
// 合同记录唯一 dataId
var dataIdSet = jsonArray.stream().map(v -> JSONUtil.parseObj(v).getInt("dataId")).collect(Collectors.toSet());
public Result(Set<String> roleCodeList, MPJLambdaWrapper<Contract> wrapper) {
this.roleCodeList = roleCodeList;
this.wrapper = wrapper;
var json1 = JSONUtil.ofObj()
.set("corpid", corpId)
.set("dataId", CollUtil.getFirst(dataIdSet));
var res1 = Request.of("https://proapi.xbongbong.com/pro/v2/api/contract/detail")
.header("sign", SecureUtil.sha256(json1.toString() + token))
.body(json1.toString())
.method(Method.POST)
.send();
var jobj1 = JSONUtil.parseObj(res1.bodyStr());
if (jobj1.getInt("code") != 1) {
log.error("获取合同详情失败,错误原因:{}", jobj1);
return json;
}
var result = jobj1.getJSONObject("result");
var jsonObj1 = result.getJSONObject("data");
Map<String, Integer> contractTypeMap = Db.list(Wrappers.<Dictionary>lambdaQuery().eq(Dictionary::getType, "contract_type"))
.stream()
.collect(Collectors.toMap(Dictionary::getValue, Dictionary::getKey));
Contract xbongContract = new Contract();
xbongContract.setName(jsonObj1.getStr("text_14"));
xbongContract.setContractNo(jsonObj1.getStr("serialNo"));
xbongContract.setType(contractTypeMap.getOrDefault(jsonObj1.getJSONObject("text_17").getStr("text"), 0));
xbongContract.setSignDate(DateUtil.date(jsonObj1.getLong("date_1") * 1000));
xbongContract.setMaintainSdate(Opt.ofNullable(jsonObj1.getLong("date_4")).map(sec -> DateUtil.date(sec * 1000)).orElse(null));
xbongContract.setMaintainEdate(Opt.ofNullable(jsonObj1.getLong("date_5")).map(sec -> DateUtil.date(sec * 1000)).orElse(null));
String warrantyPeriod = Opt.ofNullable(jsonObj1.getJSONObject("text_23")).map(wp -> wp.getStr("text")).orElse("");
if (StrUtil.isNotBlank(warrantyPeriod) && warrantyPeriod.contains("个月")) {
String substring = warrantyPeriod.substring(0, (warrantyPeriod.length() - 2));
xbongContract.setWarrantyPeriod(Integer.parseInt(substring));
}
xbongContract.setStatus(1);
xbongContract.setTotalAmount(jsonObj1.getBigDecimal("num_1"));
xbongContract.setPaidAmount(BigDecimal.ZERO);
xbongContract.setReceivableAmount(BigDecimal.ZERO);
xbongContract.setOutstandingAmount(jsonObj1.getBigDecimal("num_1"));
var paymentForm = jsonObj1.getJSONArray("subForm_1");
if (!paymentForm.isEmpty()) {
paymentForm.forEach(pf -> {
var pfObj = JSONUtil.parseObj(pf);
var ratio = NumberUtil.div(BigDecimal.valueOf(Double.parseDouble(pfObj.getStr("text_1"))), 100);
var date = DateUtil.date(pfObj.getLong("date_1") * 1000);
var stage = pfObj.getJSONObject("text_2").getStr("text");
if (StrUtil.equals(stage, "预付款")) {
xbongContract.setSignRatio(ratio);
xbongContract.setSignDate1(date);
} else if (StrUtil.equals(stage, "到货款")) {
xbongContract.setArriveRatio(ratio);
xbongContract.setArriveDate(date);
} else if (StrUtil.equals(stage, "系统验收款")) {
xbongContract.setSystemCheckRatio(ratio);
xbongContract.setSystemCheckDate(date);
} else if (StrUtil.equals(stage, "项目终验款")) {
xbongContract.setProjectCheckRatio(ratio);
xbongContract.setProjectCheckDate(date);
} else if (StrUtil.equals(stage, "质保款")) {
xbongContract.setWarrantyRatio(ratio);
xbongContract.setWarrantyDate(date);
} else if (StrUtil.equals(stage, "维保第一笔款")) {
xbongContract.setMaintainRatio1(ratio);
xbongContract.setMaintainDate1(date);
} else if (StrUtil.equals(stage, "维保第二笔款")) {
xbongContract.setMaintainRatio2(ratio);
xbongContract.setMaintainDate2(date);
} else if (StrUtil.equals(stage, "维保第三笔款")) {
xbongContract.setMaintainRatio3(ratio);
xbongContract.setMaintainDate3(date);
} else if (StrUtil.equals(stage, "维保进度款")) {
xbongContract.setMaintainProgressRatio(ratio);
xbongContract.setMaintainProgressDate(date);
} else if (StrUtil.equals(stage, "维保验收款")) {
xbongContract.setMaintainAcceptanceRatio(ratio);
xbongContract.setMaintainAcceptanceDate(date);
}
});
}
xbongContract.setSubject("北京文安智能技术股份有限公司");
xbongContract.setCustomerName(jsonObj1.getJSONObject("text_2").getStr("name"));
xbongContract.setSaleName(jsonObj1.getJSONObject("text_8").getStr("name"));
xbongContract.setCreateUser(-1L);
xbongContract.setModifyUser(-1L);
xbongContract.setEntryTime(DateUtil.date(result.getLong("addTime") * 1000));
xbongContract.setOriginalModTime(DateUtil.date(result.getLong("updateTime") * 1000));
return JSONUtil.ofObj().set("platform", platContract).set("xbongbong", xbongContract);
}
}
\ No newline at end of file
......@@ -116,7 +116,7 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
.map(l -> fileService.lambdaQuery()
.in(FileInfo::getSourceId, l)
.in(FileInfo::getStoreId, l)
.in(FileInfo::getSourceType, 1, 24, 25, 26, 27, 28)
.in(FileInfo::getSourceType, 1, 24, 25, 26, 27, 28, 29, 30)
.list())
.map(fileList -> fileList.stream().collect(Collectors.groupingBy(FileInfo::getStoreId, Collectors.counting())))
.orElse(MapUtil.empty());
......@@ -570,7 +570,6 @@ public class StoreServiceImpl extends MPJBaseServiceImpl<StoreMapper, Store> imp
String fileNameStr = Arrays.stream(fileNameArr).map(v -> StrUtil.format("{}.{}",
Arrays.asList(fileNameArr).indexOf(v) + 1, v)).collect(Collectors.joining("\n"));
content.set("title", "项目资料提交提醒")
.set("text", StrUtil.format("""
#### 项目名称:{}
......
......@@ -405,11 +405,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
JSONObject msg = buildMsg3(forwardUser, store.getName(), task);
String pushRes = dingMod.workMsg(msg);
if (StrUtil.contains(pushRes, "ok")) {
return "成功";
} else {
return "失败";
}
return StrUtil.contains(pushRes, "ok") ? "成功" : "失败";
}
@Override
......@@ -424,11 +420,7 @@ public class TaskServiceImpl extends MPJBaseServiceImpl<TaskMapper, Task> implem
JSONObject msg = buildMsg4(userid, store.getName(), task, remark);
String pushRes = dingMod.workMsg(msg);
if (StrUtil.contains(pushRes, "ok")) {
return "成功";
} else {
return "失败";
}
return StrUtil.contains(pushRes, "ok") ? "成功" : "失败";
}
@Override
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!