doum
6 天以前 308bc8e5c0db7298a127f3478995ddc6167328e9
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/InoutRecordServiceImpl.java
@@ -14,6 +14,7 @@
import com.doumee.dao.business.model.Member;
import com.doumee.dao.business.vo.GeneralDataVO;
import com.doumee.dao.business.vo.InParkUserDataVO;
import com.doumee.dao.business.vo.TelecomInParkDataVO;
import com.doumee.service.business.InoutRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -24,7 +25,7 @@
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -155,7 +156,7 @@
    //人员分类  单独处理人员数据  0劳务访客 1普通访客 2内部员工 3车辆信息 4相关方人员 5货运司机
    private static String[] userTypeList = new String[]{"","普通访客","内部人员","","相关方人员","货运司机"};
    private static String[] userTypeList = new String[]{"","普通访客","内部人员","","相关方人员"};
    /**
@@ -172,8 +173,11 @@
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        //查询本周的开始日期和结束日期
        Long weekStart = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();
        //查询本周的开始日期
        LocalDate today = LocalDate.now();
        // 计算周一和周五的日期
        LocalDate monday = today.with(DayOfWeek.MONDAY);
        Long weekStart = DateUtil.fromStringToDate("yyyy-MM-dd HH:mm:ss",monday.toString() + " 00:00:00").getTime();//LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();
        InParkUserDataVO inParkUserDataVO = new InParkUserDataVO();
        List<InoutRecord> yearList = inoutRecordMapper.selectJoinList(InoutRecord.class,new MPJLambdaWrapper<InoutRecord>()
                .selectAll(InoutRecord.class)
@@ -310,7 +314,7 @@
                for (String categoryName:setList) {
                    GeneralDataVO generalDataVO = new GeneralDataVO();
                    generalDataVO.setName(categoryName);
                    generalDataVO.setTotal(yearList.stream().filter(j->StringUtils.isNotBlank(j.getCategoryParentName())&&j.getCategoryName().equals(categoryName)).collect(Collectors.toList()).size());
                    generalDataVO.setTotal(yearList.stream().filter(j->StringUtils.isNotBlank(j.getCategoryParentName())&&j.getCategoryParentName().equals(categoryName)).collect(Collectors.toList()).size());
                    generalDataVO.setRata(new BigDecimal(generalDataVO.getTotal().toString()).divide(new BigDecimal(yearList.size()+""),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")));
                    rataList.add(generalDataVO);
                }
@@ -331,21 +335,59 @@
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        List<InoutRecord> allList = inoutRecordMapper.selectJoinList(InoutRecord.class,new MPJLambdaWrapper<InoutRecord>()
                .selectAll(InoutRecord.class)
                .eq(InoutRecord::getIsdeleted,Constants.ZERO)
        List<InoutRecord> allList = new ArrayList<>();
        MPJLambdaWrapper mpjLambdaWrapper = new MPJLambdaWrapper<InoutRecord>().eq(InoutRecord::getIsdeleted,Constants.ZERO)
                .eq(InoutRecord::getInOrOut,Constants.ZERO)
                .isNotNull(Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO),InoutRecord::getCarCode)
                .isNotNull(Constants.equalsInteger(inParkDataDTO.getType(),Constants.ONE),InoutRecord::getMemberPhone)
                .apply(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)," ( DATE_FORMAT(CREATE_DATE, '%Y') =  '"+inParkDataDTO.getDateStr()+"' ) ")
                .apply(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)," ( DATE_FORMAT(CREATE_DATE, '%Y-%m') =  '"+inParkDataDTO.getDateStr()+"' ) ")
        );
                .apply(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)," ( DATE_FORMAT(CREATE_DATE, '%Y-%m') =  '"+inParkDataDTO.getDateStr()+"' ) ");
        if(Constants.equalsInteger(inParkDataDTO.getIsGroupBy(),Constants.ONE)){
             mpjLambdaWrapper.groupBy(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO),
                            "car_code,category_name,DATE_FORMAT(CREATE_DATE, '%Y-%m')")
                    .groupBy(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO),
                            "car_code,category_name,DATE_FORMAT(CREATE_DATE, '%Y-%m-%d')")
                    .groupBy(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ONE),
                            "member_phone,MEMBER_TYPE,DATE_FORMAT(CREATE_DATE, '%Y-%m')")
                    .groupBy(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ONE),
                            "member_phone,MEMBER_TYPE,DATE_FORMAT(CREATE_DATE, '%Y-%m-%d')");
            if(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO)){
                mpjLambdaWrapper.select("car_code,category_name,DATE_FORMAT(CREATE_DATE, '%Y-%m') as createDateStr ");
            }else if(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO)){
                mpjLambdaWrapper.select("car_code,category_name,DATE_FORMAT(CREATE_DATE, '%Y-%m-%d') as createDateStr ");
            }else if(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ONE)){
                mpjLambdaWrapper.select("member_phone,MEMBER_TYPE,DATE_FORMAT(CREATE_DATE, '%Y-%m') as createDateStr");
            }else{
                mpjLambdaWrapper.select("member_phone,MEMBER_TYPE,DATE_FORMAT(CREATE_DATE, '%Y-%m-%d') as createDateStr ");
            }
        }else{
            mpjLambdaWrapper.selectAll(InoutRecord.class);
            if(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO)){
                mpjLambdaWrapper.select("DATE_FORMAT(CREATE_DATE, '%Y-%m') as createDateStr ");
            }else if(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO)){
                mpjLambdaWrapper.select("DATE_FORMAT(CREATE_DATE, '%Y-%m-%d') as createDateStr ");
            }else if(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)&&Constants.equalsInteger(inParkDataDTO.getType(),Constants.ONE)){
                mpjLambdaWrapper.select("DATE_FORMAT(CREATE_DATE, '%Y-%m') as createDateStr");
            }else{
                mpjLambdaWrapper.select("DATE_FORMAT(CREATE_DATE, '%Y-%m-%d') as createDateStr ");
            }
//           allList = inoutRecordMapper.selectJoinList(InoutRecord.class,new MPJLambdaWrapper<InoutRecord>()
//                    .selectAll(InoutRecord.class)
//                    .eq(InoutRecord::getIsdeleted,Constants.ZERO)
//                    .eq(InoutRecord::getInOrOut,Constants.ZERO)
//                    .isNotNull(Constants.equalsInteger(inParkDataDTO.getType(),Constants.ZERO),InoutRecord::getCarCode)
//                    .isNotNull(Constants.equalsInteger(inParkDataDTO.getType(),Constants.ONE),InoutRecord::getMemberPhone)
//                    .apply(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),4)," ( DATE_FORMAT(CREATE_DATE, '%Y') =  '"+inParkDataDTO.getDateStr()+"' ) ")
//                    .apply(Constants.equalsInteger(inParkDataDTO.getDateStr().length(),7)," ( DATE_FORMAT(CREATE_DATE, '%Y-%m') =  '"+inParkDataDTO.getDateStr()+"' ) ")
//            );
        }
        allList = inoutRecordMapper.selectJoinList(InoutRecord.class,mpjLambdaWrapper);
        List<List<String>>  resultList = new ArrayList<>();
        if(CollectionUtils.isEmpty(allList)){
            return resultList;
        }
        if(Constants.equalsInteger(inParkDataDTO.getIsGroupBy(),Constants.ONE)){
            allList = this.getListByType(allList,inParkDataDTO.getType());
        }
        List<String> dateList = new ArrayList<>();
@@ -384,7 +426,7 @@
    public List<List<String>> dealResultData(List<InoutRecord> allList,List<String> dataList ,Integer type,String dateStr){
        List<List<String>>  resultList = new ArrayList<>();
        List<String> totalString = new ArrayList<>();
        totalString.add("日期");
        totalString.add("数据日期");
        if(Constants.equalsInteger(type,Constants.ZERO)){
            List<String> categoryNameList = allList.stream().filter(j-> StringUtils.isNotBlank(j.getCategoryName())).map(j->j.getCategoryName()).collect(Collectors.toList());
            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(categoryNameList)){
@@ -403,14 +445,14 @@
                for (String categoryName:setList) {
                    if(Constants.equalsInteger(dateStr.length(),4)){
                        Integer childNum = allList.stream().filter(i->categoryName.equals(i.getCategoryName())
                                && DateUtil.formatDate(i.getCreateDate(),"yyyy-MM").equals(str)).collect(Collectors.toList()).size();
                                && i.getCreateDateStr().equals(str)).collect(Collectors.toList()).size();
                        dataChildList.add(
                                Integer.toString(childNum)
                        );
                        total = total + childNum;
                    }else if(Constants.equalsInteger(dateStr.length(),7)){
                        Integer childNum = allList.stream().filter(i->categoryName.equals(i.getCategoryName())
                                &&DateUtil.formatDate(i.getCreateDate(),"yyyy-MM-dd").equals(str)).collect(Collectors.toList()).size();
                                &&i.getCreateDateStr().equals(str)).collect(Collectors.toList()).size();
                        dataChildList.add(
                                Integer.toString(childNum)
                        );
@@ -441,14 +483,14 @@
                    int finalI = i;
                    if(Constants.equalsInteger(dateStr.length(),4)){
                        Integer childNum = allList.stream().filter(j->Constants.equalsInteger(j.getMemberType(), finalI)
                                && DateUtil.formatDate(j.getCreateDate(),"yyyy-MM").equals(str)).collect(Collectors.toList()).size();
                                && j.getCreateDateStr().equals(str)).collect(Collectors.toList()).size();
                        dataChildList.add(
                                Integer.toString(childNum)
                        );
                        total = total + childNum;
                    }else if(Constants.equalsInteger(dateStr.length(),7)){
                        Integer childNum = allList.stream().filter(j->Constants.equalsInteger(j.getMemberType(), finalI)
                                &&DateUtil.formatDate(j.getCreateDate(),"yyyy-MM-dd").equals(str)).collect(Collectors.toList()).size();
                                &&j.getCreateDateStr().equals(str)).collect(Collectors.toList()).size();
                        dataChildList.add(
                                Integer.toString(childNum)
                        );
@@ -461,10 +503,6 @@
        }
        return resultList;
    }
    public List<InoutRecord> getListByType(List<InoutRecord> list,Integer type){
@@ -510,4 +548,40 @@
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
    @Override
    public TelecomInParkDataVO getInParkDataForTelecom(){
        TelecomInParkDataVO telecomInParkDataVO = new TelecomInParkDataVO();
        telecomInParkDataVO.setInCarNum(Constants.ZERO);
        telecomInParkDataVO.setInUserNum(Constants.ZERO);
        List<InoutRecord> listCar = inoutRecordMapper.selectList(new MPJLambdaWrapper<InoutRecord>()
                        .eq(InoutRecord::getIsdeleted,Constants.ZERO)
                        .eq(InoutRecord::getInOrOut,Constants.ZERO)
                        .isNotNull(InoutRecord::getCarCode)
                        .apply(" ( DATE_FORMAT(CREATE_DATE, '%Y%m%d')  = DATE_FORMAT(now(), '%Y%m%d') ) "));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(listCar)){
            telecomInParkDataVO.setInCarNum(
                    new HashSet<>(listCar.stream().map(i->i.getCarCode()).collect(Collectors.toList())).size()
            );
        }
        List<InoutRecord> listUser = inoutRecordMapper.selectList(new MPJLambdaWrapper<InoutRecord>()
                        .eq(InoutRecord::getIsdeleted,Constants.ZERO)
                        .eq(InoutRecord::getInOrOut,Constants.ZERO)
                        .isNotNull(InoutRecord::getMemberPhone)
                        .apply(" ( DATE_FORMAT(CREATE_DATE, '%Y%m%d') = DATE_FORMAT(now(), '%Y%m%d') ) "));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(listUser)){
            telecomInParkDataVO.setInUserNum(
                    new HashSet<>(listUser.stream().map(i->i.getMemberPhone()).collect(Collectors.toList())).size()
            );
        }
        return telecomInParkDataVO;
    }
}