Commit edb15597 by zhiwj

修改品牌库

parent 88bc5a91
......@@ -147,7 +147,7 @@ public interface PlatformBrandApiService {
* @return com.gic.api.base.commons.ServiceResponse<java.lang.Integer>
* @throws
*/
ServiceResponse<Integer> mergeBrandRef(Integer fromBrandId, String toBrandName);
ServiceResponse<Integer> mergeBrandRef(String fromBrandId, String toBrandName);
}
......@@ -58,7 +58,7 @@ public interface TabPlatformBrandRefMapper {
Integer countByPlatformBrandId(@Param("platformBrandId") Integer platformBrandId);
List<Map<String,Integer>> countByPlatformBrandIds(@Param("ids") List<Integer> platformBrandIdList);
List<Map<String, Integer>> countByPlatformBrandIds(@Param("ids") List<Integer> platformBrandIdList);
Integer delRef(@Param("enterpriseId") Integer enterpriseId, @Param("enterpriseBrandId") Integer enterpriseBrandId);
......@@ -66,5 +66,9 @@ public interface TabPlatformBrandRefMapper {
Page<TabPlatformBrandRef> listByPlatformBrandRef(TabPlatformBrandRef brandRef);
Integer updateRef(@Param("fromBrandId") Integer fromBrandId,@Param("toBrandId") Integer toBrandId);
Integer updateRef(@Param("fromBrandId") Integer fromBrandId, @Param("toBrandId") Integer toBrandId);
Integer updateRefs(@Param("ids") List<Integer> fromBrandIds, @Param("toBrandId") Integer platformBrandId);
Integer delBrandByIds(@Param("ids") List<Integer> fromBrandIds);
}
\ No newline at end of file
......@@ -21,4 +21,8 @@ public interface PlatformBrandRefService {
Page<TabPlatformBrandRef> listByPlatformBrandRef(Integer platformBrandId);
Integer updateRef(Integer fromBrandId, Integer toBrandId);
Integer updateRefs(List<Integer> fromBrandIds, Integer platformBrandId);
Integer delBrandByIds(List<Integer> fromBrandIds);
}
......@@ -73,4 +73,14 @@ public class PlatformBrandRefServiceImpl implements PlatformBrandRefService {
public Integer updateRef(Integer fromBrandId, Integer toBrandId) {
return tabPlatformBrandRefMapper.updateRef(fromBrandId, toBrandId);
}
@Override
public Integer updateRefs(List<Integer> fromBrandIds, Integer platformBrandId) {
return tabPlatformBrandRefMapper.updateRefs(fromBrandIds, platformBrandId);
}
@Override
public Integer delBrandByIds(List<Integer> fromBrandIds) {
return tabPlatformBrandRefMapper.delBrandByIds(fromBrandIds);
}
}
......@@ -4,6 +4,7 @@ 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.util.GlobalInfo;
import com.gic.commons.util.PageHelperUtils;
import com.gic.enterprise.constant.BrandCreateTypeEnum;
import com.gic.enterprise.constant.Constants;
......@@ -26,6 +27,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service("platformBrandApiService")
public class PlatformBrandApiServiceImpl implements PlatformBrandApiService {
......@@ -200,17 +202,22 @@ public class PlatformBrandApiServiceImpl implements PlatformBrandApiService {
}
@Override
public ServiceResponse<Integer> mergeBrandRef(Integer fromBrandId, String toBrandName) {
if (fromBrandId == null || StringUtils.isBlank(toBrandName)) {
public ServiceResponse<Integer> mergeBrandRef(String fromBrandId, String toBrandName) {
if (StringUtils.isBlank(fromBrandId) || StringUtils.isBlank(toBrandName)) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), ErrorCode.PARAMETER_ERROR.getMsg());
}
TabPlatformBrand platformBrand = this.platformBrandService.getByBrandName(toBrandName);
if (platformBrand == null) {
return ServiceResponse.failure(ErrorCode.NOTEXISTS.getCode(), "品牌名称不存在或已失效");
}
Integer line = this.platformBrandRefService.updateRef(fromBrandId, platformBrand.getPlatformBrandId());
List<Integer> fromBrandIds = Stream.of(fromBrandId.split(GlobalInfo.FLAG_COMMA)).map(Integer::valueOf).collect(Collectors.toList());
if (fromBrandIds.contains(platformBrand.getPlatformBrandId())) {
return ServiceResponse.failure(ErrorCode.OPERATION_FAILED.getCode(), "目标品牌存在在源品牌中,请重新选择品牌");
}
Integer line = this.platformBrandRefService.updateRefs(fromBrandIds, platformBrand.getPlatformBrandId());
if (line > 0) {
return this.delBrandById(fromBrandId);
platformBrandRefService.delBrandByIds(fromBrandIds);
return ServiceResponse.success();
} else {
return ServiceResponse.failure(ErrorCode.NOTEXISTS.getCode(), ErrorCode.NOTEXISTS.getMsg());
}
......
......@@ -180,4 +180,22 @@
<update id="updateRef">
update tab_platform_brand_ref set platform_brand_id = #{toBrandId} where status = 1 and platform_brand_id = #{fromBrandId}
</update>
<update id="updateRefs">
update tab_platform_brand_ref set platform_brand_id = #{toBrandId} where status = 1
<if test="null != ids">
and platform_brand_id in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</update>
<update id="delBrandByIds">
update tab_platform_brand_ref set status = 0 where status = 1
<if test="null != ids">
and platform_brand_id in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</update>
</mapper>
......@@ -69,7 +69,7 @@ public class PlatformBrandController {
}
@RequestMapping("/brand-merge")
public RestResponse mergeBrand(Integer fromBrandId, String toBrandName) {
public RestResponse mergeBrand(String fromBrandId, String toBrandName) {
if (fromBrandId == null || StringUtils.isBlank(toBrandName)) {
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), ErrorCode.PARAMETER_ERROR.getMsg());
}
......
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