puhanshu
2021-12-28 44b053051033a2d6dd23ad994d3d82a34f42cec1
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
package com.panzhihua.service_community.service.impl;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import com.panzhihua.common.utlis.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.service_community.dao.McsMerchantDAO;
import com.panzhihua.service_community.entity.McsMerchant;
import com.panzhihua.service_community.service.McsMerchantService;
 
import static java.util.Objects.isNull;
 
/**
 * (McsMerchant)表服务实现类
 *
 * @author makejava
 * @since 2021-12-28 14:37:11
 */
@Service("mcsMerchantService")
public class McsMerchantServiceImpl extends ServiceImpl<McsMerchantDAO, McsMerchant> implements McsMerchantService {
 
    @Resource
    private UserService userService;
 
    /**
     * 新增数字商业街商家
     * @param mcsMerchantDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R addMcsMerchant(McsMerchantDTO mcsMerchantDTO) {
        McsMerchant mcsMerchant = new McsMerchant();
        BeanUtils.copyProperties(mcsMerchantDTO, mcsMerchant);
        if (mcsMerchantDTO.getLevel().equals(1)) {
            Integer litDays = mcsMerchantDTO.getLitDays();
            if (isNull(litDays)) {
                return R.fail("临时商家未设置点亮天数");
            }
            mcsMerchant.setExpireAt(DateUtils.addDay(new Date(), litDays));
        }
        mcsMerchant.setUserId(0L);
        int insertResult = this.baseMapper.insert(mcsMerchant);
        if (insertResult > 0) {
            //添加user
            R addUserResult = userService.addMcsMerchantUser(mcsMerchantDTO);
            if (R.isOk(addUserResult)) {
                Long merchantUserId = ((Integer) addUserResult.getData()).longValue();
                mcsMerchant.setUserId(merchantUserId);
                this.baseMapper.updateById(mcsMerchant);
            } else {
                throw new ServiceException("406", addUserResult.getMsg());
            }
            return R.ok();
        }
        return R.fail("添加失败");
    }
}