|
@@ -0,0 +1,535 @@
|
|
|
+package com.management.platform.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
+import com.management.platform.service.ContractDocumentService;
|
|
|
+import com.management.platform.service.ContractService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.service.ExcelExportService;
|
|
|
+import com.management.platform.util.*;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.EncryptedDocumentException;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2022-11-29
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements ContractService {
|
|
|
+ @Resource
|
|
|
+ private ContractTypeMapper contractTypeMapper;
|
|
|
+ @Resource
|
|
|
+ private ContractMapper contractMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
+ @Resource
|
|
|
+ private LocaleInformationMapper localeInformationMapper;
|
|
|
+ @Resource
|
|
|
+ private ExcelExportService excelExportService;
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
+ @Resource
|
|
|
+ private ContractDocumentMapper contractDocumentMapper;
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
+ private String path;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询合同
|
|
|
+ * @param request
|
|
|
+ * @param pageIndex
|
|
|
+ * @param pageSize
|
|
|
+ * @param number
|
|
|
+ * @param name
|
|
|
+ * @param typeName
|
|
|
+ * @param status
|
|
|
+ * @param startDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getContractPage(HttpServletRequest request, @RequestParam Integer pageIndex, @RequestParam Integer pageSize, String number, String name, String typeName, Integer status, String startDate, String endDate) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ String token = request.getHeader("token");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ List<ContractType> types = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", user.getCompanyId()));
|
|
|
+ if (types.size() == 0){
|
|
|
+ //String[] typeNames = {"买卖合同","赠与合同","租赁合同","借款合同","仓储合同","委托合同"};
|
|
|
+ String[] typeNames = {MessageUtils.message("contract.business"),MessageUtils.message("contract.gift"),MessageUtils.message("contract.lease"),MessageUtils.message("contract.loan"),MessageUtils.message("contract.warehousing"),MessageUtils.message("contract.entrust")};
|
|
|
+ for (String s : typeNames) {
|
|
|
+ ContractType contractType = new ContractType();
|
|
|
+ contractType.setCompanyId(user.getCompanyId());
|
|
|
+ contractType.setTypeName(s);
|
|
|
+ contractTypeMapper.insert(contractType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer pageStart = null;
|
|
|
+ if (pageIndex!=null){
|
|
|
+ pageStart = (pageIndex -1) * pageSize;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(number)){
|
|
|
+ number = "%" + number + "%";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(name)){
|
|
|
+ name = "%" + name + "%";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(typeName)){
|
|
|
+ typeName = typeName;
|
|
|
+ }
|
|
|
+ List<Contract> contracts = contractMapper.selectContract(user.getCompanyId(), pageStart, pageSize, number, name , typeName , status, startDate,endDate);
|
|
|
+ List<Contract> total = contractMapper.selectContract(user.getCompanyId(), null, null, number, name, typeName, status, startDate, endDate);
|
|
|
+ for (Contract contract : contracts) {
|
|
|
+ List<ContractDocument> fileUrl = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().eq("contract_id", id).eq("is_deleted",0));
|
|
|
+ List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ for (ContractDocument contractDocument : fileUrl) {
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ for (User item : users) {
|
|
|
+ if (item.getId().equals(contractDocument.getCreatorId())){
|
|
|
+ contractDocument.setCreatorName(item.getCorpwxUserid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("data",contracts);
|
|
|
+ map.put("total",total.size());
|
|
|
+ httpRespMsg.data = map;
|
|
|
+ return httpRespMsg;
|
|
|
+ }catch (NullPointerException e) {
|
|
|
+ //httpRespMsg.setError("验证失败");
|
|
|
+ httpRespMsg.setError(MessageUtils.message("access.verificationError"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出合同
|
|
|
+ * @param request
|
|
|
+ * @param number
|
|
|
+ * @param name
|
|
|
+ * @param typeName
|
|
|
+ * @param status
|
|
|
+ * @param startDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg ExportContract(HttpServletRequest request, String number, String name, String typeName, Integer status, String startDate, String endDate) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ HttpRespMsg contractPage = getContractPage(request, null, null, number, name, typeName, status, startDate, endDate);
|
|
|
+ List<Contract> data = (List<Contract>) contractPage.data;
|
|
|
+ List<String> headList = new ArrayList<String>();
|
|
|
+// headList.add("合同编号");
|
|
|
+// headList.add("合同名称");
|
|
|
+// headList.add("合同金额(¥)");
|
|
|
+// headList.add("合同类型");
|
|
|
+// headList.add("状态");
|
|
|
+// headList.add("创建时间");
|
|
|
+// headList.add("备注");
|
|
|
+ headList.add(MessageUtils.message("entry.contractNo"));
|
|
|
+ headList.add(MessageUtils.message("contract.name"));
|
|
|
+ headList.add(MessageUtils.message("entry.contract"));
|
|
|
+ headList.add(MessageUtils.message("contract.type"));
|
|
|
+ headList.add(MessageUtils.message("leave.status"));
|
|
|
+ headList.add(MessageUtils.message("excel.creatTime"));
|
|
|
+ headList.add(MessageUtils.message("leave.task"));
|
|
|
+ ArrayList<List<String>> allList = new ArrayList<>();
|
|
|
+ allList.add(headList);
|
|
|
+ for (Contract contract : data) {
|
|
|
+ ArrayList<String> item = new ArrayList<>();
|
|
|
+ item.add(contract.getNumber()==null?"":contract.getNumber());
|
|
|
+ item.add(contract.getName());
|
|
|
+ item.add(contract.getAmounts()==null?"":contract.getAmounts().toString() + "元");
|
|
|
+ item.add(contract.getTypeName());
|
|
|
+ switch (contract.getStatus()){
|
|
|
+ case 0 :
|
|
|
+ item.add("审核通过");
|
|
|
+ break;
|
|
|
+ case 1 :
|
|
|
+ item.add("待审核");
|
|
|
+ break;
|
|
|
+ case 2 :
|
|
|
+ item.add("驳回");
|
|
|
+ break;
|
|
|
+ case 3 :
|
|
|
+ item.add("导入待审核");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ item.add("");
|
|
|
+ }
|
|
|
+ item.add(contract.getIndate().toString());
|
|
|
+ item.add(contract.getRemarks()==null?"":contract.getRemarks());
|
|
|
+ allList.add(item);
|
|
|
+ }
|
|
|
+ String fileName = MessageUtils.message("contract.export")+System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName,allList, path);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增合同
|
|
|
+ * @param request
|
|
|
+ * @param contract
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg addContract(HttpServletRequest request, Contract contract) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ List<Contract> contracts = contractMapper.selectList(new QueryWrapper<Contract>().eq("company_id", user.getCompanyId()));
|
|
|
+ if (StringUtils.isBlank(contract.getName())){
|
|
|
+ //名称不可为空
|
|
|
+ httpRespMsg.setError(MessageUtils.message("name.nullNameError"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ //合同编号不可重复
|
|
|
+ if (StringUtils.isNotBlank(contract.getNumber())){
|
|
|
+ for (Contract ContractNumber: contracts) {
|
|
|
+ if (ContractNumber.getNumber() != null && ContractNumber.getNumber().equals(contract.getNumber())){
|
|
|
+ httpRespMsg.setError("[" + ContractNumber.getNumber() + "]" + MessageUtils.message("contract.numberRepeat"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //合同金额不可为负
|
|
|
+ if (contract.getAmounts()!=null && contract.getAmounts() < 0){
|
|
|
+ httpRespMsg.msg = MessageUtils.message("Contract.amountNegative");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ //若日期为空,则写入当前日期
|
|
|
+ if (contract.getIndate() == null){
|
|
|
+ contract.setIndate(LocalDate.now());
|
|
|
+ }
|
|
|
+ contract.setCreatorId(user.getId());
|
|
|
+ contract.setCompanyId(user.getCompanyId());
|
|
|
+ contractMapper.insert(contract);
|
|
|
+ httpRespMsg.msg = MessageUtils.message("contract.addSuc");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑合同
|
|
|
+ * @param request
|
|
|
+ * @param contract
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg editContract(HttpServletRequest request, Contract contract) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ try {
|
|
|
+ if (StringUtils.isBlank(contract.getName())){
|
|
|
+ //名称不可为空
|
|
|
+ httpRespMsg.setError(MessageUtils.message("name.nullNameError"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ //合同金额不可为负
|
|
|
+ if (contract.getAmounts()!=null && contract.getAmounts() < 0){
|
|
|
+ httpRespMsg.msg = MessageUtils.message("Contract.amountNegative");
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ //合同编号不可重复
|
|
|
+ if (StringUtils.isNotBlank(contract.getNumber())){
|
|
|
+ Contract number = contractMapper.selectOne(new QueryWrapper<Contract>().eq("number", contract.getNumber()));
|
|
|
+ if (number != null && !number.getId().equals(contract.getId())){
|
|
|
+ httpRespMsg.setError("[" + contract.getNumber() + "]" + MessageUtils.message("contract.numberRepeat"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ contractMapper.updateById(contract);
|
|
|
+ httpRespMsg.msg = MessageUtils.message("contract.editSuc");
|
|
|
+ return httpRespMsg;
|
|
|
+ }catch (NullPointerException e) {
|
|
|
+ //httpRespMsg.setError("验证失败");
|
|
|
+ httpRespMsg.setError(MessageUtils.message("access.verificationError"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入合同
|
|
|
+ * @param request
|
|
|
+ * @param multipartFile
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importContract(HttpServletRequest request, MultipartFile multipartFile) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
+ //然后处理文件
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //然后解析表格
|
|
|
+ Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
|
|
|
+ //时间格式
|
|
|
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/M/d");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/d");
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ if (rowNum == 0) {
|
|
|
+ //msg.setError("请填写合同数据");
|
|
|
+ msg.setError(MessageUtils.message("Contract.dataNull"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ List<Contract> contractList = contractMapper.selectList(new QueryWrapper<Contract>().eq("company_id", companyId));
|
|
|
+ List<ContractType> typeList = contractTypeMapper.selectList(new QueryWrapper<ContractType>().eq("company_id", companyId));
|
|
|
+ ArrayList<Contract> saveContract = new ArrayList<>();
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ int cellIndex = 0;
|
|
|
+ int dataIndex = 1;
|
|
|
+ Row row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ boolean NoExists = false;
|
|
|
+ boolean TypeExists = false;
|
|
|
+ if (row.getCell(cellIndex) != null) {
|
|
|
+ row.getCell(cellIndex).setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if (row.getCell(1) == null) {
|
|
|
+ //msg.setError("第"+dataIndex+"行缺少合同名称");
|
|
|
+ msg.setError(MessageUtils.message("",dataIndex));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ String No = row.getCell(0).getStringCellValue().trim();
|
|
|
+ String name = row.getCell(1).getStringCellValue().trim();
|
|
|
+ String amounts = row.getCell(2).getStringCellValue().trim();
|
|
|
+ String type = row.getCell(3).getStringCellValue().trim();
|
|
|
+ String remarks = row.getCell(3).getStringCellValue().trim();
|
|
|
+ Contract item = new Contract();
|
|
|
+ //检查合同编号是否存在
|
|
|
+ if (StringUtils.isNotBlank(No)){
|
|
|
+ for (Contract contract : contractList) {
|
|
|
+ if (contract.getNumber().equals(No)){
|
|
|
+ NoExists = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (NoExists){
|
|
|
+ //msg.setError("第"+dataIndex+"行合同编号已存在");
|
|
|
+ msg.setError(MessageUtils.message("Contract.NoExists",dataIndex));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < saveContract.size(); i++) {
|
|
|
+ if (saveContract.get(i).getNumber().equals(No)){
|
|
|
+ //msg.setError("第"+dataIndex+"行合同编号与第"第"+dataIndex+"行合同编号重复);
|
|
|
+ msg.setError(MessageUtils.message("Contract.NoRepeat",dataIndex,i+1));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.setNumber(No);
|
|
|
+ }
|
|
|
+ //检查类型名称是否存在
|
|
|
+ if (StringUtils.isNotBlank(type)){
|
|
|
+ for (ContractType contractType : typeList) {
|
|
|
+ if (contractType.getTypeName().equals(type)){
|
|
|
+ TypeExists = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!TypeExists){
|
|
|
+ //msg.setError("第"+dataIndex+"行和合同类型不存在");
|
|
|
+ msg.setError(MessageUtils.message("Contract.typeExists",dataIndex));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ item.setName(name);
|
|
|
+ }
|
|
|
+ item.setCompanyId(companyId);
|
|
|
+ item.setCreatorId(user.getId());
|
|
|
+ item.setIndate(LocalDate.now());
|
|
|
+ item.setStatus(3);
|
|
|
+ item.setAmounts(Integer.parseInt(amounts));
|
|
|
+ item.setRemarks(remarks);
|
|
|
+ saveContract.add(item);
|
|
|
+ }
|
|
|
+ if(saveContract.size()>0){
|
|
|
+ int i = 0;
|
|
|
+ for (Contract contract : saveContract) {
|
|
|
+ contractMapper.insert(contract);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ msg.data = i;
|
|
|
+ String originName = fileName;
|
|
|
+ //定义一个独立的文件夹
|
|
|
+ String importFolder = "contract_import";
|
|
|
+ File dir = new File(path, importFolder);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("fileName=="+originName);
|
|
|
+ String[] names = originName.split("\\.");
|
|
|
+ String destFileName = names[0] + "_"+System.currentTimeMillis()+"."+names[1];
|
|
|
+ File destFile = new File(dir, destFileName);
|
|
|
+ FileUtils.copyFile(file, destFile);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件处理出错");
|
|
|
+ msg.setError(MessageUtils.message("file.error"));
|
|
|
+ return msg;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
+ msg.setError(MessageUtils.message("file.dataFormatError"));
|
|
|
+ return msg;
|
|
|
+ }catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
|
|
|
+ return msg;
|
|
|
+ }catch (EncryptedDocumentException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件加密状态,需要先解除加密状态再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.encryption"));
|
|
|
+ return msg;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("发生其他错误:"+e.getMessage());
|
|
|
+ msg.setError(MessageUtils.message("other.errorByParameter",e.getMessage()));
|
|
|
+ return msg;
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合同审核
|
|
|
+ * @param request
|
|
|
+ * @param id
|
|
|
+ * @param status
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg processContract(HttpServletRequest request, Integer id, Integer status) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ Contract contract = new Contract();
|
|
|
+ contract.setId(id);
|
|
|
+ contract.setCheckerId(user.getId());
|
|
|
+ contract.setStatus(status);
|
|
|
+ contractMapper.updateById(contract);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回合同的附件列表
|
|
|
+ * @param request
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg contractFile(HttpServletRequest request, Integer id) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ List<ContractDocument> fileUrl = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().eq("contract_id", id).eq("is_deleted",0));
|
|
|
+ List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
+ for (ContractDocument contractDocument : fileUrl) {
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ for (User item : users) {
|
|
|
+ if (item.getId().equals(contractDocument.getCreatorId())){
|
|
|
+ contractDocument.setCreatorName(item.getCorpwxUserid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ msg.data = fileUrl;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除合同
|
|
|
+ * @param request
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg deleteContract(HttpServletRequest request, Integer id) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
+ //只有创建者才可以删除
|
|
|
+ Contract contract = contractMapper.selectById(id);
|
|
|
+ if (user.getId().equals(contract.getCreatorId())){
|
|
|
+ contractMapper.deleteById(id);
|
|
|
+ //删除附件
|
|
|
+ List<ContractDocument> contractFile = contractDocumentMapper.selectList(new QueryWrapper<ContractDocument>().eq("contract_id", id));
|
|
|
+ for (ContractDocument contractDocument : contractFile) {
|
|
|
+ contractDocument.setIsDeleted(1);
|
|
|
+ }
|
|
|
+ for (ContractDocument contractDocument : contractFile) {
|
|
|
+ contractDocumentMapper.updateById(contractDocument);
|
|
|
+ }
|
|
|
+ msg.msg = MessageUtils.message("other.deleteScu");
|
|
|
+ }else {
|
|
|
+ msg.msg = MessageUtils.message("access.createDelete");
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|