Commit d9010022 by zhiwj

门店基础查询(不包含自定义属性)

parent 1c2cdd99
package com.gic.store.constant;
/**
* @author zhiwj
* @date 2019/7/1
*/
public enum CreateTypeEnum {
BACKGROUND_ADD(1, "后台新增"),
BATCH_IMPORT(2, "批量导入"),
ORDER(3, "订单生成"),
ERP(4, "erp同步")
;
private int code;
private String message;
CreateTypeEnum(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}
......@@ -106,6 +106,10 @@ public class StoreDTO implements Serializable {
private String delBusinessTimes;
private List<StoreBusinessTimeDTO> businessTimeList;
private String storeGroupName;
private String provinceId;
private String cityId;
private String provinces;
private Integer createType;
public Integer getStoreId() {
return storeId;
......@@ -298,4 +302,36 @@ public class StoreDTO implements Serializable {
public String getStoreGroupName() {
return storeGroupName;
}
public String getProvinceId() {
return provinceId;
}
public void setProvinceId(String provinceId) {
this.provinceId = provinceId;
}
public String getCityId() {
return cityId;
}
public void setCityId(String cityId) {
this.cityId = cityId;
}
public String getProvinces() {
return provinces;
}
public void setProvinces(String provinces) {
this.provinces = provinces;
}
public Integer getCreateType() {
return createType;
}
public void setCreateType(Integer createType) {
this.createType = createType;
}
}
package com.gic.store.dao.mapper;
import com.gic.store.dto.StoreDTO;
import com.gic.store.entity.TabStore;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;
public interface TabStoreMapper {
......@@ -52,9 +54,16 @@ public interface TabStoreMapper {
*/
int updateByPrimaryKey(TabStore record);
/**
* 如果id不为null, 会查询storeId不为传入参数的数据;如果id为null, 会略过
* @param tabStore
* @return
*/
Integer countBySelective(TabStore tabStore);
Integer updateGroupId(@Param("oldStoreGroupId") Integer oldStoreGroupIds, @Param("newStoreGroupId") Integer newStoreGroupId);
Integer countByBrandId(@Param("brandId") Integer brandId);
Page listStore(StoreDTO storeDTO);
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.gic.store.service;
import com.gic.store.dto.StoreDTO;
import com.gic.store.entity.TabStore;
import com.github.pagehelper.Page;
/**
* @author zhiwj
......@@ -40,4 +41,15 @@ public interface StoreService {
* @return
*/
Integer countByBrandId(Integer brandId);
/**
* 查询如企业下门店关联主键的个数
* @param enterpriseId
* @param storeCode
* @param storeId 如果id不为null, 会查询storeId不为传入参数的数据;如果id为null, 会略过
* @return
*/
Integer countByStoreCode(Integer enterpriseId, String storeCode, Integer storeId);
Page listStore(StoreDTO storeDTO, Integer pageNum, Integer pageSize);
}
......@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
......@@ -29,14 +30,21 @@ public class StoreBusinessTimeServiceImpl implements StoreBusinessTimeService {
tabStoreBusinessTimeMapper.deleteByPrimaryKey(delId);
}
}
for (StoreBusinessTimeDTO storeBusinessTimeDTO : businessTimeList) {
TabStoreBusinessTime businessTime = new TabStoreBusinessTime();
businessTime.setStoreBusinessTimeId(storeBusinessTimeDTO.getStoreBusinessTimeId());
businessTime.setWeekday(storeBusinessTimeDTO.getWeekday());
businessTime.setOpenTime(storeBusinessTimeDTO.getOpenTime());
businessTime.setCloseTime(storeBusinessTimeDTO.getCloseTime());
businessTime.setStoreId(storeId);
tabStoreBusinessTimeMapper.insertSelective(businessTime);
if(CollectionUtils.isNotEmpty(businessTimeList)) {
for (StoreBusinessTimeDTO storeBusinessTimeDTO : businessTimeList) {
TabStoreBusinessTime businessTime = new TabStoreBusinessTime();
businessTime.setStoreBusinessTimeId(storeBusinessTimeDTO.getStoreBusinessTimeId());
businessTime.setWeekday(storeBusinessTimeDTO.getWeekday());
businessTime.setOpenTime(storeBusinessTimeDTO.getOpenTime());
businessTime.setCloseTime(storeBusinessTimeDTO.getCloseTime());
businessTime.setStoreId(storeId);
if (storeBusinessTimeDTO.getStoreBusinessTimeId() == null) {
businessTime.setCreateTime(new Date());
tabStoreBusinessTimeMapper.insertSelective(businessTime);
} else {
tabStoreBusinessTimeMapper.updateByPrimaryKeySelective(businessTime);
}
}
}
}
......
......@@ -34,19 +34,22 @@ public class StorePhotoServiceImpl implements StorePhotoService {
tabStorePhotoMapper.updateByPrimaryKeySelective(storePhoto);
}
}
for (StorePhotoDTO storePhotoDTO : photoList) {
TabStorePhoto storePhoto = new TabStorePhoto();
storePhoto.setStorePhotoId(storePhotoDTO.getStorePhotoId());
storePhoto.setStoreId(storeId);
storePhoto.setEnterpriseId(enterpriseId);
storePhoto.setImageCode(storePhotoDTO.getImageCode());
storePhoto.setImageUrl(storePhotoDTO.getImageUrl());
storePhoto.setSort(storePhotoDTO.getSort());
if (storePhoto.getStorePhotoId() == null) {
storePhoto.setCreateTime(new Date());
tabStorePhotoMapper.insertSelective(storePhoto);
} else {
tabStorePhotoMapper.updateByPrimaryKeySelective(storePhoto);
if (CollectionUtils.isNotEmpty(photoList)) {
for (StorePhotoDTO storePhotoDTO : photoList) {
TabStorePhoto storePhoto = new TabStorePhoto();
storePhoto.setStorePhotoId(storePhotoDTO.getStorePhotoId());
storePhoto.setEnterpriseId(enterpriseId);
storePhoto.setImageCode(storePhotoDTO.getImageCode());
storePhoto.setImageUrl(storePhotoDTO.getImageUrl());
storePhoto.setSort(storePhotoDTO.getSort());
storePhoto.setStatus(GlobalInfo.DATA_STATUS_NORMAL);
storePhoto.setStoreId(storeId);
if (storePhotoDTO.getStorePhotoId() == null) {
storePhoto.setCreateTime(new Date());
tabStorePhotoMapper.insertSelective(storePhoto);
} else {
tabStorePhotoMapper.updateByPrimaryKeySelective(storePhoto);
}
}
}
}
......
......@@ -4,6 +4,8 @@ import com.gic.store.dao.mapper.TabStoreMapper;
import com.gic.store.dto.StoreDTO;
import com.gic.store.entity.TabStore;
import com.gic.store.service.StoreService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -20,27 +22,34 @@ public class StoreServiceImpl implements StoreService {
TabStoreMapper tabStoreMapper;
@Override
public Integer save(StoreDTO storeDTO) {
public Integer save(StoreDTO copy) {
TabStore tabStore = new TabStore();
tabStore.setEnterpriseId(storeDTO.getEnterpriseId());
tabStore.setStoreName(storeDTO.getStoreName());
tabStore.setStoreCode(storeDTO.getStoreCode());
tabStore.setRegionId(storeDTO.getRegionId());
tabStore.setConactsPhone(storeDTO.getConactsPhone());
tabStore.setAddress(storeDTO.getAddress());
tabStore.setBrandIds(storeDTO.getBrandIds());
tabStore.setAreaId(storeDTO.getAreaId());
tabStore.setLongitude(storeDTO.getLongitude());
tabStore.setLatitude(storeDTO.getLatitude());
tabStore.setStoreId(copy.getStoreId());
tabStore.setEnterpriseId(copy.getEnterpriseId());
tabStore.setStoreName(copy.getStoreName());
tabStore.setStoreCode(copy.getStoreCode());
tabStore.setRegionId(copy.getRegionId());
tabStore.setConactsPhone(copy.getConactsPhone());
tabStore.setAddress(copy.getAddress());
tabStore.setBrandIds(copy.getBrandIds());
tabStore.setProvinceId(copy.getProvinceId());
tabStore.setCityId(copy.getCityId());
tabStore.setAreaId(copy.getAreaId());
tabStore.setProvinces(copy.getProvinces());
tabStore.setLongitude(copy.getLongitude());
tabStore.setLatitude(copy.getLatitude());
// TODO 这里要判断一下总量
tabStore.setOverflowStatus(0);
tabStore.setStatus(storeDTO.getStatus());
tabStore.setErpStatus(storeDTO.getErpStatus());
tabStore.setStoreType(storeDTO.getStoreType());
tabStore.setStoreGroupId(storeDTO.getStoreGroupId());
tabStore.setStatus(copy.getStatus());
tabStore.setErpStatus(copy.getErpStatus());
tabStore.setStoreType(copy.getStoreType());
tabStore.setStoreGroupId(copy.getStoreGroupId());
tabStore.setCreateType(copy.getCreateType());
tabStore.setCreateTime(new Date());
return tabStoreMapper.insertSelective(tabStore);
tabStoreMapper.insertSelective(tabStore);
return tabStore.getStoreId();
}
@Override
......@@ -49,19 +58,22 @@ public class StoreServiceImpl implements StoreService {
tabStore.setStoreId(copy.getStoreId());
tabStore.setEnterpriseId(copy.getEnterpriseId());
tabStore.setStoreName(copy.getStoreName());
tabStore.setStoreCode(copy.getStoreCode());
tabStore.setRegionId(copy.getRegionId());
tabStore.setConactsPhone(copy.getConactsPhone());
tabStore.setAddress(copy.getAddress());
tabStore.setBrandIds(copy.getBrandIds());
tabStore.setProvinceId(copy.getProvinceId());
tabStore.setCityId(copy.getCityId());
tabStore.setAreaId(copy.getAreaId());
tabStore.setProvinces(copy.getProvinces());
tabStore.setLongitude(copy.getLongitude());
tabStore.setLatitude(copy.getLatitude());
tabStore.setStatus(copy.getStatus());
tabStore.setErpStatus(copy.getErpStatus());
tabStore.setStoreType(copy.getStoreType());
tabStore.setStoreGroupId(copy.getStoreGroupId());
// TODO 这里要判断一下总量
tabStore.setOverflowStatus(0);
tabStore.setUpdateTime(copy.getUpdateTime());
return tabStoreMapper.updateByPrimaryKeySelective(tabStore);
}
......@@ -87,4 +99,19 @@ public class StoreServiceImpl implements StoreService {
public Integer countByBrandId(Integer brandId) {
return tabStoreMapper.countByBrandId(brandId);
}
@Override
public Integer countByStoreCode(Integer enterpriseId, String storeCode, Integer storeId) {
TabStore store = new TabStore();
store.setEnterpriseId(enterpriseId);
store.setStoreCode(storeCode);
store.setStoreId(storeId);
return tabStoreMapper.countBySelective(store);
}
@Override
public Page listStore(StoreDTO storeDTO, Integer pageNum, Integer pageSize) {
PageHelper.startPage(pageNum, pageSize);
return tabStoreMapper.listStore(storeDTO);
}
}
......@@ -3,6 +3,7 @@ package com.gic.store.service.outer;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.PageHelperUtils;
import com.gic.store.dao.mapper.TabStoreGroupMapper;
import com.gic.store.dto.StoreBrandDTO;
import com.gic.store.dto.StoreBusinessTimeDTO;
......@@ -10,6 +11,7 @@ import com.gic.store.dto.StoreDTO;
import com.gic.store.dto.StorePhotoDTO;
import com.gic.store.entity.*;
import com.gic.store.service.*;
import com.gic.store.utils.ErrorCode;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -24,6 +26,7 @@ import java.util.stream.Collectors;
* @date 2019/6/27
*/
@Service("storeApiService")
@SuppressWarnings("unchecked")
public class StoreApiServiceImpl implements StoreApiService {
@Autowired
......@@ -41,6 +44,12 @@ public class StoreApiServiceImpl implements StoreApiService {
@Override
@Transactional(rollbackFor = Exception.class)
public ServiceResponse<Integer> saveOrUpdate(StoreDTO storeDTO) {
Integer count = storeService.countByStoreCode(storeDTO.getEnterpriseId(), storeDTO.getStoreCode(), storeDTO.getStoreId());
if (count > 0) {
return ServiceResponse.failure(ErrorCode.ERR_6.getCode(), "关联主键参数已经存在");
}
// 门店自身信息
if (storeDTO.getStoreId() == null) {
Integer id = storeService.save(storeDTO);
......@@ -67,12 +76,18 @@ public class StoreApiServiceImpl implements StoreApiService {
@Override
public ServiceResponse<Page<StoreDTO>> listStore(StoreDTO storeDTO, Integer pageNum, Integer pageSize) {
return null;
// TODO es 暂时先查询数据库
com.github.pagehelper.Page storeList = storeService.listStore(storeDTO, pageNum, pageSize);
Page<StoreDTO> page = PageHelperUtils.changePageHelperToCurrentPage(storeList, StoreDTO.class);
return ServiceResponse.success(page);
}
@Override
public ServiceResponse<StoreDTO> getStoreById(Integer enterpriseId, Integer storeId) {
TabStore store = storeService.getById(storeId);
if (store == null) {
return ServiceResponse.failure(ErrorCode.ERR_5.getCode(), "门店不存在");
}
StoreDTO storeDTO = EntityUtil.changeEntityByOrika(StoreDTO.class, store);
TabStoreGroup storeGroup = tabStoreGroupMapper.selectByPrimaryKey(storeId);
if (storeGroup != null) {
......
......@@ -68,8 +68,8 @@ public class StoreBrandApiServiceImpl implements StoreBrandApiService {
@Override
public ServiceResponse<Page<StoreBrandDTO>> listStoreBrand(Integer enterpriseId, String search, Integer pageNum, Integer pageSize) {
com.github.pagehelper.Page storeStoreList = storeBrandService.listStoreBrand(enterpriseId, search, pageNum, pageSize);
Page<StoreBrandDTO> page = PageHelperUtils.changePageHelperToCurrentPage(storeStoreList, StoreBrandDTO.class);
com.github.pagehelper.Page storeBrandList = storeBrandService.listStoreBrand(enterpriseId, search, pageNum, pageSize);
Page<StoreBrandDTO> page = PageHelperUtils.changePageHelperToCurrentPage(storeBrandList, StoreBrandDTO.class);
List<StoreBrandDTO> resultList = page.getResult();
int index = (pageNum - 1) * pageSize + 1;
for (int i = 0; i < resultList.size(); i++) {
......
......@@ -168,10 +168,10 @@
where store_brand_id = #{storeBrandId,jdbcType=INTEGER}
</update>
<select id="getMinSort" resultType="java.lang.Double">
select sort from tab_store_brand where status = 1 order by sort limit 0, 1
select sort from tab_store_brand where status = 1 and enterprise_id = #{enterpriseId} order by sort limit 0, 1
</select>
<select id="getMaxSort" resultType="java.lang.Double">
select sort from tab_store_brand where status = 1 order by sort desc limit 0, 1
select sort from tab_store_brand where status = 1 and enterprise_id = #{enterpriseId} order by sort desc limit 0, 1
</select>
<select id="countBySelective" resultType="java.lang.Integer">
select count(1) from tab_store_brand
......
......@@ -41,6 +41,9 @@
where store_id = #{storeId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.gic.store.entity.TabStore">
<selectKey keyProperty="storeId" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into tab_store (store_id, enterprise_id, store_name,
store_code, region_id, conacts_phone,
address, brand_ids, province_id,
......@@ -59,6 +62,9 @@
#{updateTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.gic.store.entity.TabStore">
<selectKey keyProperty="storeId" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into tab_store
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="storeId != null">
......@@ -298,6 +304,15 @@
<if test="storeGroupId != null">
and store_group_id = #{storeGroupId}
</if>
<if test="enterpriseId != null">
and enterprise_id = #{enterpriseId}
</if>
<if test="storeCode != null and storeCode != '' ">
and store_code = #{storeCode}
</if>
<if test="storeId != null">
and store_id &lt;&gt; #{storeId}
</if>
</where>
</select>
<update id="updateGroupId">
......@@ -309,4 +324,10 @@
where
brand_ids REGEXP '^${brandId}$|^${brandId},.*$|^.*,${brandId},.*$|^.*,${brandId}$'
</select>
<select id="listStore" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_store
</select>
</mapper>
\ No newline at end of file
package com.gic.store.web.controller;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.store.constant.CreateTypeEnum;
import com.gic.store.dto.StoreBusinessTimeDTO;
import com.gic.store.dto.StoreDTO;
import com.gic.store.dto.StorePhotoDTO;
import com.gic.store.service.StoreApiService;
import com.gic.store.web.qo.PageQO;
import com.gic.store.web.qo.store.StoreQO;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -23,31 +28,34 @@ import java.util.List;
@RestController
public class StoreController {
private static final Logger logger = LogManager.getLogger(StoreController.class);
@Autowired
private StoreApiService storeApiService;
// @RequestMapping("/save-store")
// public RestResponse saveOrUpdate(StoreQO storeQO) {
// Integer enterpriseId = 1111;
// StoreDTO storeDTO = EntityUtil.changeEntityByOrika(StoreDTO.class, storeQO);
// storeDTO.setEnterpriseId(enterpriseId);
// String photos = storeQO.getPhotos();
// if (StringUtils.isNotBlank(photos)) {
// List<StorePhotoDTO> photoList = JSON.parseArray(photos, StorePhotoDTO.class);
// storeDTO.setPhotoList(photoList);
// }
// String businessTimes = storeQO.getBusinessTimes();
// if (StringUtils.isNotBlank(businessTimes)) {
// List<StoreBusinessTimeDTO> businessTimeList = JSON.parseArray(businessTimes, StoreBusinessTimeDTO.class);
// storeDTO.setBusinessTimeList(businessTimeList);
// }
// ServiceResponse<Integer> serviceResponse = storeApiService.saveOrUpdate(storeDTO);
// if (serviceResponse.isSuccess()) {
// return RestResponse.success(serviceResponse.getResult());
// } else {
// return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
// }
// }
@RequestMapping("/save-store")
public RestResponse saveOrUpdate(StoreQO storeQO) {
Integer enterpriseId = 1111;
StoreDTO storeDTO = EntityUtil.changeEntityByOrika(StoreDTO.class, storeQO);
storeDTO.setEnterpriseId(enterpriseId);
String photos = storeQO.getPhotos();
if (StringUtils.isNotBlank(photos)) {
List<StorePhotoDTO> photoList = JSON.parseArray(photos, StorePhotoDTO.class);
storeDTO.setPhotoList(photoList);
}
String businessTimes = storeQO.getBusinessTimes();
if (StringUtils.isNotBlank(businessTimes)) {
List<StoreBusinessTimeDTO> businessTimeList = JSON.parseArray(businessTimes, StoreBusinessTimeDTO.class);
storeDTO.setBusinessTimeList(businessTimeList);
}
storeDTO.setCreateType(CreateTypeEnum.BACKGROUND_ADD.getCode());
ServiceResponse<Integer> serviceResponse = storeApiService.saveOrUpdate(storeDTO);
if (serviceResponse.isSuccess()) {
return RestResponse.success(serviceResponse.getResult());
} else {
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
}
@RequestMapping("/store-detail")
public RestResponse getStoreDetail(Integer storeId) {
......@@ -60,5 +68,14 @@ public class StoreController {
}
}
@RequestMapping("/store-list")
public RestResponse storeList(StoreDTO storeDTO, PageQO pageQO) {
ServiceResponse<Page<StoreDTO>> serviceResponse = storeApiService.listStore(storeDTO, pageQO.getCurrentPage(), pageQO.getPageSize());
if (serviceResponse.isSuccess()) {
return RestResponse.success(serviceResponse.getResult());
} else {
return RestResponse.failure(serviceResponse.getCode(), serviceResponse.getMessage());
}
}
}
\ No newline at end of file
......@@ -100,6 +100,11 @@ public class StoreQO implements Serializable {
*/
private Date updateTime;
private String provinceId;
private String cityId;
private String provinces;
private Integer createType;
private String photos;
private String delPhotos;
private String delBusinessTimes;
......@@ -289,4 +294,36 @@ public class StoreQO implements Serializable {
public void setStoreGroupName(String storeGroupName) {
this.storeGroupName = storeGroupName;
}
public String getProvinceId() {
return provinceId;
}
public void setProvinceId(String provinceId) {
this.provinceId = provinceId;
}
public String getCityId() {
return cityId;
}
public void setCityId(String cityId) {
this.cityId = cityId;
}
public String getProvinces() {
return provinces;
}
public void setProvinces(String provinces) {
this.provinces = provinces;
}
public Integer getCreateType() {
return createType;
}
public void setCreateType(Integer createType) {
this.createType = createType;
}
}
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