admin
2021-07-30 a66b556036c2b3936a51fd7b7e54a204eb31dc14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.yeshi.buwan.controller;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.buwan.dao.tb.YouZhiHaoHuoGoodsDao;
import com.yeshi.buwan.domain.tb.YouZhiHaoHuoGoods;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
 
@Controller
@RequestMapping("ecgoods")
public class ECGoodsController {
 
    @Resource
    private YouZhiHaoHuoGoodsDao youZhiHaoHuoGoodsDao;
 
    @ResponseBody
    @RequestMapping("tb/youzhihaohuo")
    public String youZhiHaoHuo(String data, HttpServletResponse response) {
        //删除1小时以前的数据
        delete();
        Type type = new TypeToken<List<YouZhiHaoHuoGoods>>() {
        }.getType();
 
        List<YouZhiHaoHuoGoods> list = new Gson().fromJson(data, type);
        for (YouZhiHaoHuoGoods goods : list) {
            goods.setCreateTime(new Date());
            goods.setPromotionPriceInt(goods.getPromotionPrice().multiply(new BigDecimal(100)).intValue());
            youZhiHaoHuoGoodsDao.save(goods);
        }
        return "";
    }
 
    private void delete() {
        Query query = new Query();
        query.addCriteria(Criteria.where("createTime").lt(new Date(System.currentTimeMillis() - 1000 * 60 * 60)));
        youZhiHaoHuoGoodsDao.delete(query);
    }
 
}