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;
}