package cn.com.goldenwater.dcproj.service.impl.general; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.dao.BisInspAllRlationPersDao; import cn.com.goldenwater.dcproj.dao.BisInspPblmPlistDao; import cn.com.goldenwater.dcproj.dao.GeneralInfoDao; import cn.com.goldenwater.dcproj.dao.MenuDao; import cn.com.goldenwater.dcproj.dao.OlBisInspOrgDao; import cn.com.goldenwater.dcproj.dto.BisInspBaseListDto; import cn.com.goldenwater.dcproj.dto.EmpwtprjPadMapDto; import cn.com.goldenwater.dcproj.dto.LoginUser; import cn.com.goldenwater.dcproj.dto.MenuDto; import cn.com.goldenwater.dcproj.dto.PersCwsInfoDto; import cn.com.goldenwater.dcproj.dto.PersGrwInfoDto; import cn.com.goldenwater.dcproj.dto.PersInfoDto; import cn.com.goldenwater.dcproj.dto.PersResInfoDto; import cn.com.goldenwater.dcproj.dto.PersWtdstInfoDto; import cn.com.goldenwater.dcproj.dto.RsCountDto; import cn.com.goldenwater.dcproj.dto.RsStatusInfoDto; import cn.com.goldenwater.dcproj.enums.PrivTypeEnum; import cn.com.goldenwater.dcproj.model.AttInspType; import cn.com.goldenwater.dcproj.model.AttInteBase; import cn.com.goldenwater.dcproj.model.BisInspAllRlationPers; import cn.com.goldenwater.dcproj.model.BisInspWorkInfo; import cn.com.goldenwater.dcproj.model.OlBisInspOrg; import cn.com.goldenwater.dcproj.model.PersLoc; import cn.com.goldenwater.dcproj.model.PersPositionViewLog; import cn.com.goldenwater.dcproj.param.EmptprjPadMapInfoParam; import cn.com.goldenwater.dcproj.param.GeneralInfoParam; import cn.com.goldenwater.dcproj.param.RsStatusInfoParam; import cn.com.goldenwater.dcproj.param.StartAndEndTimeParam; import cn.com.goldenwater.dcproj.service.GeneralInfoService; import cn.com.goldenwater.dcproj.service.PersPositionViewLogService; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.BeanUtil; import cn.com.goldenwater.dcproj.utils.EnumUtil; import cn.com.goldenwater.dcproj.utils.expExcel.ExcelExport; import cn.com.goldenwater.dcproj.utils.expExcel.ExportAbstract; import cn.com.goldenwater.dcproj.utils.expExcel.ExportUtil; import cn.com.goldenwater.dcproj.vo.BisInspPblmMapVo; import cn.com.goldenwater.target.CheckException; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; /** * Created by 61618 on 2019/4/12. */ @Service @Transactional(rollbackFor = Exception.class) public class GeneralInfoServiceImpl implements GeneralInfoService { @Autowired private GeneralInfoDao generalInfoDao; @Autowired private OlBisInspOrgDao olBisInspOrgDao; @Autowired private BisInspAllRlationPersDao bisInspAllRlationPersDao; @Autowired private PersPositionViewLogService persPositionViewLogService; @Autowired private MenuDao menuDao; @Autowired private BisInspPblmPlistDao bisInspPblmPlistDao; @Override public List getInfoByPers(String persid, String sttm, String entm, String province) { //存放最终结果 List persInfoDtoList = this.generalInfoDao.getGroup(persid, sttm, entm, province); if (persInfoDtoList.size() > 0) { for (PersInfoDto persInfoDto : persInfoDtoList) { if ("001".equals(persInfoDto.getId().substring(0, 3)) || "036".equals(persInfoDto.getId().substring(0, 36))) {//小水库 String ptype = "1"; if ("036".equals(persInfoDto.getId().substring(0, 3))) { ptype = "36"; } List persResInfoDtoList = this.generalInfoDao.getPersResInfoDtoList(persInfoDto.getId(), province, ptype); if (persResInfoDtoList.size() > 0) { persInfoDto.setPersResInfoDtoList(persResInfoDtoList); } } else if (BisInspEnum.VILL.getRlation().equals(persInfoDto.getId().substring(0, 3))) {//人饮 List persCwsInfoDtoList = this.generalInfoDao.getPersCwsInfoDtoList(persInfoDto.getId(), province); if (persCwsInfoDtoList.size() > 0) { persInfoDto.setPersCwsInfoDtoList(persCwsInfoDtoList); } } else if (BisInspEnum.TRACK.getRlation().equals(persInfoDto.getId().substring(0, 3))) {//水毁 List persWtdstInfoDtoList = this.generalInfoDao.getPersWtdstInfoDtoList(persInfoDto.getId(), province); if (persWtdstInfoDtoList.size() > 0) { persInfoDto.setPersWtdstInfoDtoList(persWtdstInfoDtoList); } } else if (BisInspEnum.GRW.getRlation().equals(persInfoDto.getId().substring(0, 3))) {//地下水 List persGrwInfoDtoList = this.generalInfoDao.getPersGrwInfoDtoList(persInfoDto.getId(), province); if (persGrwInfoDtoList.size() > 0) { persInfoDto.setPersGrwInfoDtoList(persGrwInfoDtoList); } } } } return persInfoDtoList; } @Override public PageInfo getRsSupData(RsStatusInfoParam rsStatusInfoParam, HttpServletResponse response) { if (!"".equals(rsStatusInfoParam.getAdCode())) { String subAd = AdLevelUtil.SubAd(rsStatusInfoParam.getAdCode()).get("subAd").toString(); rsStatusInfoParam.setAdCode(subAd); } if ("1".equals(rsStatusInfoParam.getIsExport())) { List> mapList = new ArrayList<>(); for (RsStatusInfoDto info : this.generalInfoDao.getRsSupData(rsStatusInfoParam)) { mapList.add(BeanUtil.transBean2Map(info)); } ExportAbstract export = new ExcelExport(); export.setFileName("水库列表"); export.setExport_ps_export(true); export.setExport_ps_type(ExportAbstract.XLS); export.setExport_bzip(false); export.setTitle("水库列表"); ArrayList cols = new ArrayList(); cols.add("rsCode[水库编码]"); cols.add("rsName[水库名称]"); cols.add("rsType[水库类型]"); cols.add("totCap[总容量(万m3)]"); cols.add("rsAdmName[负责公司]"); cols.add("rsAdmDep[部门]"); export.setCols(cols); export.setGroupable(false); // 设置视图指标 export.setLevel(1); export.setLocksize(0); try { export.Export(response); export.ExportHeadForCustom(response);//导出表头 export.ContinueExport(mapList); export.EndExport(); } catch (Exception e) { e.printStackTrace(); } } PageHelper.startPage(rsStatusInfoParam.getPageNum(), rsStatusInfoParam.getPageSize()); List rsStatusInfoList = this.generalInfoDao.getRsSupData(rsStatusInfoParam); if (rsStatusInfoList.size() > 0) { for (RsStatusInfoDto rs : rsStatusInfoList) { if (rs.getObjId() != null) { if (rs.getRgstrStatus().equals("0")) { rs.setStatus(rs.getUptm() + "年 未填报"); } else if (rs.getRgstrStatus().equals("1")) { rs.setStatus(rs.getUptm() + "年 督查中"); } else if (rs.getRgstrStatus().equals("2")) { rs.setStatus(rs.getUptm() + "年 已督查"); } } else { rs.setStatus("未督查"); } } } PageInfo pageInfo = new PageInfo(rsStatusInfoList); return pageInfo; } @Override public PageInfo getEmptprjData(EmptprjPadMapInfoParam p) throws Exception { if (!"".equals(p.getAdCode())) { String subAd = AdLevelUtil.SubAd(p.getAdCode()).get("subAd").toString(); p.setAdCode(subAd); } PageHelper.startPage(p.getPageNum(), p.getPageSize()); List rsStatusInfoList = this.generalInfoDao.getEmptprjData(p); if (rsStatusInfoList.size() > 0) { for (EmpwtprjPadMapDto rs : rsStatusInfoList) { if ("1".equals(rs.getHstInsp()) && rs.getObjId() != null) { if ("0".equals(rs.getRgstrStatus())) { rs.setStatus("复查-未督查"); } else if ("1".equals(rs.getRgstrStatus())) { rs.setStatus("复查-督查中"); } else if ("2".equals(rs.getRgstrStatus())) { rs.setStatus("复查-已督查"); } } else if ("1".equals(rs.getHstInsp()) && rs.getObjId() == null) { rs.setStatus("2018-已督查"); } else if (!"1".equals(rs.getHstInsp()) && rs.getObjId() != null) { if ("0".equals(rs.getRgstrStatus())) { rs.setStatus("2019-未督查"); } else if ("1".equals(rs.getRgstrStatus())) { rs.setStatus("2019-督查中"); } else if ("2".equals(rs.getRgstrStatus())) { rs.setStatus("2019-已督查"); } } else { rs.setStatus("督查计划外"); } } } PageInfo pageInfo = new PageInfo(rsStatusInfoList); return pageInfo; } @Override public int insertInte(AttInteBase attInteBase) { return this.generalInfoDao.insertInte(attInteBase); } @Override public int deleteInte(String id) { return this.generalInfoDao.deleteInte(id); } @Override public int updateInte(AttInteBase attInteBase) { return this.generalInfoDao.updateInte(attInteBase); } @Override public List getWorkInfoByPersId(String persId, String province) { //获取人员所在组的督查对象 List workInfoList = this.generalInfoDao.getWorkDetailByPersId(persId); return workInfoList; } @Override public List getSttmEntmByPersId(String persId, Double lon, Double lat,String orgId,LoginUser currentLoginUser) { OlBisInspOrg inspOrg = olBisInspOrgDao.get(orgId); // 查询轨迹记录 List persLocList = this.generalInfoDao.getSttmEntm(persId, lon, lat, inspOrg.getRlcode()); // 增加查询轨迹记录的日志 BisInspAllRlationPers pers = bisInspAllRlationPersDao.get(persId); PersPositionViewLog persPositionViewLog = new PersPositionViewLog(); persPositionViewLog.setPersIdViewed(persId); persPositionViewLog.setPersNameViewed(pers.getPersName()); persPositionViewLog.setOrgId(orgId); persPositionViewLog.setAdCode(inspOrg.getAdCode()); persPositionViewLog.setAdName(inspOrg.getOrgNm()); persPositionViewLog.setPersId(currentLoginUser.getPersId()); persPositionViewLog.setPersName(currentLoginUser.getPersName()); persPositionViewLog.setNote(String.format("persid:%s;lon:%s;lat:%s",persId,null== lon?"null":lon.toString(),null== lat?"null":lat.toString())); persPositionViewLogService.insert(persPositionViewLog); return persLocList; } @Override public PageInfo getIntePage(StartAndEndTimeParam startAndEndTimeParam) { PageHelper.startPage(startAndEndTimeParam); List list = this.generalInfoDao.getIntePage(startAndEndTimeParam); PageInfo pageInfo = new PageInfo(list); return pageInfo; } @Override public List getObjCount(GeneralInfoParam param) { if (StringUtils.isNotBlank(param.getAdCode())) { param.setAdCode(AdLevelUtil.SubAd(param.getAdCode()).get("subAd").toString()); } List list = new ArrayList<>(); if (StringUtils.isBlank(param.getAdGrad())) { return list; } if ("1".equals(param.getObjType())) { list = generalInfoDao.getObjRsCount(param); return list; } else if ("2".equals(param.getObjType())) { list = generalInfoDao.getObjVlgCount(param); } else if ("21".equals(param.getObjType())) { param.setObjType(param.getObjType().substring(0, 1)); list = generalInfoDao.getObjCwsCount(param); } else if ("22".equals(param.getObjType())) { param.setObjType(param.getObjType().substring(0, 1)); list = generalInfoDao.getObjPspCount(param); } else if ("23".equals(param.getObjType())) { param.setObjType(param.getObjType().substring(0, 1)); list = generalInfoDao.getObjAdBaseCount(param); } else if ("3".equals(param.getObjType())) { list = generalInfoDao.getObjWtdstCount(param); } else if ("4".equals(param.getObjType())) { list = generalInfoDao.getObjEmpwtCount(param); } else if ("6".equals(param.getObjType())) { list = generalInfoDao.getObjWagaCount(param); } return list; } @Override public List getBaseList(GeneralInfoParam param) { if (StringUtils.isNotBlank(param.getAdCode())) { param.setAdCode(String.valueOf(AdLevelUtil.SubAd(param.getAdCode()).get("subAd"))); } return generalInfoDao.getBaseList(param); } @Override public PageInfo getBasePage(GeneralInfoParam param, HttpServletResponse response) { if (StringUtils.isNotBlank(param.getAdCode())) { param.setAdCode(String.valueOf(AdLevelUtil.SubAd(param.getAdCode()).get("subAd"))); } if ("1".equals(param.getIsExport())) { BisInspEnum bisInspEnum = EnumUtil.getBisInspEnum(param.getObjType()); String fileName = "结果列表"; if (bisInspEnum != null) { fileName = bisInspEnum.getDesc() + "列表"; } List columns = new ArrayList<>(); columns.add("id"); columns.add("code"); columns.add("objId"); columns.add("rgstrId"); columns.add("objType"); columns.add("displayLevel"); columns.add("baseCode"); ExportUtil.exportExcel(generalInfoDao.getBaseList(param), response, fileName, columns, BisInspBaseListDto.class); } PageHelper.startPage(param); List listDtos = generalInfoDao.getBaseList(param); return new PageInfo<>(listDtos); } /** * 查询当前用户机构的督查类型列表 * @param param * @return */ @Override public List getObjTypeList(GeneralInfoParam param){ return this.generalInfoDao.getObjTypeList(param); } /** * 查询当前用户机构的督查类型的问题列表 * @param param * @return */ @Override public List getPblmList(GeneralInfoParam param){ if(StringUtils.isBlank(param.getObjType())){ throw new CheckException("督查对象类型不能为空!"); } if(StringUtils.isBlank(param.getStartTime()) && StringUtils.isBlank(param.getEndTime())){ // 没有时间限制 默认设置为当年 LocalDate curDate = LocalDate.now(); param.setStartTime(String.format("%d-1-1",curDate.getYear())); param.setEndTime(String.format("%d-%d-%d",curDate.getYear(),curDate.getMonthValue(),curDate.getDayOfMonth())); } List pblmMapVoList = this.generalInfoDao.selectPblmListByObjType(param); if(null != pblmMapVoList && pblmMapVoList.size()>0 ){ // 设置 工作流信息 for(BisInspPblmMapVo pblmVo :pblmMapVoList){ String plistId = pblmVo.getId(); if(StringUtils.isNotEmpty(plistId)){ // 查询 List> bpmDataIdList = this.bisInspPblmPlistDao.getBpmDataId(plistId, param.getOrgId(), param.getProvince()); if (CollectionUtils.isNotEmpty(bpmDataIdList)) { Map bpmData = bpmDataIdList.get(0); pblmVo.setTaskInstId(bpmData.get("taskInstId")); pblmVo.setProcInstId(bpmData.get("procInstId")); pblmVo.setProcTypeName("督查-" + bpmData.get("procTypeName")); } } } } return pblmMapVoList; } /** * 查询当前用户督查填报菜单 * @param param * @return */ @Override public List getObjTypeMenuListByPersId(GeneralInfoParam param){ String curUserId = param.getPersId(); BisInspAllRlationPers pers = bisInspAllRlationPersDao.get(curUserId); Optional.ofNullable(pers).orElseThrow(() -> new CheckException("此人员不存在:" + curUserId)); String owerSystem = pers.getOwnerSystem(); List menuList = menuDao.getListByUserId(curUserId, PrivTypeEnum.MENU.getValue(), param.getOwnApp(), owerSystem); if(null != menuList && menuList.size()>0){ MenuDto menuDto = menuList.stream().filter(f -> "督查填报".equals(f.getMenuName())).findFirst().orElse(null); return null == menuDto? new ArrayList<>():menuDto.getMenuList(); }else { return new ArrayList<>() ; } } }