lidongdong
2022-11-10 bdbe40f077aa9ca2ec184707d3eab41af13def03
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.community.convenient.ConvenientElevatingPointDTO;
import com.panzhihua.common.model.dtos.community.convenient.ConvenientMerchantDTO;
import com.panzhihua.common.model.dtos.community.convenient.PageConvenientElevatingPointDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.convenient.ConvenientElevatingPointVO;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.ConvenientElevatingPointDAO;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.model.dos.ConvenientElevatingPointDO;
import com.panzhihua.service_community.model.dos.ConvenientMerchantDO;
import com.panzhihua.service_community.model.dos.ConvenientServiceCategoryDO;
import com.panzhihua.service_community.service.ConvenientElevatingPointService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;
 
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
 
/**
 * @ClassName: ConvenientElevatingPointServiceImpl
 * @Author: yh
 * @Date: 2022/11/8 10:34
 * @Description: 自提点
 */
@Service
@Slf4j
public class ConvenientElevatingPointServiceImpl extends ServiceImpl<ConvenientElevatingPointDAO, ConvenientElevatingPointDO> implements ConvenientElevatingPointService {
    @Resource
    private ComActDAO comActDAO;
 
    /**
     * 分页查询
     * @param pageConvenientElevatingPointDTO
     * @return
     */
    @Override
    public R pagePoint(PageConvenientElevatingPointDTO pageConvenientElevatingPointDTO) {
        Page page = new Page<>();
        page.setSize(pageConvenientElevatingPointDTO.getPageSize());
        page.setCurrent(pageConvenientElevatingPointDTO.getPageNum());
        IPage<ConvenientElevatingPointVO> iPage = this.baseMapper.page(page, pageConvenientElevatingPointDTO);
        return R.ok(iPage);
    }
 
    /**
     * 新增
     * @param convenientElevatingPointDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R addPoint(ConvenientElevatingPointDTO convenientElevatingPointDTO) {
        ConvenientElevatingPointDO convenientElevatingPointDO = new ConvenientElevatingPointDO();
        BeanUtils.copyProperties(convenientElevatingPointDTO,convenientElevatingPointDO);
        String communityId = convenientElevatingPointDTO.getCommunityId();
        if (nonNull(communityId)) {
            ComActDO comActDO = comActDAO.selectById(Long.parseLong(communityId.substring(communityId.lastIndexOf(",")+1)));
            if(comActDO!=null){
                convenientElevatingPointDO.setCommunityName(comActDO.getName());
            }
        }
        this.baseMapper.insert(convenientElevatingPointDO);
        return R.ok();
    }
 
    /**
     * 修改
     * @param convenientElevatingPointDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R putPoint(ConvenientElevatingPointDTO convenientElevatingPointDTO) {
        Long id = convenientElevatingPointDTO.getId();
        ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(id);
        if (isNull(convenientElevatingPointDO)) {
            return R.fail("自提点不存在");
        }
        String communityId = convenientElevatingPointDTO.getCommunityId();
        if (nonNull(communityId)) {
            ComActDO comActDO = comActDAO.selectById(Long.parseLong(communityId.substring(communityId.lastIndexOf(",")+1)));
            if(comActDO!=null){
                convenientElevatingPointDO.setCommunityName(comActDO.getName());
            }
        }
        BeanUtils.copyProperties(convenientElevatingPointDTO, convenientElevatingPointDO);
        this.baseMapper.updateById(convenientElevatingPointDO);
        return R.ok();
    }
 
 
    @Override
    public R deletePoint(Long pointId, Long operator) {
        ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(pointId);
        if (convenientElevatingPointDO.getPrepareGoodsNum() > 0){
            return R.fail("该提货点暂时无法删除!若想删除需保证待提货数量为0");
        }
        int result = this.baseMapper.deletePointById(pointId, operator);
        if (result > 0) {
            return R.ok();
        }
        return R.fail("删除失败");
    }
 
    @Override
    public R detailPoint(Long pointId) {
        ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(pointId);
        return R.ok(convenientElevatingPointDO);
    }
}