|
@@ -1,20 +1,199 @@
|
|
|
package com.usky.fire.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.usky.common.core.bean.ApiResult;
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import com.usky.common.security.utils.SecurityUtils;
|
|
|
+import com.usky.fire.domain.PatrolInspectionArea;
|
|
|
import com.usky.fire.domain.PatrolInspectionPersonnel;
|
|
|
+import com.usky.fire.domain.PatrolInspectionSite;
|
|
|
+import com.usky.fire.domain.PlanSchedule;
|
|
|
import com.usky.fire.mapper.PatrolInspectionPersonnelMapper;
|
|
|
+import com.usky.fire.service.PatrolInspectionAreaService;
|
|
|
import com.usky.fire.service.PatrolInspectionPersonnelService;
|
|
|
+import com.usky.fire.service.PlanScheduleService;
|
|
|
+import com.usky.fire.service.util.OnlineMethod;
|
|
|
+import com.usky.fire.service.vo.DataCountVo;
|
|
|
+import com.usky.fire.service.vo.PatrolInspectionAreaVo;
|
|
|
+import com.usky.fire.service.vo.PatrolInspectionPersonnelVo;
|
|
|
+import com.usky.system.RemoteUserService;
|
|
|
+import com.usky.system.domain.SysUser;
|
|
|
+import com.usky.system.model.LoginUser;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 巡检人员表 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author JCB
|
|
|
- * @since 2022-07-12
|
|
|
+ * @since 2022-07-26
|
|
|
*/
|
|
|
@Service
|
|
|
public class PatrolInspectionPersonnelServiceImpl extends AbstractCrudService<PatrolInspectionPersonnelMapper, PatrolInspectionPersonnel> implements PatrolInspectionPersonnelService {
|
|
|
|
|
|
-}
|
|
|
+ @Autowired
|
|
|
+ private PlanScheduleService planScheduleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionAreaService patrolInspectionAreaService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RemoteUserService remoteUserService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addPatrolInspectionPersonnel(PatrolInspectionPersonnel patrolInspectionPersonnel) {
|
|
|
+ patrolInspectionPersonnel.setCompanyId(0);
|
|
|
+ patrolInspectionPersonnel.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ patrolInspectionPersonnel.setCreator(SecurityUtils.getUsername());
|
|
|
+ patrolInspectionPersonnel.setEnable(1);
|
|
|
+ patrolInspectionPersonnel.setCreateTime(LocalDateTime.now());
|
|
|
+ this.save(patrolInspectionPersonnel);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updatePatrolInspectionPersonnel(PatrolInspectionPersonnel patrolInspectionPersonnel) {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ String userType = null;
|
|
|
+ if (loginUser != null && !"".equals(loginUser)) {
|
|
|
+ userType = loginUser.getUserType();
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPersonnel> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionPersonnel::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionPersonnel::getUserId, patrolInspectionPersonnel.getUserId())
|
|
|
+ .eq(PatrolInspectionPersonnel::getAreaId, patrolInspectionPersonnel.getAreaId())
|
|
|
+ .eq(PatrolInspectionPersonnel::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if ("00".equals(userType)) {
|
|
|
+ queryWrapper.eq(PatrolInspectionPersonnel::getCreator, SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPersonnel> list = this.list(queryWrapper);
|
|
|
+ if (list.size() > 0) {
|
|
|
+ throw new BusinessException("巡检人员录入重复不可修改");
|
|
|
+ }
|
|
|
+ this.updateById(patrolInspectionPersonnel);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void delPatrolInspectionPersonnel(Integer id) {
|
|
|
+ LambdaQueryWrapper<PlanSchedule> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PlanSchedule::getPersonnelId, id);
|
|
|
+ List<PlanSchedule> listOne = planScheduleService.list(queryWrapper);
|
|
|
+ if (listOne.size() > 0) {
|
|
|
+ throw new BusinessException("人员使用中重复不可删除");
|
|
|
+ }
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<PatrolInspectionPersonnelVo> patrolInspectionPersonnelList(Integer areaId, Integer pageNum, Integer pageSize, Integer id) {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ String userType = null;
|
|
|
+ if (loginUser != null && !"".equals(loginUser)) {
|
|
|
+ userType = loginUser.getUserType();
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPersonnel> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionPersonnel::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionPersonnel::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if ("00".equals(userType)) {
|
|
|
+ queryWrapper.eq(PatrolInspectionPersonnel::getCreator, SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+ if (id != 0 && id != null) {
|
|
|
+ queryWrapper.eq(PatrolInspectionPersonnel::getId, id);
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPersonnel> list = this.list(queryWrapper);
|
|
|
+ List<PatrolInspectionPersonnelVo> list1 = new ArrayList<>();
|
|
|
+ if (list.size() > 0) {
|
|
|
+ ApiResult<List<SysUser>> userApi = remoteUserService.userList();
|
|
|
+ List<SysUser> userList = userApi.getData();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ PatrolInspectionPersonnelVo patrolInspectionPersonnelVo = new PatrolInspectionPersonnelVo();
|
|
|
+ patrolInspectionPersonnelVo.setCreator(list.get(i).getCreator());
|
|
|
+ patrolInspectionPersonnelVo.setCompanyId(list.get(i).getCompanyId());
|
|
|
+ patrolInspectionPersonnelVo.setEnable(list.get(i).getEnable());
|
|
|
+ patrolInspectionPersonnelVo.setCreateTime(list.get(i).getCreateTime());
|
|
|
+ patrolInspectionPersonnelVo.setId(list.get(i).getId());
|
|
|
+ patrolInspectionPersonnelVo.setTenantId(list.get(i).getTenantId());
|
|
|
+ patrolInspectionPersonnelVo.setAreaId(list.get(i).getAreaId());
|
|
|
+ patrolInspectionPersonnelVo.setUserId(list.get(i).getUserId());
|
|
|
+ for (int j = 0; j <userList.size(); j++) {
|
|
|
+ if (list.get(i).getUserId().longValue()==userList.get(j).getUserId()){
|
|
|
+ patrolInspectionPersonnelVo.setName(userList.get(j).getNickName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list1.add(patrolInspectionPersonnelVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPersonnelVo> list2 = list1.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
|
|
|
+ return new CommonPage<>(list2, list1.size(), pageSize,pageNum);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PatrolInspectionAreaVo> personnelLeftList() {
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ String userType = null;
|
|
|
+ if (loginUser != null && !"".equals(loginUser)) {
|
|
|
+ userType = loginUser.getUserType();
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PatrolInspectionArea> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PatrolInspectionArea::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionArea::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if ("00".equals(userType)) {
|
|
|
+ queryWrapper.eq(PatrolInspectionArea::getCreator, SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+ List<PatrolInspectionArea> patrolInspectionAreaList = patrolInspectionAreaService.list(queryWrapper);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PatrolInspectionPersonnel> queryWrapperOne = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperOne.eq(PatrolInspectionPersonnel::getEnable, 1)
|
|
|
+ .eq(PatrolInspectionPersonnel::getTenantId, SecurityUtils.getTenantId());
|
|
|
+ if ("00".equals(userType)) {
|
|
|
+ queryWrapperOne.eq(PatrolInspectionPersonnel::getCreator, SecurityUtils.getUsername());
|
|
|
+ }
|
|
|
+ List<PatrolInspectionPersonnel> list = this.list(queryWrapperOne);
|
|
|
+ Map<Integer, List<PatrolInspectionPersonnel>> grouypByAreaId = list.stream().collect(
|
|
|
+ Collectors.groupingBy(o -> o.getAreaId())
|
|
|
+ );
|
|
|
+ List<DataCountVo> dataCountVoList = new ArrayList<>();
|
|
|
+ grouypByAreaId.forEach((k, v) -> {
|
|
|
+ DataCountVo dataCountVo = new DataCountVo();
|
|
|
+ dataCountVo.setListCount(v.size());
|
|
|
+ dataCountVo.setId(k);
|
|
|
+ dataCountVoList.add(dataCountVo);
|
|
|
+ });
|
|
|
+ List<PatrolInspectionAreaVo> patrolInspectionAreaVoList = new ArrayList<>();
|
|
|
+ if (patrolInspectionAreaList.size() > 0) {
|
|
|
+ for (int i = 0; i < patrolInspectionAreaList.size(); i++) {
|
|
|
+ PatrolInspectionAreaVo patrolInspectionAreaVo = new PatrolInspectionAreaVo();
|
|
|
+ patrolInspectionAreaVo.setId(patrolInspectionAreaList.get(i).getId());
|
|
|
+ patrolInspectionAreaVo.setAreaName(patrolInspectionAreaList.get(i).getAreaName());
|
|
|
+ patrolInspectionAreaVo.setAreaFid(patrolInspectionAreaList.get(i).getAreaFid());
|
|
|
+ patrolInspectionAreaVo.setCompanyId(patrolInspectionAreaList.get(i).getCompanyId());
|
|
|
+ patrolInspectionAreaVo.setTenantId(patrolInspectionAreaList.get(i).getTenantId());
|
|
|
+ patrolInspectionAreaVo.setCreator(patrolInspectionAreaList.get(i).getCreator());
|
|
|
+ patrolInspectionAreaVo.setCreateTime(patrolInspectionAreaList.get(i).getCreateTime());
|
|
|
+ patrolInspectionAreaVo.setEnable(patrolInspectionAreaList.get(i).getEnable());
|
|
|
+ patrolInspectionAreaVo.setPersonnelCount(0);
|
|
|
+ for (int j = 0; j < dataCountVoList.size(); j++) {
|
|
|
+ if (patrolInspectionAreaList.get(i).getId() == dataCountVoList.get(j).getId()) {
|
|
|
+ patrolInspectionAreaVo.setPersonnelCount(dataCountVoList.get(j).getListCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ patrolInspectionAreaVoList.add(patrolInspectionAreaVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PatrolInspectionAreaVo> patrolInspectionAreaVoListOne = new ArrayList<>();
|
|
|
+ if (patrolInspectionAreaVoList.size() > 0) {
|
|
|
+ patrolInspectionAreaVoListOne = OnlineMethod.getChildPerms(patrolInspectionAreaVoList, 0);
|
|
|
+ }
|
|
|
+ return patrolInspectionAreaVoListOne;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|