对比新文件 |
| | |
| | | package com.thhy.secure.modules.biz.regionInspection.service.impl; |
| | | |
| | | import com.github.pagehelper.Page; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.thhy.general.common.BasicResult; |
| | | import com.thhy.general.config.SysUserInfo; |
| | | import com.thhy.general.utils.UUIDUtils; |
| | | import com.thhy.general.utils.UserInfoUtils; |
| | | import com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionEntity; |
| | | import com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionHazardInformEntity; |
| | | import com.thhy.secure.modules.biz.regionInspection.entity.RegionInspectionUserEntity; |
| | | import com.thhy.secure.modules.biz.regionInspection.mapper.RegionInspectionMapper; |
| | | import com.thhy.secure.modules.biz.regionInspection.service.RegionInspectionService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Author QiuYuHao |
| | | * @CreateDate 2023-11-10 11:26:29 |
| | | * 区域巡检接口实现 |
| | | */ |
| | | @Service |
| | | public class RegionInspectionServiceImpl implements RegionInspectionService |
| | | { |
| | | |
| | | @Autowired |
| | | private RegionInspectionMapper regionInspectionMapper; |
| | | |
| | | private static final Object lock = new Object(); |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public BasicResult insert(RegionInspectionEntity regionInspectionEntity) { |
| | | SysUserInfo s = UserInfoUtils.getInstance().getUserInfo(); |
| | | String companyId = s.getCompanyId(); |
| | | String userId = s.getUserId(); |
| | | regionInspectionEntity.setCompanyId(companyId); |
| | | //默认给uuid |
| | | String regionInspectId = UUIDUtils.create(); |
| | | //修改区域巡检判断 |
| | | if (!"".equals(regionInspectionEntity.getId())){ |
| | | regionInspectId = regionInspectionEntity.getId(); |
| | | //根据区域巡检id删除中间表 |
| | | regionInspectionEntity.setUpdateTime(new Date()); |
| | | regionInspectionEntity.setUpdateUser(userId); |
| | | regionInspectionMapper.deleteUser(regionInspectId); |
| | | regionInspectionMapper.deleteInspectionHazardInform(regionInspectId); |
| | | } |
| | | //添加/修改区域巡检 |
| | | synchronized (lock) { |
| | | regionInspectionEntity.setId(regionInspectId); |
| | | regionInspectionEntity.setCreateUser(userId); |
| | | regionInspectionMapper.insert(regionInspectionEntity); |
| | | //添加巡检人 |
| | | for (RegionInspectionUserEntity userEntity : regionInspectionEntity.getRegionUsersList()) { |
| | | userEntity.setId(UUIDUtils.create()); |
| | | userEntity.setRegionInspectionId(regionInspectId); |
| | | regionInspectionMapper.insertUser(userEntity); |
| | | } |
| | | //添加巡检的区域 |
| | | for (RegionInspectionHazardInformEntity region : regionInspectionEntity.getRegionList()) { |
| | | region.setId(UUIDUtils.create()); |
| | | region.setRegionInspectionId(regionInspectId); |
| | | regionInspectionMapper.insertInspectionHazardInform(region); |
| | | } |
| | | } |
| | | return BasicResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public BasicResult delete(String id) { |
| | | regionInspectionMapper.delete(id); |
| | | regionInspectionMapper.deleteUser(id); |
| | | regionInspectionMapper.deleteInspectionHazardInform(id); |
| | | return BasicResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public BasicResult selectPageList(Map map) { |
| | | SysUserInfo s = UserInfoUtils.getInstance().getUserInfo(); |
| | | String companyId = s.getCompanyId(); |
| | | map.put("companyId",companyId); |
| | | int pageNum = (int) map.get("pageNum"); |
| | | int pageSize = (int) map.get("pageSize"); |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | List<RegionInspectionEntity> regionInspectionEntities = regionInspectionMapper.selectPageList(map); |
| | | //处理区域巡检对象数组 |
| | | regionInspectionEntities.forEach(obj->{ |
| | | List<RegionInspectionHazardInformEntity> regionList = new ArrayList<>(); |
| | | List<RegionInspectionUserEntity> userList = new ArrayList<>(); |
| | | if(obj.getRealNames() !=null){ |
| | | String[] realNames = obj.getRealNames().intern().split("、"); |
| | | String[] userIds = obj.getUserIds().intern().split("、"); |
| | | //人员对象数组 |
| | | for (int i = 0; i < realNames.length; i++) { |
| | | RegionInspectionUserEntity userEntity = RegionInspectionUserEntity |
| | | .builder() |
| | | .regionInspectionId(obj.getId()) |
| | | .userId(userIds[i]) |
| | | .realName(realNames[i]).build(); |
| | | userList.add(userEntity); |
| | | } |
| | | } |
| | | if (obj.getRegionIds()!=null){ |
| | | String[] regionIds = obj.getRegionIds().intern().split(","); |
| | | String[] regions = obj.getRegions().intern().split(","); |
| | | //区域对象数组 |
| | | for (int i = 0; i < regionIds.length; i++) { |
| | | RegionInspectionHazardInformEntity regionEntity = RegionInspectionHazardInformEntity |
| | | .builder() |
| | | .regionInspectionId(obj.getId()) |
| | | .regionHazardInformId(regionIds[i]) |
| | | .region(regions[i]).build(); |
| | | regionList.add(regionEntity); |
| | | } |
| | | } |
| | | obj.setRegionList(regionList); |
| | | obj.setRegionUsersList(userList); |
| | | }); |
| | | return BasicResult.success(new PageInfo<>(regionInspectionEntities)); |
| | | } |
| | | |
| | | } |