package com.muyu.enterprise.service.impl;

import cn.hutool.core.map.MapUtil;
import com.muyu.enterprise.domain.Enterprise;
import com.muyu.enterprise.mapper.EnterpriseDao;
import com.muyu.enterprise.service.EnterpriseService;
import com.muyu.enterprise.util.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author YuPing
 * @Description 企业运营实现层
 * @Version 1.0
 * @Data 2024-09-26 20:23:21
 */
@Service
public class EnterpriseServiceImpl implements EnterpriseService {

    @Autowired
    private EnterpriseDao enterpriseDao;

    /**
     * 分页查询企业运营信息
     * @param param
     * @return
     */
    @Override
    public PageUtils selectEnterprise(Map param) {
        ArrayList<HashMap> list = new ArrayList<>();
        long count = enterpriseDao.selectEnterpriseCount();
        if (count > 0){
            list = enterpriseDao.selectEnterprise(param);
        }
        int page = MapUtil.getInt(param, "page");
        int length = MapUtil.getInt(param,"length");
        PageUtils pageUtils = new PageUtils(list, count, page, length);
        return pageUtils;
    }


    /**
     * 新增企业信息
     * @param enterprise
     * @return
     */
    @Override
    public int insert(Enterprise enterprise) {
        int rows = enterpriseDao.insert(enterprise);
        return rows;
    }


    /**
     * 根据编号查询企业信息
     * @param enterpriseId
     * @return
     */
    @Override
    public HashMap searchById(int enterpriseId) {
        HashMap map = enterpriseDao.searchById(enterpriseId);
        return map;
    }


    /**
     * 修改企业信息
     * @param enterprise
     * @return
     */
    @Override
    public int updateEnterprise(Enterprise enterprise) {
        int rows = enterpriseDao.updateEnterprise(enterprise);
        return rows;
    }


    /**
     * 删除企业信息
     * @param ids
     * @return
     */
    @Override
    public int deleteByIds(Integer[] ids) {
        int rows = enterpriseDao.deleteByIds(ids);
        return rows;
    }
}
