| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import java.util.List; |
| | | |
| | | import com.ycl.platform.base.BaseSelect; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.domain.form.YwUnitForm; |
| | | import com.ycl.platform.domain.query.DistributeWorkOrderQuery; |
| | | import com.ycl.platform.domain.query.YwUnitQuery; |
| | | import com.ycl.platform.domain.vo.YwUnitVO; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.platform.mapper.YwUnitMapper; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.platform.service.YwUnitService; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.Assert; |
| | | import java.util.stream.Collectors; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.domain.SysUserRole; |
| | | import com.ycl.system.entity.SysRole; |
| | | import com.ycl.system.entity.SysUser; |
| | | import com.ycl.system.mapper.SysRoleMapper; |
| | | import com.ycl.system.mapper.SysUserMapper; |
| | | import com.ycl.system.mapper.SysUserRoleMapper; |
| | | import com.ycl.system.model.LoginUser; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import enumeration.ErrorType; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 运维单位 服务实现类 |
| | |
| | | public class YwUnitServiceImpl extends ServiceImpl<YwUnitMapper, YwUnit> implements YwUnitService { |
| | | |
| | | private final YwUnitMapper ywUnitMapper; |
| | | private final SysUserMapper sysUserMapper; |
| | | private final SysUserRoleMapper sysUserRoleMapper; |
| | | private final SysRoleMapper sysRoleMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result add(YwUnitForm form) { |
| | | // todo 增加对应账号 |
| | | YwUnit entity = YwUnitForm.getEntityByForm(form, null); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | // 新增运维人员账号 |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setDeptId(null); |
| | | sysUser.setUnitId(entity.getId()); |
| | | sysUser.setUserName(entity.getUnitAdminAccount()); |
| | | sysUser.setNickName(entity.getUnitContact()); |
| | | sysUser.setPhonenumber(entity.getUnitContactPhone()); |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(form.getPassword())); |
| | | sysUser.setDelFlag(0); |
| | | sysUserMapper.insertUser(sysUser); |
| | | // 获取运维人员角色 |
| | | SysRole sysRole = sysRoleMapper.selectRoleByKey("yw_user"); |
| | | if (Objects.isNull(sysRole)) { throw new RuntimeException("运维角色不存在"); } |
| | | // 绑定账号角色关系 |
| | | SysUserRole sysUserRole = new SysUserRole(); |
| | | sysUserRole.setRoleId(sysRole.getRoleId()); |
| | | sysUserRole.setUserId(sysUser.getUserId()); |
| | | sysUserRoleMapper.batchUserRole(Collections.singletonList(sysUserRole)); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result update(YwUnitForm form) { |
| | | // todo 修改对应账号 |
| | | YwUnit entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | Date now = new Date(); |
| | | entity.setUpdateTime(now); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | // 修改运维单位账号信息 |
| | | SysUser sysUser = sysUserMapper.selectUserByUserName(entity.getUnitAdminAccount()); |
| | | if (Objects.nonNull(sysUser)) { |
| | | sysUser.setPhonenumber(entity.getUnitContactPhone()); |
| | | sysUser.setNickName(entity.getUnitContact()); |
| | | sysUserMapper.updateUser(sysUser); |
| | | } |
| | | return Result.ok("修改成功"); |
| | | } |
| | | return Result.error("修改失败"); |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result remove(List<String> ids) { |
| | | List<Long> userIds = sysUserMapper.selectUserIdByNames( |
| | | baseMapper.selectList( |
| | | new LambdaQueryWrapper<YwUnit>().in(YwUnit::getId, ids)) |
| | | .stream().map(YwUnit::getUnitAdminAccount).toList()); |
| | | if (!userIds.isEmpty()) { |
| | | sysUserMapper.deleteUserByIds(userIds.toArray(new Long[0])); |
| | | sysUserRoleMapper.deleteUserRoleByUserIds(userIds); |
| | | } |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | // 删除运维人员账号 |
| | | SysUser sysUser = sysUserMapper.selectUserByUserName(baseMapper.selectById(id).getUnitAdminAccount()); |
| | | if (Objects.nonNull(sysUser)) { |
| | | sysUserRoleMapper.deleteUserRoleByUserId(sysUser.getUserId()); |
| | | sysUserMapper.deleteUserById(sysUser.getUserId()); |
| | | } |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public Result page(YwUnitQuery query) { |
| | | |
| | | // 分页条件查询你 |
| | | IPage<YwUnit> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(StringUtils.hasText(query.getUnitCode()), YwUnit::getUnitCode, query.getUnitCode()) |
| | | .like(StringUtils.hasText(query.getUnitName()), YwUnit::getUnitName, query.getUnitName()) |
| | | .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()), |
| | | YwUnit::getCreateTime, |
| | | DateUtils.getDayStart(query.getStart()), |
| | | DateUtils.getDayEnd(query.getEnd())) |
| | | .orderByDesc(YwUnit::getCreateTime) |
| | | .page(PageUtil.getPage(query, YwUnit.class)); |
| | | |
| | |
| | | @Override |
| | | public Result all() { |
| | | List<YwUnit> entities = baseMapper.selectList(null); |
| | | List<YwUnitVO> vos = entities.stream() |
| | | |
| | | List<BaseSelect> vos = entities.stream() |
| | | .map( |
| | | entity -> { |
| | | BaseSelect baseSelect = new BaseSelect(); |
| | | baseSelect.setId(entity.getId()); |
| | | baseSelect.setValue(entity.getUnitName()); |
| | | return baseSelect; |
| | | } |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public Result workList(DistributeWorkOrderQuery query) { |
| | | if(query.getStart()!=null) { |
| | | query.setStart(DateUtils.getDayStart(query.getStart())); |
| | | } |
| | | if(query.getEnd()!=null) { |
| | | query.setEnd(DateUtils.getDayEnd(query.getEnd())); |
| | | } |
| | | if (query.getErrorType() != null) { |
| | | List<String> errorTypeList = new ArrayList<>(); |
| | | errorTypeList.add(query.getErrorType()); |
| | | if (ErrorType.ABNORMAL_PIC.getValue().equals(query.getErrorType())) { |
| | | //List添加之前几种工单类型 |
| | | errorTypeList.add(ErrorType.SIGNAL_LOSS.getValue()); |
| | | errorTypeList.add(ErrorType.SCREEN_COLOR_DEVIATION.getValue()); |
| | | errorTypeList.add(ErrorType.SNOW_STORM.getValue()); |
| | | errorTypeList.add(ErrorType.STRIPE_INTERFERENCE.getValue()); |
| | | errorTypeList.add(ErrorType.SCREEN_OCCLUSION.getValue()); |
| | | errorTypeList.add(ErrorType.ABNORMAL_CLARITY.getValue()); |
| | | } |
| | | query.setErrorTypeList(errorTypeList); |
| | | } |
| | | List<YwUnit> ywUnits = baseMapper.selectList(null); |
| | | List<YwUnitVO> lists = ywUnits.stream().map(item -> { |
| | | YwUnitVO vo = new YwUnitVO(); |
| | | BeanUtils.copyProperties(item, vo); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | for (YwUnitVO ywUnit : lists) { |
| | | query.setUnitId(ywUnit.getId()); |
| | | Integer workOrderNum = baseMapper.workList(query); |
| | | ywUnit.setWorkOrderCount(workOrderNum); |
| | | } |
| | | return Result.ok().data(lists); |
| | | } |
| | | |
| | | @Override |
| | | public void setUnitInfo(LoginUser loginUser) { |
| | | // 单位管理员查询 |
| | | YwUnit unit = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(YwUnit::getUnitAdminAccount, loginUser.getUsername()) |
| | | .one(); |
| | | if (Objects.nonNull(unit)) { |
| | | loginUser.setUnitAdmin(Boolean.TRUE); |
| | | loginUser.setUnitId(unit.getId()); |
| | | } else { |
| | | unit = baseMapper.getByUserId(loginUser.getUserId()); |
| | | if (Objects.nonNull(unit)) { |
| | | loginUser.setUnitAdmin(Boolean.FALSE); |
| | | loginUser.setUnitId(unit.getId()); |
| | | } |
| | | else { |
| | | loginUser.setUnitAdmin(Boolean.FALSE); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<YwUnitVO> export(YwUnitQuery query) { |
| | | // 分页条件查询你 |
| | | IPage<YwUnit> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(StringUtils.hasText(query.getUnitCode()), YwUnit::getUnitCode, query.getUnitCode()) |
| | | .like(StringUtils.hasText(query.getUnitName()), YwUnit::getUnitName, query.getUnitName()) |
| | | .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()), |
| | | YwUnit::getCreateTime, |
| | | DateUtils.getDayStart(query.getStart()), |
| | | DateUtils.getDayEnd(query.getEnd())) |
| | | .orderByDesc(YwUnit::getCreateTime) |
| | | .page(PageUtil.getPage(query, YwUnit.class)); |
| | | |
| | | List<YwUnitVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> YwUnitVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | return vos; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> ywUnitCount() { |
| | | return baseMapper.ywUnitCount(); |
| | | } |
| | | } |