package com.sqx.modules.artificer.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.artificer.dao.ArtificerDao;
import com.sqx.modules.artificer.dao.MassageTypeDao;
import com.sqx.modules.artificer.entity.Artificer;
import com.sqx.modules.artificer.entity.MassageType;
import com.sqx.modules.artificer.service.ArtificerService;
import com.sqx.modules.artificer.service.MassageTypeService;
import com.sqx.modules.search.service.AppSearchService;
import com.sqx.modules.sys.entity.SysDictEntity;
import com.sqx.modules.sys.service.SysDictService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MassageTypeServiceImpl extends ServiceImpl<MassageTypeDao, MassageType> implements MassageTypeService {

    @Autowired
    private AppSearchService appSearchService;
    @Autowired
    SysDictService sysDictService;

    @Override
    public Result selectArtificerMassageList(Long artificerId,Integer status){
        List<MassageType> massageTypes = baseMapper.selectArtificerMassageList(artificerId, status);
        return Result.success().put("data",massageTypes);
    }

    @Override
    public Result selectMassageTypePage(Integer page,Integer limit,Integer status,String city,Integer sort,Integer authentication,Integer by,String title,Long artificerId,Long userId,Long parentId,Long classifyId){
        if(StringUtils.isNotEmpty(title) && userId!=null){
            appSearchService.insetAppSearch(title, userId);
        }
        Page<MassageType> pages=new Page<>(page,limit);
        return Result.success().put("data",new PageUtils(baseMapper.selectMassageTypePage(pages,status,city,sort,authentication,by,title,artificerId,parentId,classifyId)));
    }
    @Override
    public Result selectMassageTypeChildrenPage(Integer page,Integer limit,Integer status,String city,Integer sort,Integer authentication,Integer by,String title,Long artificerId,Long userId,Long parentId,Long classifyId){
        if(StringUtils.isNotEmpty(title) && userId!=null){
            appSearchService.insetAppSearch(title, userId);
        }
        Page<MassageType> pages=new Page<>(page,limit);
        return Result.success().put("data",new PageUtils(baseMapper.selectMassageTypeChildrenPage(pages,status,city,sort,authentication,by,title,artificerId,parentId,classifyId)));
    }

    @Override
    public Result selectMassageTypeList(Integer status,String city,Integer sort,Integer authentication,Integer by,String title,Long artificerId,Long userId,Long parentId,Long classifyId){
        if(StringUtils.isNotEmpty(title) && userId!=null){
            appSearchService.insetAppSearch(title, userId);
        }
        return Result.success().put("data",baseMapper.selectMassageTypeList(status,city,sort,authentication,by,title,artificerId,parentId,classifyId));
    }

    @Override
    public Result selectMassageTypeById(Long massageTypeId,Long userId){
        MassageType massageType = this.getById(massageTypeId);
        SysDictEntity sysDictEntity = sysDictService.getById(massageType.getClassifyId());
        if(sysDictEntity!=null){
            massageType.setClassifyName(sysDictEntity.getCode());
        }
        List<MassageType> children = baseMapper.selectMassageTypeList(1,null,null,null,3,null,null,massageTypeId,null);
        massageType.setChildrenMassageList(children);
        return Result.success().put("data",massageType);
    }

    @Override
    public Result selectMassageTypeQyPage(Integer page, Integer limit, String city, String title) {
        Page<MassageType> pages=new Page<>(page,limit);
        return Result.success().put("data",new PageUtils(baseMapper.selectMassageTypeQyPage(pages,city,title)));
    }

}