package com.changhu.module.policeManagement.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.utils.UserUtil;
import com.changhu.module.miniProgram.pojo.params.SecurityUserSaveOrUpdateParams;
import com.changhu.module.miniProgram.pojo.queryParams.ServiceProjectSecurityUserPagerQueryParams;
import com.changhu.module.miniProgram.pojo.vo.ServiceProjectSecurityUserPagerVo;
import com.changhu.module.miniProgram.service.UserService;
import com.changhu.module.policeManagement.mapper.PoliceEnterprisesUnitMapper;
import com.changhu.module.policeManagement.pojo.params.ServiceProjectSaveOrUpdateParams;
import com.changhu.module.policeManagement.pojo.vo.ServiceProjectListVo;
import com.changhu.module.policeManagement.service.PoliceEnterprisesUnitService;
import com.changhu.pojo.entity.ServiceProject;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 20252
 * @createTime 2024/11/27 下午2:38
 * @desc PoliceEnterprisesUnitServiceImpl...
 */
@Service
public class PoliceEnterprisesUnitServiceImpl implements PoliceEnterprisesUnitService {

    @Autowired
    private PoliceEnterprisesUnitMapper policeEnterprisesUnitMapper;

    @Autowired
    private UserService userService;

    @Override
    public List<ServiceProjectListVo> listSp(Long enterprisesUnitId) {
        return policeEnterprisesUnitMapper.listSp(UserUtil.getUnitId(), enterprisesUnitId);
    }

    @Override
    public void saveOrUpdateSp(ServiceProjectSaveOrUpdateParams params) {
        ServiceProject serviceProject = BeanUtil.copyProperties(params, ServiceProject.class);
        Assert.isTrue(Db.saveOrUpdate(serviceProject), ResultCode.ERROR.getMessage());
    }

    @Override
    public void saveOrUpdateSecurityUser(SecurityUserSaveOrUpdateParams params) {
        userService.saveOrUpdateSecurityUser(params);
    }

    @Override
    public Page<ServiceProjectSecurityUserPagerVo> securityUserPager(PageParams<ServiceProjectSecurityUserPagerQueryParams, ServiceProjectSecurityUserPagerVo> queryParams) {
        return userService.securityUserPager(queryParams);
    }

    @Override
    public void deleteSecurityUserById(Long securityUserId) {
        userService.deleteSecurityUserById(securityUserId);
    }
}
