package com.mosty.sjzx.service.impl;

import com.mosty.base.model.dto.sjzx.TbSjSpbfDTO;
import com.mosty.base.model.entity.sjzx.TbSjSpbf;
import com.mosty.common.token.UserInfo;
import com.mosty.common.token.UserInfoManager;
import com.mosty.common.util.PermissionsUtil;
import com.mosty.sjzx.mapper.TbSjSpbfMapper;
import com.mosty.sjzx.service.TbSjSpbfService;
import org.springframework.stereotype.Service;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;

@Service("tbSjSpbfService")
public class TbSjSpbfServiceImpl implements TbSjSpbfService {
    @Resource
    private TbSjSpbfMapper tbSjSpbfMapper;


    @Override
    public List<TbSjSpbf> queryAll() {
        return this.tbSjSpbfMapper.queryAll(PermissionsUtil.createSql("", UserInfoManager.get()));
    }

    @Override
    public TbSjSpbf queryById(String id) {
        return this.tbSjSpbfMapper.queryById(id);
    }

    @Override
    public TbSjSpbfDTO insert(TbSjSpbfDTO dto) {
        UserInfo user = UserInfoManager.get();
        TbSjSpbf tb = new TbSjSpbf();
        BeanUtils.copyProperties(dto, tb);
        tb.setSsbm(user.getDeptName());
        tb.setSsbmid(String.valueOf(user.getDeptId()));
        tb.setSsbmdm(user.getDeptCode());
        tb.setSsxgaj(user.getFxjDeptName());
        tb.setSsxgajid(String.valueOf(user.getFxjDeptId()));
        tb.setSsxgajdm(user.getFxjDeptCode());
        tb.setSssgaj(user.getDszDeptName());
        tb.setSssgajid(String.valueOf(user.getDszDeptId()));
        tb.setSssgajdm(user.getDszDeptCode());
        tb.setXtSjly("1");
        this.tbSjSpbfMapper.insert(tb);
        return dto;
    }

    @Override
    public TbSjSpbf update(TbSjSpbf tbSjSpbf) {
        this.tbSjSpbfMapper.updateById(tbSjSpbf);
        return this.queryById(tbSjSpbf.getId());
    }

    @Override
    public boolean deleteById(String id) {
        return this.tbSjSpbfMapper.deleteById(id) > 0;
    }
}

