| | |
| | | */ |
| | | package org.springblade.modules.place.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.param.CommonParamSet; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.place.entity.PlaceEntity; |
| | | import org.springblade.modules.place.entity.PlaceExtEntity; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.modules.place.vo.PlaceExtVO; |
| | | import org.springblade.modules.place.entity.PlacePractitionerEntity; |
| | | import org.springblade.modules.place.mapper.PlaceExtMapper; |
| | | import org.springblade.modules.place.service.IPlaceExtService; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.modules.task.entity.TaskEntity; |
| | | import org.springblade.modules.task.service.ITaskService; |
| | | import org.springblade.modules.place.service.IPlacePractitionerService; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.modules.place.vo.PlaceExtVO; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 场所详情表 服务实现类 |
| | |
| | | public class PlaceExtServiceImpl extends ServiceImpl<PlaceExtMapper, PlaceExtEntity> implements IPlaceExtService { |
| | | |
| | | @Autowired |
| | | private ITaskService taskService; |
| | | private IPlaceService placeService; |
| | | |
| | | @Autowired |
| | | private IPlaceService placeService; |
| | | private IPlacePractitionerService placePractitionerService; |
| | | |
| | | // @Autowired |
| | | // private IGridService gridService; |
| | | // |
| | | // @Autowired |
| | | // private IDeptService deptService; |
| | | |
| | | /** |
| | | * 自定义查询 |
| | | * |
| | | * @param page |
| | | * @param placeExt |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<PlaceExtVO> selectPlaceExtPage(IPage<PlaceExtVO> page, PlaceExtVO placeExt) { |
| | | return page.setRecords(baseMapper.selectPlaceExtPage(page, placeExt)); |
| | | // List<String> list = new ArrayList<>(); |
| | | // String roleName = SpringUtils.getRequestParam("roleName"); |
| | | // String communityCode = SpringUtils.getRequestParam("communityCode"); |
| | | // if (!Strings.isBlank(communityCode)){ |
| | | // // 校验社区编号是否合规 |
| | | // if(null!=SpringUtils.getBean(IRegionService.class).getById(communityCode)) { |
| | | // placeExt.setCommunityCode(communityCode); |
| | | // } |
| | | // } |
| | | // List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId()); |
| | | // Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2; |
| | | // // 网格编号集合 |
| | | // List<String> gridCodeList = new ArrayList<>(); |
| | | // // 民警角色 |
| | | // if (!Strings.isBlank(roleName)){ |
| | | // placeExt.setRoleName(roleName); |
| | | // if(roleName.equals("mj")) { |
| | | // regionChildCodesList = SpringUtil.getBean(IPoliceAffairsGridService.class).getCommunityCodeListByUserId(AuthUtil.getUserId()); |
| | | // } |
| | | // if (roleName.equals("wgy")) { |
| | | // gridCodeList = SpringUtil.getBean(IGridService.class).getGridListByUserId(AuthUtil.getUserId()); |
| | | // } |
| | | // } |
| | | // if (AuthUtil.getUserAccount().equals("18879306957")) { |
| | | // placeExt.setCommunityCode("361102003027"); |
| | | // placeExt.setCreateUser(null); |
| | | // } |
| | | CommonParamSet<Object> commonParamSet = new CommonParamSet<>().invoke(PlaceExtVO.class, placeExt); |
| | | |
| | | |
| | | return page.setRecords(baseMapper.selectPlaceExtPage(page, placeExt, commonParamSet.getRegionChildCodesList(), |
| | | commonParamSet.getIsAdministrator(), commonParamSet.getGridCodeList())); |
| | | } |
| | | |
| | | /** |
| | | * 场所详情表 自定义更新 |
| | | * |
| | | * @param placeExt |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean updatePlaceExt(PlaceExtEntity placeExt) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updatePlaceExt(PlaceExtVO placeExt) { |
| | | // 设置参数 |
| | | placeExt.setUpdateTime(new Date()); |
| | | placeExt.setUpdateUser(AuthUtil.getUserId()); |
| | | // 更新从业人员信息 |
| | | boolean addFlag = true; |
| | | boolean updateFlag = true; |
| | | boolean removeFlag = true; |
| | | //更新自身 |
| | | boolean update = updateById(placeExt); |
| | | // 更新场所place 表信息 |
| | | updatePlaceInfo(placeExt); |
| | | // 查询对应已存在的从业人员 |
| | | QueryWrapper<PlacePractitionerEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id", placeExt.getPlaceId()).eq("is_deleted", 0); |
| | | List<PlacePractitionerEntity> oldList = placePractitionerService.list(wrapper); |
| | | List<PlacePractitionerEntity> list = placeExt.getPlacePractitioner(); |
| | | // 申明新增,修改,删除集合 |
| | | List<PlacePractitionerEntity> newList = new ArrayList<>(); |
| | | List<PlacePractitionerEntity> addList = new ArrayList<>(); |
| | | List<PlacePractitionerEntity> updateList = new ArrayList<>(); |
| | | List<PlacePractitionerEntity> removeList = new ArrayList<>(); |
| | | // 找出需要新增的,否则组成新集合进行比对 |
| | | for (PlacePractitionerEntity practitionerEntity : list) { |
| | | if (practitionerEntity.getResignationTime() != null) { |
| | | practitionerEntity.setResignationFlag(2); |
| | | } |
| | | practitionerEntity.setPlaceId(placeExt.getPlaceId()); |
| | | if (null == practitionerEntity.getId()) { |
| | | // 新增 |
| | | practitionerEntity.setPlaceId(placeExt.getPlaceId()); |
| | | addList.add(practitionerEntity); |
| | | } else { |
| | | newList.add(practitionerEntity); |
| | | } |
| | | } |
| | | // 遍历去差集,判断是新增还是删除还是更新 |
| | | // 取旧数据和新提交数据差集--删除 |
| | | removeList = oldList.stream().filter(vo -> !newList.stream().map(e -> |
| | | e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList()); |
| | | // 取旧数据和新提交数据交集--更新 |
| | | updateList = newList.stream().filter(vo -> oldList.stream().map(e -> |
| | | e.getId()).collect(Collectors.toList()).contains(vo.getId())).collect(Collectors.toList()); |
| | | |
| | | // 批量新增 |
| | | if (addList.size() > 0) { |
| | | addFlag = placePractitionerService.saveBatch(addList); |
| | | } |
| | | // 批量修改 |
| | | if (updateList.size() > 0) { |
| | | updateFlag = placePractitionerService.updateBatchById(updateList); |
| | | } |
| | | // 批量删除 |
| | | if (removeList.size() > 0) { |
| | | removeFlag = placePractitionerService.removeBatchByIds(removeList); |
| | | } |
| | | // 返回 |
| | | return update && addFlag && updateFlag && removeFlag; |
| | | } |
| | | |
| | | /** |
| | | * 更新场所表信息 |
| | | * |
| | | * @param placeExt |
| | | */ |
| | | public void updatePlaceInfo(PlaceExtVO placeExt) { |
| | | PlaceEntity placeEntity = new PlaceEntity(); |
| | | placeEntity.setId(placeExt.getPlaceId()); |
| | | placeEntity.setPlaceName(placeExt.getPlaceName()); |
| | | if (!Strings.isBlank(placeExt.getLng())) { |
| | | placeEntity.setLng(placeExt.getLng()); |
| | | } |
| | | if (!Strings.isBlank(placeExt.getLat())) { |
| | | placeEntity.setLat(placeExt.getLat()); |
| | | } |
| | | if (!Strings.isBlank(placeExt.getLocation())) { |
| | | placeEntity.setLocation(placeExt.getLocation()); |
| | | } |
| | | // 更新 |
| | | return updateById(placeExt); |
| | | placeService.updateById(placeEntity); |
| | | // 警格网格绑定修改 |
| | | if (!Strings.isBlank(placeEntity.getHouseCode()) && !Strings.isBlank(placeEntity.getLng())) { |
| | | PlaceVO placeVO = new PlaceVO(); |
| | | placeVO.setHouseCode(placeEntity.getHouseCode()); |
| | | placeVO.setLng(placeEntity.getLng()); |
| | | placeVO.setLat(placeEntity.getLat()); |
| | | // 网格绑定 |
| | | placeService.policePositionHandle(placeVO); |
| | | // 警务网格绑定 |
| | | placeService.jwGridCodeBind(placeVO); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 场所详情表 审核 |
| | | * |
| | | * @param placeExt |
| | | * @return |
| | | */ |
| | |
| | | boolean flag = false; |
| | | // 设置更新时间 |
| | | placeExt.setConfirmTime(new Date()); |
| | | placeExt.setConfirmUserId(AuthUtil.getUserId()); |
| | | // 更新数据 |
| | | boolean b = updateById(placeExt); |
| | | if (b) { |
| | | // 更新任务表状态 |
| | | TaskEntity taskEntity = new TaskEntity(); |
| | | taskEntity.setId(placeExt.getTaskId()); |
| | | taskEntity.setStatus(placeExt.getConfirmFlag()); |
| | | flag = taskService.updateById(taskEntity); |
| | | } |
| | | flag = updateById(placeExt); |
| | | // if (b) { |
| | | // PlaceExtEntity entity = getById(placeExt.getId()); |
| | | // // 更新任务表状态 |
| | | // TaskEntity taskEntity = new TaskEntity(); |
| | | // taskEntity.setId(entity.getTaskId()); |
| | | // taskEntity.setStatus(placeExt.getConfirmFlag()); |
| | | // flag = taskService.updateById(taskEntity); |
| | | // } |
| | | // 返回 |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 场所详情表 新增 |
| | | * |
| | | * @param placeExt |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean savePlaceExt(PlaceExtEntity placeExt) { |
| | | PlaceEntity placeEntity = placeService.getById(placeExt.getPlaceId()); |
| | | TaskEntity taskEntity = new TaskEntity(); |
| | | taskEntity.setId(placeExt.getTaskId()); |
| | | taskEntity.setStatus(placeExt.getConfirmFlag()); |
| | | taskEntity.setType(1); |
| | | taskEntity.setFrequency(3); |
| | | taskEntity.setName(placeEntity.getPlaceName() + "信息完善任务" + System.currentTimeMillis()); |
| | | // 新增任务 |
| | | boolean save = taskService.save(taskEntity); |
| | | if (save){ |
| | | placeExt.setTaskId(taskEntity.getId()); |
| | | placeExt.setConfirmFlag(1); |
| | | placeExt.setCreateTime(new Date()); |
| | | placeExt.setUpdateTime(new Date()); |
| | | placeExt.setCreateUser(AuthUtil.getUserId()); |
| | | placeExt.setUpdateUser(AuthUtil.getUserId()); |
| | | // 新增场所详情 |
| | | save(placeExt); |
| | | // PlaceEntity placeEntity = placeService.getById(placeExt.getPlaceId()); |
| | | // TaskEntity taskEntity = new TaskEntity(); |
| | | // taskEntity.setId(placeExt.getTaskId()); |
| | | // taskEntity.setStatus(placeExt.getConfirmFlag()); |
| | | // taskEntity.setType(1); |
| | | // taskEntity.setFrequency(1); |
| | | // taskEntity.setName(placeEntity.getPlaceName() + "信息完善"); |
| | | // // 新增任务 |
| | | // boolean save = taskService.save(taskEntity); |
| | | // if (save){ |
| | | // placeExt.setTaskId(taskEntity.getId()); |
| | | placeExt.setConfirmFlag(1); |
| | | placeExt.setCreateTime(new Date()); |
| | | placeExt.setUpdateTime(new Date()); |
| | | placeExt.setCreateUser(AuthUtil.getUserId()); |
| | | placeExt.setUpdateUser(AuthUtil.getUserId()); |
| | | // 新增场所详情 |
| | | boolean save = save(placeExt); |
| | | // } |
| | | return save; |
| | | } |
| | | |
| | | /** |
| | | * 场所详情表 自定义详情 |
| | | * |
| | | * @param placeExt |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PlaceExtVO getDetail(PlaceExtVO placeExt) { |
| | | PlaceExtVO detail = baseMapper.getDetail(placeExt); |
| | | if (null != detail) { |
| | | // 查询从业人员信息 |
| | | QueryWrapper<PlacePractitionerEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("place_id", placeExt.getPlaceId()); |
| | | queryWrapper.eq("resignation_flag",1); |
| | | detail.setPlacePractitioner(placePractitionerService.list(queryWrapper)); |
| | | } |
| | | return false; |
| | | // 返回 |
| | | return detail; |
| | | } |
| | | |
| | | @Override |
| | | public Integer selectCount(Long userId, String neiCode, Integer confirmFlag) { |
| | | PlaceExtVO placeExt = new PlaceExtVO(); |
| | | placeExt.setConfirmFlag(confirmFlag); |
| | | placeExt.setNeiCode(neiCode); |
| | | CommonParamSet<Object> commonParamSet = new CommonParamSet<>().invoke(PlaceExtVO.class, placeExt); |
| | | return baseMapper.selectCount(placeExt, commonParamSet.getRegionChildCodesList(), commonParamSet.getIsAdministrator(), commonParamSet.getGridCodeList()); |
| | | } |
| | | } |