|
@@ -1,27 +1,39 @@
|
|
|
package cn.efunbox.manage.base.service.impl;
|
|
|
|
|
|
import cn.efunbox.manage.base.entity.*;
|
|
|
-import cn.efunbox.manage.base.enums.CompanyTypeEnum;
|
|
|
+import cn.efunbox.manage.base.enums.BaseStatusEnum;
|
|
|
+import cn.efunbox.manage.base.enums.IncomeStatusEnum;
|
|
|
import cn.efunbox.manage.base.enums.ManageTypeEnum;
|
|
|
import cn.efunbox.manage.base.repository.*;
|
|
|
import cn.efunbox.manage.base.service.ManageService;
|
|
|
+import cn.efunbox.manage.base.util.TimeUtil;
|
|
|
import cn.efunbox.manage.base.vo.ManageVO;
|
|
|
+import cn.efunbox.manage.common.enums.BaseOrderEnum;
|
|
|
+import cn.efunbox.manage.common.helper.SortHelper;
|
|
|
import cn.efunbox.manage.common.result.ApiCode;
|
|
|
import cn.efunbox.manage.common.result.ApiResult;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.bind.annotation.Mapping;
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
-import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
-import static cn.efunbox.manage.base.enums.CompanyTypeEnum.COMPANY;
|
|
|
-
|
|
|
/**
|
|
|
* ManageSreviceImpl
|
|
|
* Created by wangys on 2019/03/08
|
|
@@ -49,56 +61,145 @@ public class ManageServiceImpl implements ManageService {
|
|
|
|
|
|
@Override
|
|
|
public ApiResult list(ManageVO manageVO) {
|
|
|
- Specification querySpecifi = new Specification<Manage>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<Manage> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
|
+ Pageable pageable = new PageRequest(manageVO.getPageNo() - 1, manageVO.getPageSize(), SortHelper.sortMap2Sort(new LinkedHashMap<String, BaseOrderEnum>(){{put("status", BaseOrderEnum.ASC);put("gmtModified", BaseOrderEnum.DESC);}}));
|
|
|
+// manageVO.setStatus(BaseStatusEnum.NORMAL);
|
|
|
+ if(!manageVO.getIsEntry()){
|
|
|
+ pageable = new PageRequest(manageVO.getPageNo() - 1,manageVO.getPageSize(), SortHelper.sortMap2Sort(new LinkedHashMap<String, BaseOrderEnum>(){{put("status", BaseOrderEnum.ASC);put("happenTime", BaseOrderEnum.DESC);}}));
|
|
|
+ manageVO.setStatus(BaseStatusEnum.NORMAL);
|
|
|
+ }
|
|
|
+ Specification specification = (Specification<Manage>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
- if(Objects.nonNull(manageVO.getToProjectId()) && 0 == manageVO.getToProjectId()){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("toProjectId"), manageVO.getToProjectId()));
|
|
|
- }
|
|
|
- if(Objects.nonNull(manageVO.getToDeptId()) && 0 == manageVO.getToDeptId()){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("toDeptId"), manageVO.getToProjectId()));
|
|
|
- }
|
|
|
- if(Objects.nonNull(manageVO.getProductId()) && 0 == manageVO.getProductId()){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("productId"), manageVO.getProductId()));
|
|
|
- }
|
|
|
- if(Objects.nonNull(manageVO.getProductId()) && 0 == manageVO.getProductId()){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("projectId"), manageVO.getProductId()));
|
|
|
- }
|
|
|
- if(Objects.nonNull(manageVO.getType())){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("type"), manageVO.getType()));
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if(manageVO.getToProjectId() != null && manageVO.getToProjectId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getToProjectId() != null && manageVO.getToProjectId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("toProjectId"));
|
|
|
+ for (Long id : manageVO.getToProjectId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- if(Objects.nonNull(manageVO.getCostTypeId()) && 0 == manageVO.getCostTypeId()){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("costTypeId"), manageVO.getCostTypeId()));
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+// if(Objects.nonNull(manageVO.getToProjectId()) && 0 != manageVO.getToProjectId()){
|
|
|
+// predicates.add(criteriaBuilder.equal(root.get("toProjectId"), manageVO.getToProjectId()));
|
|
|
+// }
|
|
|
+ if(manageVO.getToDeptId() != null && manageVO.getToDeptId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getToDeptId() != null && manageVO.getToDeptId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("toDeptId"));
|
|
|
+ for (Long id : manageVO.getToDeptId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- if(Objects.nonNull(manageVO.getIncomeStatus())){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("incomeStatus"), manageVO.getIncomeStatus()));
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+// if(Objects.nonNull(manageVO.getToDeptId()) && 0 != manageVO.getToDeptId()){
|
|
|
+// predicates.add(criteriaBuilder.equal(root.get("toDeptId"), manageVO.getToDeptId()));
|
|
|
+// }
|
|
|
+ if(manageVO.getProductId() != null && manageVO.getProductId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getProductId() != null && manageVO.getProductId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("productId"));
|
|
|
+ for (Long id : manageVO.getProductId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- if(Objects.nonNull(manageVO.getStatus())){
|
|
|
- predicates.add(criteriaBuilder.equal(root.get("status"), manageVO.getStatus()));
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+// if(Objects.nonNull(manageVO.getProductId()) && 0 != manageVO.getProductId()){
|
|
|
+// predicates.add(criteriaBuilder.equal(root.get("productId"), manageVO.getProductId()));
|
|
|
+// }
|
|
|
+ if(manageVO.getProjectId() != null && manageVO.getProjectId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getProjectId() != null && manageVO.getProjectId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("projectId"));
|
|
|
+ for (Long id : manageVO.getProjectId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- if(Objects.nonNull(manageVO.getStartTime())){
|
|
|
- predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("happenTime"), manageVO.getStartTime()));
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+// if(Objects.nonNull(manageVO.getProjectId()) && 0 != manageVO.getProjectId()){
|
|
|
+// predicates.add(criteriaBuilder.equal(root.get("projectId"), manageVO.getProjectId()));
|
|
|
+// }
|
|
|
+ if(Objects.nonNull(manageVO.getType())){
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("type"), manageVO.getType()));
|
|
|
+ }
|
|
|
+ if(manageVO.getCostTypeId() != null && manageVO.getCostTypeId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getCostTypeId() != null && manageVO.getCostTypeId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("costTypeId"));
|
|
|
+ for (Long id : manageVO.getCostTypeId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- if(Objects.nonNull(manageVO.getEndTime())){
|
|
|
- predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("happenTime"), manageVO.getEndTime()));
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+// if(Objects.nonNull(manageVO.getCostTypeId()) && 0 != manageVO.getCostTypeId()){
|
|
|
+// predicates.add(criteriaBuilder.equal(root.get("costTypeId"), manageVO.getCostTypeId()));
|
|
|
+// }
|
|
|
+ if(manageVO.getIncomeStatus() != null && manageVO.getIncomeStatus().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getIncomeStatus() != null && manageVO.getIncomeStatus().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("incomeStatus"));
|
|
|
+ for (IncomeStatusEnum incomeStatus : manageVO.getIncomeStatus()) {
|
|
|
+ in.value(incomeStatus);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- if(manageVO.getDeptIds() != null && manageVO.getDeptIds().size() > 0){
|
|
|
- List<Predicate> list = new ArrayList<>();
|
|
|
- if (manageVO.getDeptIds() != null && manageVO.getDeptIds().size() > 0) {
|
|
|
- CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("deptId"));
|
|
|
- for (Long id : manageVO.getDeptIds()) {
|
|
|
- in.value(id);
|
|
|
- }
|
|
|
- list.add(in);
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+// if(Objects.nonNull(manageVO.getIncomeStatus())){
|
|
|
+// predicates.add(criteriaBuilder.equal(root.get("incomeStatus"), manageVO.getIncomeStatus()));
|
|
|
+// }
|
|
|
+
|
|
|
+ if(Objects.nonNull(manageVO.getStatus())){
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("status"), manageVO.getStatus()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getStartTime())){
|
|
|
+ predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("happenTime"), manageVO.getStartTime()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getEndTime())){
|
|
|
+ predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("happenTime"), manageVO.getEndTime()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getMinAmount()) && manageVO.getMinAmount() > 0){
|
|
|
+ predicates.add(criteriaBuilder.ge(root.get("amount"), manageVO.getMinAmount()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getMaxAmount()) && manageVO.getMaxAmount() > 0){
|
|
|
+ predicates.add(criteriaBuilder.le(root.get("amount"), manageVO.getMaxAmount()));
|
|
|
+ }
|
|
|
+ if(manageVO.getDeptIds() != null && manageVO.getDeptIds().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getDeptIds() != null && manageVO.getDeptIds().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("deptId"));
|
|
|
+ for (Long id : manageVO.getDeptIds()) {
|
|
|
+ in.value(id);
|
|
|
}
|
|
|
- predicates.addAll(list);
|
|
|
+ list.add(in);
|
|
|
}
|
|
|
- return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ predicates.addAll(list);
|
|
|
}
|
|
|
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
- List<Manage> manages = manageRepository.findAll(querySpecifi);
|
|
|
+ Long count = manageRepository.count(specification);
|
|
|
+ if (count == 0) {
|
|
|
+ return ApiResult.ok(null);
|
|
|
+ }
|
|
|
+ Page<Manage> manages = manageRepository.findAll(specification, pageable);
|
|
|
+ List<Manage> totalManages = manageRepository.findAll(specification);
|
|
|
+ BigDecimal sum = new BigDecimal("0");
|
|
|
+ for (Manage manage: totalManages) {
|
|
|
+ if (Objects.equals(manage.getType(), ManageTypeEnum.COST)){
|
|
|
+ sum = sum.subtract(new BigDecimal(Double.toString(manage.getAmount())));
|
|
|
+ }else {
|
|
|
+ sum = sum.add(new BigDecimal(Double.toString(manage.getAmount())));
|
|
|
+ }
|
|
|
+ }
|
|
|
if(Objects.isNull(manages)){
|
|
|
return ApiResult.error(ApiCode.UNKNOWN_ERROR);
|
|
|
|
|
@@ -108,7 +209,8 @@ public class ManageServiceImpl implements ManageService {
|
|
|
List<Long> productIds = new ArrayList<>();
|
|
|
List<Long> companyIds = new ArrayList<>();
|
|
|
List<Long> costTypeIds = new ArrayList<>();
|
|
|
- manages.stream().forEach(m -> {
|
|
|
+ for(Manage m : manages){
|
|
|
+ m.setTotalAmount(sum.doubleValue());
|
|
|
if(Objects.nonNull(m.getDeptId())){
|
|
|
deptIds.add(m.getDeptId());
|
|
|
}
|
|
@@ -150,7 +252,8 @@ public class ManageServiceImpl implements ManageService {
|
|
|
if(Objects.nonNull(m.getToDeptId())){
|
|
|
deptIds.add(m.getToDeptId());
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
+
|
|
|
//部门
|
|
|
List<Department> departments = departmentRepository.findByIds(deptIds);
|
|
|
Map<Long, Department> departmentMap = new HashMap<>();
|
|
@@ -182,7 +285,7 @@ public class ManageServiceImpl implements ManageService {
|
|
|
costTypeMap.put(costType.getId(), costType);
|
|
|
});
|
|
|
|
|
|
- manages.stream().forEach(m -> {
|
|
|
+ for(Manage m : manages){
|
|
|
m.setDepartment(departmentMap.get(m.getDeptId()));
|
|
|
m.setProject(projectMap.get(m.getProjectId()));
|
|
|
m.setProduct(producMap.get(m.getProductId()));
|
|
@@ -207,11 +310,378 @@ public class ManageServiceImpl implements ManageService {
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
- });
|
|
|
+ };
|
|
|
return ApiResult.ok(manages);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void export(ManageVO manageVO, HttpServletResponse response) throws Exception {
|
|
|
+ if(!manageVO.getIsEntry()){
|
|
|
+ manageVO.setStatus(BaseStatusEnum.NORMAL);
|
|
|
+ }
|
|
|
+ Specification specification = (Specification<Manage>) (root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if(manageVO.getToProjectId() != null && manageVO.getToProjectId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getToProjectId() != null && manageVO.getToProjectId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("toProjectId"));
|
|
|
+ for (Long id : manageVO.getToProjectId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ if(manageVO.getToDeptId() != null && manageVO.getToDeptId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getToDeptId() != null && manageVO.getToDeptId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("toDeptId"));
|
|
|
+ for (Long id : manageVO.getToDeptId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ if(manageVO.getProductId() != null && manageVO.getProductId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getProductId() != null && manageVO.getProductId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("productId"));
|
|
|
+ for (Long id : manageVO.getProductId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ if(manageVO.getProjectId() != null && manageVO.getProjectId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getProjectId() != null && manageVO.getProjectId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("projectId"));
|
|
|
+ for (Long id : manageVO.getProjectId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getType())){
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("type"), manageVO.getType()));
|
|
|
+ }
|
|
|
+ if(manageVO.getCostTypeId() != null && manageVO.getCostTypeId().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getCostTypeId() != null && manageVO.getCostTypeId().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("costTypeId"));
|
|
|
+ for (Long id : manageVO.getCostTypeId()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ if(manageVO.getIncomeStatus() != null && manageVO.getIncomeStatus().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getIncomeStatus() != null && manageVO.getIncomeStatus().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("incomeStatus"));
|
|
|
+ for (IncomeStatusEnum incomeStatus : manageVO.getIncomeStatus()) {
|
|
|
+ in.value(incomeStatus);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getStatus())){
|
|
|
+ predicates.add(criteriaBuilder.equal(root.get("status"), manageVO.getStatus()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getStartTime())){
|
|
|
+ predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("happenTime"), manageVO.getStartTime()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getEndTime())){
|
|
|
+ predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("happenTime"), manageVO.getEndTime()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getMinAmount()) && manageVO.getMinAmount() > 0){
|
|
|
+ predicates.add(criteriaBuilder.ge(root.get("amount"), manageVO.getMinAmount()));
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(manageVO.getMaxAmount()) && manageVO.getMaxAmount() > 0){
|
|
|
+ predicates.add(criteriaBuilder.le(root.get("amount"), manageVO.getMaxAmount()));
|
|
|
+ }
|
|
|
+ if(manageVO.getDeptIds() != null && manageVO.getDeptIds().size() > 0){
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ if (manageVO.getDeptIds() != null && manageVO.getDeptIds().size() > 0) {
|
|
|
+ CriteriaBuilder.In<Object> in = criteriaBuilder.in(root.get("deptId"));
|
|
|
+ for (Long id : manageVO.getDeptIds()) {
|
|
|
+ in.value(id);
|
|
|
+ }
|
|
|
+ list.add(in);
|
|
|
+ }
|
|
|
+ predicates.addAll(list);
|
|
|
+ }
|
|
|
+ return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+ Long count = manageRepository.count(specification);
|
|
|
+ if (count == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Manage> totalManages = manageRepository.findAll(specification);
|
|
|
+ BigDecimal sum = new BigDecimal("0");
|
|
|
+ for (Manage manage: totalManages) {
|
|
|
+ if (Objects.equals(manage.getType(), ManageTypeEnum.COST)){
|
|
|
+ sum = sum.subtract(new BigDecimal(Double.toString(manage.getAmount())));
|
|
|
+ }else {
|
|
|
+ sum = sum.add(new BigDecimal(Double.toString(manage.getAmount())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(Objects.isNull(totalManages)){
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+ List<Long> deptIds = new ArrayList<>();
|
|
|
+ List<Long> projectIds = new ArrayList<>();
|
|
|
+ List<Long> productIds = new ArrayList<>();
|
|
|
+ List<Long> companyIds = new ArrayList<>();
|
|
|
+ List<Long> costTypeIds = new ArrayList<>();
|
|
|
+ for(Manage m : totalManages){
|
|
|
+ m.setTotalAmount(sum.doubleValue());
|
|
|
+ if(Objects.nonNull(m.getDeptId())){
|
|
|
+ deptIds.add(m.getDeptId());
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(m.getProjectId())){
|
|
|
+ projectIds.add(m.getProjectId());
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(m.getToDeptId())){
|
|
|
+ deptIds.add(m.getToDeptId());
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(m.getProductId())){
|
|
|
+ productIds.add(m.getProductId());
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(m.getCostTypeId())){
|
|
|
+ costTypeIds.add(m.getCostTypeId());
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(m.getToProjectId())){
|
|
|
+ projectIds.add(m.getToProjectId());
|
|
|
+ }
|
|
|
+ if(Objects.nonNull(m.getToDeptId())){
|
|
|
+ deptIds.add(m.getToDeptId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //部门
|
|
|
+ List<Department> departments = departmentRepository.findByIds(deptIds);
|
|
|
+ Map<Long, Department> departmentMap = new HashMap<>();
|
|
|
+ departments.stream().forEach(department -> {
|
|
|
+ departmentMap.put(department.getId(), department);
|
|
|
+ });
|
|
|
+ //项目
|
|
|
+ List<Project> projects = projectRepository.findByIds(projectIds);
|
|
|
+ Map<Long, Project> projectMap = new HashMap<>();
|
|
|
+ projects.stream().forEach(project -> {
|
|
|
+ projectMap.put(project.getId(), project);
|
|
|
+ });
|
|
|
+ //产品
|
|
|
+ List<Product> products = productRepository.findByIds(productIds);
|
|
|
+ Map<Long, Product> producMap = new HashMap<>();
|
|
|
+ products.stream().forEach(product -> {
|
|
|
+ producMap.put(product.getId(), product);
|
|
|
+ });
|
|
|
+ //支出发起人
|
|
|
+ List<Company> companies = companyRepository.findByIds(companyIds);
|
|
|
+ Map<Long, Company> companyMap = new HashMap<>();
|
|
|
+ companies.stream().forEach(company -> {
|
|
|
+ companyMap.put(company.getId(), company);
|
|
|
+ });
|
|
|
+ //成本类型
|
|
|
+ List<CostType> costTypes = costTypeRepository.findByIds(costTypeIds);
|
|
|
+ Map<Long, CostType> costTypeMap = new HashMap<>();
|
|
|
+ costTypes.stream().forEach(costType -> {
|
|
|
+ costTypeMap.put(costType.getId(), costType);
|
|
|
+ });
|
|
|
+
|
|
|
+ for(Manage m : totalManages){
|
|
|
+ m.setDepartment(departmentMap.get(m.getDeptId()));
|
|
|
+ m.setProject(projectMap.get(m.getProjectId()));
|
|
|
+ m.setProduct(producMap.get(m.getProductId()));
|
|
|
+ m.setToProject(projectMap.get(m.getToProjectId()));
|
|
|
+ if(Objects.nonNull(m.getCostTypeId())){
|
|
|
+ m.setCostType(costTypeMap.get(m.getCostTypeId()));
|
|
|
+ }
|
|
|
+ m.setToDepartment(departmentMap.get(m.getToDeptId()));
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ HSSFSheet sheet = workbook.createSheet("经营数据管理平台数据统计表");
|
|
|
+ createTitle(workbook, sheet, manageVO.getType());
|
|
|
+
|
|
|
+ for (int i = 0; i < totalManages.size(); i++){
|
|
|
+ Manage m = totalManages.get(i);
|
|
|
+ HSSFRow r = sheet.createRow(i + 1);
|
|
|
+ HSSFCell cell;
|
|
|
+ cell = r.createCell(0);
|
|
|
+ cell.setCellValue(m.getHappenTime().toString());
|
|
|
+
|
|
|
+ cell = r.createCell(1);
|
|
|
+ cell.setCellValue(m.getAmount());
|
|
|
+ if(Objects.equals(manageVO.getType(), ManageTypeEnum.INCOME)){
|
|
|
+ cell = r.createCell(2);
|
|
|
+ cell.setCellValue(m.getIncomeStatus().toString());
|
|
|
+
|
|
|
+ cell = r.createCell(3);
|
|
|
+ if(Objects.nonNull(m.getProduct())){
|
|
|
+ cell.setCellValue(m.getProduct().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(4);
|
|
|
+ if(Objects.nonNull(m.getProject())){
|
|
|
+ cell.setCellValue(m.getProject().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(5);
|
|
|
+ if(Objects.nonNull(m.getDepartment())){
|
|
|
+ cell.setCellValue(m.getDepartment().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(6);
|
|
|
+ if(Objects.nonNull(m.getToDepartment())){
|
|
|
+ cell.setCellValue(m.getToDepartment().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ cell = r.createCell(7);
|
|
|
+ cell.setCellValue(m.getRemark());
|
|
|
+
|
|
|
+ cell = r.createCell(8);
|
|
|
+ cell.setCellValue(m.getGmtModified().toString());
|
|
|
+
|
|
|
+
|
|
|
+ }else {
|
|
|
+ cell = r.createCell(2);
|
|
|
+ if(Objects.nonNull(m.getCostType())){
|
|
|
+ cell.setCellValue(m.getCostType().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(3);
|
|
|
+ if(Objects.nonNull(m.getDepartment())){
|
|
|
+ cell.setCellValue(m.getDepartment().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(4);
|
|
|
+ if(Objects.nonNull(m.getProject())){
|
|
|
+ cell.setCellValue(m.getProject().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(5);
|
|
|
+ if(Objects.nonNull(m.getToDepartment())){
|
|
|
+ cell.setCellValue(m.getToDepartment().getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = r.createCell(6);
|
|
|
+ cell.setCellValue(m.getRemark());
|
|
|
+
|
|
|
+ cell = r.createCell(7);
|
|
|
+ cell.setCellValue(m.getGmtModified().toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //清空response
|
|
|
+ response.reset();
|
|
|
+ //设置response的Header
|
|
|
+ String fileName = "经营数据管理平台数据统计表_" + TimeUtil.getPreDateStr() + ".xls";
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("contentType=application/vnd.ms-excel");
|
|
|
+ response.setHeader("Content-disposition","attachment;filename="+URLEncoder.encode(fileName,"utf-8"));
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
+ response.flushBuffer();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createTitle(HSSFWorkbook workbook, HSSFSheet sheet, ManageTypeEnum type) {
|
|
|
+ HSSFRow row0 = sheet.createRow(0);
|
|
|
+
|
|
|
+ int columnNum = 10;
|
|
|
+ for (int i = 0; i < columnNum; i++) {
|
|
|
+ sheet.setColumnWidth(i, 20 * 256);
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置为居中
|
|
|
+ HSSFCellStyle style = workbook.createCellStyle();
|
|
|
+ HSSFFont font = workbook.createFont();
|
|
|
+ style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
|
|
|
+ style.setFont(font);
|
|
|
+ HSSFCell cell;
|
|
|
+
|
|
|
+ if(Objects.equals(type, ManageTypeEnum.INCOME)){
|
|
|
+ cell = row0.createCell(0);
|
|
|
+ cell.setCellValue("发生日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(1);
|
|
|
+ cell.setCellValue("金额");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(2);
|
|
|
+ cell.setCellValue("收入状态");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(3);
|
|
|
+ cell.setCellValue("产品");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(4);
|
|
|
+ cell.setCellValue("归属项目");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(5);
|
|
|
+ cell.setCellValue("归属部门");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(6);
|
|
|
+ cell.setCellValue("客户");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(7);
|
|
|
+ cell.setCellValue("备注");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(8);
|
|
|
+ cell.setCellValue("录入日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }else {
|
|
|
+ cell = row0.createCell(0);
|
|
|
+ cell.setCellValue("发生日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(1);
|
|
|
+ cell.setCellValue("金额");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(2);
|
|
|
+ cell.setCellValue("成本类型");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(3);
|
|
|
+ cell.setCellValue("发生部门");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(4);
|
|
|
+ cell.setCellValue("发生项目/人");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(5);
|
|
|
+ cell.setCellValue("供应商");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(6);
|
|
|
+ cell.setCellValue("备注");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+
|
|
|
+ cell = row0.createCell(7);
|
|
|
+ cell.setCellValue("录入日期");
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public ApiResult save(Manage manage) {
|
|
|
if(Objects.isNull(manage)){
|
|
|
return ApiResult.error(ApiCode.PARAMETER_ERROR);
|