| | |
| | | import com.stylefeng.guns.core.log.LogObjectHolder; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.SinataUtil; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.model.*; |
| | | import com.stylefeng.guns.modular.system.service.*; |
| | | import com.stylefeng.guns.modular.system.util.ResultUtil; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * 跨城线路管理控制器 |
| | |
| | | |
| | | @Autowired |
| | | private ITLineShiftService itLineShiftService; |
| | | |
| | | @Autowired |
| | | private ITLineDestinationService itLineDestinationService; |
| | | |
| | | @Autowired |
| | | private ITCompanyService itCompanyService; |
| | |
| | | //查询所有班次 |
| | | List<TLineShift> lineShiftList = itLineShiftService.selectList(new EntityWrapper<TLineShift>().eq("lineId", tLineId).last(" and not FIND_IN_SET(state,'3')")); |
| | | model.addAttribute("lineShiftList",lineShiftList); |
| | | //查询线路目的地 |
| | | List<TLineDestination> lineDestinationList = itLineDestinationService.selectList( |
| | | new EntityWrapper<TLineDestination>().eq("lineId", tLineId).ne("state", 3).orderBy("isMain", false).orderBy("id", true)); |
| | | model.addAttribute("lineDestinationList", lineDestinationList); |
| | | return PREFIX + "tLine_edit.html"; |
| | | } |
| | | |
| | |
| | | */ |
| | | @RequestMapping(value = "/add") |
| | | @ResponseBody |
| | | public ResultUtil add(TLine tLine,Integer startSiteId,Integer endSiteId,@RequestParam String subArr,@RequestParam String shuArr) { |
| | | public ResultUtil add(TLine tLine,Integer startSiteId,Integer endSiteId,@RequestParam String subArr, |
| | | @RequestParam String shuArr, @RequestParam(required = false) String destArr) { |
| | | JSONArray jsonArray1 = JSON.parseArray(shuArr); |
| | | int size1 = jsonArray1.size(); |
| | | for (int i = 0; i < size1; i++) { |
| | |
| | | addPrice(tLine.getId(), subArr); |
| | | |
| | | //添加班次设置 |
| | | return addShift(tLine.getId(), shuArr); |
| | | ResultUtil shiftResult = addShift(tLine.getId(), shuArr); |
| | | if(200 != shiftResult.getStatus()){ |
| | | return shiftResult; |
| | | } |
| | | //添加目的地设置 |
| | | ResultUtil destinationResult = addDestination(tLine.getId(), destArr); |
| | | if(200 != destinationResult.getStatus()){ |
| | | return destinationResult; |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @RequestMapping(value = "/update") |
| | | @ResponseBody |
| | | public ResultUtil update(TLine tLine,Integer startSiteId,Integer endSiteId,@RequestParam String subArr,@RequestParam String shuArr) { |
| | | public ResultUtil update(TLine tLine,Integer startSiteId,Integer endSiteId,@RequestParam String subArr, |
| | | @RequestParam String shuArr, @RequestParam(required = false) String destArr) { |
| | | JSONArray jsonArray1 = JSON.parseArray(shuArr); |
| | | int size1 = jsonArray1.size(); |
| | | for (int i = 0; i < size1; i++) { |
| | |
| | | //删除线路班次 |
| | | itLineShiftService.delete(new EntityWrapper<TLineShift>().eq("lineId",tLine.getId())); |
| | | //添加班次设置 |
| | | return addShift(tLine.getId(), shuArr); |
| | | ResultUtil shiftResult = addShift(tLine.getId(), shuArr); |
| | | if(200 != shiftResult.getStatus()){ |
| | | return shiftResult; |
| | | } |
| | | //删除线路目的地并重建 |
| | | itLineDestinationService.delete(new EntityWrapper<TLineDestination>().eq("lineId", tLine.getId())); |
| | | ResultUtil destinationResult = addDestination(tLine.getId(), destArr); |
| | | if(200 != destinationResult.getStatus()){ |
| | | return destinationResult; |
| | | } |
| | | return ResultUtil.success(); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 添加线路目的地配置 |
| | | */ |
| | | private ResultUtil addDestination(Integer lineId, String destArr) { |
| | | if (SinataUtil.isEmpty(destArr)) { |
| | | return ResultUtil.success(); |
| | | } |
| | | JSONArray jsonArray = JSON.parseArray(destArr); |
| | | int size = jsonArray.size(); |
| | | if(size <= 0){ |
| | | return ResultUtil.success(); |
| | | } |
| | | if(size > 3){ |
| | | return ResultUtil.error("最多只能添加3个目的地"); |
| | | } |
| | | int mainCount = 0; |
| | | for (int i = 0; i < size; i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | String name = ToolUtil.formatting(jsonObject.getString("name")); |
| | | if (SinataUtil.isEmpty(name)) { |
| | | return ResultUtil.error("目的地名称不能为空"); |
| | | } |
| | | Integer fenceType = jsonObject.getInteger("fenceType"); |
| | | if (fenceType == null || (fenceType != 1 && fenceType != 2)) { |
| | | return ResultUtil.error("围栏类型错误"); |
| | | } |
| | | String coordinate = jsonObject.getString("coordinate"); |
| | | if (SinataUtil.isEmpty(coordinate)) { |
| | | return ResultUtil.error("目的地围栏不能为空"); |
| | | } |
| | | |
| | | BigDecimal price5; |
| | | BigDecimal price7; |
| | | try { |
| | | price5 = new BigDecimal(jsonObject.getString("price5")); |
| | | price7 = new BigDecimal(jsonObject.getString("price7")); |
| | | } catch (Exception ex) { |
| | | return ResultUtil.error("目的地价格格式不正确"); |
| | | } |
| | | if (price5.compareTo(BigDecimal.ZERO) < 0 || price7.compareTo(BigDecimal.ZERO) < 0) { |
| | | return ResultUtil.error("目的地价格不能小于0"); |
| | | } |
| | | |
| | | Integer isMain = jsonObject.getInteger("isMain"); |
| | | if (isMain != null && isMain == 1) { |
| | | mainCount++; |
| | | } |
| | | if(mainCount > 1){ |
| | | return ResultUtil.error("最多只能设置一个主要目的地"); |
| | | } |
| | | |
| | | Double defaultPointLon = jsonObject.getDouble("defaultPointLon"); |
| | | Double defaultPointLat = jsonObject.getDouble("defaultPointLat"); |
| | | if (fenceType == 1) { |
| | | String[] arr = coordinate.split(";"); |
| | | if (arr.length != 2) { |
| | | return ResultUtil.error("圆形围栏坐标格式错误"); |
| | | } |
| | | String[] center = arr[0].split(","); |
| | | if (center.length != 2) { |
| | | return ResultUtil.error("圆形围栏中心点格式错误"); |
| | | } |
| | | try { |
| | | defaultPointLon = Double.valueOf(center[0]); |
| | | defaultPointLat = Double.valueOf(center[1]); |
| | | double radius = Double.valueOf(arr[1]); |
| | | if(radius <= 0 || radius > 5000){ |
| | | return ResultUtil.error("圆形围栏半径必须在(0,5000]米"); |
| | | } |
| | | } catch (Exception ex) { |
| | | return ResultUtil.error("圆形围栏坐标格式错误"); |
| | | } |
| | | } else { |
| | | if(defaultPointLon == null || defaultPointLat == null){ |
| | | return ResultUtil.error("多边形围栏需要设置默认点"); |
| | | } |
| | | } |
| | | |
| | | TLineDestination destination = new TLineDestination(); |
| | | destination.setLineId(lineId); |
| | | destination.setName(name); |
| | | destination.setFenceType(fenceType); |
| | | destination.setCoordinate(coordinate); |
| | | destination.setDefaultPointLon(defaultPointLon); |
| | | destination.setDefaultPointLat(defaultPointLat); |
| | | destination.setPrice5(price5); |
| | | destination.setPrice7(price7); |
| | | Integer state = jsonObject.getInteger("state"); |
| | | destination.setState(state == null ? 1 : state); |
| | | destination.setIsMain(isMain == null ? 0 : isMain); |
| | | destination.setAddTime(jsonObject.getString("time")); |
| | | destination.setInsertTime(new Date()); |
| | | itLineDestinationService.insert(destination); |
| | | } |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | } |