Authored by mali

Merge branch 'master' into dev_20190130_import

package com.yoho.ufo.restapi;
import com.yoho.quartz.job.YhJob;
import com.yoho.ufo.service.model.*;
import com.yoho.ufo.service.model.ApiResponse;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by li.ma on 2019/2/1.
*/
@Controller
@RequestMapping("/scheduled")
public class ScheduledManualController implements ApplicationContextAware{
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@RequestMapping(value = "/scheduledManual")
@ResponseBody
public ApiResponse scheduledManual(@RequestParam(name = "scheduledName",required = true) String scheduledName) {
YhJob jobObject = applicationContext.getBean(scheduledName, YhJob.class);
jobObject.process(null);
return new ApiResponse(200, "处理成功", null);
}
}
... ...
... ... @@ -4,6 +4,7 @@ import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.HiddenSkup;
import com.yoho.ufo.dal.model.StoragePrice;
public interface StoragePriceMapper {
... ... @@ -56,4 +57,6 @@ public interface StoragePriceMapper {
int selectStoragePriceCountBySellerUid(@Param("storagePrice") StoragePrice storagePrice, @Param("list") List<Integer> sellerUid);
List<StoragePrice> selectStoragePriceListBySellerUid(@Param("storagePrice") StoragePrice storagePrice, @Param("start") int startIndex, @Param("rows") int rows, @Param("list") List<Integer> sellerUid);
List<HiddenSkup> selectHiddenSkup();
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
import com.alibaba.fastjson.JSONObject;
public class HiddenSkup {
private Integer sellerUid;
private int skupNum;
public Integer getSellerUid() {
return sellerUid;
}
public void setSellerUid(Integer sellerUid) {
this.sellerUid = sellerUid;
}
public int getSkupNum() {
return skupNum;
}
public void setSkupNum(int skupNum) {
this.skupNum = skupNum;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
}
\ No newline at end of file
... ...
... ... @@ -257,5 +257,17 @@
</foreach>
order by sp.id desc limit #{start},#{rows}
</select>
<resultMap id="HiddenSkupMap" type="com.yoho.ufo.dal.model.HiddenSkup">
<result column="seller_uid" jdbcType="INTEGER" property="sellerUid"/>
<result column="skup_num" jdbcType="INTEGER" property="skupNum"/>
</resultMap>
<select id="selectHiddenSkup" resultMap="HiddenSkupMap">
select t2.seller_uid as seller_uid, count(t2.skup) as skup_num from storage t1, storage_price t2
where t1.id=t2.storage_id and t2.status=1 and t1.suggest_high_price is not null and t2.price > t1.suggest_high_price
group by t2.seller_uid
having skup_num >0;
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -51,5 +51,10 @@
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-message-sdk</artifactId>
<version>1.1.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
... ...
... ... @@ -15,4 +15,6 @@ public interface IChannelSkuCompareService {
int updateSuggestRate(ChannelSkuCompareReq req);
void synChannelSkuCompare();
void noticeSellerHiddenSkup();
}
... ...
... ... @@ -16,8 +16,10 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.core.config.ConfigReader;
import com.yoho.error.exception.ServiceException;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
import com.yoho.message.sdk.service.ufo.IUFOSendService;
import com.yoho.ufo.dal.ChannelSkuCompareMapper;
import com.yoho.ufo.dal.GoodsMapper;
import com.yoho.ufo.dal.ProductMapper;
... ... @@ -25,6 +27,7 @@ import com.yoho.ufo.dal.StorageMapper;
import com.yoho.ufo.dal.StoragePriceMapper;
import com.yoho.ufo.dal.UfoSizeMapper;
import com.yoho.ufo.dal.model.Goods;
import com.yoho.ufo.dal.model.HiddenSkup;
import com.yoho.ufo.dal.model.Product;
import com.yoho.ufo.dal.model.Storage;
import com.yoho.ufo.dal.model.StoragePrice;
... ... @@ -65,6 +68,12 @@ public class ChannelSkuCompareServiceImpl implements IChannelSkuCompareService,
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private ConfigReader configReader;
@Autowired
private IUFOSendService ufoSendService;
private static final int CHANNEL_SKU_COMPARE_ABNORMAL = 1;
private static final int CHANNEL_SKU_COMPARE_NORMAL = 0;
... ... @@ -198,6 +207,41 @@ public class ChannelSkuCompareServiceImpl implements IChannelSkuCompareService,
LOGGER.info("synChannelSkuCompare end");
}
@Override
public void noticeSellerHiddenSkup() {
List<HiddenSkup> list = storagePriceMapper.selectHiddenSkup();
List<Integer> uidList = list.stream().map(HiddenSkup::getSellerUid).collect(Collectors.toList());
if(CollectionUtils.isEmpty(uidList)) {
return;
}
//去除不需要PUSH的uid
List<Integer> noPushUidList = getNoPushUidList();
uidList.removeAll(noPushUidList);
Map<Integer, Integer> sellerUidSkupNumMap = list.stream().collect(Collectors.toMap(HiddenSkup::getSellerUid, HiddenSkup::getSkupNum));
//PUSH消息
for(Integer uid : uidList) {
SendMessageRspBo bo = ufoSendService.sendAdjustPrice(String.valueOf(uid), sellerUidSkupNumMap.get(uid));
LOGGER.info("push uid is {}, skupNum is {}, result is {}", uid, sellerUidSkupNumMap.get(uid), bo);
}
}
private List<Integer> getNoPushUidList(){
String noPushUidStr = configReader.getString("ufo.hiddenSkup.noPushUid", "");
LOGGER.info("noPushUid is {}", noPushUidStr);
if(StringUtils.isEmpty(noPushUidStr)) {
return Lists.newArrayList();
}
String[] noPushUidArray = noPushUidStr.split(",");
List<Integer> noPushUidList = Lists.newArrayList();
for(int i=0; i < noPushUidArray.length; i++) {
noPushUidList.add(Integer.parseInt(noPushUidArray[i]));
}
return noPushUidList;
}
private void dealSynChannelSkuCompareData(ChannelSkuCompareReq req) {
List<ChannelSkuCompare> cscList = channelSkuCompareMapper.selectByCondition(req);
List<Integer> productIdList = CollectionUtil.map(cscList, ChannelSkuCompare::getProductId);
... ...
package com.yoho.ufo.service.scheduled;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.quartz.annotation.JobType;
import com.yoho.quartz.annotation.MisfiredPolicy;
import com.yoho.quartz.annotation.YhJobDef;
import com.yoho.quartz.domain.JobProcessResult;
import com.yoho.quartz.domain.JobResultCode;
import com.yoho.quartz.job.YhJob;
import com.yoho.ufo.service.IChannelSkuCompareService;
/**
* 通知卖家有隐藏的Skup
* @author caoyan
*
*/
@Service(value="scheduledNoticeSellerHiddenSkup")
@YhJobDef(desc = "定时通知卖家有隐藏skup", jobName = "scheduledNoticeSellerHiddenSkup", cron = "0 0 12,20 * * ?", misfiredPolicy = MisfiredPolicy.CRON_DO_NOTHING,
jobType = JobType.CRON, jobGroup = "ufoPlatform", needUpdate=true)
public class ScheduledNoticeSellerHiddenSkup implements YhJob{
private static final Logger LOGGER = LoggerFactory.getLogger("scheduledLog");
@Autowired
private IChannelSkuCompareService channelSkuCompareService;
public JobProcessResult process(String jobContext) {
LOGGER.info("scheduledNoticeSellerHiddenSkup begin.");
JobProcessResult result = new JobProcessResult();
channelSkuCompareService.noticeSellerHiddenSkup();
result.setJobResultCode(JobResultCode.SUCCESS);
return result;
}
}
\ No newline at end of file
... ...