|  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.moral.api.entity.MonitorPoint; | 
|---|
|  |  |  | import com.moral.api.entity.Organization; | 
|---|
|  |  |  | import com.moral.api.entity.SysArea; | 
|---|
|  |  |  | import com.moral.api.mapper.MonitorPointMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.OrganizationMapper; | 
|---|
|  |  |  | import com.moral.api.mapper.SysAreaMapper; | 
|---|
|  |  |  | import com.moral.api.service.MonitorPointService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | import com.moral.api.util.LogUtils; | 
|---|
|  |  |  | import com.moral.constant.Constants; | 
|---|
|  |  |  | import com.moral.constant.ResponseCodeEnum; | 
|---|
|  |  |  | import com.moral.util.ConvertUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private OrganizationMapper organizationMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired(required = false) | 
|---|
|  |  |  | private SysAreaMapper sysAreaMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | LogUtils logUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | int totalNumber = monitorPointMapper.selectCount(wrapper); | 
|---|
|  |  |  | String orderType = map.get("orderType").toString(); | 
|---|
|  |  |  | if (orderType.equals(Constants.ORDER_ASC)){ | 
|---|
|  |  |  | wrapper.orderByAsc("create_time"); | 
|---|
|  |  |  | wrapper.orderByAsc("update_time"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | wrapper.orderByDesc("create_time"); | 
|---|
|  |  |  | wrapper.orderByDesc("update_time"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Page resultPage = monitorPointMapper.selectPage(page,wrapper); | 
|---|
|  |  |  | List<MonitorPoint> monitorPoints = resultPage.getRecords(); | 
|---|
|  |  |  | 
|---|
|  |  |  | monitorPointMap.put("createTime",createTime); | 
|---|
|  |  |  | monitorPointMap.put("updateTime",updateTime); | 
|---|
|  |  |  | monitorPointMap.put("key",monitorPoint.getId()); | 
|---|
|  |  |  | if (monitorPointMap.get("provinceCode")!=null&&monitorPointMap.get("provinceCode")!=""){ | 
|---|
|  |  |  | monitorPointMap.put("provinceCode",getAreaArr(monitorPointMap.get("provinceCode").toString())); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("provinceCode",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (monitorPointMap.get("cityCode")!=null&&monitorPointMap.get("cityCode")!=""){ | 
|---|
|  |  |  | monitorPointMap.put("cityCode",getAreaArr(monitorPointMap.get("cityCode").toString())); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("cityCode",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (monitorPointMap.get("areaCode")!=null&&monitorPointMap.get("areaCode")!=""){ | 
|---|
|  |  |  | monitorPointMap.put("areaCode",getAreaArr(monitorPointMap.get("areaCode").toString())); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("areaCode",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (monitorPointMap.get("organizationId")!=null&&monitorPointMap.get("organizationId")!=""){ | 
|---|
|  |  |  | Organization organization = organizationMapper.selectById(Integer.parseInt(monitorPointMap.get("organizationId").toString())); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(organization)) { | 
|---|
|  |  |  | String[] organizationArr = {monitorPointMap.get("organizationId").toString(),organization.getName()}; | 
|---|
|  |  |  | monitorPointMap.put("organizationId",organizationArr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("organizationId",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | monitorPointtList.add(monitorPointMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("manageRoles",monitorPointtList); | 
|---|
|  |  |  | resultMap.put("monitorPoints",monitorPointtList); | 
|---|
|  |  |  | resultMap.put("totalNumber",totalNumber); | 
|---|
|  |  |  | resultMap.put("current",current); | 
|---|
|  |  |  | int totalPageNumber = totalNumber/size; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public Map<String, Object> updateMonitorPoint(Map<String,Object> updateMap) { | 
|---|
|  |  |  | public Map<String, Object> updateMonitorPoint(Map<String,Object> parameterMap) { | 
|---|
|  |  |  | Map resultMap = new HashMap(); | 
|---|
|  |  |  | Map<String,Object> updateMap = new HashMap<>(); | 
|---|
|  |  |  | for (String key : parameterMap.keySet()) { | 
|---|
|  |  |  | updateMap.put(ConvertUtils.toLine(key),parameterMap.get(key)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!updateMap.containsKey("id")){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (updateMap.get("name")==null||updateMap.get("name")==""){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<MonitorPoint> wapper_name = new QueryWrapper<>(); | 
|---|
|  |  |  | wapper_name.eq("name",updateMap.get("name")); | 
|---|
|  |  |  | wapper_name.eq("is_delete",Constants.NOT_DELETE); | 
|---|
|  |  |  | MonitorPoint monitorPoint_name = monitorPointMapper.selectOne(wapper_name); | 
|---|
|  |  |  | if(monitorPoint_name!=null&&!monitorPoint_name.getId().toString().equals(updateMap.get("id").toString())){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | QueryWrapper<MonitorPoint> wapper_id = new QueryWrapper<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_NOT_EXIST.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (updateMap.get("name")!=null&&updateMap.get("name").equals("")){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (updateMap.get("name")!=null){ | 
|---|
|  |  |  | QueryWrapper<MonitorPoint> wapper_name = new QueryWrapper<>(); | 
|---|
|  |  |  | wapper_name.eq("name",updateMap.get("name")); | 
|---|
|  |  |  | wapper_name.eq("is_delete",Constants.NOT_DELETE); | 
|---|
|  |  |  | MonitorPoint monitorPoint_name = monitorPointMapper.selectOne(wapper_name); | 
|---|
|  |  |  | if(monitorPoint_name!=null&&!monitorPoint_name.getId().toString().equals(updateMap.get("id").toString())){ | 
|---|
|  |  |  | resultMap.put("code",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getCode()); | 
|---|
|  |  |  | resultMap.put("msg",ResponseCodeEnum.MONITOR_POINT_IS_EXIST.getMsg()); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | monitorPointMapper.updateMonitorPoint(updateMap); | 
|---|
|  |  |  | HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | 
|---|
|  |  |  | String content = "修改了站点:"+oldMonitorPoint.getName()+";"; | 
|---|
|  |  |  | for (Object key:updateMap.keySet()) { | 
|---|
|  |  |  | if (key.toString().equals("name")){ | 
|---|
|  |  |  | if (key.toString().equals("name")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"站点名称:"+oldMonitorPoint.getName()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("longitude")){ | 
|---|
|  |  |  | if (key.toString().equals("longitude")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"经度:"+oldMonitorPoint.getLongitude()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("latitude")){ | 
|---|
|  |  |  | if (key.toString().equals("latitude")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"纬度:"+oldMonitorPoint.getLatitude()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("province_code")){ | 
|---|
|  |  |  | if (key.toString().equals("province_code")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"省份编码:"+oldMonitorPoint.getProvinceCode()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("city_code")){ | 
|---|
|  |  |  | if (key.toString().equals("city_code")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"地级市编码:"+oldMonitorPoint.getCityCode()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("area_code")){ | 
|---|
|  |  |  | if (key.toString().equals("area_code")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"县/区/县级市:"+oldMonitorPoint.getAreaCode()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("address")){ | 
|---|
|  |  |  | if (key.toString().equals("address")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"地址:"+oldMonitorPoint.getAddress()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("organization_id")){ | 
|---|
|  |  |  | if (key.toString().equals("organization_id")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"组织id:"+oldMonitorPoint.getOrganizationId()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (key.toString().equals("desc")){ | 
|---|
|  |  |  | if (key.toString().equals("desc")&&updateMap.get(key)!=null){ | 
|---|
|  |  |  | content = content+"描述:"+oldMonitorPoint.getDesc()+"->"+updateMap.get(key)+";"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | int totalNumber = monitorPointMapper.selectCount(wrapper); | 
|---|
|  |  |  | String orderType = map.get("orderType").toString(); | 
|---|
|  |  |  | if (orderType.equals(Constants.ORDER_ASC)){ | 
|---|
|  |  |  | wrapper.orderByAsc("create_time"); | 
|---|
|  |  |  | wrapper.orderByAsc("update_time"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | wrapper.orderByDesc("create_time"); | 
|---|
|  |  |  | wrapper.orderByDesc("update_time"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Page resultPage = monitorPointMapper.selectPage(page,wrapper); | 
|---|
|  |  |  | List<MonitorPoint> monitorPoints = resultPage.getRecords(); | 
|---|
|  |  |  | 
|---|
|  |  |  | monitorPointMap.put("createTime",createTime); | 
|---|
|  |  |  | monitorPointMap.put("updateTime",updateTime); | 
|---|
|  |  |  | monitorPointMap.put("key",monitorPoint.getId()); | 
|---|
|  |  |  | if (monitorPointMap.get("provinceCode")!=null&&monitorPointMap.get("provinceCode")!=""){ | 
|---|
|  |  |  | monitorPointMap.put("provinceCode",getAreaArr(monitorPointMap.get("provinceCode").toString())); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("provinceCode",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (monitorPointMap.get("cityCode")!=null&&monitorPointMap.get("cityCode")!=""){ | 
|---|
|  |  |  | monitorPointMap.put("cityCode",getAreaArr(monitorPointMap.get("cityCode").toString())); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("cityCode",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (monitorPointMap.get("areaCode")!=null&&monitorPointMap.get("areaCode")!=""){ | 
|---|
|  |  |  | monitorPointMap.put("areaCode",getAreaArr(monitorPointMap.get("areaCode").toString())); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("areaCode",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /*Organization organization = organizationMapper.selectById(Integer.parseInt(monitorPointMap.get("organizationId").toString())); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(organization)) { | 
|---|
|  |  |  | String[] organizationArr = {monitorPointMap.get("organizationId").toString(),organization.getName()}; | 
|---|
|  |  |  | monitorPointMap.put("organizationId",organizationArr); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | if (monitorPointMap.get("organizationId")!=null&&monitorPointMap.get("organizationId")!=""){ | 
|---|
|  |  |  | Organization organization = organizationMapper.selectById(Integer.parseInt(monitorPointMap.get("organizationId").toString())); | 
|---|
|  |  |  | if (!ObjectUtils.isEmpty(organization)) { | 
|---|
|  |  |  | String[] organizationArr = {monitorPointMap.get("organizationId").toString(),organization.getName()}; | 
|---|
|  |  |  | monitorPointMap.put("organizationId",organizationArr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String[] arr = {null,null}; | 
|---|
|  |  |  | monitorPointMap.put("organizationId",arr); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | monitorPointtList.add(monitorPointMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resultMap.put("manageRoles",monitorPointtList); | 
|---|
|  |  |  | resultMap.put("monitorPoints",monitorPointtList); | 
|---|
|  |  |  | resultMap.put("totalNumber",totalNumber); | 
|---|
|  |  |  | resultMap.put("current",current); | 
|---|
|  |  |  | int totalPageNumber = totalNumber/size; | 
|---|
|  |  |  | 
|---|
|  |  |  | resultMap.put("totalPageNumber",totalPageNumber); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<MonitorPoint> getMonitorPointsByOrganizationId(Integer organizationId) { | 
|---|
|  |  |  | QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | MonitorPoint monitorPoint = new MonitorPoint(); | 
|---|
|  |  |  | monitorPoint.setOrganizationId(organizationId); | 
|---|
|  |  |  | monitorPoint.setIsDelete(Constants.NOT_DELETE); | 
|---|
|  |  |  | monitorPointQueryWrapper.setEntity(monitorPoint); | 
|---|
|  |  |  | List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(monitorPointQueryWrapper); | 
|---|
|  |  |  | return monitorPoints; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 获取地区名 | 
|---|
|  |  |  | * @Param: [areaArr, menu]menuMap:key为menuid,value为menu | 
|---|
|  |  |  | * @return: Array | 
|---|
|  |  |  | * @Author: lizijie | 
|---|
|  |  |  | * @Date: 2021/4/7 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String[] getAreaArr(String areaCode) { | 
|---|
|  |  |  | QueryWrapper<SysArea> wrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | wrapper.eq("area_code",areaCode); | 
|---|
|  |  |  | SysArea sysArea = sysAreaMapper.selectOne(wrapper); | 
|---|
|  |  |  | String[] arr = {areaCode,sysArea.getAreaName()}; | 
|---|
|  |  |  | return arr; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|