fq
zj
2025-06-13 08ea05f85c9dd77834e56a2b912b2c43ac8888cd
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package project.c2c.internal;
 
import java.util.Arrays;
import java.util.List;
 
import org.apache.commons.collections.CollectionUtils;
import org.springframework.jdbc.core.JdbcTemplate;
 
import kernel.bo.RecordObjectMapper;
import project.RedisKeys;
import project.c2c.C2cAppeal;
import project.c2c.C2cAppealService;
import project.redis.RedisHandler;
 
public class C2cAppealServiceImpl implements C2cAppealService {
 
    private JdbcTemplate jdbcTemplate;
    private RedisHandler redisHandler;
    
    public C2cAppeal get(String order_no) {
        C2cAppeal appeal = (C2cAppeal) this.redisHandler.get(RedisKeys.C2C_APPEAL_ORDER_NO + order_no);
        if (null != appeal) {
            return appeal;
        } else {
            List<C2cAppeal> list = jdbcTemplate.query("SELECT * FROM T_C2C_APPEAL WHERE ORDER_NO=?", RecordObjectMapper.newInstance(C2cAppeal.class), order_no);
            if (list.size() > 0) {
                return (C2cAppeal) list.get(0);
            }
            return null;
        }
    }
    
    public void save(C2cAppeal entity) {
        if (null == entity) {
            return;
        }
        String insertSql = "INSERT INTO T_C2C_APPEAL(UUID,ORDER_NO,REASON,DESCRIPTION,IMG,NAME,PHONE,STATE,CREATE_TIME,UPDATE_TIME) VALUES (?,?,?,?,?,?,?,?,?,?)";
        jdbcTemplate.update(insertSql,entity.getId(),entity.getOrderNo(),entity.getReason(),entity.getDescription(),entity.getImg(),entity.getName(),entity.getPhone(),entity.getState(),entity.getCreateTime(),entity.getUpdateTime());
        if (null != entity && Arrays.asList("0").contains(entity.getState())) {
            // 只有已提交的申诉存入redis            
            this.redisHandler.setSync(RedisKeys.C2C_APPEAL_ORDER_NO + entity.getOrderNo(), entity);
        }
    }
 
    public void update(C2cAppeal entity) {
        if (null != entity) {
            String insertSql="UPDATE T_C2C_APPEAL SET ORDER_NO=?, REASON=?, DESCRIPTION=?, IMG=?, NAME=?, PHONE=?, STATE=?, UPDATE_TIME=? WHERE UUID=?";
            jdbcTemplate.update(insertSql, entity.getOrderNo(), entity.getReason(), entity.getDescription(), entity.getImg(), 
                    entity.getName(), entity.getPhone(), entity.getState(), entity.getUpdateTime(),entity.getId());
            if (Arrays.asList("0").contains(entity.getState())) {
                // 只有已提交的申诉存入redis
                this.redisHandler.setSync(RedisKeys.C2C_APPEAL_ORDER_NO + entity.getOrderNo(), entity);
            } else {
                this.redisHandler.remove(RedisKeys.C2C_APPEAL_ORDER_NO + entity.getOrderNo());
            }
        }
    }
 
    public void delete(String id) {
        C2cAppeal entity = this.get(id);
        if (entity != null) {
            jdbcTemplate.update("DELETE FROM T_C2C_APPEAL WHERE UUID=?", entity.getId());
            this.redisHandler.remove(RedisKeys.C2C_APPEAL_ORDER_NO + entity.getOrderNo());
        }
    }
 
    public C2cAppeal findById(String id) {
         List<C2cAppeal> list = jdbcTemplate.query("SELECT * FROM T_C2C_APPEAL WHERE UUID=?", RecordObjectMapper.newInstance(C2cAppeal.class), id);
            if (null != list && list.size() > 0) {
                return list.get(0);
            }
            return null;
    }
    
    /*
     * 查询未处理申诉数量,根据广告ID
     */
    public Long findNoHandleAppealsCountByAdvertId(String c2cAdvertId) {
 
        List find = jdbcTemplate.queryForList(" SELECT COUNT(*) FROM T_C2C_APPEAL appeal LEFT JOIN T_C2C_ORDER ord ON appeal.ORDER_NO = ord.ORDER_NO WHERE ord.C2C_ADVERT_ID = ? AND appeal.state = '0' ", String.class, c2cAdvertId);
        return CollectionUtils.isEmpty(find) ? 0L : (null == find.get(0) ? 0L : Long.valueOf(find.get(0).toString()));
    }
 
    public void setRedisHandler(RedisHandler redisHandler) {
        this.redisHandler = redisHandler;
    }
 
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    
}