doum
2025-12-11 3cd92951fd2a67a02e649a870d100b3e8776ae11
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package com.doumee.service.business.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.MultifileMapper;
import com.doumee.dao.business.ShopApplyMapper;
import com.doumee.dao.business.ShopMapper;
import com.doumee.dao.business.join.ShopApplyJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.web.dto.ShopApplyDTO;
import com.doumee.service.business.ShopApplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 店铺申请信息表Service实现
 * @author 江蹄蹄
 * @date 2023/03/21 15:48
 */
@Service
public class ShopApplyServiceImpl implements ShopApplyService {
 
    @Autowired
    private ShopApplyMapper shopApplyMapper;
 
    @Autowired
    private ShopApplyJoinMapper shopApplyJoinMapper;
 
    @Autowired
    private MultifileMapper multifileMapper;
 
 
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
 
    @Autowired
    private ShopMapper shopMapper;
 
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    @Override
    public Integer create(ShopApplyDTO shopApplyDTO) {
        LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        ShopApply shopApply = new ShopApply();
        shopApply.setCreator(loginUserInfo.getId());
        shopApply.setEditor(loginUserInfo.getId());
        shopApply.setRemark(shopApplyDTO.getRemark());
        shopApply.setImgurl(shopApplyDTO.getImgurl());
        shopApply.setName(shopApplyDTO.getName());
        shopApply.setRealname(shopApplyDTO.getRealname());
        shopApply.setSex(shopApplyDTO.getSex() != null ? shopApplyDTO.getSex() : 2);
        shopApply.setPhone(shopApplyDTO.getPhone());
        shopApply.setIdcard(shopApplyDTO.getIdcard());
        shopApply.setIdcardImg(shopApplyDTO.getIdcardImg());
        shopApply.setIdcardImgBack(shopApplyDTO.getIdcardImgBack());
        shopApply.setBusinessImg(shopApplyDTO.getBusinessImg());
        shopApply.setStatus(Constants.ZERO);
        shopApply.setAreaId(shopApplyDTO.getAreaId());
        shopApply.setLongitude(shopApplyDTO.getLongitude());
        shopApply.setLatitude(shopApplyDTO.getLatitude());
        shopApply.setAddr(shopApplyDTO.getAddr());
        shopApply.setInfo(shopApplyDTO.getInfo());
        shopApply.setOrigin(shopApplyDTO.getOrigin());
        shopApply.setMemberId(shopApplyDTO.getMemberId());
//        shopApply.setCheckInfo(shopApplyDTO.getCheckInfo());
//        shopApply.setCheckDate();
 
        shopApplyMapper.insert(shopApply);
        return shopApply.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        shopApplyMapper.deleteById(id);
    }
 
    @Override
    public void delete(ShopApply shopApply) {
        UpdateWrapper<ShopApply> deleteWrapper = new UpdateWrapper<>(shopApply);
        shopApplyMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        shopApplyMapper.deleteBatchIds(ids);
    }
 
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public void updateById(ShopApply shopApply) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        shopApply.setEditor(user.getId());
        shopApply.setEditDate(new Date());
 
        ShopApply result=shopApplyMapper.selectById(shopApply.getId());
        if(result!=null&&Constants.equalsInteger(result.getStatus(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "审核已通过,禁止操作");
        }
        if(Constants.equalsInteger(shopApply.getStatus(),Constants.ONE)){
            //审核通过
            approved(shopApply,user);
        }
        shopApplyMapper.updateById(shopApply);
    }
 
    public void approved(ShopApply shopApply,LoginUserInfo user){
        Shop query=new Shop();
        query.setIsdeleted(Constants.ZERO);
        query.setApplyId(shopApply.getId());
        Shop result=shopMapper.selectOne(new QueryWrapper<>(query));
        Shop shop=new Shop();
        BeanUtils.copyProperties(shop, shopApply);
        if(Objects.nonNull(result)){
      /*      shop.setId(result.getId());
            shop.setStatus(Constants.ZERO);
            shop.setEditDate(new Date());
            shop.setEditor(user.getId());
            shopMapper.updateById(shop);*/
        }else{
            shop.setId(null);
            shop.setStatus(Constants.ZERO);
            shop.setCreateDate(new Date());
            shop.setCreator(user.getId());
            shopMapper.insert(shop);
        }
    }
 
    @Override
    public void updateByIdInBatch(List<ShopApply> shopApplys) {
        if (CollectionUtils.isEmpty(shopApplys)) {
            return;
        }
        for (ShopApply shopApply: shopApplys) {
            this.updateById(shopApply);
        }
    }
 
    @Override
    public ShopApply findById(Integer id) {
        ShopApply shopApply=   shopApplyMapper.selectById(id);
        String path = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.ACTIVITY_FILE).getCode();
 
        Multifile queryfile = new Multifile();
        queryfile.setObjId(shopApply.getId());
        queryfile.setObjType(Constants.MultiFile.SHOP_PICTURE.getKey());
        List<Multifile> filelist = multifileMapper.selectList(new QueryWrapper<>(queryfile));
        shopApply.setResourcePath(path);
        shopApply.setFileList(filelist);
        return shopApply;
    }
 
    @Override
    public ShopApply findOne(ShopApply shopApply) {
        QueryWrapper<ShopApply> wrapper = new QueryWrapper<>(shopApply);
        return shopApplyMapper.selectOne(wrapper);
    }
 
    @Override
    public ShopApply findLastOne(Integer memberId) {
        QueryWrapper<ShopApply> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(ShopApply::getMemberId,memberId)
                .orderByDesc(ShopApply::getCheckDate).last("limit 1");
        return shopApplyMapper.selectOne(wrapper);
    }
 
    @Override
    public List<ShopApply> findList(ShopApply shopApply) {
        QueryWrapper<ShopApply> wrapper = new QueryWrapper<>(shopApply);
        return shopApplyMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<ShopApply> findPage(PageWrap<ShopApply> pageWrap) {
        IPage<ShopApply> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<ShopApply> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
 
        queryWrapper.selectAll(ShopApply.class);
        queryWrapper.selectAs(Member::getNickname,ShopApply::getNikeName);
 
        queryWrapper.leftJoin(Member.class,Member::getId,ShopApply::getMemberId);
 
        queryWrapper.eq(pageWrap.getModel().getStatus()!=null,ShopApply::getStatus, pageWrap.getModel().getStatus());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getName()),ShopApply::getName,pageWrap.getModel().getName());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getRealname()),ShopApply::getRealname,pageWrap.getModel().getRealname());
        queryWrapper.eq(ShopApply::getIsdeleted, Constants.ZERO);
        queryWrapper.orderByDesc(ShopApply::getCreateDate);
        IPage<ShopApply> result = shopApplyJoinMapper.selectJoinPage(page, ShopApply.class, queryWrapper);
 
        return PageData.from(result);
    }
 
    @Override
    public long count(ShopApply shopApply) {
        QueryWrapper<ShopApply> wrapper = new QueryWrapper<>(shopApply);
        return shopApplyMapper.selectCount(wrapper);
    }
}