kongzy
2023-11-28 59d9ea33f503e363f2e2941c7c00cc9dd9d9d1c7
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
package com.nanometer.smartlab.service;
 
import com.nanometer.smartlab.dao.OpeApplyOrderDao;
import com.nanometer.smartlab.entity.OpeApplyOrder;
import com.nanometer.smartlab.exception.AlarmCode;
import com.nanometer.smartlab.exception.AlarmException;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.exception.ExceptionEnumCode;
import com.nanometer.smartlab.util.IDUtils;
import com.nanometer.smartlab.util.MessageUtil;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * Created by johnny on 17/12/15.
 */
@Service("opeApplyOrderService")
public class OpeApplyOrderServiceImpl implements OpeApplyOrderService {
 
    private static Logger logger = Logger.getLogger(OpeApplyOrderService.class);
 
    @Resource(name = "opeApplyOrderDao")
    OpeApplyOrderDao opeApplyOrderDao;
 
    @Transactional(propagation = Propagation.REQUIRED)
    public List<OpeApplyOrder> getOpeApplyOrderList(String opeOrderId, String opeApplyId) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("opeOrderId", opeOrderId);
            params.put("opeApplyId", opeApplyId);
            return this.opeApplyOrderDao.getOpeApplyOrderList(params);
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public int getOpeApplyOrderTotalCount(String opeOrderId, String opeApplyId) {
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("opeOrderId", opeOrderId);
            params.put("opeApplyId", opeApplyId);
            return this.opeApplyOrderDao.getOpeApplyOrderTotalCount(params);
        } catch (DataAccessException e) {
            logger.error(e.getMessage(), e);
            throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), e);
        }
    }
 
    @Transactional(propagation = Propagation.REQUIRED)
    public OpeApplyOrder insertOpeApplyOrder(OpeApplyOrder opeApplyOrder) {
        try {
            opeApplyOrder.setId(IDUtils.uuid());
            this.opeApplyOrderDao.insertOpeApplyOrder(opeApplyOrder);
            return opeApplyOrder;
        } catch (DuplicateKeyException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_DUPLICATE, MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode()));
        } catch (DataIntegrityViolationException ex) {
            logger.warn(ex.getMessage(), ex);
            throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode()));
        } catch (DataAccessException ex) {
            logger.error(ex.getMessage(), ex);
            throw new BusinessException(ExceptionEnumCode.DB_ERR, MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex);
        }
    }
}