lishuai
2023-12-26 1293d3dba10c4e291dfbce4c936f952875557edb
server/dmvisit_service/src/main/java/com/doumee/service/business/impl/RetentionServiceImpl.java
@@ -1,31 +1,51 @@
package com.doumee.service.business.impl;
import cn.hutool.core.lang.PatternPool;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.ReUtil;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.admin.request.RetentionQuery;
import com.doumee.dao.business.RetentionMapper;
import com.doumee.dao.business.model.Retention;
import com.doumee.dao.business.join.RetentionJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.SystemDictDataMapper;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.dao.system.vo.RetentionVo;
import com.doumee.service.business.RetentionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
 * 在厂人员信息 表(滞留)Service实现
 * @author 江蹄蹄
 * @date 2023/11/23 18:16
 * @date 2023/11/30 15:33
 */
@Service
public class RetentionServiceImpl implements RetentionService {
    @Autowired
    private RetentionMapper retentionMapper;
    @Autowired
    private RetentionJoinMapper retentionJoinMapper;
    @Autowired
    private SystemDictDataMapper systemDictDataMapper;
    @Override
    public Integer create(Retention retention) {
@@ -83,7 +103,7 @@
        QueryWrapper<Retention> wrapper = new QueryWrapper<>(retention);
        return retentionMapper.selectList(wrapper);
    }
    @Override
    public PageData<Retention> findPage(PageWrap<Retention> pageWrap) {
        IPage<Retention> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
@@ -171,4 +191,86 @@
        QueryWrapper<Retention> wrapper = new QueryWrapper<>(retention);
        return retentionMapper.selectCount(wrapper);
    }
    @Override
    public PageData<Retention> findTrainTimePage(PageWrap<Retention> pageWrap) {
        IPage<Retention> retentionIPage = getDataInfo(pageWrap);
        if(null != retentionIPage && retentionIPage.getRecords().size() > 0) {
            List<String> codes = Arrays.asList(Constants.FTP_RESOURCE_PATH,Constants.MEMBER_IMG);
            List<SystemDictData> list = systemDictDataMapper.list(codes);
            Map<String,SystemDictData> dataMap = list.stream().collect(Collectors.toMap(SystemDictData::getLabel, Function.identity()));
            retentionIPage.getRecords().stream().forEach(obj->{
                obj.setFaceImg(dataMap.get(Constants.FTP_RESOURCE_PATH).getCode()
                        +dataMap.get(Constants.MEMBER_IMG).getCode()
                        +obj.getFaceImg());
            });
        }
        return PageData.from(retentionIPage);
    }
    /**
     * 导出
     *
     * @param pageWrap 分页对象
     * @return PageData<RetentionVo>
     */
    public List<RetentionVo> findPageExcel(PageWrap<Retention> pageWrap) {
        IPage<Retention> retentionInfo = getDataInfo(pageWrap);
        List<RetentionVo> retentionVoList = new ArrayList<>();
        if(null != retentionInfo && retentionInfo.getRecords().size() > 0) {
            for (Retention obj:retentionInfo.getRecords()) {
                RetentionVo vo = new RetentionVo();
                vo.setCompanyName(obj.getCompanyName());
                if(null != obj.getType()) {
                    if(Constants.ZERO == obj.getType()){
                        vo.setTypeName(Constants.Status.LW_FK.getDes());
                    }else if(Constants.ONE == obj.getType()) {
                        vo.setTypeName(Constants.Status.PT_FK.getDes());
                    }else {
                        vo.setTypeName(Constants.Status.NB_FK.getDes());
                    }
                }else {
                    vo.setTypeName("");
                }
                vo.setName(obj.getName());
                vo.setPhone(obj.getPhone());
                vo.setIdcardNo(obj.getIdcardNo());
                vo.setDeviceName(obj.getDeviceName());
                vo.setEventDate(obj.getEventDate());
                retentionVoList.add(vo);
            }
        }
        return retentionVoList;
    }
    private  IPage<Retention> getDataInfo(PageWrap<Retention> pageWrap) {
        //是否是数字
        boolean number = Validator.isNumber(pageWrap.getModel().getKeyWords());
        //是否包含中文
        boolean b = Validator.hasChinese(pageWrap.getModel().getKeyWords());
        //是否包含英文
        boolean hasWord = ReUtil.contains(PatternPool.WORD, pageWrap.getModel().getKeyWords());
        IPage<Retention> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Retention> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.leftJoin(Company.class,Company::getId,Retention::getId);
        queryWrapper.selectAll(Retention.class)
                .selectAs(Company::getName,Retention::getCompanyName);
        queryWrapper.like(number,Retention::getPhone,pageWrap.getModel().getKeyWords())
                .like((b||hasWord),Retention::getName,pageWrap.getModel().getKeyWords())
                .eq(Objects.nonNull(pageWrap.getModel().getType()),
                        Retention::getType,
                        pageWrap.getModel().getType())
                .like(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()),
                        Company::getName,
                        pageWrap.getModel().getCompanyName())
                .ge(Objects.nonNull(pageWrap.getModel().getStartTime()),
                        Retention::getEventDate,pageWrap.getModel().getStartTime())
                .le(Objects.nonNull(pageWrap.getModel().getEndTime()),
                        Retention::getEventDate,pageWrap.getModel().getStartTime());
        queryWrapper.orderByDesc(Retention::getCreateDate);
        IPage<Retention> retentionIPage = retentionJoinMapper.selectJoinPage(page, Retention.class, queryWrapper);
        return retentionIPage;
    }
}