package com.xtd.project.activiti.service.impl;


import com.xtd.common.utils.SecurityUtils;
import com.xtd.project.activiti.domain.MyFormData;
import com.xtd.project.activiti.domain.MyFormDataExample;
import com.xtd.project.activiti.mapper.MyFormDataMapper;
import com.xtd.project.activiti.service.MyFormDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class FormDataServiceImp implements MyFormDataService {

    @Autowired
    private MyFormDataMapper myFormDataMapper;

    @Override
    public void add(MyFormData myFormData) {
        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
        myFormData.setCreateBy(userId.toString());
        myFormData.setCreateTime(new Date());
        myFormDataMapper.insertSelective(myFormData);
    }

    @Override
    public List<MyFormData> list(MyFormData myFormData) {
        MyFormDataExample example = new MyFormDataExample();
        MyFormDataExample.Criteria criteria = example.createCriteria();
        List<MyFormData> list = myFormDataMapper.selectByExample(example);
        return list;
    }

    @Override
    public void update(MyFormData myFormData) {
        myFormDataMapper.updateByPrimaryKeySelective(myFormData);
    }

    @Override
    public MyFormData get(Long id) {
        return myFormDataMapper.selectByPrimaryKey(id);
    }

    @Override
    public void delete(List<Long> ids) {
        MyFormDataExample myFormDataExample=new MyFormDataExample();
        MyFormDataExample.Criteria criteria = myFormDataExample.createCriteria();
        criteria.andFIdIn(ids);
        myFormDataMapper.deleteByExample(myFormDataExample);
    }
}
