Commit 4eb15b24 authored by hezhen's avatar hezhen

添加门店

parent c179a05f
......@@ -2,13 +2,16 @@ package com.github.wxiaoqi.security.common.biz;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.util.EntityUtils;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.Collection;
import java.util.List;
......@@ -125,6 +128,88 @@ public abstract class BaseBiz<M extends Mapper<T>, T> {
return new TableResultResponse<T>(result.getTotal(), list);
}
public TableResultResponse<T> selectPageByQuery(Query query) {
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
Example example = new Example(clazz);
Example.Criteria criteria=null;
if (checkFieldName(clazz,"isDel")){
criteria=example.createCriteria();
criteria.andEqualTo("isDel",0);
}
if (checkFieldName(clazz,"isDelete")){
criteria=example.createCriteria();
criteria.andEqualTo("isDelete",0);
}
if(query.entrySet().size()>0) {
if (criteria==null){
criteria=example.createCriteria();
}
for (Map.Entry<String, Object> entry : query.entrySet()) {
if(null != entry.getValue()) {
criteria.andLike(entry.getKey(), "%" + entry.getValue().toString() + "%");
}
}
}
if (checkFieldName(clazz,"sortOrder")) {
example.setOrderByClause("sort_order desc");
}else if(checkFieldName(clazz,"rank")){
example.setOrderByClause("rank desc");
}else {
example.setOrderByClause("id desc");
}
Page<Object> result = PageHelper.startPage(query.getPage(), query.getLimit());
List<T> list = mapper.selectByExample(example);
return new TableResultResponse<T>(result.getTotal(), list);
}
public ObjectRestResponse selectAll(){
List<T> list = selectListAlls();
return ObjectRestResponse.succ(list);
}
public List<T> selectListAlls(){
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
Example example = new Example(clazz);
Example.Criteria criteria=example.createCriteria();
if (checkFieldName(clazz,"isDel")){
criteria.andEqualTo("isDel",0);
}
if (checkFieldName(clazz,"sortOrder")){
example.setOrderByClause("sort_order desc");
}else if(checkFieldName(clazz,"rank")){
example.setOrderByClause("rank desc");
}else {
example.setOrderByClause("id desc");
}
return mapper.selectByExample(example);
}
public List<T> getList(String appId)throws Exception{
Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
Example example = new Example(clazz);
Example.Criteria criteria=example.createCriteria();
if (checkFieldName(clazz,"isDel")){
criteria.andEqualTo("isDel",0);
}
example.setOrderByClause("id desc");
return mapper.selectByExample(example);
}
public boolean checkFieldName(Class<T> clazz,String fieldname){
Field[] fields=clazz.getDeclaredFields();
boolean flag=false;
for (int i = 0; i < fields.length; i++) {
if(fields[i].getName().equals(fieldname))
{
flag=true;
break;
}
}
return flag;
}
}
......@@ -5,6 +5,7 @@ import com.github.wxiaoqi.security.common.context.BaseContextHandler;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.util.ReflectionUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -76,7 +77,7 @@ public class BaseController<Biz extends BaseBiz,Entity> extends CommonBaseContro
public TableResultResponse<Entity> list(@RequestParam Map<String, Object> params){
//查询列表数据
Query query = new Query(params);
return baseBiz.selectByQuery(query);
return baseBiz.selectPageByQuery(query);
}
@ApiOperation("根据参数查询,等于")
......@@ -88,4 +89,22 @@ public class BaseController<Biz extends BaseBiz,Entity> extends CommonBaseContro
}
@ApiOperation("查询所有")
@RequestMapping(value = "/alls",method = RequestMethod.GET)
@ResponseBody
public ObjectRestResponse alls(){
return baseBiz.selectAll();
}
@ApiOperation("删除")
@RequestMapping(value = "/del",method = RequestMethod.DELETE)
@ResponseBody
public ObjectRestResponse del( Entity entity){
ReflectionUtils.setFieldValue(entity,"isDel",1);
baseBiz.updateSelectiveById(entity);
return ObjectRestResponse.succ();
}
}
......@@ -22,12 +22,22 @@ public class BranchCompany {
@ApiModelProperty("主键id")
private Integer companyBaseId;
@Column(name = "company_id")
@ApiModelProperty("公司id")
private Long companyId;
/**
* 分公司名称
*/
@ApiModelProperty("分公司名称")
private String name;
@Column(name = "short_name")
@ApiModelProperty("简称")
private String shortName;
/**
* 分支机构类型
*/
......
package com.xxfc.platform.vehicle.pojo;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.Data;
@Data
public class CompanySearchDTO {
Integer page;
Integer limit;
public class CompanySearchDTO extends PageParam {
Integer addrCity;
String lon;
String lat;
Integer state;
Integer isShow = 1;
Integer isDel = 0;
Integer isShow;
Integer isDel;
Integer addrProvince;
Long companyId;
String name;
Integer id;
}
......@@ -8,4 +8,6 @@ import java.math.BigDecimal;
@Data
public class CompanySearchVO extends BranchCompany {
BigDecimal distance;
String companyName;
}
......@@ -24,6 +24,7 @@ import com.xxfc.platform.vehicle.mapper.BranchCompanyMapper;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVo;
import com.xxfc.platform.vehicle.pojo.CompanyDetail;
import com.xxfc.platform.vehicle.pojo.CompanySearchDTO;
import com.xxfc.platform.vehicle.pojo.CompanySearchVO;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyAreaDTO;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyFindDTO;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyListDTO;
......@@ -214,13 +215,18 @@ public class BranchCompanyBiz extends BaseBiz<BranchCompanyMapper, BranchCompany
return PageDataVO.pageInfo(branchCompanyPageInfo);
}
public PageDataVO<BranchCompany> search(CompanySearchDTO vo) {
public PageDataVO<CompanySearchVO> search(CompanySearchDTO vo) {
PageHelper.startPage(vo.getPage(), vo.getLimit());
PageInfo<BranchCompany> branchCompanyPageInfo = new PageInfo<>(mapper.search(vo.getLon(), vo.getLat(), vo.getAddrCity(), vo.getState(), vo.getIsShow(), vo.getIsDel()));
PageInfo<CompanySearchVO> branchCompanyPageInfo = new PageInfo<>(getList(vo));
return PageDataVO.pageInfo(branchCompanyPageInfo);
}
public List<CompanySearchVO> getList(CompanySearchDTO vo){
return mapper.search(vo);
}
@Cache(key = RedisKey.BRANCH_COMPANY_CACHE_ALL)
public List<BranchCompany> getAll() {
Example example = new Example(BranchCompany.class);
......
......@@ -2,6 +2,8 @@ package com.xxfc.platform.vehicle.mapper;
import com.alibaba.fastjson.JSONObject;
import com.xxfc.platform.vehicle.entity.BranchCompany;
import com.xxfc.platform.vehicle.pojo.CompanySearchDTO;
import com.xxfc.platform.vehicle.pojo.CompanySearchVO;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyAreaDTO;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyListDTO;
import org.apache.ibatis.annotations.Param;
......@@ -13,7 +15,7 @@ import java.util.List;
import java.util.Map;
public interface BranchCompanyMapper extends Mapper<BranchCompany>, SelectByIdListMapper<BranchCompany,Integer> {
List<BranchCompany> search(@Param("lon") String lon, @Param("lat") String lat, @Param("addrCity") Integer addrCity, Integer state, Integer isShow, Integer isDel);
List<CompanySearchVO> search(CompanySearchDTO companySearchDTO);
List<BranchCompany> selectByZoneId(Map<String, Object> param);
List<Integer> findCompanyIdsByAreaId(@Param("areaId") Integer areaId);
......
......@@ -74,12 +74,6 @@ public class BranchCompanyController extends BaseController<BranchCompanyBiz> {
return RestResponse.data(baseBiz.getAll(page,limit,addrProvince, addrCity, addrTown, null,null));
}
@RequestMapping(value ="/search",method = RequestMethod.GET)
@IgnoreUserToken
@IgnoreClientToken
public RestResponse<PageDataVO<BranchCompany>> search(@Validated CompanySearchDTO vo) {
return RestResponse.data(baseBiz.search(vo));
}
@RequestMapping(value ="",method = RequestMethod.GET)
public RestResponse<List<BranchCompany>> getAll() {
......
package com.xxfc.platform.vehicle.rest.admin;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.vehicle.biz.BranchCompanyBiz;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.entity.BranchCompany;
import com.xxfc.platform.vehicle.pojo.CompanySearchDTO;
import com.xxfc.platform.vehicle.pojo.CompanySearchVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("admin/branchCompany")
@Slf4j
@IgnoreClientToken
@IgnoreUserToken
@Api(value="公司controller",tags={"公司操作接口"})
public class AdminBranchCompanyController extends BaseController<BranchCompanyBiz,BranchCompany> {
@RequestMapping(value ="/search",method = RequestMethod.GET)
public RestResponse<PageDataVO<CompanySearchVO>> search(@Validated CompanySearchDTO vo) {
return RestResponse.data(baseBiz.search(vo));
}
@RequestMapping(value ="/details",method = RequestMethod.GET)
public RestResponse details(@Validated CompanySearchDTO vo) {
List<CompanySearchVO> list = baseBiz.getList(vo);
CompanySearchVO companySearchVO=new CompanySearchVO();
if (list.size() > 0){
companySearchVO=list.get(0);
}
return RestResponse.data(companySearchVO);
}
}
......@@ -2,8 +2,8 @@ package com.xxfc.platform.vehicle.rest.admin;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.xxfc.platform.vehicle.biz.CompanyInfoBiz;
import com.xxfc.platform.vehicle.common.BaseController;
import com.xxfc.platform.vehicle.entity.CompanyInfo;
import com.xxfc.platform.vehicle.pojo.dto.CompanyInfoFindDTO;
import io.swagger.annotations.ApiOperation;
......@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("company/info")
public class CompanyInfoController extends BaseController<CompanyInfoBiz> {
public class CompanyInfoController extends BaseController<CompanyInfoBiz,CompanyInfo> {
......
......@@ -7,6 +7,7 @@
-->
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="short_name" property="shortName" jdbcType="VARCHAR"/>
<result column="branch_type" property="branchType" jdbcType="INTEGER"/>
<result column="subordinate_branch" property="subordinateBranch" jdbcType="INTEGER"/>
<result column="addr_province" property="addrProvince" jdbcType="INTEGER"/>
......@@ -23,32 +24,48 @@
<result column="state" property="state"/>
</resultMap>
<select id="search" resultType="com.xxfc.platform.vehicle.pojo.CompanySearchVO">
select *
<select id="search" parameterType="com.xxfc.platform.vehicle.pojo.CompanySearchDTO" resultType="com.xxfc.platform.vehicle.pojo.CompanySearchVO">
select c.*,i.name as companyName
<if test="lon != null and lat != null">
, st_distance_sphere(point(#{lon}, #{lat}), point(longitude, latitude)) as distance
, st_distance_sphere(point(#{lon}, #{lat}), point(c.longitude, c.latitude)) as distance
</if>
from branch_company
from branch_company c
LEFT JOIN company_info i on c.company_id=i.id
<where>
c.is_del = 0
<if test="id != null">
and c.id = #{id}
</if>
<if test="addrCity != null">
and (addr_city = #{addrCity} or addr_province = #{addrCity} or addr_town = #{addrCity})
and (c.addr_city = #{addrCity} or c.addr_province = #{addrCity} or c.addr_town = #{addrCity})
</if>
<if test="addrProvince != null">
and c.addr_province = #{addrCity}
</if>
<if test="lon != null and lat != null">
and longitude is not null and latitude is not null
and c.longitude is not null and c.latitude is not null
</if>
<if test="state != null">
and state = #{state}
and c.state = #{state}
</if>
<if test="companyId != null">
and c.company_id = #{companyId}
</if>
<if test="isShow != null">
and is_show = #{isShow}
and c.is_show = #{isShow}
</if>
<if test="isDel != null">
and is_del = #{isDel}
<if test="name != null and name != '' ">
and ( c.name like concat('%',#{name},'%') or c.short_name like concat('%',#{name},'%') )
</if>
</where>
<if test="lon != null and lat != null">
order by distance asc
</if>
<choose>
<when test="lon != null and lat != null">
order by c.distance asc
</when>
<otherwise>
order by c.id desc
</otherwise>
</choose>
</select>
<select id="selectByZoneId" parameterType="java.util.Map"
resultType="com.xxfc.platform.vehicle.entity.BranchCompany">
......
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