package com.ruoyi.docking.service.impl;

import cn.hutool.core.util.CreditCodeUtil;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.docking.entity.SmartDeclaration;
import com.ruoyi.docking.service.SmartDeclarationService;
import com.ruoyi.docking.service.UserService;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户数据（服务实现类）
 *
 * @author makejava
 * @since 2025-03-25 14:49:04
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private SmartDeclarationService smartDeclarationService;

    @Override
    public void getAllZwUser(String content, Long id, Long smartRemindersId, String time) {
        SysUser user = new SysUser();
        List<SysUser> sysUsers = sysUserMapper.selectUserList(user);
        //获取到所有的符合条件的政务用户
        List<SysUser> collect = sysUsers.stream().filter(x -> "0".equals(x.getDelFlag()) && "0".equals(x.getStatus()))
                .filter(y -> !CreditCodeUtil.isCreditCode(y.getUserName()))
                .collect(Collectors.toList());
        List<SmartDeclaration> list = new ArrayList<>();
        collect.forEach(x->{
            SmartDeclaration smartDeclaration = new SmartDeclaration();
            smartDeclaration.setZwId(x.getUserId());
            smartDeclaration.setContent(content);
            smartDeclaration.setProjectId(id);
            if(time!=null&& !time.isEmpty()){
                smartDeclaration.setAlertTime(LocalDateTime.parse(time));
            }
            smartDeclaration.setSmartRemindersId(smartRemindersId);
            list.add(smartDeclaration);
        });
        smartDeclarationService.saveBatch(list);
    }
}

