implemented city and std_operator related services
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package net.irext.server.service;
|
||||
|
||||
import net.irext.server.service.model.Category;
|
||||
import net.irext.server.service.model.RemoteIndex;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package net.irext.server.service.businesslogic;
|
||||
|
||||
import net.irext.server.service.mapper.CategoryMapper;
|
||||
import net.irext.server.service.mapper.RemoteIndexMapper;
|
||||
import net.irext.server.service.model.Category;
|
||||
import net.irext.server.service.model.RemoteIndex;
|
||||
import net.irext.server.service.Constants;
|
||||
import net.irext.server.service.mapper.*;
|
||||
import net.irext.server.service.model.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@@ -25,6 +24,15 @@ public class IndexingLogic {
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Autowired
|
||||
private BrandMapper brandMapper;
|
||||
|
||||
@Autowired
|
||||
private CityMapper cityMapper;
|
||||
|
||||
@Autowired
|
||||
private OperatorMapper operatorMapper;
|
||||
|
||||
@Autowired
|
||||
private RemoteIndexMapper remoteIndexMapper;
|
||||
|
||||
@@ -37,6 +45,42 @@ public class IndexingLogic {
|
||||
}
|
||||
|
||||
public List<Category> listCategories(int lang, int from, int count) {
|
||||
return categoryMapper.listCategories(from, count);
|
||||
List<Category> categoryList = categoryMapper.listCategories(from, count);
|
||||
if (lang == Constants.LANG_EN) {
|
||||
for (Category category : categoryList) {
|
||||
category.setName(category.getNameEn());
|
||||
}
|
||||
} else if (lang == Constants.LANG_TW_CN) {
|
||||
for (Category category : categoryList) {
|
||||
category.setName(category.getNameTw());
|
||||
}
|
||||
}
|
||||
return categoryList;
|
||||
}
|
||||
|
||||
public List<Brand> listBrands(int lang, int categoryId, int from, int count) {
|
||||
List<Brand> brandList = brandMapper.listBrands(categoryId, from, count);
|
||||
if (lang == Constants.LANG_EN) {
|
||||
for (Brand brand : brandList) {
|
||||
brand.setName(brand.getNameEn());
|
||||
}
|
||||
} else if (lang == Constants.LANG_TW_CN) {
|
||||
for (Brand brand : brandList) {
|
||||
brand.setName(brand.getNameTw());
|
||||
}
|
||||
}
|
||||
return brandList;
|
||||
}
|
||||
|
||||
public List<City> listProvinces() {
|
||||
return cityMapper.listProvinces();
|
||||
}
|
||||
|
||||
public List<City> listCities(String provincePrefix) {
|
||||
return cityMapper.listCities(provincePrefix);
|
||||
}
|
||||
|
||||
public List<StbOperator> listOperators(String cityCode) {
|
||||
return operatorMapper.listOperators(cityCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.irext.server.service.mapper;
|
||||
|
||||
import net.irext.server.service.model.Brand;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.ResultMap;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Filename: BrandMapper.java
|
||||
* Revised: Date: 2019-06-21
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
* Description: BrandMapper
|
||||
* <p>
|
||||
* Revision log:
|
||||
* 2019-06-21: created by strawmanbobi
|
||||
*/
|
||||
@Mapper
|
||||
public interface BrandMapper {
|
||||
@Select("SELECT * FROM brand WHERE status = 1 AND category_id = #{categoryId} ORDER BY id LIMIT #{from}, #{count}")
|
||||
@ResultMap("BaseResultMap")
|
||||
List<Brand> listBrands(int categoryId, int from, int count);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package net.irext.server.service.mapper;
|
||||
|
||||
import net.irext.server.service.model.City;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.ResultMap;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Filename: CityMapper.java
|
||||
* Revised: Date: 2019-06-21
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
* Description: CityMapper
|
||||
* <p>
|
||||
* Revision log:
|
||||
* 2019-06-21: created by strawmanbobi
|
||||
*/
|
||||
@Mapper
|
||||
public interface CityMapper {
|
||||
@Select("SELECT * FROM city WHERE code LIKE '__0000'")
|
||||
@ResultMap("BaseResultMap")
|
||||
List<City> listProvinces();
|
||||
|
||||
@Select("SELECT * FROM city WHERE code like '#{provincePrefix}__00' and code not like '__0000'")
|
||||
@ResultMap("BaseResultMap")
|
||||
List<City> listCities(String provincePrefix);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.irext.server.service.mapper;
|
||||
|
||||
import net.irext.server.service.model.StbOperator;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.ResultMap;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Filename: OperatorMapper.java
|
||||
* Revised: Date: 2019-06-21
|
||||
* Revision: Revision: 1.0
|
||||
* <p>
|
||||
* Description: OperatorMapper
|
||||
* <p>
|
||||
* Revision log:
|
||||
* 2019-06-21: created by strawmanbobi
|
||||
*/
|
||||
@Mapper
|
||||
public interface OperatorMapper {
|
||||
@Select("SELECT * FROM stb_operator WHERE city_code = #{cityCode}")
|
||||
@ResultMap("BaseResultMap")
|
||||
List<StbOperator> listOperators(String cityCode);
|
||||
}
|
||||
@@ -3,7 +3,10 @@ package net.irext.server.service.restapi;
|
||||
import net.irext.server.service.Constants;
|
||||
import net.irext.server.service.businesslogic.IndexingLogic;
|
||||
import net.irext.server.service.mapper.RemoteIndexMapper;
|
||||
import net.irext.server.service.model.Brand;
|
||||
import net.irext.server.service.model.Category;
|
||||
import net.irext.server.service.model.City;
|
||||
import net.irext.server.service.model.StbOperator;
|
||||
import net.irext.server.service.request.*;
|
||||
import net.irext.server.service.response.*;
|
||||
import net.irext.server.service.restapi.base.AbstractBaseService;
|
||||
@@ -56,15 +59,7 @@ public class IRIndexingService extends AbstractBaseService {
|
||||
int count = listCategoriesRequest.getCount();
|
||||
int lang = Constants.LANG_ZH_CN;
|
||||
|
||||
if (null != userLang) {
|
||||
if (userLang.equals("en-US")) {
|
||||
lang = Constants.LANG_EN;
|
||||
} else if (userLang.equals("zh-TW")) {
|
||||
lang = Constants.LANG_TW_CN;
|
||||
} else {
|
||||
lang = Constants.LANG_ZH_CN;
|
||||
}
|
||||
}
|
||||
lang = getLanguage(userLang);
|
||||
|
||||
CategoriesResponse response = validateToken(id, token, CategoriesResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
@@ -87,4 +82,120 @@ public class IRIndexingService extends AbstractBaseService {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/list_brands")
|
||||
public BrandsResponse listBrands(HttpServletRequest request,
|
||||
@HeaderParam("user-lang") String userLang,
|
||||
@RequestBody ListBrandsRequest listBrandsRequest) {
|
||||
try {
|
||||
int id = listBrandsRequest.getId();
|
||||
String token = listBrandsRequest.getToken();
|
||||
int categoryId = listBrandsRequest.getCategoryId();
|
||||
int from = listBrandsRequest.getFrom();
|
||||
int count = listBrandsRequest.getCount();
|
||||
int lang = Constants.LANG_ZH_CN;
|
||||
|
||||
lang = getLanguage(userLang);
|
||||
|
||||
BrandsResponse response = validateToken(id, token, BrandsResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
return response;
|
||||
}
|
||||
|
||||
List<Brand> brandList = indexingLogic.listBrands(lang, categoryId, from, count);
|
||||
|
||||
if (brandList != null) {
|
||||
response.getStatus().setCode(Constants.ERROR_CODE_SUCCESS);
|
||||
response.setEntity(brandList);
|
||||
} else {
|
||||
response.getStatus().setCode(Constants.ERROR_CODE_NETWORK_ERROR);
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getExceptionResponse(BrandsResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/list_provinces")
|
||||
public CitiesResponse listProvinces(HttpServletRequest request,
|
||||
@HeaderParam("user-lang") String userLang,
|
||||
ListCitiesRequest listCitiesRequest) {
|
||||
try {
|
||||
int id = listCitiesRequest.getId();
|
||||
String token = listCitiesRequest.getToken();
|
||||
|
||||
CitiesResponse response = validateToken(id, token, CitiesResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
return response;
|
||||
}
|
||||
|
||||
List<City> cityList = indexingLogic.listProvinces();
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getExceptionResponse(CitiesResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/list_cities")
|
||||
public CitiesResponse listCities(HttpServletRequest request,
|
||||
@HeaderParam("user-lang") String userLang,
|
||||
ListCitiesRequest listCitiesRequest) {
|
||||
try {
|
||||
int id = listCitiesRequest.getId();
|
||||
String token = listCitiesRequest.getToken();
|
||||
String provincePrefix = listCitiesRequest.getProvincePrefix();
|
||||
|
||||
CitiesResponse response = validateToken(id, token, CitiesResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
return response;
|
||||
}
|
||||
|
||||
List<City> cityList = indexingLogic.listCities(provincePrefix);
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getExceptionResponse(CitiesResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/list_operators")
|
||||
public OperatorsResponse listOperators(HttpServletRequest request,
|
||||
@HeaderParam("user-lang") String userLang,
|
||||
ListOperatorsRequest listOperatorsRequest) {
|
||||
try {
|
||||
int id = listOperatorsRequest.getId();
|
||||
String token = listOperatorsRequest.getToken();
|
||||
String cityCode = listOperatorsRequest.getCityCode();
|
||||
|
||||
OperatorsResponse response = validateToken(id, token, OperatorsResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
return response;
|
||||
}
|
||||
|
||||
List<StbOperator> operatorList = indexingLogic.listOperators(cityCode);
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return getExceptionResponse(OperatorsResponse.class);
|
||||
}
|
||||
}
|
||||
|
||||
private int getLanguage(String userLang) {
|
||||
int lang = Constants.LANG_ZH_CN;
|
||||
if (null != userLang) {
|
||||
if (userLang.equals("en-US")) {
|
||||
lang = Constants.LANG_EN;
|
||||
} else if (userLang.equals("zh-TW")) {
|
||||
lang = Constants.LANG_TW_CN;
|
||||
} else {
|
||||
lang = Constants.LANG_ZH_CN;
|
||||
}
|
||||
}
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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" >
|
||||
<mapper namespace="net.irext.server.service.mapper.BrandMapper">
|
||||
<resultMap id="BaseResultMap" type="net.irext.server.service.model.Brand">
|
||||
<!--
|
||||
WARNING - @mbggenerated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
This element was generated on Thu May 04 12:06:44 CST 2017.
|
||||
-->
|
||||
<id column="id" property="id" jdbcType="INTEGER"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="category_id" property="categoryId" jdbcType="INTEGER"/>
|
||||
<result column="category_name" property="categoryName" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="TINYINT"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="CHAR"/>
|
||||
<result column="priority" property="priority" jdbcType="INTEGER"/>
|
||||
<result column="name_en" property="nameEn" jdbcType="VARCHAR"/>
|
||||
<result column="name_tw" property="nameTw" jdbcType="VARCHAR"/>
|
||||
<result column="contributor" property="contributor" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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" >
|
||||
<mapper namespace="net.irext.server.service.mapper.CityMapper">
|
||||
<resultMap id="BaseResultMap" type="net.irext.server.service.model.City">
|
||||
<!--
|
||||
WARNING - @mbggenerated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
This element was generated on Thu May 04 12:06:44 CST 2017.
|
||||
-->
|
||||
<id column="id" property="id" jdbcType="INTEGER"/>
|
||||
<result column="code" property="code" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="longitude" property="longitude" jdbcType="DOUBLE"/>
|
||||
<result column="latitude" property="latitude" jdbcType="DOUBLE"/>
|
||||
<result column="status" property="status" jdbcType="TINYINT"/>
|
||||
<result column="name_tw" property="nameTw" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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" >
|
||||
<mapper namespace="net.irext.server.service.mapper.StbOperatorMapper">
|
||||
<resultMap id="BaseResultMap" type="net.irext.server.service.model.StbOperator">
|
||||
<!--
|
||||
WARNING - @mbggenerated
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
This element was generated on Thu May 04 12:06:44 CST 2017.
|
||||
-->
|
||||
<id column="id" property="id" jdbcType="INTEGER"/>
|
||||
<result column="operator_id" property="operatorId" jdbcType="VARCHAR"/>
|
||||
<result column="operator_name" property="operatorName" jdbcType="VARCHAR"/>
|
||||
<result column="city_code" property="cityCode" jdbcType="VARCHAR"/>
|
||||
<result column="city_name" property="cityName" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="TINYINT"/>
|
||||
<result column="operator_name_tw" property="operatorNameTw" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user