package com.th.demo.service.impl.system;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.th.demo.mapping.system.SysUserRoleMapper;
import com.th.demo.model.system.SysUserRole;
import com.th.demo.model.system.Type;
import com.th.demo.service.system.SysUserRoleService;
import com.th.demo.tools.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service("SysUserRoleService")//必须写  Service的名字
public class SysUserRoleServiceImpl implements SysUserRoleService {

	@Autowired//自动注入 Mapper
	public SysUserRoleMapper sysUserRoleMapper;//如果这里报错不用管    IDEA问题
	int num = 0;
	String result=Type.FAIL;
	Gson gson=new GsonBuilder().setDateFormat("yyyy-MM-dd hh:mm:ss").create();//gson json的三方框架 数据传递格式

	@Override
	public int remove(String userId, String roleId) {
		 num = 0;
		 num =sysUserRoleMapper.deleteByUserRole(userId, roleId);
		 return num;
	}

	@Override
	public String save(String userId, String roleId, String addId) {
		SysUserRole userRole = new SysUserRole();
		userRole.setUserId(userId);
		userRole.setRoleId(roleId);
		userRole.setAddId(addId);
		userRole.setAddTime(new Date());
		userRole.setCancelFlag("0");
		num =sysUserRoleMapper.insert(userRole);
		result = Tools.moreThanZero(num);
		return result;
	}

}
