| package com.xzx.gc.role.service;  | 
|   | 
|   | 
| import cn.hutool.core.lang.Snowflake;  | 
| import cn.hutool.core.util.IdUtil;  | 
| import cn.hutool.core.util.RandomUtil;  | 
| import com.github.pagehelper.PageHelper;  | 
| import com.github.pagehelper.PageInfo;  | 
| import com.xzx.gc.common.exception.PlatformException;  | 
| import com.xzx.gc.common.exception.RestException;  | 
| import com.xzx.gc.common.utils.IdUtils;  | 
| import com.xzx.gc.common.utils.SecurityUtil;  | 
| import com.xzx.gc.entity.CityPartner;  | 
| import com.xzx.gc.entity.CoreUser;  | 
| import com.xzx.gc.entity.CoreUserRole;  | 
| import com.xzx.gc.role.mapper.CoreUserMapper;  | 
| import com.xzx.gc.role.mapper.CoreUserRoleMapper;  | 
| import com.xzx.gc.role.mapper.UserConsoleMapper;  | 
| import com.xzx.gc.role.model.CoreUserModel;  | 
| import com.xzx.gc.util.enums.DelFlagEnum;  | 
| import com.xzx.gc.util.enums.GeneralStateEnum;  | 
| import org.apache.commons.lang3.StringUtils;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.stereotype.Service;  | 
| import org.springframework.transaction.annotation.Transactional;  | 
|   | 
| import java.util.Date;  | 
| import java.util.HashMap;  | 
| import java.util.List;  | 
| import java.util.Map;  | 
|   | 
| /**  | 
|  * 用户管理----->身份设定  | 
|  */  | 
| @Service  | 
| @Transactional  | 
| public class CuserConsoleService {  | 
|   | 
|     @Autowired  | 
|     CoreUserMapper userDao;  | 
|     @Autowired  | 
|     CoreUserRoleMapper roleDao;  | 
|     @Autowired  | 
|     CityPartnerService cityPartnerService;  | 
|     @Autowired  | 
|     UserConsoleMapper cuserdao;  | 
|     @Autowired  | 
|     private IdUtils idUtils;  | 
|     @Autowired  | 
|     private CoreUserRoleService coreUserRoleService;  | 
|     /**  | 
|      * 根据条件查询  | 
|      *  | 
|      * @param query  | 
|      */  | 
|     public PageInfo<CoreUserModel> queryByCondtion(CoreUserModel query) {  | 
|         if(null!=query.getStartTime()&&!"".equals(query.getStartTime())){  | 
|             query.setStartTime(query.getStartTime()+" 00:00:00");  | 
|         }  | 
|         if(null!=query.getEndTime()&&!"".equals(query.getEndTime())){  | 
|             query.setEndTime(query.getEndTime()+" 23:59:59");  | 
|         }  | 
|         PageHelper.startPage(query.getPage(),query.getLimit());  | 
|         List<CoreUserModel> ret = userDao.queryByCondtion(query);  | 
|         PageInfo<CoreUserModel> pageInfo=new PageInfo(ret);  | 
|         return pageInfo;  | 
|     }  | 
|   | 
|     public void batchDelSysUser(List<Long> userIds) {  | 
|         try {  | 
|             userDao.batchDelUserByIds(userIds);  | 
|         } catch (Exception e) {  | 
|             throw new PlatformException("批量删除用户失败", e);  | 
|         }  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 插入一条用户数据  | 
|      *  | 
|      * @param user  | 
|      */  | 
|     public void saveUser(CoreUser user,Long roleId) {  | 
|         CoreUser query = new CoreUser();  | 
|         query.setCode(user.getCode());  | 
|         query.setDelFlag(0);  | 
|         CoreUser dbUser = userDao.selectOne(query);  | 
|         if (dbUser != null) {  | 
|             throw new RestException("账户已存在");  | 
|         }  | 
|         user.setCreateTime(new Date());  | 
|         user.setState(GeneralStateEnum.ENABLE.getValue());  | 
|         user.setPassword(user.getPassword());  | 
|         user.setDelFlag(DelFlagEnum.NORMAL.getValue());  | 
|         userDao.insertUseGeneratedKeys(user);  | 
|         if(StringUtils.isNotEmpty(user.getAttachmentId())){  | 
|         }  | 
|         CoreUserRole coreUserRole = new CoreUserRole();  | 
|         coreUserRole.setCreateTime(new Date());  | 
|         coreUserRole.setOrgId(user.getOrgId());  | 
|         coreUserRole.setUserId(user.getId());  | 
|         coreUserRole.setRoleId(roleId);  | 
|         roleDao.insert(coreUserRole);  | 
|         // 添加账号表  | 
|         String value = "0";  | 
|   | 
|         String accountNo=idUtils.generate("ZH",4);  | 
|         cuserdao.addCuserAccountRole(accountNo, "", user.getId()+"",value);  | 
|   | 
|     }  | 
|   | 
|     public int resetPassword(Long id, String password) {  | 
|         CoreUser user = new CoreUser();  | 
|         user.setId(id);  | 
|         String salt = RandomUtil.randomString(16);  | 
|         String newPassword = SecurityUtil.encrypt(salt, password);  | 
|         user.setPassword(newPassword);  | 
|         user.setSalt(salt);  | 
|         user.setUpdateTime(new Date());  | 
|         return userDao.updateByPrimaryKeySelective(user);  | 
|     }  | 
| }  |