package com.bonus.hn.bearing.capacity.backstage.manager.dao;

import com.bonus.hn.bearing.capacity.backstage.manager.entity.LonLat;
import com.bonus.hn.bearing.capacity.backstage.manager.entity.MapBean;
import com.bonus.hn.bearing.capacity.backstage.manager.entity.ZNode;
import com.bonus.hn.bearing.capacity.backstage.manager.model.SysUser;
import com.bonus.hn.bearing.capacity.backstage.project.entity.FileBean;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
/**
 * @author bonus
 */
@Mapper
public interface UserDao {

	@Options(useGeneratedKeys = true, keyProperty = "id")
	@Insert("insert into sys_user(username, password, type, phone, sex, status, createTime, updateTime) values(#{username}, #{password}, #{nickname}, #{phone}, #{sex}, #{status}, now(), now())")
	int save(SysUser user);

	/**
	 * 获取用户信息
	 * @param id ID
	 * @return 信息
	 */
	@Select("select t.ID,t.username,t.login_name as loginName,t.phone, t.nickname,t.type,t.role_id as roleId, t.org_id as orgId, t.password, t.status,t.createTime from sys_user t where t.id = #{id}")
	SysUser getById(Long id);

	@Select("select t.* ,t.role_id as roleId,t.org_id as orgId,t.org_id as orgId,so.`level`,so.org_name as department,so.parent_id as pId FROM sys_user t LEFT JOIN sys_organization so on so.id = t.org_id where t.phone = #{username} and t.is_active = '1'")
	SysUser getUser(String username);

	@Update("update sys_user t set t.password = #{password} where t.id = #{id}")
	int changePassword(@Param("id") Long id, @Param("password") String password);

	Integer count(@Param("params") Map<String, Object> params);

	List<SysUser> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
			@Param("limit") Integer limit);

	@Delete("delete from sys_role_user where userId = #{userId}")
	int deleteUserRole(Long userId);

	int saveUserRoles(@Param("userId") Long userId, @Param("roleIds") List<Long> roleIds);

	int update(SysUser user);

	List<SysUser> getMsgList(SysUser o);

//	List<ZNode> getDepartmentTree();

	List<MapBean> getRole();

	int addInfo(SysUser bean);

	int insertroleUser(SysUser bean);

	int updateInfo(SysUser bean);

	int updateRoleUser(SysUser bean);

	SysUser getEyId(Long userId);

	int delById(SysUser bean);

	int resetPassword(SysUser bean);

	int updateSwitchListen(SysUser bean);

	SysUser getListById(String id);

	int updateMyInfo(SysUser bean);

    List<SysUser> getSystemNotification(SysUser o);

	List<SysUser> findAllByOrderByCreateTimeDesc(String userId);


    List<FileBean> getDownloadRecord(FileBean o);

	int delRecordById(FileBean bean);

	int delAll(FileBean bean);

	int delReadAlready(FileBean bean);

	List<ZNode> getDepartmentTree(ZNode o);

	List<LonLat> getLonLatByProId(String proId);

	int updateLonLat(LonLat bean);
}
