|
|
@@ -4,20 +4,18 @@ import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.ningdatech.basic.function.VUtils; |
|
|
|
import com.ningdatech.basic.model.PageVo; |
|
|
|
import com.ningdatech.basic.util.CollUtils; |
|
|
|
import com.ningdatech.basic.util.NdDateUtils; |
|
|
|
import com.ningdatech.pmapi.common.constant.BizConst; |
|
|
|
import com.ningdatech.pmapi.common.constant.RegionConst; |
|
|
|
import com.ningdatech.pmapi.common.helper.UserInfoHelper; |
|
|
|
import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; |
|
|
|
import com.ningdatech.pmapi.common.util.ExcelDownUtil; |
|
|
|
import com.ningdatech.pmapi.common.util.ExcelExportStyle; |
|
|
|
import com.ningdatech.pmapi.projectdeclared.model.dto.*; |
|
|
|
import com.ningdatech.pmapi.projectdeclared.model.dto.DeclaredProjectExportDTO; |
|
|
|
import com.ningdatech.pmapi.projectdeclared.model.dto.PurchaseSaveDTO; |
|
|
|
import com.ningdatech.pmapi.projectdeclared.model.entity.Purchase; |
|
|
|
import com.ningdatech.pmapi.projectdeclared.model.vo.PurchaseVO; |
|
|
|
import com.ningdatech.pmapi.projectdeclared.service.IPurchaseService; |
|
|
@@ -35,11 +33,14 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
@@ -64,6 +65,7 @@ public class PurchaseManage { |
|
|
|
|
|
|
|
/** |
|
|
|
* 待采购的-项目列表 |
|
|
|
* |
|
|
|
* @param req |
|
|
|
* @return |
|
|
|
*/ |
|
|
@@ -72,9 +74,9 @@ public class PurchaseManage { |
|
|
|
VUtils.isTrue(Objects.isNull(user)).throwMessage("获取登录用户失败!"); |
|
|
|
LambdaQueryWrapper<Project> query = ProjectHelper.projectQuery(req); |
|
|
|
//待采购状态 |
|
|
|
query.eq(Project::getStatus,ProjectStatusEnum.TO_BE_PURCHASED.getCode()); |
|
|
|
query.eq(Project::getStage,ProjectStatusEnum.PROJECT_APPROVED.getCode()); |
|
|
|
query.eq(Project::getNewest,Boolean.TRUE); |
|
|
|
query.eq(Project::getStatus, ProjectStatusEnum.TO_BE_PURCHASED.getCode()); |
|
|
|
query.eq(Project::getStage, ProjectStatusEnum.PROJECT_APPROVED.getCode()); |
|
|
|
query.eq(Project::getNewest, Boolean.TRUE); |
|
|
|
query.orderByAsc(Project::getApprovalDate); |
|
|
|
Page<Project> page = projectService.page(req.page(), query); |
|
|
|
long total; |
|
|
@@ -108,16 +110,16 @@ public class PurchaseManage { |
|
|
|
VUtils.isTrue(Objects.isNull(user)).throwMessage("获取登录用户失败!"); |
|
|
|
LambdaQueryWrapper<Project> query = ProjectHelper.projectQuery(param); |
|
|
|
//待采购状态 |
|
|
|
query.eq(Project::getStatus,ProjectStatusEnum.TO_BE_PURCHASED.getCode()); |
|
|
|
query.eq(Project::getStage,ProjectStatusEnum.PROJECT_APPROVED.getCode()); |
|
|
|
query.eq(Project::getNewest,Boolean.TRUE); |
|
|
|
query.eq(Project::getStatus, ProjectStatusEnum.TO_BE_PURCHASED.getCode()); |
|
|
|
query.eq(Project::getStage, ProjectStatusEnum.PROJECT_APPROVED.getCode()); |
|
|
|
query.eq(Project::getNewest, Boolean.TRUE); |
|
|
|
query.orderByAsc(Project::getApprovalDate); |
|
|
|
List<Project> records = projectService.list(query); |
|
|
|
|
|
|
|
AtomicInteger serialNumber = new AtomicInteger(0); |
|
|
|
List<DeclaredProjectExportDTO> data = Lists.newArrayList(); |
|
|
|
|
|
|
|
if(CollUtil.isNotEmpty(records)){ |
|
|
|
if (CollUtil.isNotEmpty(records)) { |
|
|
|
data = records.stream().map(r -> { |
|
|
|
DeclaredProjectExportDTO exportDTO = new DeclaredProjectExportDTO(); |
|
|
|
BeanUtils.copyProperties(r, exportDTO); |
|
|
@@ -133,7 +135,7 @@ public class PurchaseManage { |
|
|
|
} |
|
|
|
|
|
|
|
String fileName = "采购结果待备案项目列表"; |
|
|
|
ExcelDownUtil.setFileName(fileName,response); |
|
|
|
ExcelDownUtil.setFileName(fileName, response); |
|
|
|
//数据导出处理函数 |
|
|
|
try { |
|
|
|
EasyExcel.write(response.getOutputStream(), DeclaredProjectExportDTO.class) |
|
|
@@ -148,19 +150,18 @@ public class PurchaseManage { |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取采购结果备案详情 |
|
|
|
* |
|
|
|
* @param projectId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public PurchaseVO detailByProjectId(Long projectId) { |
|
|
|
Purchase purchase = purchaseService.getOne(Wrappers.lambdaQuery(Purchase.class) |
|
|
|
.eq(Purchase::getProjectId, projectId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
|
|
|
|
return BeanUtil.copyProperties(purchase,PurchaseVO.class); |
|
|
|
public List<PurchaseVO> detailByProjectId(Long projectId) { |
|
|
|
List<Purchase> purchases = purchaseService.listByProjectId(projectId); |
|
|
|
return BeanUtil.copyToList(purchases, PurchaseVO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 填写采购结果 |
|
|
|
* |
|
|
|
* @param dto |
|
|
|
* @return |
|
|
|
*/ |
|
|
@@ -175,40 +176,50 @@ public class PurchaseManage { |
|
|
|
VUtils.isTrue(Objects.isNull(project)).throwMessage("提交失败 此项目不存在!"); |
|
|
|
|
|
|
|
//首先要判断 项目当前状态 是不是 采购结果备案 |
|
|
|
VUtils.isTrue(!ProjectStatusEnum.TO_BE_PURCHASED.getCode().equals(project.getStatus()) || |
|
|
|
!ProjectStatusEnum.PROJECT_APPROVED.getCode().equals(project.getStage())) |
|
|
|
VUtils.isTrue(!ProjectStatusEnum.TO_BE_PURCHASED.eq(project.getStatus()) |
|
|
|
|| !ProjectStatusEnum.PROJECT_APPROVED.eq(project.getStage())) |
|
|
|
.throwMessage("提交失败 该项目不是 待采购备案状态或者已立项阶段"); |
|
|
|
|
|
|
|
Purchase purchaseEntity = new Purchase(); |
|
|
|
Purchase purchase = purchaseService.getOne(Wrappers.lambdaQuery(Purchase.class) |
|
|
|
.eq(Purchase::getProjectId, projectId) |
|
|
|
.last(BizConst.LIMIT_1)); |
|
|
|
|
|
|
|
BeanUtil.copyProperties(dto,purchaseEntity); |
|
|
|
if(Objects.isNull(purchase)){ |
|
|
|
purchaseEntity.setCreateOn(LocalDateTime.now()); |
|
|
|
purchaseEntity.setCreateBy(employeeCode); |
|
|
|
}else{ |
|
|
|
purchaseEntity.setId(purchase.getId()); |
|
|
|
} |
|
|
|
purchaseEntity.setProjectId(projectId); |
|
|
|
if(purchaseService.saveOrUpdate(purchaseEntity)){ |
|
|
|
//如果 需要推送项目和应用管理的话 只有遂昌县才有 |
|
|
|
// String areaCode = project.getAreaCode(); |
|
|
|
// String appCode = dto.getAppCode(); |
|
|
|
// if(RegionConst.RC_SC.equals(areaCode) && StringUtils.isNotBlank(appCode)){ |
|
|
|
// try{ |
|
|
|
// |
|
|
|
// }catch (Exception e){ |
|
|
|
// log.info("绑定以及推送项目和应用关系 失败! {}" + e.getMessage()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
List<Purchase> purchases = purchaseService.listByProjectId(projectId); |
|
|
|
Map<Long, Purchase> purchaseMap = CollUtils.listToMap(purchases, Purchase::getId); |
|
|
|
List<Purchase> purchaseEntities = CollUtils.convert(dto.getTenders(), w -> { |
|
|
|
Purchase purchase = BeanUtil.copyProperties(w, Purchase.class); |
|
|
|
purchase.setProjectId(projectId); |
|
|
|
if (!purchaseMap.containsKey(w.getId())) { |
|
|
|
purchase.setCreateBy(employeeCode); |
|
|
|
} |
|
|
|
return purchase; |
|
|
|
}); |
|
|
|
|
|
|
|
if (purchaseService.saveOrUpdateBatch(purchaseEntities)) { |
|
|
|
// 如果 需要推送项目和应用管理的话 只有遂昌县才有 |
|
|
|
// String areaCode = project.getAreaCode(); |
|
|
|
// String appCode = dto.getAppCode(); |
|
|
|
// if(RegionConst.RC_SC.equals(areaCode) && StringUtils.isNotBlank(appCode)){ |
|
|
|
// try{ |
|
|
|
// |
|
|
|
// }catch (Exception e){ |
|
|
|
// log.info("绑定以及推送项目和应用关系 失败! {}" + e.getMessage()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
//进入到下一状态 |
|
|
|
stateMachineUtils.pass(project); |
|
|
|
project.setUpdateOn(LocalDateTime.now()); |
|
|
|
project.setTransactionAmount(dto.getTransactionAmount()); |
|
|
|
project.setTransactionTime(dto.getTransactionTime()); |
|
|
|
|
|
|
|
// 获最的成时以总成交金 |
|
|
|
LocalDateTime lastTransactionTime = null; |
|
|
|
BigDecimal transactionAmountTotal = BigDecimal.ZERO; |
|
|
|
for (Purchase purchase : purchases) { |
|
|
|
if (lastTransactionTime == null) { |
|
|
|
lastTransactionTime = purchase.getTransactionTime(); |
|
|
|
} else if (purchase.getTransactionTime().isAfter(lastTransactionTime)) { |
|
|
|
lastTransactionTime = purchase.getTransactionTime(); |
|
|
|
} |
|
|
|
transactionAmountTotal = transactionAmountTotal.add(purchase.getTransactionAmount()); |
|
|
|
} |
|
|
|
|
|
|
|
project.setTransactionAmount(transactionAmountTotal); |
|
|
|
project.setTransactionTime(lastTransactionTime); |
|
|
|
projectService.updateById(project); |
|
|
|
|
|
|
|
return "填写成功"; |
|
|
|