| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- package com.goafanti.customer.controller;
- import java.lang.reflect.InvocationTargetException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.List;
- import java.util.UUID;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.beanutils.BeanUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.goafanti.customer.bo.AdminOut;
- import com.goafanti.customer.bo.CustomerIn;
- import com.goafanti.customer.bo.CustomerOut;
- import com.goafanti.customer.service.CustomerOrganizationService;
- import com.goafanti.customer.service.CustomerService;
- import com.goafanti.customer.service.CustomerUserService;
- import com.goafanti.customer.service.FollowUpService;
- import com.goafanti.admin.service.AdminService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.controller.BaseController;
- import com.goafanti.common.model.Customer;
- import com.goafanti.common.model.CustomerOrganizationInfo;
- import com.goafanti.common.model.CustomerUserInfo;
- import com.goafanti.common.model.FollowUpRecord;
- import com.goafanti.core.mybatis.page.Pagination;
- @RestController
- @RequestMapping(value = "/api/admin/customer")
- public class AdminCustomerApiController extends BaseController {
- @Resource
- private CustomerService customerService;
- @Resource
- private CustomerUserService customerUserService;
- @Resource
- private CustomerOrganizationService customerOrganizationService;
- @Resource
- private AdminService adminService;
- @Resource
- private FollowUpService followUpService;
- /**
- * 新增客户
- *
- * @return
- * @throws ParseException
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
- public Result addCustomer(CustomerIn cusIn,CustomerOrganizationInfo coi,CustomerUserInfo cui,FollowUpRecord fur) throws ParseException, IllegalAccessException, InvocationTargetException {
- Result res=new Result();
- //添加 customer
- String customerId = UUID.randomUUID().toString();//客户记录ID
- String customerUsrId= UUID.randomUUID().toString();//客户联系人ID
- String followId=UUID.randomUUID().toString();//跟进记录ID
- Customer c = new Customer();
- cusIn.setFollowId(followId);
- cusIn.setId(customerId);
-
- cui.setId(customerUsrId);
- cui.setCid(customerId);//客户联系人表中的cid
-
- coi.setId(UUID.randomUUID().toString());//客户公司ID
- coi.setCid(customerId);//客户公司表中的cid
-
- fur.setId(followId);//跟进记录的ID
- fur.setCid(customerId);//跟进记录表中的cid
- fur.setCuid(customerUsrId);//跟进记录表中的联系人id
- /*if(StringUtils.isNotBlank(cusIn.getAid())) fur.setAid(cusIn.getAid());*//*暂时注释*/
-
- BeanUtils.copyProperties(c, cusIn);
- c.setShareType(Integer.parseInt(cusIn.getShareTyp()));
- c.setCustomerType(Integer.parseInt(cusIn.getCustomerTyp()));
- c.setId(customerId);
-
- customerService.addCustomer(c);
- //插入 customerUserInfo
- customerUserService.addCustomerUserInfo(cui);
- //插入 customerOrganizationInfo
- customerOrganizationService.addCustomerOrganizationInfo(coi);
- //插入跟进表
- followUpService.addFollowUp(fur,cusIn);
- //添加日志
- customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_CREATE,customerId);
- return res;
- }
-
-
- /**
- * 删除
- *
- * @return
- * @throws ParseException
- */
- @RequestMapping(value = "/deleteCustomer", method = RequestMethod.POST)
- public Result deleteCustomer(String id,CustomerIn cusIn) throws ParseException {
- Result res=new Result();
- customerService.deleteCustomer(id);
- customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_DELETE,id);
- return res;
- }
-
-
- /**
- * 查询操作员信息
- *
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- * @throws ParseException
- */
- @RequestMapping(value = "/findAdmin", method = RequestMethod.POST)
- public Result selectAllAdmin(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
- Result res = new Result();
- List<AdminOut> adminList = adminService.selectAdmin();
- for (int i = 0; i < adminList.size(); i++) {
- adminList.get(i).setBeforeAdminName(cusIn.getBeforeAdminName());
- adminList.get(i).setBeforeCompanyIntention(cusIn.getBeforeCompanyIntention());
- adminList.get(i).setBeforeCustomerStatus(cusIn.getBeforeCustomerStatus());
- adminList.get(i).setBeforeFollowSituation(cusIn.getBeforeFollowSituation());
- adminList.get(i).setCid(cusIn.getId());
- }
- res.setData(adminList);
- return res;
- }
- /**
- * 查看私有客户
- * @param request
- * @return
- */
- @RequestMapping(value = "/listPrivateCustomer", method = RequestMethod.POST)
- public Result listPrivateCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNumber){
- Result res = new Result();
- Pagination<CustomerOut> boList = customerService.getPrivateCustomer(cin, pageSize, pageNumber);
- res.setData(boList);
- return res;
- }
-
-
- /**
- * 查询客户资料
- *
- * @return
- */
- @RequestMapping(value = "/findCustomerUserDetails", method = RequestMethod.POST)
- public Result findCustomerUserDetails(String id) {
- Result res=new Result();
- res.setData(customerService.findCustomerDetails(id));
- return res;
- }
-
- /**
- * 查询联系人姓名列表
- *
- * @return
- */
- @RequestMapping(value = "/findCustomerUserNameList", method = RequestMethod.POST)
- public Result findCustomerUserNameList (String cid) {
- Result res =new Result();
- res.setData(customerUserService.findCustomerUserNameList(cid));
- return res;
- }
-
- /**
- * 添加联系人
- *
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/addContacter", method = RequestMethod.POST)
- public Result addContacter (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
- Result res =new Result();
- CustomerUserInfo cui =new CustomerUserInfo();
- BeanUtils.copyProperties(cui, cusIn);
- cui.setId(UUID.randomUUID().toString());
- if(cui.getPrimaryFlg()==0) {//0:主要联系人,1-非主要联系人
- String primaryId = customerUserService.selectPrimaryFlgByCid(cusIn.getId());
- if(StringUtils.isNoneBlank(primaryId)) {
- customerUserService.updPrimaryFlg(cusIn.getId());//把主要联系人状态给去掉
- }
- customerUserService.addCustomerUserInfo(cui);//再添加联系人
- }else {
- customerUserService.addCustomerUserInfo(cui);
- }
- return res;
- }
-
-
- /**
- * 修改客户信息
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/updCustomer", method = RequestMethod.POST)
- public Result updCustomer (CustomerIn cusIn,CustomerOrganizationInfo coi) throws IllegalAccessException, InvocationTargetException {
- Result res=new Result();
- Customer c =new Customer();
- BeanUtils.copyProperties(c, cusIn);
- c.setShareType(Integer.parseInt(cusIn.getShareTyp()));
- c.setCustomerType(Integer.parseInt(cusIn.getCustomerTyp()));
- coi.setCid(cusIn.getId());
- //更新主表
- customerService.updateCustomer(c);
- //更新公司表
- customerOrganizationService.updateCustomerOrganizationInfo(coi);
- //插入日志表
- customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_MODIFY,cusIn.getId());
- return res;
- }
-
- /**
- * 转交
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/transferCustomer", method = RequestMethod.POST)
- public Result transferCustomer (CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException {
- Result res=new Result();
- Customer c =new Customer();
- BeanUtils.copyProperties(c, cusIn);
- //更新主表
- customerService.updateCustomer(c);
- //插入日志表
- customerService.saveCustomerLogo(cusIn, AFTConstants.CUSTOMER_TRANSFER,cusIn.getId());
- return res;
- }
-
- /**
- * 查询单个联系人信息
- * @return
- */
- /*@RequestMapping(value = "/transferCsutomer", method = RequestMethod.POST)
- public Result findContractById (String id) {
- Result res=new Result();
- res.setData(customerUserService.findContractById(id));
- return res;
- }*/
-
- /**
- * 修改单个联系人信息
- * @return
- */
- /*@RequestMapping(value = "/transferCsutomer", method = RequestMethod.POST)
- public Result updContractById (String id) {
- Result res=new Result();
- return res;
- }*/
-
- /**
- * 添加跟进记录
- * @param fur
- * @return
- * @throws ParseException
- */
- @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
- public Result addFollowUpRecord(FollowUpRecord fur, CustomerIn cusIn ,String followDate) throws ParseException{
- Result res = new Result();
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
- if(StringUtils.isNotBlank(followDate)) fur.setFollowDate(format.parse(followDate));
- String followId = UUID.randomUUID().toString();
- fur.setId(followId);
- cusIn.setFollowId(followId);
- followUpService.addFollowUp(fur, cusIn);
- Customer cus = new Customer();
- try {
- BeanUtils.copyProperties(cus, cusIn);
- if(StringUtils.isNotBlank(cusIn.getFollowSituation()))
- cus.setFollowSituation(Integer.parseInt(cusIn.getFollowSituation()));
- if(StringUtils.isNotBlank(cusIn.getCustomerStatus()))
- cus.setCustomerStatus(Integer.parseInt(cusIn.getCustomerStatus()));
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
-
- customerService.updateCustomer(cus);
- return res;
- }
-
- /**
- * 查看公司基本信息
- * @return
- */
- @RequestMapping(value = "/findCustomerBaseInfo" , method = RequestMethod.GET)
- public Result findCustomerBaseInfo(String customerId,String customerName){
- Result res= new Result();
- CustomerOut cusOut = customerService.findCustomerBaseInfo(customerId);
- cusOut.setCustomerName(customerName);
- res.setData(cusOut);
- return res;
- }
-
- /**
- * 查看跟进记录
- * @param customerId
- * @return
- */
- @RequestMapping(value = "/listFollowUpRecord" , method = RequestMethod.GET)
- public Result listFollowUpRecord(String customerId){
- Result res= new Result();
- res.setData(followUpService.listFollowUpRecord(customerId));
- return res;
- }
-
-
- }
|