CRM项目后端在manager内完成操作两表将线索转换为客户------CRM项目

package com.alatus.service.impl;

import com.alatus.manager.CustomerManager;
import com.alatus.mapper.TCustomerMapper;
import com.alatus.query.CustomerQuery;
import com.alatus.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private CustomerManager customerManager;

    @Override
    public Boolean convertCustomer(CustomerQuery customerQuery) {
        return customerManager.transferCustomer(customerQuery);
    }
}

package com.alatus.service.impl;

import com.alatus.manager.CustomerManager;
import com.alatus.mapper.TCustomerMapper;
import com.alatus.query.CustomerQuery;
import com.alatus.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private CustomerManager customerManager;

    @Override
    public Boolean convertCustomer(CustomerQuery customerQuery) {
        return customerManager.transferCustomer(customerQuery);
    }
}

package com.alatus.manager;

import com.alatus.mapper.TClueMapper;
import com.alatus.mapper.TCustomerMapper;
import com.alatus.model.TClue;
import com.alatus.model.TCustomer;
import com.alatus.query.CustomerQuery;
import com.alatus.util.JWTUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class CustomerManager {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private TClueMapper tClueMapper;

    public Boolean transferCustomer(CustomerQuery customerQuery) {
        TClue tClue = tClueMapper.selectByPrimaryKey(customerQuery.getClueId());
        if(tClue.getState() == -1){
            throw new RuntimeException("该线索已被使用");
        }
        else{
            TCustomer tCustomer = new TCustomer();
            BeanUtils.copyProperties(customerQuery,tCustomer);
            tCustomer.setCreateTime(new Date());
            tCustomer.setCreateBy(JWTUtils.parseUserFromJWT(customerQuery.getToken()).getId());
            tCustomerMapper.insert(tCustomer);
            TClue clue = new TClue();
            clue.setId(customerQuery.getClueId());
            clue.setState(-1);
            tClueMapper.updateByPrimaryKeySelective(clue);
            return true;
        }
    }
}
package com.alatus.manager;

import com.alatus.mapper.TClueMapper;
import com.alatus.mapper.TCustomerMapper;
import com.alatus.model.TClue;
import com.alatus.model.TCustomer;
import com.alatus.query.CustomerQuery;
import com.alatus.util.JWTUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class CustomerManager {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private TClueMapper tClueMapper;

    public Boolean transferCustomer(CustomerQuery customerQuery) {
        TClue tClue = tClueMapper.selectByPrimaryKey(customerQuery.getClueId());
        if(tClue.getState() == -1){
            throw new RuntimeException("该线索已被使用");
        }
        else{
            TCustomer tCustomer = new TCustomer();
            BeanUtils.copyProperties(customerQuery,tCustomer);
            tCustomer.setCreateTime(new Date());
            tCustomer.setCreateBy(JWTUtils.parseUserFromJWT(customerQuery.getToken()).getId());
            tCustomerMapper.insert(tCustomer);
            TClue clue = new TClue();
            clue.setId(customerQuery.getClueId());
            clue.setState(-1);
            tClueMapper.updateByPrimaryKeySelective(clue);
            return true;
        }
    }
}
package com.alatus.web;

import com.alatus.constant.Constants;
import com.alatus.query.CustomerQuery;
import com.alatus.result.Result;
import com.alatus.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerController {
    @Resource
    private CustomerService customerService;

    @PostMapping(value = "/api/clue/customer")
    public Result transferCustomer(@RequestBody CustomerQuery customerQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        customerQuery.setToken(token);
        Boolean convert = customerService.convertCustomer(customerQuery);
        return convert ? Result.OK() : Result.FAIL();
    }
}
package com.alatus.web;

import com.alatus.constant.Constants;
import com.alatus.query.CustomerQuery;
import com.alatus.result.Result;
import com.alatus.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerController {
    @Resource
    private CustomerService customerService;

    @PostMapping(value = "/api/clue/customer")
    public Result transferCustomer(@RequestBody CustomerQuery customerQuery, @RequestHeader(value = Constants.TOKEN_NAME)String token){
        customerQuery.setToken(token);
        Boolean convert = customerService.convertCustomer(customerQuery);
        return convert ? Result.OK() : Result.FAIL();
    }
}
package com.alatus.service;

import com.alatus.query.CustomerQuery;

public interface CustomerService {
    Boolean convertCustomer(CustomerQuery customerQuery);
}
package com.alatus.service;

import com.alatus.query.CustomerQuery;

public interface CustomerService {
    Boolean convertCustomer(CustomerQuery customerQuery);
}
package com.alatus.query;

import lombok.Data;
import java.util.Date;

@Data
public class CustomerQuery extends BaseQuery{

    private Integer clueId;

    private Integer product;

    private String description;

    private Date nextContactTime;
}
package com.alatus.query;

import lombok.Data;
import java.util.Date;

@Data
public class CustomerQuery extends BaseQuery{

    private Integer clueId;

    private Integer product;

    private String description;

    private Date nextContactTime;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值