From b3b566ebdfed4005aaa513da3d5d2fd3924903cc Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Wed, 31 Jan 2024 16:17:54 +0800
Subject: [PATCH] 拿不到地址总表数据,不设置网格信息

---
 src/main/java/org/springblade/modules/task/service/impl/TaskServiceImpl.java |  332 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 312 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/springblade/modules/task/service/impl/TaskServiceImpl.java b/src/main/java/org/springblade/modules/task/service/impl/TaskServiceImpl.java
index 85c64c4..3cab74b 100644
--- a/src/main/java/org/springblade/modules/task/service/impl/TaskServiceImpl.java
+++ b/src/main/java/org/springblade/modules/task/service/impl/TaskServiceImpl.java
@@ -16,17 +16,34 @@
  */
 package org.springblade.modules.task.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import liquibase.pro.packaged.W;
 import org.apache.commons.lang3.StringUtils;
+import org.springblade.common.cache.SysCache;
+import org.springblade.common.constant.DictConstant;
 import org.springblade.common.utils.SpringUtils;
-import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.secure.utils.AuthUtil;
+import org.springblade.modules.category.entity.CategoryEntity;
+import org.springblade.modules.category.service.ICategoryService;
+import org.springblade.modules.grid.entity.GridEntity;
+import org.springblade.modules.grid.entity.GridWorkLogEntity;
+import org.springblade.modules.grid.entity.GridmanEntity;
+import org.springblade.modules.grid.service.IGridService;
+import org.springblade.modules.grid.service.IGridWorkLogService;
+import org.springblade.modules.grid.service.IGridmanService;
 import org.springblade.modules.house.service.IHouseRentalService;
 import org.springblade.modules.house.service.IHouseholdService;
 import org.springblade.modules.house.vo.HouseRentalTenantVO;
+import org.springblade.modules.house.vo.HouseholdVO;
 import org.springblade.modules.place.service.IPlaceExtService;
+import org.springblade.modules.place.service.IPlaceService;
+import org.springblade.modules.place.vo.PlaceVO;
 import org.springblade.modules.system.entity.Dept;
 import org.springblade.modules.system.service.IDeptService;
 import org.springblade.modules.task.entity.*;
@@ -35,11 +52,10 @@
 import org.springblade.modules.task.vo.TaskVO;
 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;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 任务表 服务实现类
@@ -48,10 +64,10 @@
  * @since 2023-11-06
  */
 @Service
-public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, TaskEntity> implements ITaskService {
+public class TaskServiceImpl extends ServiceImpl<TaskMapper, TaskEntity> implements ITaskService {
 
-	// @Autowired
-	// private ITaskReportForRepairsService iTaskReportForRepairsService;
+	 @Autowired
+	 private IPlaceService placeService;
 
 	@Autowired
 	private IHouseholdService iHouseholdService;
@@ -59,20 +75,29 @@
 	@Autowired
 	private IHouseRentalService iHouseRentalService;
 
+	@Autowired
+	private ICategoryService categoryService;
 
 	@Autowired
-	private IDeptService deptService;
+	private ITaskCampusReportingEventService taskCampusReportingEventService;
+
+	@Autowired
+	private ITaskLabelReportingEventService taskLabelReportingEventService;
+
+	@Autowired
+	private ITaskHotelReportingService taskHotelReportingService;
+
+	@Autowired
+	private IGridWorkLogService gridWorkLogService;
 
 	@Override
 	public IPage<TaskVO> selectTaskPage(IPage<TaskVO> page, TaskVO task) {
-		Dept dept = deptService.getById(AuthUtil.getDeptId());
-		if (null != dept) {
-			task.setCommunityCode(dept.getRegionCode());
-		}
+		List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
+		Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2;
 		// 民警角色
 		if (AuthUtil.getUserRole().equals("mj")) {
 			task.setUserId(AuthUtil.getUserId());
-			return page.setRecords(baseMapper.selectTaskPageBy(page, task));
+			return page.setRecords(baseMapper.selectTaskPageBy(page, task,regionChildCodesList,isAdministrator));
 		} else {
 			if (AuthUtil.getUserAccount().equals("18879306957")) {
 				task.setCommunityCode("361102003027");
@@ -82,21 +107,19 @@
 				task.setUserId(AuthUtil.getUserId());
 			}
 			// 非民警角色
-			List<TaskVO> taskVOS = baseMapper.selectTaskPage(page, task);
+			List<TaskVO> taskVOS = baseMapper.selectTaskPage(page, task,regionChildCodesList,isAdministrator);
 			return page.setRecords(taskVOS);
 		}
 	}
 
 	@Override
 	public IPage<TaskVO> getBailReportingPage(IPage<TaskVO> page, TaskVO task) {
-		Dept dept = deptService.getById(AuthUtil.getDeptId());
-		if (null != dept) {
-			task.setCommunityCode(dept.getRegionCode());
-		}
+		List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId());
+		Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2;
 		// 民警角色
 		if (AuthUtil.getUserRole().equals("mj")) {
 			task.setUserId(AuthUtil.getUserId());
-			return page.setRecords(baseMapper.selectTaskPageBy(page, task));
+			return page.setRecords(baseMapper.selectTaskPageBy(page, task,regionChildCodesList,isAdministrator));
 		} else {
 			if (AuthUtil.getUserAccount().equals("18879306957")) {
 				task.setCommunityCode("361102003027");
@@ -180,6 +203,8 @@
 		taskVO.setNeiCode(neiCode);
 		taskVO.setReportType(2);
 		taskVO.setIsDeleted(0);
+		// 查询网格员对应的网格id
+		String gridCode = getGridCode();
 		// 标签事件
 		Integer bqsj = baseMapper.selectTaskCount(taskVO);
 		taskVO.setReportType(1);
@@ -196,13 +221,29 @@
 		Integer czsh = iHouseRentalService.getStatisticsCount(houseRentalTenantVO);
 		// 场所审核
 		Integer cssh = SpringUtils.getBean(IPlaceExtService.class).selectCount(roleType > 0 ? AuthUtil.getUserId() : null, neiCode, 1);
+		// 走访日志
+		Integer zfrw = SpringUtils.getBean(IGridWorkLogService.class).getGridWorkCountHandleCount(gridCode,1);
+		// 设置
 		objectObjectHashMap.put("qbhs", qbhs);
 		objectObjectHashMap.put("bqsj", bqsj);
 		objectObjectHashMap.put("bsbx", bsbx);
 		objectObjectHashMap.put("zhsh", zhsh);
 		objectObjectHashMap.put("czsh", czsh);
 		objectObjectHashMap.put("cssh", cssh);
+		objectObjectHashMap.put("zfrw", zfrw);
 		return objectObjectHashMap;
+	}
+
+	/**
+	 * 获取网格员id
+	 * @return
+	 */
+	private String getGridCode() {
+		GridEntity grid = SpringUtils.getBean(IGridService.class).getGridByUserId(AuthUtil.getUserId());
+		if (null!=grid){
+			return grid.getGridCode();
+		}
+		return null;
 	}
 
 	@Override
@@ -268,4 +309,255 @@
 
 		return update1;
 	}
+
+	/**
+	 * 根据类型创建任务
+	 * @param param 参数
+	 * @return
+	 */
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public boolean createTaskJob(String param) {
+		// 解析参数
+		JSONObject jsonParam = JSON.parseObject(param);
+//		String params = jsonParam.getString("params");
+		boolean flag = false;
+		// 校园安全自查任务生成
+		createCampusReportingTask();
+		// 打金店/二手车/二手手机任务生成
+		createLabelReportingTask();
+		// 旅馆安全自查任务生成
+		createHotelReportingTask();
+		// 人员类-肇事肇祸精神障碍患者走访任务生成
+		createGridWordTask();
+		// 返回
+		return flag;
+	}
+
+
+	/**
+	 * 人员类-肇事肇祸精神障碍患者走访任务生成
+	 */
+	public void createGridWordTask() {
+		// 肇事肇祸精神障碍患者走访任务生成,查询标签为:1006
+		List<Integer> list = new ArrayList<Integer>(){{
+			add(1006);
+		}};
+		// 根据人员标签编号集合查询对应的住户(按颜色区分近多少天没有发过任务的住户)
+		List<HouseholdVO> householdVOList = iHouseholdService.getHouseholdListByParam(list);
+		// 生成任务
+		for (HouseholdVO household : householdVOList) {
+			// 新增走访任务
+			saveGridWordTask(household);
+		}
+	}
+
+	/**
+	 * 新增走访任务
+	 * @param household
+	 */
+	public void saveGridWordTask(HouseholdVO household) {
+		GridWorkLogEntity gridWorkLogEntity = new GridWorkLogEntity();
+		gridWorkLogEntity.setHouseholdId(household.getId());
+		gridWorkLogEntity.setType(2);
+		gridWorkLogEntity.setPersonType(1006);
+		// 系统下发
+		gridWorkLogEntity.setSource(2);
+		// 待处理
+		gridWorkLogEntity.setStatus(1);
+		// 新增
+		gridWorkLogService.save(gridWorkLogEntity);
+	}
+
+	/**
+	 * 打金店/二手车/二手手机任务生成
+	 */
+	public void createLabelReportingTask() {
+		// 打金店/二手车/二手手机任务生成,标签:130808/140304/130604
+		List<String> stringList = new ArrayList<String>(){{
+			add("130808");
+			add("140304");
+			add("130604");
+		}};
+		String tableName = "jczz_task_label_reporting_event";
+		// 根据编号集合查询对应的场所(按颜色区分近多少天没有发过任务的场所)
+		List<PlaceVO> placeVOList = placeService.getPlaceListByParam(stringList,tableName);
+		// 生成任务
+		for (PlaceVO placeVO : placeVOList) {
+			String taskName = "";
+			Integer reportType = 3;
+			if (placeVO.getLabel().equals("130808")){
+				taskName = DictConstant.DA_JIN_DIAN;
+				reportType = 3;
+			}
+			if (placeVO.getLabel().equals("130604")){
+				taskName = DictConstant.USED_MOBILE_PHONES;
+				reportType = 4;
+			}
+			if (placeVO.getLabel().equals("140304")){
+				taskName = DictConstant.USED_CAR;
+				reportType = 5;
+			}
+			// 新增任务
+			TaskEntity taskEntity = saveTaskEntity(placeVO.getHouseCode(), 1, taskName, 2, reportType);
+			// 同时新增打金店/二手车/二手手机任务
+			saveGoldShop(placeVO, taskEntity,taskName,reportType);
+		}
+	}
+
+	/**
+	 * 旅馆安全自查任务生成
+	 */
+	public void createHotelReportingTask() {
+		// 旅馆标签为
+		List<String> stringList = new ArrayList<String>(){{
+			add("120101");
+			add("120102");
+			add("120103");
+			add("120104");
+		}};
+		String tableName = "jczz_task_hotel_reporting";
+		// 根据编号集合查询对应的场所(按颜色区分近多少天没有发过任务的场所)
+		List<PlaceVO> placeVOList = placeService.getPlaceListByParam(stringList,tableName);
+		// 生成任务
+		for (PlaceVO placeVO : placeVOList) {
+			// 新增任务
+			TaskEntity taskEntity = saveTaskEntity(placeVO.getHouseCode(), 1, DictConstant.HOTEL_SECURITY, 2, 2);
+			// 同时新增校园安全检查任务
+			saveHotel(placeVO, taskEntity);
+		}
+	}
+
+	/**
+	 * 校园安全自查任务生成
+	 */
+	public void createCampusReportingTask() {
+		// 校园安全自查,查询标签为教育的场所 parentNo = 1601
+		String parentNo = "1601";
+		QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
+		wrapper.eq("is_deleted",0).eq("parent_no",parentNo);
+		List<CategoryEntity> categoryEntityList = categoryService.list(wrapper);
+		// 取出编号集合
+		List<String> stringList = categoryEntityList.stream().map(categoryEntity -> categoryEntity.getCategoryNo()).collect(Collectors.toList());
+		// 根据编号集合查询对应的场所(按颜色区分近多少天没有发过任务的场所)
+		String tableName = "jczz_task_campus_reporting_event";
+		List<PlaceVO> placeVOList = placeService.getPlaceListByParam(stringList,tableName);
+		// 生成任务
+		for (PlaceVO placeVO : placeVOList) {
+			// 新增任务
+			TaskEntity taskEntity = saveTaskEntity(placeVO.getHouseCode(), 1, DictConstant.CAMPUS_SECURITY_INSPECTION, 2, 6);
+			// 同时新增校园安全检查任务
+			saveCampus(placeVO, taskEntity);
+		}
+	}
+
+	/**
+	 * 新增校园安全检查任务
+	 * @param placeVO
+	 * @param taskEntity
+	 */
+	private void saveCampus(PlaceVO placeVO, TaskEntity taskEntity) {
+		TaskCampusReportingEventEntity campusReportingEventEntity = new TaskCampusReportingEventEntity();
+		campusReportingEventEntity.setTaskId(taskEntity.getId());
+		campusReportingEventEntity.setPlaceId(placeVO.getId());
+		campusReportingEventEntity.setCampusName(placeVO.getPlaceName());
+		campusReportingEventEntity.setCheckUserId(placeVO.getPrincipalUserId());
+		campusReportingEventEntity.setCheckUserName(placeVO.getPrincipal());
+		campusReportingEventEntity.setCheckTelephone(placeVO.getPrincipalPhone());
+		// 系统下发
+		campusReportingEventEntity.setSource(2);
+		// 待完善
+		campusReportingEventEntity.setConfirmFlag("4");
+		// 新增
+		taskCampusReportingEventService.save(campusReportingEventEntity);
+	}
+
+	/**
+	 * 新增旅馆安全检查任务
+	 * @param placeVO
+	 * @param taskEntity
+	 */
+	private void saveHotel(PlaceVO placeVO, TaskEntity taskEntity) {
+		TaskHotelReportingEntity taskHotelReportingEntity = new TaskHotelReportingEntity();
+		taskHotelReportingEntity.setTaskId(taskEntity.getId());
+		taskHotelReportingEntity.setPlaceId(placeVO.getId());
+		taskHotelReportingEntity.setHotelName(placeVO.getPlaceName());
+		taskHotelReportingEntity.setCheckUserId(placeVO.getPrincipalUserId());
+		taskHotelReportingEntity.setCheckUserName(placeVO.getPrincipal());
+		taskHotelReportingEntity.setCheckTelephone(placeVO.getPrincipalPhone());
+		// 系统下发
+		taskHotelReportingEntity.setSource(2);
+		// 待完善
+		taskHotelReportingEntity.setConfirmFlag("4");
+		// 新增
+		taskHotelReportingService.save(taskHotelReportingEntity);
+	}
+
+
+	/**
+	 * 新增打金店/二手车/二手手机任务
+	 * @param placeVO
+	 * @param taskEntity
+	 * @param taskName
+	 * @param reportType
+	 */
+	private void saveGoldShop(PlaceVO placeVO, TaskEntity taskEntity,String taskName,Integer reportType) {
+		TaskLabelReportingEventEntity taskLabelReportingEventEntity = new TaskLabelReportingEventEntity();
+		taskLabelReportingEventEntity.setTaskId(taskEntity.getId());
+		taskLabelReportingEventEntity.setPlaceId(placeVO.getId());
+		taskLabelReportingEventEntity.setDistrictName(placeVO.getPlaceName());
+		taskLabelReportingEventEntity.setUserId(placeVO.getPrincipalUserId());
+		taskLabelReportingEventEntity.setOwner(placeVO.getPrincipal());
+		taskLabelReportingEventEntity.setPhoneNumber(placeVO.getPrincipalPhone());
+		taskLabelReportingEventEntity.setLabelName(taskName);
+		// 打金店
+		if (reportType==3){
+			taskLabelReportingEventEntity.setEventType("1");
+		}
+		// 二手车
+		if (reportType==4){
+			taskLabelReportingEventEntity.setEventType("3");
+		}
+		// 二手手机
+		if (reportType==5){
+			taskLabelReportingEventEntity.setEventType("2");
+		}
+		// 系统下发
+		taskLabelReportingEventEntity.setSource(2);
+		// 待完善
+		taskLabelReportingEventEntity.setConfirmFlag("4");
+		// 新增
+		taskLabelReportingEventService.save(taskLabelReportingEventEntity);
+	}
+
+	/**
+	 * 插入任务信息
+	 * @param houseCode
+	 * @param type
+	 * @param taskName
+	 * @param frequency
+	 * @param reportType
+	 * @return
+	 */
+	private TaskEntity saveTaskEntity(String houseCode,
+									  Integer type,
+									  String taskName,
+									  Integer frequency,
+									  Integer reportType) {
+		TaskEntity taskEntity = new TaskEntity();
+		taskEntity.setType(type);
+		taskEntity.setName(taskName);
+		taskEntity.setFrequency(frequency);
+		taskEntity.setCreateTime(new Date());
+		taskEntity.setHouseCode(houseCode);
+		taskEntity.setReportType(reportType);
+		// 系统下发
+		taskEntity.setSource(2);
+		// 待场所负责人上报完善处理
+		taskEntity.setStatus(4);
+		// 新增
+		save(taskEntity);
+		// 返回
+		return taskEntity;
+	}
 }

--
Gitblit v1.9.3