package cn.com.goldenwater.dcproj.service.impl.ducha; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.dao.BisInspAllObjDao; import cn.com.goldenwater.dcproj.dto.BisInspAllObjDto; import cn.com.goldenwater.dcproj.model.AttInspType; import cn.com.goldenwater.dcproj.model.BisInspAllObj; import cn.com.goldenwater.dcproj.model.BisInspAllRlation; import cn.com.goldenwater.dcproj.param.BisInspAllObjParam; import cn.com.goldenwater.dcproj.service.AttInspTypeService; import cn.com.goldenwater.dcproj.service.BisInspAllObjService; import cn.com.goldenwater.dcproj.util.StatisticalUtil; import cn.com.goldenwater.dcproj.utils.InspUtils; import cn.com.goldenwater.dcproj.utils.ListUtil; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; /** * @author lune * @date 2019-2-23 */ @Service @Transactional public class BisInspAllObjServiceImpl extends AbstractCrudService implements BisInspAllObjService { private Logger log = LoggerFactory.getLogger(getClass()); @Autowired private BisInspAllObjDao bisInspAllObjDao; @Autowired private AttInspTypeService attInspTypeService; public BisInspAllObjServiceImpl(BisInspAllObjDao bisInspAllObjDao) { super(bisInspAllObjDao); this.bisInspAllObjDao = bisInspAllObjDao; } @Override public Integer insertObj(BisInspAllObjDto bisInspAllObjDto) { String ptype = ""; if (bisInspAllObjDto.getPtype().equals(BisInspEnum.REVER.getValue())) { ptype = BisInspEnum.REVER.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.VILL.getValue())) { ptype = BisInspEnum.VILL.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.TRACK.getValue())) { ptype = BisInspEnum.TRACK.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.EMPWT.getValue())) { ptype = BisInspEnum.EMPWT.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.GRW.getValue())) { ptype = BisInspEnum.GRW.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.WAGA.getValue())) { ptype = BisInspEnum.WAGA.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.EMPWTRUN.getValue())) { ptype = BisInspEnum.EMPWTRUN.getRlation(); } else if (bisInspAllObjDto.getPtype().equals(BisInspEnum.PAWP.getValue())) { ptype = BisInspEnum.PAWP.getRlation(); } //根据人员id找到所在督查节点ID if (StringUtils.isNotBlank(bisInspAllObjDto.getId())) { return bisInspAllObjDao.insertObj(bisInspAllObjDto); } else { List bisInspAllRlations = getIdByUserId(bisInspAllObjDto.getPersonid(), ptype, bisInspAllObjDto.getAdCode()); if (bisInspAllRlations.size() == 1) { bisInspAllObjDto.setId(bisInspAllRlations.get(0).getId()); return bisInspAllObjDao.insertObj(bisInspAllObjDto); } else { bisInspAllObjDto.setId(bisInspAllRlations.get(0).getId()); return bisInspAllObjDao.insertObj(bisInspAllObjDto); } } } @Override public Integer selectCount(BisInspAllObjDto bisInspAllObjDto) { return bisInspAllObjDao.selectCount(bisInspAllObjDto); } @Override public PageInfo listByMap(Map paramMap) { log.info(JSON.toJSONString(paramMap)); StatisticalUtil.setDate(paramMap); PageHelper.startPage(MapUtils.getIntValue(paramMap, "pageNum"), MapUtils.getIntValue(paramMap, "pageSize")); List allList = bisInspAllObjDao.listByMap(paramMap); allList.forEach(all -> { if (StringUtils.isNotBlank(all.getAdFullName())) { String[] adFullNames = all.getAdFullName().split("-"); all.setProvince(adFullNames[0]); if (adFullNames.length > 1) { all.setCity(adFullNames[1]); } if (adFullNames.length > 2) { all.setCountry(adFullNames[2]); } } if (StringUtils.isNotBlank(all.getPtype())) { String tableName = bisInspAllObjDao.getTableName(all.getPtype()); String idName = "ID"; int choice = Integer.parseInt(all.getPtype()); switch (choice) { case 1: case 106: idName = "RGSTR_ID"; break; case 3: idName = "TRACK_ID"; break; default: } if (StringUtils.isNotBlank(tableName)) { BisInspAllObjDto rgstrIdAndState = bisInspAllObjDao.getRgstrIdAndState(all.getObjId(), idName, tableName); Optional.ofNullable(rgstrIdAndState).ifPresent(r -> { all.setRgstrId(r.getRgstrId()); all.setState(r.getState()); }); } } }); return new PageInfo<>(allList); } @Override public List> listOfRgstr(Map map) { String stateName = "STATE"; if ("BIS_INSP_GRW".equals(MapUtils.getString(map, "tableName"))) { stateName = "INSP_STATE"; } map.put("stateName", stateName); return bisInspAllObjDao.listOfRgstr(map); } @Override public void updateRgstrState(Map map) { List objIdList = (List) map.get("objIdList"); if (CollectionUtils.isNotEmpty(objIdList)) { List> list = ListUtil.partition(objIdList, 1000); List aaa = new ArrayList<>(list.size()); for (List l : list) { aaa.add(l.stream().collect(Collectors.joining("','", "'", "'"))); } map.put("objIdList", aaa); } String stateName = "STATE"; if ("BIS_INSP_GRW".equals(MapUtils.getString(map, "tableName"))) { stateName = "INSP_STATE"; } map.put("stateName", stateName); bisInspAllObjDao.updateRgstrState(map); } public List getIdByUserId(String userid, String ptype, String adCode) { return bisInspAllObjDao.getIdByUserId(userid, ptype, adCode); } /** * 更新登记表状态 为督察中 * * @param objId 对象ID */ @Override public void updateRgstrByObjId(String objId) { updateRgstrByObjId(objId, "1"); } /** * 更新登记表状态 * * @param objId 对象ID */ @Override public void updateRgstrByObjId(String objId, String state) { BisInspAllObj bisInspAllObj = get(objId); if (null == bisInspAllObj) { return; } updateRgstrByObjId(objId, state, bisInspAllObj.getPtype()); } /** * 更新登记表状态 * * @param objId 对象ID */ @Override public void updateRgstrByObjId(String objId, String state, String ptype) { AttInspType attInspType = attInspTypeService.get(InspUtils.convertThirdLengthStr(ptype)); if (attInspType == null) { return; } Map paramMap = new HashMap<>(4); paramMap.put("tableName", attInspType.getRgstrTableName()); paramMap.put("objId", objId); // 查询对象状态 List> objList = listOfRgstr(paramMap); if (CollectionUtils.isEmpty(objList)) { return; } String currentState = MapUtils.getString(objList.get(0), "state", "0"); switch (state) { case "1": if ("0".equals(currentState)) { // 3. 批量更新登记表 paramMap.put("state", state); updateRgstrState(paramMap); } break; case "2": if ("0".equals(currentState) || "2".equals(currentState)) { // 3. 批量更新登记表 paramMap.put("state", state); updateRgstrState(paramMap); } break; default: } } @Override public List listOfGenrl(BisInspAllObjParam param) { return bisInspAllObjDao.listOfGenrl(param); } }