| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 接口控制器提供 |
| | |
| | | if (user.size()==0) { |
| | | return new ErrorTip(500, "Account password error!"); |
| | | } |
| | | if(user.get(0).getExpirationTime().getTime()<new Date().getTime()){ |
| | | return new ErrorTip(500, "Account Expire!"); |
| | | } |
| | | UserInfo userInfo = new UserInfo(); |
| | | BeanUtils.copyProperties(user, userInfo); |
| | | // String credentials = user.getPassword(); |
| | |
| | | import com.stylefeng.guns.modular.system.enums.UserFeeSettingEnum; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.utils.AddressLookup; |
| | | import com.stylefeng.guns.modular.system.utils.ExcelUtil; |
| | | import com.stylefeng.guns.modular.system.utils.GoogleMap.DistancematrixVo; |
| | | import com.stylefeng.guns.modular.system.utils.GoogleMap.GeocodeVo; |
| | | import com.stylefeng.guns.modular.system.utils.GoogleMap.GoogleMapUtil; |
| | | import com.stylefeng.guns.modular.system.utils.PointInPolygon; |
| | | import com.stylefeng.guns.modular.system.utils.tips.ErrorTip; |
| | | import com.stylefeng.guns.modular.system.utils.tips.SuccessTip; |
| | | import io.swagger.annotations.Api; |
| | |
| | | |
| | | // 基础价格 |
| | | String zipCode = demandDto.getZipCode(); |
| | | String address1 = AddressLookup.getAddress(zipCode); |
| | | TCompanyBasic tCompanyBasic = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("port_id",ratesId).eq("zip_code", zipCode).eq("type", 1)); |
| | | if(Objects.nonNull(tCompanyBasic)){ |
| | | tCompanyResp=new TCompanyResp(); |
| | |
| | | objects.add(tCompanyResp); |
| | | }else { |
| | | // 画圈 拿到的zipcode集合 去对比当前zipcode是否在集合中 |
| | | TCompanyBasic type = companyBasicService.selectOne(new EntityWrapper<TCompanyBasic>().eq("type", 2).eq("port_id",ratesId).like("zip_code", zipCode)); |
| | | if(Objects.nonNull(type)){ |
| | | tCompanyResp=new TCompanyResp(); |
| | | tCompanyResp.setPrice(type.getFee()); |
| | | tCompanyResp.setName("LH+FSC"); |
| | | objects.add(tCompanyResp); |
| | | // 画圈 拿到的zipcode集合 去对比当前zipcode是否在集合中 |
| | | List<TCompanyBasic> type = companyBasicService.selectList(new EntityWrapper<TCompanyBasic>().eq("type", 2).eq("port_id",ratesId).orderBy("fee",true)); |
| | | if(type.size()>0){ |
| | | GeocodeVo geocode1 = googleMapUtil.getGeocode(zipCode); |
| | | for (TCompanyBasic companyBasic : type) { |
| | | boolean inPolygon = PointInPolygon.isInPolygon(geocode1.getLat(), geocode1.getLng(), companyBasic.getLonLat()); |
| | | if(inPolygon){ |
| | | tCompanyResp=new TCompanyResp(); |
| | | tCompanyResp.setPrice(type.get(0).getFee()); |
| | | tCompanyResp.setName("LH+FSC"); |
| | | objects.add(tCompanyResp); |
| | | break; |
| | | } |
| | | } |
| | | if(tCompanyResp==null){ |
| | | // 距离 |
| | | tCompanyResp=new TCompanyResp(); |
| | | // 1条数据 不需要zipcode |
| | | DistancematrixVo distancematrix = googleMapUtil.getDistancematrix(address, address1); |
| | | double distance = distancematrix.getDistance().doubleValue(); |
| | | BigDecimal bigDecimal = new BigDecimal(distance * 0.0006214); |
| | | List<TCompanyBasic> type1 = companyBasicService.selectList(new EntityWrapper<TCompanyBasic>().eq("type", 3).eq("port_id",ratesId).le("start",bigDecimal.doubleValue()).orderBy("start",true)); |
| | | if(type1.size()>0) { |
| | | BigDecimal multiply = type1.get(0).getFee().multiply(bigDecimal); |
| | | tCompanyResp.setPrice(multiply); |
| | | tCompanyResp.setName("LH+FSC"); |
| | | objects.add(tCompanyResp); |
| | | }else { |
| | | tCompanyResp.setPrice(new BigDecimal(0)); |
| | | tCompanyResp.setName("LH+FSC"); |
| | | objects.add(tCompanyResp); |
| | | } |
| | | } |
| | | }else { |
| | | tCompanyResp=new TCompanyResp(); |
| | | // 1条数据 不需要zipcode |
| | |
| | | @PostMapping(value = "/updatePrice") |
| | | @ResponseBody |
| | | public Object updatePrice(@RequestBody List<TPrice> prices,String note) { |
| | | String randomString = ToolUtil.getRandomString(15); |
| | | prices.forEach(e->e.setNumber(randomString)); |
| | | priceService.insertBatch(prices); |
| | | Long orderId = prices.get(0).getOrderId(); |
| | | TOrder tOrder = orderService.selectById(orderId); |
| | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), |
| | | @ApiImplicitParam(name = "time", value = "2000-01-01 - 2000-11-11", required = false, dataType = "String"), |
| | | @ApiImplicitParam(name = "id", value = "卡车公司id", required = true, dataType = "String"), |
| | | @ApiImplicitParam(name = "id", value = "卡车公司id", required = true, dataType = "int"), |
| | | }) |
| | | @GetMapping(value = "/index") |
| | | @ResponseBody |
| | |
| | | return new SuccessTip(orderInfo); |
| | | } |
| | | |
| | | @ApiOperation(value = "订单详情--修改reference numbers",notes="订单详情--修改reference numbers") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), |
| | | }) |
| | | @PostMapping(value = "/updateReference") |
| | | @ResponseBody |
| | | public Object updateReference( TGoods tGoods) { |
| | | boolean b = goodsService.updateById(tGoods); |
| | | return new SuccessTip(); |
| | | } |
| | | |
| | | @Resource |
| | | private TTransportationService tTransportationService; |
| | | |
| | |
| | | if(driverIdOne!=null){ |
| | | driverIds.add(driverIdOne); |
| | | } |
| | | List<TTransportation> tTransportations = tTransportationService.selectList(new EntityWrapper<TTransportation>().eq("order_id", orderId).in("driver_id", driverIds)); |
| | | transportInfo.setShipmentDate(tOrder.getShipmentDate()); |
| | | List<TTransportation> tTransportations = tTransportationService.selectList(new EntityWrapper<TTransportation>().eq("order_id", orderId).in("driver_id", driverIds).orderBy("type")); |
| | | for (TTransportation tDriver : tTransportations) { |
| | | OrderDriverInfo orderDriverInfo = new OrderDriverInfo(); |
| | | orderDriverInfo.setId(tDriver.getId()); |
| | | orderDriverInfo.setDriverId(tDriver.getDriverId()); |
| | | if(tDriver.getId().equals(sDriverIdOne)&&tDriver.getType()==2){ |
| | | orderDriverInfo.setPickUp(tDriver.getPickDate()); |
| | | } |
| | |
| | | List<TTransportation> list = companySelectDriverDto.getList(); |
| | | tOrder.setsDriverid(list.get(0).getDriverId()); |
| | | tOrder.setsDriverIdOne(list.get(1).getDriverId()); |
| | | tOrder.seteDriverid(list.get(2).getDriverId()); |
| | | tOrder.seteDriverIdOne(list.get(3).getDriverId()); |
| | | if(companySelectDriverDto.getStreetTurn()==1){ |
| | | tOrder.seteDriverid(list.get(2).getDriverId()); |
| | | tOrder.seteDriverIdOne(list.get(3).getDriverId()); |
| | | } |
| | | tOrder.setTruckCompany(companySelectDriverDto.getTruckCompany()); |
| | | tOrder.setPickupTimeTruck(companySelectDriverDto.getPickupTime()); |
| | | tOrder.setStreetTurn(companySelectDriverDto.getStreetTurn()); |
| | | companySelectDriverDto.getList().forEach(e->e.setOrderId(orderId)); |
| | | // 添加司机信息 |
| | | tTransportationService.insertBatch(companySelectDriverDto.getList()); |
| | | // 更改订单信息 |
| | |
| | | // 找出这个订单 |
| | | TOrder tOrder = orderService.selectById(orderId); |
| | | List<TTransportation> list = companySelectDriverDto.getList(); |
| | | list.forEach(e->e.setOrderId(companySelectDriverDto.getOrderId())); |
| | | tOrder.setsDriverid(list.get(0).getDriverId()); |
| | | tOrder.setsDriverIdOne(list.get(1).getDriverId()); |
| | | tOrder.seteDriverid(list.get(2).getDriverId()); |
| | | tOrder.seteDriverIdOne(list.get(3).getDriverId()); |
| | | if(companySelectDriverDto.getStreetTurn()==1){ |
| | | tOrder.seteDriverid(list.get(2).getDriverId()); |
| | | tOrder.seteDriverIdOne(list.get(3).getDriverId()); |
| | | } |
| | | tOrder.setTruckCompany(companySelectDriverDto.getTruckCompany()); |
| | | tOrder.setPickupTimeTruck(companySelectDriverDto.getPickupTime()); |
| | | tOrder.setStreetTurn(companySelectDriverDto.getStreetTurn()); |
| | | // 删除原来的司机信息 |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId)); |
| | | // 添加新司机信息 |
| | | tTransportationService.insertBatch(companySelectDriverDto.getList()); |
| | | tTransportationService.insertBatch(list); |
| | | // 更改订单信息 |
| | | orderService.updateById(tOrder); |
| | | return new SuccessTip(); |
| | |
| | | // 找出这个订单 |
| | | TOrder tOrder = orderService.selectById(orderId); |
| | | TTransportation list = companySelectDriverSingleDto.getList(); |
| | | list.setOrderId(companySelectDriverSingleDto.getOrderId()); |
| | | Integer type = companySelectDriverSingleDto.getType(); |
| | | if(type==1){ |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverid())); |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverid()).eq("type",1)); |
| | | tOrder.setsDriverid(list.getDriverId()); |
| | | }else if(type==2){ |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverIdOne())); |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.getsDriverIdOne()).eq("type",2)); |
| | | tOrder.setsDriverIdOne(list.getDriverId()); |
| | | }else if(type==3){ |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverid())); |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverid()).eq("type",3)); |
| | | tOrder.seteDriverid(list.getDriverId()); |
| | | }else { |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverIdOne())); |
| | | tTransportationService.delete(new EntityWrapper<TTransportation>().eq("order_id",orderId).eq("driver_id",tOrder.geteDriverIdOne()).eq("type",4)); |
| | | tOrder.seteDriverIdOne(list.getDriverId()); |
| | | } |
| | | tTransportationService.insert(list); |
| | |
| | | // 找出这个订单 |
| | | TOrder tOrder = orderService.selectById(orderId); |
| | | Integer type = companyLocationDto.getType(); |
| | | if(type==1){ |
| | | TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.getsDriverIdOne())); |
| | | if(type==2){ |
| | | TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.getsDriverIdOne()).eq("type",2)); |
| | | if(tTransportation!=null){ |
| | | Integer yardId = tTransportation.getYardId(); |
| | | TYard tYard = yardService.selectById(yardId); |
| | | return new SuccessTip(tYard); |
| | | } |
| | | }else if(type==2){ |
| | | TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.geteDriverid())); |
| | | }else if(type==3){ |
| | | TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.geteDriverid()).eq("type",3)); |
| | | if(tTransportation!=null) { |
| | | Integer yardId = tTransportation.getYardId(); |
| | | TYard tYard = yardService.selectById(yardId); |
| | | return new SuccessTip(tYard); |
| | | } |
| | | }else if(type==3){ |
| | | TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.geteDriverIdOne())); |
| | | }else if(type==4){ |
| | | TTransportation tTransportation = tTransportationService.selectOne(new EntityWrapper<TTransportation>().eq("order_id", orderId).eq("driver_id", tOrder.geteDriverIdOne()).eq("type",4)); |
| | | if(tTransportation!=null) { |
| | | Integer portId = tTransportation.getPortId(); |
| | | TPort tPort = portService.selectById(portId); |
| | |
| | | |
| | | TOrder tOrder = orderService.selectById(orderId); |
| | | // 根据订单获取报价 |
| | | |
| | | map.put("invoice",tOrder.getInvoiceNumber()); |
| | | map.put("pickUpDate",tOrder.getShipmentDate()); |
| | | map.put("returnDate",tOrder.getOrderOkTime()); |
| | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "卡车公司- 点对点/范围/距离详情",notes="卡车公司-点对点/范围/距离详情") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), |
| | | @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int",paramType = "query"), |
| | | }) |
| | | @PostMapping(value = "/laneInfo") |
| | | @ResponseBody |
| | | public Object laneInfo( int id) { |
| | | TCompanyBasic tCompanyBasic = basicService.selectById(id); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("data",tCompanyBasic); |
| | | |
| | | if(tCompanyBasic.getType()==2){ |
| | | String lonLat = tCompanyBasic.getLonLat(); |
| | | String[] split = lonLat.split("_"); |
| | | ArrayList<LonLat> lonLats = new ArrayList<>(); |
| | | for (String s : split) { |
| | | String[] split1 = s.split(","); |
| | | LonLat lonLat1 = new LonLat(); |
| | | lonLat1.setLat(split1[0]); |
| | | lonLat1.setLng(split1[1]); |
| | | lonLats.add(lonLat1); |
| | | } |
| | | map.put("lonlat",lonLats); |
| | | }else { |
| | | map.put("lonlat",new ArrayList<>()); |
| | | } |
| | | return new SuccessTip(map); |
| | | } |
| | | @ApiOperation(value = "卡车公司- 添加点对点/范围/距离",notes="卡车公司-添加点对点/范围/距离") |
| | | |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."), |
| | | }) |
| | |
| | | t1.describe, |
| | | t1.remark, |
| | | t1.number, |
| | | t1.price,t1.order_id orderId |
| | | t1.price,t1.order_id orderId,t1.status |
| | | FROM |
| | | t_claim t1 LEFT JOIN t_company t2 on t1.trucking_company_id = t2.id where t1.id =#{id} |
| | | </select> |
| | |
| | | order_id, |
| | | file, |
| | | name, |
| | | create_time |
| | | ) value (null ,#{orderId},#{url},#{name},now()) |
| | | create_time,category |
| | | ) value (null ,#{orderId},#{url},#{name},now(),4) |
| | | </insert> |
| | | |
| | | <update id="agreePay"> |
| | |
| | | |
| | | private TPowerUnits chassiess; |
| | | |
| | | private Integer driverId; |
| | | |
| | | } |
| | |
| | | |
| | | private Integer state; |
| | | |
| | | private Integer goodsId; |
| | | |
| | | } |
| | |
| | | ) |
| | | private Long orderId; |
| | | |
| | | private Integer status; |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | @TableField("create_time") |
| | | private Date createTime; |
| | | |
| | | private String contactNumber; |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | private Date pickupTime; |
| | | |
| | | private Integer streetTurn; |
| | | |
| | | private Date shipmentDate; |
| | | } |
| | |
| | | } |
| | | // 获取卡车公司收入 |
| | | Double companyIncome = this.baseMapper.getCompanyIncome(id, sTime, eTime); |
| | | if(companyIncome==null){ |
| | | indexInfo.setAccountsReceivable(new BigDecimal(0)); |
| | | }else { |
| | | |
| | | indexInfo.setAccountsReceivable(new BigDecimal(companyIncome)); |
| | | indexInfo.setAccountsReceivable(new BigDecimal(companyIncome)); |
| | | } |
| | | // 获取卡车公司支出-》 是否存在承运商 -》算价格 |
| | | EntityWrapper<TOrder> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("company_id",id); |
| | |
| | | for (int i = 0; i <12; i++) { |
| | | if(i==0){ |
| | | IndexMonth indexMonth = new IndexMonth(); |
| | | int month = DateUtil.thisMonth(); |
| | | int month = DateUtil.thisMonth()+1; |
| | | indexMonth.setMonth(month); |
| | | indexMonth.setOrderNumber(this.baseMapper.selectCount(new EntityWrapper<TOrder>().eq("company_id",id).between("pay_time",DateUtil.beginOfMonth(new Date()),DateUtil.endOfMonth(new Date())))); |
| | | indexMonths.add(indexMonth); |
| | |
| | | IndexMonth indexMonth = new IndexMonth(); |
| | | instance.add(Calendar.MONTH, -1); |
| | | Date time1 = instance.getTime(); |
| | | int month = DateUtil.month(time1); |
| | | int month = DateUtil.month(time1)+1; |
| | | indexMonth.setMonth(month); |
| | | indexMonth.setOrderNumber(this.baseMapper.selectCount(new EntityWrapper<TOrder>().eq("company_id",id).between("pay_time",DateUtil.beginOfMonth(time1),DateUtil.endOfMonth(time1)))); |
| | | indexMonths.add(indexMonth); |
| | |
| | | } |
| | | |
| | | // 根据订单id 获取价格 |
| | | List<TPrice> prices = priceMapper.selectList(new EntityWrapper<TPrice>().eq("order_id", tOrder.getId())); |
| | | List<TPrice> prices = priceMapper.selectList(new EntityWrapper<TPrice>().eq("order_id", tOrder.getId()).eq("status",1)); |
| | | |
| | | ArrayList<TPriceVo> priceVos = new ArrayList<TPriceVo>(); |
| | | for (TPrice price : prices) { |
| | |
| | | if(!"0".equals(warehouse)){ |
| | | TWarehouse tWarehouse = wareHouseMapper.selectList(new EntityWrapper<TWarehouse>().eq("company_id", tOrder.getCompanyId()).eq("code", warehouse)).get(0); |
| | | orderInfo.setWareHouse(tWarehouse.getAddress()); |
| | | orderInfo.setEndAddress(tWarehouse.getAddress()); |
| | | }else { |
| | | // destination信息 |
| | | orderInfo.setEndAddress(tOrder.geteAddress()); |
| | | } |
| | | // destination信息 |
| | | orderInfo.setEndAddress(tOrder.geteAddress()); |
| | | orderInfo.setECompanyName(tOrder.geteCompanyName()); |
| | | orderInfo.setEContactName(tOrder.geteName()); |
| | | orderInfo.setEContactPhone(tOrder.getePhone()); |
| | |
| | | ArrayList<String> strings = new ArrayList<>(); |
| | | goods.forEach(e->{ |
| | | strings.add(e.getContainerNumber()); |
| | | orderInfo.setGoodsId(e.getId()); |
| | | orderInfo.setBl(e.getBillNumber()); |
| | | }); |
| | | orderInfo.setContainer(strings); |
New file |
| | |
| | | package com.stylefeng.guns.modular.system.utils; |
| | | |
| | | import com.google.maps.GeoApiContext; |
| | | import com.google.maps.GeocodingApi; |
| | | import com.google.maps.model.AddressComponent; |
| | | import com.google.maps.model.GeocodingResult; |
| | | |
| | | public class AddressLookup { |
| | | |
| | | public static String getAddress(String administrativeCode) { |
| | | GeoApiContext context = new GeoApiContext.Builder() |
| | | .apiKey("AIzaSyBBW0XxW1FK7IXmmS7KFtAjX3o99eFPsss") // REPLACE WITH YOUR API KEY |
| | | .build(); |
| | | |
| | | GeocodingResult[] results = GeocodingApi.geocode(context, "EN " + administrativeCode).awaitIgnoreError(); |
| | | |
| | | if (results == null || results.length == 0) { |
| | | return null; |
| | | } |
| | | |
| | | AddressComponent[] components = results[0].addressComponents; |
| | | String province = getComponent(components, "administrative_area_level_1"); |
| | | String city = getComponent(components, "locality"); |
| | | String district = getComponent(components, "administrative_area_level_3"); |
| | | String street = getComponent(components, "route"); |
| | | String number = getComponent(components, "street_number"); |
| | | |
| | | StringBuilder builder = new StringBuilder(); |
| | | |
| | | if (province != null) { |
| | | builder.append(province); |
| | | } |
| | | |
| | | if (city != null && !city.equals(province)) { |
| | | builder.append(city); |
| | | } |
| | | |
| | | if (district != null && !district.equals(city)) { |
| | | builder.append(district); |
| | | } |
| | | |
| | | if (street != null) { |
| | | builder.append(street); |
| | | } |
| | | |
| | | if (number != null) { |
| | | builder.append(number); |
| | | } |
| | | |
| | | return builder.toString(); |
| | | } |
| | | |
| | | private static String getComponent(AddressComponent[] components, String type) { |
| | | for (AddressComponent component : components) { |
| | | if (component.types[0].equals(type)) { |
| | | return component.longName; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
New file |
| | |
| | | package com.stylefeng.guns.modular.system.utils; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class PointInPolygon { |
| | | |
| | | /** |
| | | * 判断当前位置是否在多边形区域内 |
| | | * @param partitionLocation 区域顶点 |
| | | * @return |
| | | */ |
| | | public static boolean isInPolygon(double p_x,double p_y,String partitionLocation){ |
| | | Point2D.Double point = new Point2D.Double(p_x, p_y); |
| | | List<Point2D.Double> pointList= new ArrayList<Point2D.Double>(); |
| | | String[] strList = partitionLocation.split("_"); |
| | | for (String str : strList){ |
| | | String[] points = str.split(","); |
| | | double polygonPoint_x=Double.parseDouble(points[0]); |
| | | double polygonPoint_y=Double.parseDouble(points[1]); |
| | | Point2D.Double polygonPoint = new Point2D.Double(polygonPoint_x,polygonPoint_y); |
| | | pointList.add(polygonPoint); |
| | | } |
| | | return IsPtInPoly(point,pointList); |
| | | } |
| | | /** |
| | | * 判断点是否在多边形内,如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true |
| | | * @param point 检测点 |
| | | * @param pts 多边形的顶点 |
| | | * @return 点在多边形内返回true,否则返回false |
| | | */ |
| | | public static boolean IsPtInPoly(Point2D.Double point, List<Point2D.Double> pts){ |
| | | |
| | | int N = pts.size(); |
| | | boolean boundOrVertex = true; //如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true |
| | | int intersectCount = 0;//cross points count of x |
| | | double precision = 2e-10; //浮点类型计算时候与0比较时候的容差 |
| | | Point2D.Double p1, p2;//neighbour bound vertices |
| | | Point2D.Double p = point; //当前点 |
| | | |
| | | p1 = pts.get(0);//left vertex |
| | | for(int i = 1; i <= N; ++i){//check all rays |
| | | if(p.equals(p1)){ |
| | | return boundOrVertex;//p is an vertex |
| | | } |
| | | |
| | | p2 = pts.get(i % N); |
| | | if(p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)){ |
| | | p1 = p2; |
| | | continue; |
| | | } |
| | | |
| | | if(p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)){ |
| | | if(p.y <= Math.max(p1.y, p2.y)){ |
| | | if(p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)){ |
| | | return boundOrVertex; |
| | | } |
| | | |
| | | if(p1.y == p2.y){ |
| | | if(p1.y == p.y){ |
| | | return boundOrVertex; |
| | | }else{//before ray |
| | | ++intersectCount; |
| | | } |
| | | }else{ |
| | | double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y; |
| | | if(Math.abs(p.y - xinters) < precision){ |
| | | return boundOrVertex; |
| | | } |
| | | |
| | | if(p.y < xinters){ |
| | | ++intersectCount; |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | if(p.x == p2.x && p.y <= p2.y){ |
| | | Point2D.Double p3 = pts.get((i+1) % N); |
| | | if(p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)){ |
| | | ++intersectCount; |
| | | }else{ |
| | | intersectCount += 2; |
| | | } |
| | | } |
| | | } |
| | | p1 = p2; |
| | | } |
| | | |
| | | if(intersectCount % 2 == 0){//偶数在多边形外 |
| | | return false; |
| | | } else { //奇数在多边形内 |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | } |