Commit 83ff5968 by caiyt

Merge remote-tracking branch 'origin/v2' into v2

# Conflicts:
#	soss-framework/src/main/java/com/soss/framework/web/service/WeixinServiceImpl.java
parents 7e120bd0 541843a9
......@@ -9,6 +9,7 @@ import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.domain.Customer;
import com.soss.system.domain.Shop;
import com.soss.system.domain.po.LocationPo;
import com.soss.system.service.ICustomerService;
import com.soss.system.service.impl.AppServiceImpl;
import com.soss.system.service.impl.OrderTakingServiceImpl;
......@@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
......@@ -102,6 +104,31 @@ public class WeixinController {
return weixinService.wxNotifyTest(orderNo);
}
@RequestMapping("/v2/getShop")
public AjaxResult getShopV2(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) throws ParseException {
LoginUser loginUser = tokenService.getLoginUser(request);
boolean testFlag = false;
if (loginUser != null) {
Customer customer = customerService.selectCustById(loginUser.getOpenId());
if (customer != null) {
testFlag = customer.getTestFlag();
}
}
return AjaxResult.success(appService.getShop(loginUser, lng, lat, testFlag));
}
@RequestMapping("/v2/getLocationShops")
public AjaxResult getSameLocationShops(HttpServletRequest request, @RequestBody LocationPo locationPo) throws ParseException {
LoginUser loginUser = tokenService.getLoginUser(request);
boolean testFlag = false;
if (loginUser != null) {
Customer customer = customerService.selectCustById(loginUser.getOpenId());
if (customer != null) {
testFlag = customer.getTestFlag();
}
}
return AjaxResult.success(appService.getSameLocationShops(loginUser, locationPo, testFlag));
}
@RequestMapping("/getShop")
public AjaxResult getShop(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) {
......@@ -117,7 +144,7 @@ public class WeixinController {
}
@RequestMapping("/getArea")
public AjaxResult getArea(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) {
public AjaxResult getArea(HttpServletRequest request, @RequestParam(required = false) String lng, @RequestParam(required = false) String lat) throws ParseException {
LoginUser loginUser = tokenService.getLoginUser(request);
List<JSONObject> area;
if (loginUser == null || StringUtils.isEmpty(loginUser.getOpenId())) {
......@@ -129,7 +156,6 @@ public class WeixinController {
return AjaxResult.success(area);
}
@GetMapping(value = "/infoByShop")
public AjaxResult infoByShop(Long shopId) {
return AjaxResult.success(orderTakingService.getInfoByShop(shopId));
......
import java.util.Calendar;
import com.soss.common.utils.DateUtils;
import com.soss.system.domain.Shop;
import java.text.ParseException;
public class JavaTest {
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
System.out.println(calendar.get(Calendar.DAY_OF_WEEK) - 1);
public static void main(String[] args) throws ParseException {
Shop shop = new Shop();
shop.setStartTime("14:21");
shop.setEndTime("18:00");
System.out.println(DateUtils.isEffectiveDate(shop.getStartTime(), shop.getEndTime()));
// Shop shop = new Shop();
// shop.setLat("39.91571");
// shop.setLng("116.463485");
// String lat = "39.789916";
// String lng = "116.531469";
// double realDistance = DistanceUtil.getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()));
// System.out.println(realDistance);
// Calendar calendar = Calendar.getInstance();
// System.out.println(calendar.get(Calendar.DAY_OF_WEEK) - 1);
}
}
......@@ -6,6 +6,7 @@ import java.lang.management.ManagementFactory;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.Calendar;
import java.util.Date;
/**
......@@ -29,6 +30,38 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
public static boolean isEffectiveDate(String shopStartTime, String shopEndTime) throws ParseException {
String format = "HH:mm";
SimpleDateFormat sf = new SimpleDateFormat("HH:mm");
String now = sf.format(new Date());
Date nowTime = new SimpleDateFormat(format).parse(now);
Date startTime = new SimpleDateFormat(format).parse(shopStartTime);
Date endTime = new SimpleDateFormat(format).parse(shopEndTime);
return DateUtils.isEffectiveDate(nowTime, startTime, endTime);
}
public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
if (nowTime.getTime() == startTime.getTime()
|| nowTime.getTime() == endTime.getTime()) {
return true;
}
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(startTime);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.after(begin) && date.before(end)) {
return true;
} else {
return false;
}
}
/**
* 获取当前Date型日期
*
......
......@@ -12,13 +12,16 @@ import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.wxpay.sdk.WXPayUtil;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.soss.common.core.domain.entity.SysUser;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.RefundState;
import com.soss.common.enums.ShopState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.QRCodeUtil;
import com.soss.common.utils.StringUtils;
import com.soss.common.utils.ip.IpUtils;
import com.soss.common.utils.sign.Base64;
......@@ -54,8 +57,6 @@ import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
......@@ -64,7 +65,6 @@ import java.math.BigDecimal;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.security.spec.AlgorithmParameterSpec;
import java.util.List;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
......@@ -94,6 +94,8 @@ public class WeixinServiceImpl {
private ShopMapper shopMapper;
@Autowired
private OssFileServiceImpl ossFileService;
@Autowired
private AppServiceImpl appService;
private final ReentrantLock lock = new ReentrantLock();
......@@ -623,7 +625,7 @@ public class WeixinServiceImpl {
return WxPayNotifyResponse.fail("回调有误!");
}
public List<JSONObject> getArea(String lng, String lat, Boolean testFlag) {
public List<JSONObject> getArea(String lng, String lat, Boolean testFlag) throws ParseException {
String provinceString ="[value ='%s'][0].label";
String cityString ="[value='%s'][0].children[value='%s'][0].label";
String zoneString = "[value='%s'][0].children[value='%s'][0].children[value='%s'][0].label";
......@@ -641,8 +643,10 @@ public class WeixinServiceImpl {
double realDistance = DistanceUtil.getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop1.getLng()), Double.parseDouble(shop1.getLat()));
shop1.setRealDistance(realDistance);
shop1.setDistance(DistanceUtil.getDistanceDesc(realDistance));
appService.perfectOrderState(shop1, lng, lat);
} else {
shop1.setDistance("-1");
shop1.setOrderState(1);
}
String province = shop1.getProvince();
if(proString.contains(province)){
......
......@@ -19,8 +19,7 @@ import java.util.List;
* @date 2022-04-28
*/
@Data
public class Shop extends BaseEntity
{
public class Shop extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 主键 */
......@@ -135,6 +134,15 @@ public class Shop extends BaseEntity
private Integer salesVolume;
/**
* 是否允许下单, 1-可以下单,0-不可以下单
*/
private Integer orderState;
/**
* 不允许下单原因
*/
private String stateDesc;
public Shop() {
super();
}
......@@ -154,7 +162,7 @@ public class Shop extends BaseEntity
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("name", getName())
.append("code", getCode())
......
package com.soss.system.domain.po;
import com.soss.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel("优惠券请求类")
public class LocationPo {
private String lng;
private String lat;
private String province;
private String city;
private String area;
public boolean isEmpty() {
return StringUtils.isEmpty(lng) || StringUtils.isEmpty(lat) || StringUtils.isEmpty(province) || StringUtils.isEmpty(city) || StringUtils.isEmpty(area);
}
}
package com.soss.system.domain.vo;
import com.soss.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import lombok.Data;
@Data
@ApiModel("优惠券请求类")
public class LocationVo {
private String lng;
private String lat;
private String province;
private String city;
private String area;
private String provinceCode;
private String cityCode;
private String areaCode;
}
package com.soss.system.mapper;
import com.soss.system.domain.Shop;
import com.soss.system.domain.vo.LocationVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
......@@ -76,4 +77,10 @@ public interface ShopMapper {
public int deleteShopByIds(String[] ids);
void updateNoDefault();
List<Shop> selectEnableShops(@Param("states") List<Integer> states);
List<Shop> selectDefaultSameLocationShops(@Param("states") List<Integer> states);
List<Shop> selectSameLocationShops(@Param("states") List<Integer> states, @Param("location") LocationVo locationVo);
}
......@@ -2,15 +2,21 @@ package com.soss.system.service.impl;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.ShopState;
import com.soss.common.utils.DateUtils;
import com.soss.common.utils.StringUtils;
import com.soss.system.domain.Order;
import com.soss.system.domain.Shop;
import com.soss.system.domain.po.LocationPo;
import com.soss.system.domain.vo.LocationVo;
import com.soss.system.mapper.ShopMapper;
import com.soss.system.utils.AreaUtil;
import com.soss.system.utils.DistanceUtil;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
......@@ -23,6 +29,140 @@ public class AppServiceImpl {
private ShopServiceImpl shopService;
@Autowired
private OrderServiceImpl orderService;
@Autowired
private AreaUtil areaUtil;
public Shop getShop(LoginUser loginUser, String lng, String lat, Boolean testFlag) throws ParseException {
Shop shop = null;
if (StringUtils.isEmpty(lng) || StringUtils.isEmpty(lat)) {
// 未授权位置
if (loginUser == null) {
// 未登录,返回默认店铺
shop = getDefaultShop();
} else {
// 已登录
List<Order> myOrder = orderService.getMyOrder(loginUser.getOpenId());
if (CollectionUtils.isEmpty(myOrder)) {
// 未下过单返回默认店铺
shop = getDefaultShop();
} else {
// 返回最后下单店铺
Order order = myOrder.get(0);
shop = shopService.selectShopById(order.getShopId());
}
}
} else {
// 授权了位置
List<Integer> states = null;
if (BooleanUtils.isTrue(testFlag)) {
states = Arrays.asList(ShopState.TESTING.getState(), ShopState.OPEN.getState());
} else {
states = Arrays.asList(ShopState.OPEN.getState(), ShopState.CLOSE.getState());
}
List<Shop> shops = shopMapper.selectEnableShops(states); // 获取所有非关闭的店铺
if (CollectionUtils.isEmpty(shops)) {
return null;
}
for (Shop s : shops) { // 获取所有店铺距离
double realDistance = DistanceUtil.getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(s.getLng()), Double.parseDouble(s.getLat()));
s.setRealDistance(realDistance);
}
shops.sort(Comparator.comparing(Shop::getRealDistance)); // 按距离排序
for (Shop s : shops) {
if (perfectOrderState(s, lng, lat)) { // 是否能下单
shop = s;
}
}
if (shop == null) { // 没有能下单店铺选择最近的店铺
shop = shops.get(0);
}
}
if (shop.getOrderState() == null) {
perfectOrderState(shop, lng, lat);
}
return shop;
}
public boolean perfectOrderState(Shop shop, String lng, String lat) throws ParseException {
if (shop == null) {
return false;
}
// 状态已停止营业
if (shop.getState() != 1) {
shop.setOrderState(0);
shop.setStateDesc("门店已暂停营业");
return false;
}
// 不在营业时间范围内
if (!DateUtils.isEffectiveDate(shop.getStartTime(), shop.getEndTime())) {
shop.setOrderState(0);
shop.setStateDesc("门店已休息");
return false;
}
// 超出最大配送距离10KM 或 超出店铺设置最大距离
if (!StringUtils.isEmpty(lng) && !StringUtils.isEmpty(lat)) {
double realDistance = DistanceUtil.getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()));
double realKm = realDistance / 1000;
double shopLimit = shop.getDistanceLimit() == null ? 0 : shop.getDistanceLimit();
if (realKm > 10 || realKm > shopLimit) {
shop.setOrderState(0);
shop.setStateDesc("距离较远,门店暂停接单");
return false;
}
}
shop.setOrderState(1);
return true;
}
public List<Shop> getSameLocationShops(LoginUser loginUser, LocationPo locationPo, Boolean testFlag) throws ParseException {
List<Integer> states = null;
if (BooleanUtils.isTrue(testFlag)) {
states = Arrays.asList(ShopState.TESTING.getState(), ShopState.OPEN.getState());
} else {
states = Arrays.asList(ShopState.OPEN.getState(), ShopState.CLOSE.getState());
}
List<Shop> shops = null;
if (locationPo == null || locationPo.isEmpty()) {
// 未授权位置,返回默认店铺相同区域的所有店铺
shops = shopMapper.selectDefaultSameLocationShops(states);
} else {
// 授权了位置
LocationVo locationVo = areaUtil.translateLocation(locationPo);
if (locationVo == null) {
shops = shopMapper.selectDefaultSameLocationShops(states);
} else {
shops = shopMapper.selectSameLocationShops(states, locationVo);
}
}
if (CollectionUtils.isEmpty(shops)) {
return null;
}
for (Shop s : shops) {
if (locationPo == null || locationPo.isEmpty()) {
s.setRealDistance(0d);
s.setDistance("-1");
s.setOrderState(1);
} else {
// 获取所有店铺距离
double realDistance = DistanceUtil.getRealDistance(Double.parseDouble(locationPo.getLng()), Double.parseDouble(locationPo.getLat()), Double.parseDouble(s.getLng()), Double.parseDouble(s.getLat()));
s.setRealDistance(realDistance);
s.setDistance(DistanceUtil.getDistanceDesc(realDistance));
perfectOrderState(s, locationPo.getLng(), locationPo.getLat());
}
}
shops.sort(Comparator.comparing(Shop::getRealDistance)); // 按距离排序
return shops;
}
public Shop getShop(LoginUser loginUser) {
if (loginUser == null) {
......
package com.soss.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.soss.common.exception.ServiceException;
import com.soss.system.domain.Machine;
import com.soss.system.domain.ShopGoods;
import com.soss.system.domain.Spec;
import com.soss.system.domain.SpecRule;
import com.soss.system.domain.*;
import com.soss.system.domain.vo.orderTaking.SkuVo;
import com.soss.system.mapper.*;
import com.soss.system.service.IShopGoodsService;
......@@ -13,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -118,18 +113,15 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
return null;
}
Map<Long, SpecRule> selloutRules = new HashMap<>();
Map<Long, SpecRule> sellinRules = new HashMap<>();
Set<Long> selloutRules = new HashSet<>();
Set<Long> sellinRules = new HashSet<>();
List<SkuVo> selloutSkus = skuMap.get("2");
if (!CollectionUtils.isEmpty(selloutSkus)) {
selloutSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> {
rule.setState(2);
selloutRules.put(rule.getId(), rule);
});
rules.forEach(rule -> selloutRules.add(rule.getId()));
}
});
}
......@@ -139,42 +131,62 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
sellinSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> {
rule.setState(1);
sellinRules.put(rule.getId(), rule);
});
rules.forEach(rule -> sellinRules.add(rule.getId()));
}
});
}
// 从售罄sku选项列表中删除 未售罄sku选项
sellinRules.values().forEach(rule -> selloutRules.remove(rule.getId()));
Map<Long, List<SpecRule>> selloutRulesBySpec = selloutRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
Map<Long, List<SpecRule>> sellinRulesBySpec = sellinRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
sellinRules.forEach(sellinId -> selloutRules.remove(sellinId));
List<Long> specIds = new ArrayList<>();
specIds.addAll(sellinRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
specIds.addAll(selloutRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
// 构建返回数据
List<Spec> specVos = specMapper.selectSpecByIds(specIds);
if (CollectionUtils.isEmpty(specVos)) {
Goods goods = goodsMapper.selectGoodsById(goodsId);
if (goods == null) {
return null;
}
specVos.forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getSpecRules())) {
spec.setSpecRules(new ArrayList<>());
List<Spec> specs = JSONArray.parseArray(goods.getSpec(), Spec.class);
if (CollectionUtils.isEmpty(specs)) {
return specs;
}
if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) {
spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId()));
specs.forEach(spec -> {
List<SpecRule> rules = spec.getSpecRules();
if (CollectionUtils.isEmpty(rules)) {
return;
}
if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) {
spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
rules.forEach(rule -> {
if (sellinRules.contains(rule.getId())) {
rule.setState(1);
} else {
rule.setState(0);
}
});
});
// Map<Long, List<SpecRule>> selloutRulesBySpec = selloutRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
// Map<Long, List<SpecRule>> sellinRulesBySpec = sellinRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
//
// List<Long> specIds = new ArrayList<>();
// specIds.addAll(sellinRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
// specIds.addAll(selloutRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
//
// // 构建返回数据
// List<Spec> specVos = specMapper.selectSpecByIds(specIds);
// if (CollectionUtils.isEmpty(specVos)) {
// return null;
// }
// specVos.forEach(spec -> {
// if (CollectionUtils.isEmpty(spec.getSpecRules())) {
// spec.setSpecRules(new ArrayList<>());
// }
// if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId()));
// }
// if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
// }
// });
return specVos;
return specs;
}
public Boolean updateShopGoodsSpecState(Long shopId, Long goodsId, Long ruleId, Integer state) {
......
......@@ -2,6 +2,8 @@ package com.soss.system.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.soss.system.domain.po.LocationPo;
import com.soss.system.domain.vo.LocationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
......@@ -20,6 +22,7 @@ public class AreaUtil {
// private Map<String, Area> areaMap;
private Map<String, String> provNameMap = new HashMap<>();
private Map<String, String> areaOrCityFullNameMap = new HashMap<>();
private static JSONArray DATA;
@PostConstruct
public void init() {
......@@ -27,15 +30,17 @@ public class AreaUtil {
ClassPathResource resource = new ClassPathResource("province.json");
byte[] bdata = FileCopyUtils.copyToByteArray(resource.getInputStream());
String data = new String(bdata, StandardCharsets.UTF_8);
JSONArray areaArray = JSONArray.parseArray(data);
if (DATA == null) {
DATA = JSONArray.parseArray(data);
}
// areaMap = buildAreaTree(areaArray);
deepAreaTree(areaArray, "");
deepAreaTree(DATA, "", 0);
} catch (IOException e) {
log.error("解析区域文件出错", e);
}
}
private void deepAreaTree(JSONArray areaArray, String parentName) {
private void deepAreaTree(JSONArray areaArray, String parentName, Integer deep) {
if (CollectionUtils.isEmpty(areaArray)) {
return;
}
......@@ -50,7 +55,7 @@ public class AreaUtil {
areaOrCityFullNameMap.put(code, curLabel);
}
JSONArray children = area.getJSONArray("children");
deepAreaTree(children, curLabel);
deepAreaTree(children, curLabel, deep + 1);
}
}
......@@ -62,6 +67,46 @@ public class AreaUtil {
return areaOrCityFullNameMap.get(code);
}
public LocationVo translateLocation(LocationPo locationPo) {
if (locationPo == null || locationPo.isEmpty()) {
return null;
}
for (int i = 0; i < DATA.size(); i++) {
JSONObject provinceObj = DATA.getJSONObject(i);
String provinceName = provinceObj.getString("label");
String provinceCode = provinceObj.getString("value");
if (!provinceName.equals(locationPo.getProvince())) {
continue;
}
JSONArray cityArray = provinceObj.getJSONArray("children");
for (int j = 0; j < cityArray.size(); j++) {
JSONObject cityObj = cityArray.getJSONObject(j);
String cityName = cityObj.getString("label");
String cityCode = cityObj.getString("value");
if (!cityName.equals(locationPo.getCity())) {
continue;
}
JSONArray areaArray = cityObj.getJSONArray("children");
for (int k = 0; k < areaArray.size(); k++) {
JSONObject areaObj = areaArray.getJSONObject(k);
String areaName = areaObj.getString("label");
String areaCode = areaObj.getString("value");
if (!areaName.equals(locationPo.getArea())) {
continue;
}
LocationVo locationVo = new LocationVo();
locationVo.setProvinceCode(provinceCode);
locationVo.setCityCode(cityCode);
locationVo.setAreaCode(areaCode);
return locationVo;
}
}
}
return null;
}
/*private Map<String, Area> buildAreaTree(JSONArray areaArray) {
if (CollectionUtils.isEmpty(areaArray)) {
return null;
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.soss.system.mapper.ShopMapper">
<resultMap type="Shop" id="ShopResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="code" column="code" />
<result property="lng" column="lng" />
<result property="lat" column="lat" />
<result property="remarks" column="remarks" />
<result property="startTime" column="start_time" />
<result property="endTime" column="end_time" />
<result property="address" column="address" />
<result property="province" column="province" />
<result property="city" column="city" />
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="code" column="code"/>
<result property="lng" column="lng"/>
<result property="lat" column="lat"/>
<result property="remarks" column="remarks"/>
<result property="startTime" column="start_time"/>
<result property="endTime" column="end_time"/>
<result property="address" column="address"/>
<result property="province" column="province"/>
<result property="city" column="city"/>
<result property="zone" column="zone"/>
<result property="distanceLimit" column="distance_limit"/>
<result property="state" column="state"/>
......@@ -25,11 +25,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectShopVo">
select * from shop
select *
from shop
</sql>
<select id="selectAllShop" resultMap="ShopResult">
select id, name, code, province, city, zone from shop
select id, name, code, province, city, zone
from shop
</select>
<select id="selectEnableShops" resultMap="ShopResult">
select * from shop s
<where>
<if test="states != null and states.size() > 0">
and s.state in
<foreach collection="states" item="state" separator="," open="(" close=")">#{state}</foreach>
</if>
</where>
</select>
<select id="selectDefaultSameLocationShops" resultMap="ShopResult">
select s1.* from shop s1 left join shop s2
on s1.province = s2.province and s1.city = s2.city and s1.`zone` = s2.`zone`
<where>
<if test="states != null and states.size() > 0">
and s1.state in
<foreach collection="states" item="state" separator="," open="(" close=")">#{state}</foreach>
</if>
and s2.is_default = 1
</where>
</select>
<select id="selectSameLocationShops" resultMap="ShopResult">
select s1.* from shop s1
<where>
<if test="states != null and states.size() > 0">
and s1.state in
<foreach collection="states" item="state" separator="," open="(" close=")">#{state}</foreach>
</if>
and s1.province = #{location.provinceCode}
and s1.city = #{location.cityCode}
and s1.`zone` = #{location.areaCode}
</where>
</select>
<select id="selectShopList" parameterType="Shop" resultMap="ShopResult">
......@@ -131,7 +168,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update>
<delete id="deleteShopById" parameterType="String">
delete from shop where id = #{id}
delete
from shop
where id = #{id}
</delete>
<delete id="deleteShopByIds" parameterType="String">
......@@ -141,6 +180,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</delete>
<update id="updateNoDefault">
update shop set is_default = 0
update shop
set is_default = 0
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment