package com.liang.service.impl;

import com.liang.dao.LsUserDao;
import com.liang.dao.StaTempMemberDtileDao;
import com.liang.dao.StaTempmemberDao;
import com.liang.entity.BasePerson;
import com.liang.entity.SysLsUserEntity;
import com.liang.entity.baobiao.StaTempMemberDtile;
import com.liang.service.LsUserService;
import org.apache.ibatis.annotations.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.security.acl.LastOwnerException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author ly
 * @Date 2024/4/3 9:24
 * @Version 1.0
 */
@Service
public class LsUserServiceImpl implements LsUserService {

    @Resource
    private LsUserDao lsUserDao;

    @Resource
    private StaTempMemberDtileDao staTempMemberDtileDao;

    @Resource
    private StaTempmemberDao staTempmemberDao;

    /**
     * 获取临时人员全部信息
     *
     * @return
     */
    @Override
    public List<SysLsUserEntity> UserAll(Map map) {

        List<SysLsUserEntity> list = lsUserDao.UserAll(map);
        try {
            DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
            for (int i = 0; i < list.size(); i++) {
                Date date1 = dft.parse(list.get(i).getDqsj());
                Date date2 = dft.parse(list.get(i).getQpsj());
                Long date3 = date1.getTime();
                Long date4 = date2.getTime();
                Long num = date3 - date4;
                Long date = num / 24 / 60 / 60 / 1000;
                double zq = (double) date / 365.0;
                DecimalFormat df = new DecimalFormat("0.00");
                String formattedNumber = df.format(zq);
                Double nums = Double.valueOf(formattedNumber);
                list.get(i).setZq(nums);
                // 获取起始时间
                // 处理数据 获得周期
            }
            return list;
        } catch (Exception a) {
            a.printStackTrace();
        }
        return list;

    }

    @Override
    public SysLsUserEntity getUserId(Integer ID) {


        return this.lsUserDao.getLsuserID(ID);
    }

    @Override
    public List<SysLsUserEntity> getUserxm(Map map) {


        return this.lsUserDao.getUserxm(map);
    }

    @Override
    public List<SysLsUserEntity> getZb(Integer zb) {
        return this.lsUserDao.getZb(zb);
    }

    @Override
    public boolean jy(String sfzh) {
        Map<String, String>map = new HashMap<>();
        map.put("sfzh",sfzh);
        List<SysLsUserEntity> sysLsUserEntity = lsUserDao.getUserxm(map);
        if (sysLsUserEntity.size()>0){
            return false;
        }
        return true;
    }


    @Override
    public int insert(StaTempMemberDtile staTempMemberDtile) {
        return staTempMemberDtileDao.insertNormal(staTempMemberDtile);
    }

    @Override
    public int upSt(Map map) {
        return this.staTempmemberDao.upSt(map) ;
    }

    @Override
    public int batchDelete(List<Integer> idList) {

        return lsUserDao.batchDelete(idList);
    }

    /**
     * 保存人员信息
     *
     * @param sysLsUserEntity
     * @return
     */
    @Override
    public Integer saveOperLog(SysLsUserEntity sysLsUserEntity) {

        Integer save = lsUserDao.saveOperLog(sysLsUserEntity);

        return save;
    }

    /**
     * 根据id 删除 数据
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteUser(Integer id) {
        boolean deletes = lsUserDao.deleteUser(id);

        return deletes;
    }

    /**
     * 修改数据
     *
     * @param sysLsUserEntity
     * @return
     */
    @Override
    public boolean upDate(SysLsUserEntity sysLsUserEntity) {


        return this.lsUserDao.upDate(sysLsUserEntity);
    }




}
