|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package com.qtzl.alterSales.manager.service;
-
- import cn.com.taiji.common.manager.net.http.ServiceHandleException;
- import cn.com.taiji.common.pub.CollectionTools;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.util.DesensitizedUtil;
- import com.google.common.collect.Lists;
- import com.qtzl.alterSales.dao.entity.second.AflOrderInfo;
- import com.qtzl.alterSales.dao.repo.jpa.second.AflOrderInfoRepo;
- import com.qtzl.alterSales.manager.model.protocol.UcServiceError;
- import com.qtzl.alterSales.manager.model.protocol.sales.AflOrderInfoFindPageViewRequest;
- import com.qtzl.alterSales.manager.model.protocol.sales.AflOrderInfoFindPageViewResponse;
- import com.qtzl.alterSales.manager.service.third.ConstantConfig;
- import com.qtzl.alterSales.manager.service.third.FmsService;
- import com.qtzl.alterSales.manager.tools.ExcelUtils;
- import com.qtzl.alterSales.manager.vo.AflOrderInfoVo;
- import org.apache.commons.lang3.StringUtils;
- import org.slf4j.Logger;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.data.domain.Sort;
- import org.springframework.stereotype.Service;
-
- import javax.annotation.Resource;
- import javax.persistence.criteria.CriteriaBuilder;
- import javax.persistence.criteria.Predicate;
- import javax.persistence.criteria.Root;
- import java.io.File;
- import java.util.List;
- import java.util.stream.Collectors;
-
-
- @Service
- public class AflOrderInfoServiceImpl implements AflOrderInfoService{
-
- @Resource
- AflOrderInfoRepo aflOrderInfoRepo;
- @Resource
- FmsService fmsService;
- @Resource
- ConstantConfig constantConfig;
-
- @Override
- public AflOrderInfo findById(String id) throws ServiceHandleException {
- if (StringUtils.isEmpty(id)) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请选择订单信息编号");
- }
- AflOrderInfo aflOrderInfo = aflOrderInfoRepo.findById(id).orElse(null);
- if (null == aflOrderInfo) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("该编号订单信息不存在");
- }
- return aflOrderInfo;
- }
-
-
- @Override
- public String export(AflOrderInfoFindPageViewRequest request, Logger logger) throws ServiceHandleException {
- String pathFile =null;
- try {
- long count = count(request);
- if (count>10000){
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("订单信息管理导出失败,数据大于10000,禁止导出");
- }
- List<AflOrderInfo> aflOrderInfos= selectList(request);
- List<AflOrderInfoVo> aflOrderInfoVos = getAflOrderInfoVos(aflOrderInfos);
- if (aflOrderInfoVos==null||aflOrderInfoVos.size()==0) {
- pathFile = ExcelUtils.export(null, "订单信息",constantConfig.getFilePath() ,null, AflOrderInfoVo.class);
- } else {
- pathFile = ExcelUtils.export(null, "订单信息",constantConfig.getFilePath(), aflOrderInfoVos, AflOrderInfoVo.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();
- }
- }
- }
-
-
- @Override
- public String select(AflOrderInfoFindPageViewRequest request) throws ServiceHandleException {
- try {
- Page<AflOrderInfo> page = selectPage(request);
- return toResponse(page,request).toJson();
- } catch (Exception e) {
- if (e instanceof ServiceHandleException) {
- throw e;
- }
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("查询订单记录管理失败,"+ e.getMessage());
- }
- }
-
- private long count(AflOrderInfoFindPageViewRequest request) {
-
- return aflOrderInfoRepo.count(((root, query, cb) -> {
- List<Predicate> list = Lists.newArrayList();
- getList(list,request,cb,root);
- Predicate[] p = new Predicate[list.size()];
- return cb.and(list.toArray(p));
- }));
- }
-
- private List<AflOrderInfo> selectList(AflOrderInfoFindPageViewRequest request) {
-
- return aflOrderInfoRepo.findAll(((root, query, cb) -> {
- List<Predicate> list = Lists.newArrayList();
- getList(list,request,cb,root);
- Predicate[] p = new Predicate[list.size()];
- return cb.and(list.toArray(p));
- }), Sort.by(Sort.Direction.DESC, "createTime"));
- }
-
-
- private AflOrderInfoFindPageViewResponse toResponse(Page<AflOrderInfo> page, AflOrderInfoFindPageViewRequest request) {
- final AflOrderInfoFindPageViewResponse response = new AflOrderInfoFindPageViewResponse();
- response.setCurrentPage(request.getPageNo());
- response.setPageSize(request.getPageSize());
- response.setPageCount(page.getTotalPages());
- response.setTotalCount(page.getTotalElements());
- if (CollectionTools.isEmpty(page.getContent())) {
- response.setData(Lists.newArrayList());
- return response;
- }
- List<AflOrderInfoVo> formVoList = getAflOrderInfoVos(page.getContent());
- response.setData(formVoList);
- return response;
- }
-
- private Page<AflOrderInfo> selectPage(AflOrderInfoFindPageViewRequest request) throws ServiceHandleException {
- if (request.getPageSize() > 100) {
- throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("请求每页数量过大 " + request.getPageSize());
- }
- return aflOrderInfoRepo.findAll(((root, query, cb) -> {
- List<Predicate> list = Lists.newArrayList();
- getList(list,request,cb,root);
- Predicate[] p = new Predicate[list.size()];
- return cb.and(list.toArray(p));
- }), PageRequest.of(request.getPageNo() - 1, request.getPageSize(),
- Sort.by(Sort.Direction.DESC, "createTime")));
- }
-
- private List<AflOrderInfoVo> getAflOrderInfoVos(List<AflOrderInfo> aflOrderInfos){
- List<AflOrderInfoVo> aflActivationInfoVos = aflOrderInfos.stream().map(this::toVo).collect(Collectors.toList());
- return aflActivationInfoVos;
- }
- private AflOrderInfoVo toVo(AflOrderInfo aflOrderInfo) {
- AflOrderInfoVo aflOrderInfoVo = new AflOrderInfoVo();
- BeanUtil.copyProperties(aflOrderInfo, aflOrderInfoVo);
- if (!StringUtils.isEmpty(aflOrderInfoVo.getMobile())&&aflOrderInfoVo.getMobile().length()==11){
- aflOrderInfoVo.setMobile(DesensitizedUtil.mobilePhone(aflOrderInfoVo.getMobile()));
- }
- if (!StringUtils.isEmpty(aflOrderInfoVo.getIdNum())&&aflOrderInfoVo.getIdNum().length()==18){
- aflOrderInfoVo.setIdNum(DesensitizedUtil.idCardNum(aflOrderInfoVo.getIdNum(), 0, 4));
- }
- aflOrderInfoVo.setPatternOpenId(aflOrderInfo.getOpenId());
- return aflOrderInfoVo;
- }
-
- private void getList(List list, AflOrderInfoFindPageViewRequest request, CriteriaBuilder cb, Root<AflOrderInfo> root){
- if (!StringUtils.isEmpty(request.getPlateNum())) {
- list.add(cb.equal(root.<String>get("plateNum"), request.getPlateNum()));
- }
- if (request.getPlateColor()!=null) {
- list.add(cb.equal(root.<Integer>get("plateColor"), request.getPlateColor()));
- }
- if (!StringUtils.isEmpty(request.getOrderNo())) {
- list.add(cb.equal(root.<String>get("orderNo"), request.getOrderNo()));
- }
- if (!StringUtils.isEmpty(request.getPatternOpenId())) {
- list.add(cb.equal(root.<String>get("openId"), request.getPatternOpenId()));
- }
- if (!StringUtils.isEmpty(request.getIdNum())) {
- list.add(cb.equal(root.<String>get("idNum"), request.getIdNum()));
- }
- if (!StringUtils.isEmpty(request.getVehicleId())) {
- list.add(cb.equal(root.<String>get("vehicleId"), request.getVehicleId()));
- }
- if (request.getIsPay()!=null) {
- list.add(cb.equal(root.<Integer>get("isPay"), request.getIsPay()));
- }
-
- }
- }
|