123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- package com.qtzl.alterSales.manager.service;
-
- import cn.com.taiji.common.manager.net.http.ServiceHandleException;
- import com.google.common.collect.Lists;
- import com.qtzl.alterSales.dao.entity.second.AflBlackInfo;
- import com.qtzl.alterSales.dao.repo.jpa.second.AflBlackInfoRepo;
- import com.qtzl.alterSales.manager.enums.BlacklistOpType;
- import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
- import com.qtzl.alterSales.manager.model.protocol.sales.AflBlackInfoFindPageViewRequest;
- import com.qtzl.alterSales.manager.service.third.ConstantConfig;
- import com.qtzl.alterSales.manager.service.third.FmsService;
- import com.qtzl.alterSales.manager.tools.ExcelUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.springframework.data.domain.Sort;
- import org.springframework.stereotype.Service;
-
- import javax.annotation.Resource;
- import javax.persistence.criteria.Predicate;
- import java.io.File;
- import java.time.LocalDateTime;
- import java.util.List;
-
-
- @Service
- public class AflBlackInfoServiceImpl implements AflBlackInfoService{
-
- @Resource
- AflBlackInfoRepo aflBlackInfoRepo;
-
- @Resource
- FmsService fmsService;
-
- @Resource
- ConstantConfig constantConfig;
-
-
- @Override
- public String export(AflBlackInfoFindPageViewRequest request, Logger logger) throws ServiceHandleException {
- String pathFile =null;
- try {
- long count = count(request);
- if (count> 10000l){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败,数据大于10000不允许导出");
- }
- List<AflBlackInfo> aflBlackInfos = select(request);
- if (aflBlackInfos==null||aflBlackInfos.size()==0) {
- pathFile = ExcelUtils.export(null, "状态名单",constantConfig.getFilePath() ,null, AflBlackInfo.class);
- } else {
- pathFile = ExcelUtils.export(null, "状态名单",constantConfig.getFilePath(), aflBlackInfos, AflBlackInfo.class);
- }
- if (StringUtils.isEmpty(pathFile)){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败");
- }
- String s = null;
- try {
- s = fmsService.uploadFile(constantConfig.getUploadFile(),pathFile, 90000);
- } catch (ServiceHandleException e) {
- logger.error("选装-状态名单管理导出失败:{}", e.getMessage());
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException(e.getMessage());
- }
-
- if (StringUtils.isEmpty(s)){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败");
- }
- return s;
- } catch (Exception e) {
- if (e instanceof ServiceHandleException) {
- throw e;
- }
- logger.error("选装-状态名单管理导出失败:{}", e.getMessage());
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("状态名单管理导出失败");
- }finally {
- File file = null;
- try {
- file = new File(pathFile);
- } catch (Exception e) {
-
- }
- if (file!=null){
- file.delete();
- }
- }
- }
- private List<AflBlackInfo> select(AflBlackInfoFindPageViewRequest request) throws ServiceHandleException {
- return aflBlackInfoRepo.findAll(((root, query, cb) -> {
- List<Predicate> list = Lists.newArrayList();
- if (!StringUtils.isEmpty(request.getAgreementNum())) {
- list.add(cb.equal(root.<String>get("agreementNum"), request.getAgreementNum()));
- }
- if (!StringUtils.isEmpty(request.getIdNum())) {
- list.add(cb.equal(root.<String>get("idNum"), request.getIdNum()));
- }
- if (!StringUtils.isEmpty(request.getMobile())) {
- list.add(cb.equal(root.<String>get("mobile"), request.getMobile()));
- }
- if (request.getOpType()!=null) {
- list.add(cb.equal(root.<BlacklistOpType>get("opType"), request.getOpType()));
- }
- if (request.getInsertTimeEnd()!=null) {
- list.add(cb.lessThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeEnd()));
- }
- if (request.getInsertTimeStart()!=null) {
- list.add(cb.greaterThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeStart()));
- }
- Predicate[] p = new Predicate[list.size()];
- return cb.and(list.toArray(p));
- }), Sort.by(Sort.Direction.DESC, "insertTime"));
- }
- private long count(AflBlackInfoFindPageViewRequest request) throws ServiceHandleException {
- return aflBlackInfoRepo.count(((root, query, cb) -> {
- List<Predicate> list = Lists.newArrayList();
- if (!StringUtils.isEmpty(request.getAgreementNum())) {
- list.add(cb.equal(root.<String>get("agreementNum"), request.getAgreementNum()));
- }
- if (!StringUtils.isEmpty(request.getIdNum())) {
- list.add(cb.equal(root.<String>get("idNum"), request.getIdNum()));
- }
- if (!StringUtils.isEmpty(request.getMobile())) {
- list.add(cb.equal(root.<String>get("mobile"), request.getMobile()));
- }
- if (request.getOpType()!=null) {
- list.add(cb.equal(root.<BlacklistOpType>get("opType"), request.getOpType()));
- }
- if (request.getInsertTimeEnd()!=null) {
- list.add(cb.lessThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeEnd()));
- }
- if (request.getInsertTimeStart()!=null) {
- list.add(cb.greaterThanOrEqualTo(root.<LocalDateTime>get("insertTime"), request.getInsertTimeStart()));
- }
- Predicate[] p = new Predicate[list.size()];
- return cb.and(list.toArray(p));
- }));
- }
- }
|