| | |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.PinYinUtil; |
| | | import com.doumee.core.utils.geocode.MapUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.AreasMapper; |
| | | import com.doumee.dao.business.PricingRuleMapper; |
| | | import com.doumee.dao.business.model.Areas; |
| | | import com.doumee.dao.business.model.PricingRule; |
| | | import com.doumee.service.business.AreasService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | * @author 江蹄蹄 |
| | | * @date 2023/02/15 08:55 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class AreasServiceImpl implements AreasService { |
| | | public static List<Areas> ALL_AREA_LIST; |
| | |
| | | |
| | | @Autowired |
| | | private AreasMapper areasMapper; |
| | | |
| | | @Autowired |
| | | private PricingRuleMapper pricingRuleMapper; |
| | | |
| | | @Autowired |
| | | RestTemplate restTemplate ; |
| | |
| | | } |
| | | }*/ |
| | | areas.setIsdeleted(Constants.ZERO); |
| | | areas.setCreateDate(new Date()); |
| | | areasMapper.insert(areas); |
| | | areas.setCode(areas.getId().toString()); |
| | | // 城市级区划自动填充经纬度 |
| | | if (Constants.equalsInteger(areas.getType(), Constants.ONE)) { |
| | | areas.setInfo(geocodeCity(areas)); |
| | | } |
| | | areasMapper.updateById(areas); |
| | | //刷新缓存数据 |
| | | cacheData(); |
| | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | areasMapper.deleteById(id); |
| | | // 同步删除该城市关联的计价规则配置 |
| | | PricingRule deleteRule = new PricingRule(); |
| | | deleteRule.setCityId(id); |
| | | QueryWrapper<PricingRule> deleteWrapper = new QueryWrapper<>(deleteRule); |
| | | pricingRuleMapper.delete(deleteWrapper); |
| | | //刷新缓存数据 |
| | | cacheData(); |
| | | } |
| | |
| | | Areas update = new Areas(); |
| | | update.setName(areas.getName()); |
| | | update.setSortnum(areas.getSortnum()); |
| | | // 城市级区划自动更新经纬度 |
| | | Areas existing = areasMapper.selectById(areas.getId()); |
| | | if (existing != null && Constants.equalsInteger(existing.getType(), Constants.ONE)) { |
| | | String location = MapUtil.geocode(getParentName(existing.getParentId()) + areas.getName()); |
| | | if (location != null) { |
| | | update.setInfo(location); |
| | | } |
| | | } |
| | | areasMapper.update(update,wrapper); |
| | | //刷新缓存数据 |
| | | cacheData(); |
| | |
| | | } |
| | | //刷新缓存数据 |
| | | cacheData(); |
| | | } |
| | | |
| | | @Override |
| | | public Areas getById(Integer id) { |
| | | return areasMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Areas getOpenedCityByName(String cityName) { |
| | | if (StringUtils.isBlank(cityName)) { |
| | |
| | | return areasMapper.selectOne(qw); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Areas getOpenedCityByCode(String code) { |
| | | if (StringUtils.isBlank(code)) { |
| | | return null; |
| | | } |
| | | Areas areas = areasMapper.selectById(code); |
| | | if(Objects.isNull(areas)||Objects.isNull(areas.getParentId())){ |
| | | return null; |
| | | } |
| | | Areas city = areasMapper.selectById(areas.getParentId()); |
| | | if(Objects.isNull(city)||Constants.equalsInteger(city.getIsdeleted(),Constants.ONE)|| |
| | | Constants.equalsInteger(city.getStatus(),Constants.ZERO)){ |
| | | return null; |
| | | } |
| | | return city; |
| | | } |
| | | |
| | | @Override |
| | | public void updateStatus(Areas areas) { |
| | | if (areas == null || areas.getId() == null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | Areas update = new Areas(); |
| | | update.setId(areas.getId()); |
| | | update.setStatus(areas.getStatus()); |
| | | areasMapper.updateById(update); |
| | | } |
| | | |
| | | @Override |
| | | public String fillCityLocation() { |
| | | Areas query = new Areas(); |
| | | query.setType(1); |
| | | List<Areas> cities = areasMapper.selectList(new QueryWrapper<Areas>().lambda() |
| | | .eq(Areas::getType, 1)); |
| | | int success = 0, fail = 0; |
| | | for (Areas city : cities) { |
| | | if (StringUtils.isNotBlank(city.getInfo())) { |
| | | continue; |
| | | } |
| | | String parentName = ""; |
| | | if (city.getParentId() != null) { |
| | | Areas parent = getById(city.getParentId()); |
| | | if (parent != null) { |
| | | parentName = parent.getName(); |
| | | } |
| | | } |
| | | String address = parentName + city.getName(); |
| | | String location = MapUtil.geocode(address); |
| | | if (location != null) { |
| | | city.setInfo(location); |
| | | areasMapper.updateById(city); |
| | | success++; |
| | | log.info("城市经纬度填充成功: {} => {}", address, location); |
| | | } else { |
| | | fail++; |
| | | log.warn("城市经纬度填充失败: {}", address); |
| | | } |
| | | try { Thread.sleep(200); } catch (InterruptedException ignored) {} |
| | | } |
| | | return "处理完成,成功: " + success + ",失败: " + fail + ",总计: " + cities.size(); |
| | | } |
| | | |
| | | private String getParentName(Integer parentId) { |
| | | if (parentId == null) { |
| | | return ""; |
| | | } |
| | | Areas parent = getById(parentId); |
| | | return parent != null ? parent.getName() : ""; |
| | | } |
| | | |
| | | private String geocodeCity(Areas city) { |
| | | String address = getParentName(city.getParentId()) + city.getName(); |
| | | return MapUtil.geocode(address); |
| | | } |
| | | |
| | | } |