package com.mvc.service.app;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mvc.dao.AppAuthMapper;
import com.mvc.entity.AppAuth;
import com.mvc.model.AppAuthModel;
import com.mvc.utils.StringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service
@Transactional
public class AppAuthService {
    

        @Autowired
        private AppAuthMapper appAuthMapper;

        public Map<String, Object> findAllAppAuth(Integer page, Integer rows) {
        Map<String, Object> resMap=new HashMap<>();
        Page<Object> pageObject = PageHelper.startPage(page, rows);
        List<AppAuth> AppAuths = appAuthMapper.selectByExample(null);
        List<AppAuthModel> resList=new ArrayList<>();
        for(AppAuth AppAuth:AppAuths){
            AppAuthModel model = new AppAuthModel();
            BeanUtils.copyProperties(AppAuth,model);
            resList.add(model);
        }
        resMap.put("total",pageObject.getTotal());
        resMap.put("list",resList);
        return resMap;
    }

        public AppAuthModel saveAppAuth(AppAuthModel model) {
        model.setAuthId(StringUtil.getUuid());
        model.setCreateTime(new Date());
        AppAuth AppAuth = new AppAuth();
        BeanUtils.copyProperties(model,AppAuth);
        int insert = appAuthMapper.insert(AppAuth);
        model.setId(AppAuth.getId());
        return model;
    }

        public AppAuthModel updateAppAuth(AppAuthModel model) {
        AppAuth AppAuth = appAuthMapper.selectByPrimaryKey(model.getId());
        BeanUtils.copyProperties(model,AppAuth);
        int i = appAuthMapper.updateByPrimaryKey(AppAuth);
        return model;
    }

        public int deleteAppAuth(int id) {
        int i = appAuthMapper.deleteByPrimaryKey(id);
        return i;
    }


}
