package com.ssm.manage.service.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.AESUtils;
import com.ssm.manage.dao.SsmStoreMemberFileDao;
import com.ssm.manage.entity.StoreMemberFile;
import com.ssm.manage.query.StoreMemberPhoneRequest;
import com.ssm.manage.service.SsmStoreMemberFileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SsmStoreMemberFileServiceImpl extends BaseServiceImpl<StoreMemberFile> implements SsmStoreMemberFileService {
    @Autowired
    private SsmStoreMemberFileDao dao;

    @Override
    public SsmStoreMemberFileDao getDao() {
        return dao;
    }

    @Override
    public PageInfo<StoreMemberFile> selectPage(StoreMemberPhoneRequest memberFileRequest) {
        if (StringUtils.isNotBlank(memberFileRequest.getOldPhone())) {
            memberFileRequest.setOldPhone(AESUtils.encrypt(memberFileRequest.getOldPhone()));
        }
        PageInfo pageInfo = dao.selectPage(memberFileRequest);
        List<StoreMemberFile> lists = pageInfo.getList();
//        lists.forEach(storeMemberFile -> {
//            try {
//                storeMemberFile.setOldPhone(AESUtils.decrypt(storeMemberFile.getOldPhone()).replaceAll("\u0000",""));
//            } catch (Exception e) {
//                log.error("SsmStoreMemberFileServiceImpl.selectPage:",e);
//            }
//        });
        return pageInfo;
    }
}
