package com.chinaweal.aiccs.aiccs.punishment.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinaweal.aiccs.aiccs.punishment.entity.EntLock;
import com.chinaweal.aiccs.aiccs.punishment.entity.Tolockentlist;
import com.chinaweal.aiccs.aiccs.punishment.entity.excel.EntLockExcel;
import com.chinaweal.aiccs.aiccs.punishment.mapper.EntlockMapper;
import com.chinaweal.aiccs.aiccs.punishment.service.EntlockService;
import com.chinaweal.aiccs.aiccs.system.entity.TRBaseCode;
import com.chinaweal.aiccs.aiccs.system.service.TRBaseCodeService;
import com.chinaweal.aiccs.common.util.StringUtils;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 业户锁定 服务实现类
 * </p>
 *
 * @author Lee
 * @since 2021-06-06
 */
@Service
public class EntlockServiceImpl extends BaseServiceImpl<EntlockMapper, EntLock> implements EntlockService {

    @Resource
    private EntlockMapper entlockMapper;

    @Autowired
    TRBaseCodeService trBaseCodeService;

    @Override
    public List<EntLock> selectEntLockList() {
        return entlockMapper.selectEntLockList();
    }

    @Override
    public List<EntLock> queryByPripid(String pripid) {
        return entlockMapper.queryByPripid(pripid);
    }

    @Override
    public List<EntLockExcel> queryForExcel(IPage<EntLockExcel> page, Map<String, Object> customParamMap) {
        String searchCode = StringUtils.tranObject(customParamMap.get("searchCode"));
        if(StringUtils.isNotBlank(searchCode)){
            if(StringUtils.isUscc(searchCode)){
                customParamMap.put("unisicd",searchCode);
            }else {
                customParamMap.put("regno",searchCode);
            }
        }
        IPage<EntLockExcel> entLockExcelIPage = entlockMapper.queryForExcel(page,customParamMap);
        List<TRBaseCode> trBaseCodes = trBaseCodeService.getBaseCodeListFromCache("sdlx");
        Map<String,String> map = new HashMap<>();
        for(TRBaseCode trBaseCode : trBaseCodes){
            map.put(trBaseCode.getCode(),trBaseCode.getName());
        }
        List<EntLockExcel> entLockExcels = entLockExcelIPage.getRecords();
        for(EntLockExcel entLockExcel : entLockExcels){
            if(StringUtils.isNotBlank(entLockExcel.getUniscid())){
                entLockExcel.setNo(entLockExcel.getUniscid());
            } else {
                entLockExcel.setNo(entLockExcel.getRegno());
            }
            entLockExcel.setLocktype(map.get(entLockExcel.getLocktype()));
        }
        return entLockExcels;
    }

    @Override
    public List<EntLock> queryByState(String pripid,String punishFrom) {
        return entlockMapper.queryByState(pripid,punishFrom);
    }

    @Override
    public List<EntLock> selectLockEntity(String entName) {
        return entlockMapper.selectLockEntity(entName);
    }

    @Override
    public void insert(EntLock entLock) {
        entlockMapper.insert(entLock);
    }

    @Override
    public EntLock check(String pripid) {
        return entlockMapper.check(pripid);
    }


}
