Authored by caoyan

UFO比价

... ... @@ -16,4 +16,6 @@ public interface ChannelSkuCompareMapper {
List<ChannelSkuCompare> selectByCondition(@Param("channelSkuCompareReq") ChannelSkuCompareReq req);
ChannelSkuCompare selectById(@Param("id") Integer id);
}
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.Storage;
import java.math.BigDecimal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.Storage;
public interface StorageMapper {
int deleteByPrimaryKey(Integer id);
... ... @@ -23,4 +25,7 @@ public interface StorageMapper {
int updateStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum, @Param("oldStorageNum")Integer oldStorageNum);
List<Storage> selectByIds(@Param("storageIdList")List<Integer> storageIdList);
int updateSuggestPriceById(@Param("id") Integer id, @Param("suggestLowPrice") BigDecimal suggestLowPrice,
@Param("suggestHighPrice") BigDecimal suggestHighPrice);
}
\ No newline at end of file
... ...
... ... @@ -11,6 +11,8 @@ public class ChannelSkuCompareReq extends PageRequestBO {
*
*/
private static final long serialVersionUID = 1L;
private Integer id;
private Integer sku;
... ... @@ -25,8 +27,16 @@ public class ChannelSkuCompareReq extends PageRequestBO {
private List<Integer> productIdList;
private List<Integer> sizeIdList;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSku() {
public Integer getSku() {
return sku;
}
... ...
... ... @@ -16,6 +16,12 @@
<sql id="Base_Column_List">
id, product_id, sku, size_id, channel_price, low_rate, high_rate, update_time, channel_url
</sql>
<select id="selectById" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from channel_sku_compare
where id=#{id}
</select>
<sql id="Query_Sql" >
<if test="channelSkuCompareReq.sku != null and channelSkuCompareReq.sku != 0 ">
... ...
... ... @@ -66,4 +66,7 @@
#{item}
</foreach>
</select>
<update id="updateSuggestPriceById">
update storage set suggest_low_price=#{suggestLowPrice}, suggest_high_price=#{suggestHighPrice} where id=#{id}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -23,9 +23,21 @@ public class ChannelSkuCompareController {
private IChannelSkuCompareService channelSkuCompareService;
@RequestMapping(value = "/queryList")
public ApiResponse queryList(@RequestBody ChannelSkuCompareReq req) {
public ApiResponse queryList(ChannelSkuCompareReq req) {
LOGGER.info("queryOrderList in. req is {}", req);
PageResponseBO<ChannelSkuCompareRspBo> result = channelSkuCompareService.queryList(req);
return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
}
@RequestMapping(value = "/updateSuggestPrice")
public ApiResponse updateSuggestPrice(ChannelSkuCompareReq req) {
LOGGER.info("updateSuggestPrice in. req is {}", req);
int result = channelSkuCompareService.updateSuggestPrice(req);
if(result > 0) {
return new ApiResponse.ApiResponseBuilder().code(200).message("更新成功").data(result).build();
}else {
return new ApiResponse.ApiResponseBuilder().code(500).message("更新失败").data(result).build();
}
}
}
... ...
... ... @@ -10,4 +10,5 @@ import com.yohobuy.ufo.model.resp.product.ChannelSkuCompareRspBo;
public interface IChannelSkuCompareService {
PageResponseBO<ChannelSkuCompareRspBo> queryList(ChannelSkuCompareReq req);
int updateSuggestPrice(ChannelSkuCompareReq req);
}
... ...
... ... @@ -100,11 +100,37 @@ public class ChannelSkuCompareServiceImpl implements IChannelSkuCompareService {
return result;
}
@Override
public int updateSuggestPrice(ChannelSkuCompareReq req) {
if(null == req.getStatus() || req.getStatus().intValue() != 0 || null == req.getId()) {
return 0;
}
ChannelSkuCompare csc = channelSkuCompareMapper.selectById(req.getId());
if(null == csc) {
LOGGER.error("id not exist! id is {}", req.getId());
return 0;
}
Storage storage = storageMapper.selectByPrimaryKey(csc.getSku());
if(null == storage) {
LOGGER.error("storageId not exist! storageId is {}", csc.getSku());
return 0;
}
//更新
BigDecimal suggestLowPrice = csc.getChannelPrice().multiply(BigDecimal.valueOf(1).subtract(csc.getLowRate()));
BigDecimal suggestHighPrice = csc.getChannelPrice().multiply(BigDecimal.valueOf(1).add(csc.getHighRate()));
return storageMapper.updateSuggestPriceById(csc.getSku(), suggestLowPrice, suggestHighPrice);
}
private List<ChannelSkuCompareRspBo> convertToResp(List<ChannelSkuCompare> cscList, Map<Integer, Product> productMap,
Map<Integer, String> sizeIdNameMap, Map<Integer, Storage> storageMap, Map<Integer, BigDecimal> storageMinPriceMap){
List<ChannelSkuCompareRspBo> boList = Lists.newArrayList();
for(ChannelSkuCompare csc : cscList) {
ChannelSkuCompareRspBo bo = new ChannelSkuCompareRspBo();
bo.setId(csc.getId());
bo.setProductId(csc.getProductId());
bo.setSku(csc.getSku());
bo.setProductName(productMap.get(csc.getProductId()).getProductName());
... ... @@ -137,7 +163,7 @@ public class ChannelSkuCompareServiceImpl implements IChannelSkuCompareService {
}
private static String getFormatPrice(BigDecimal price) {
return String.format("%d", price.intValue());
return String.format("%.2f", price.doubleValue());
}
private boolean checkAndBuildParam(ChannelSkuCompareReq req) {
... ...