| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- package com.goafanti.customer.controller;
- import java.lang.reflect.InvocationTargetException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import java.util.UUID;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- 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.Error;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.controller.BaseApiController;
- 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;
- import com.goafanti.core.shiro.token.TokenManager;
- @RestController
- @RequestMapping(value = "/api/admin/customer")
- public class AdminCustomerApiController extends BaseApiController {
- @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();
- //查询客户是否已经存在
- if(customerOrganizationService.findCustomerOrganizationByName(cusIn.getCompanyName())>0){
- res.getError().add(buildError(ErrorConstants.CUSTOMER_ALREADY_EXIST));
- return res;
- }
- //添加 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
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDD);
- fur.setFollowDate(format.parse(cusIn.getFollowDates()));
- 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.getShareType()));
- c.setCustomerType(Integer.parseInt(cusIn.getCustomerType()));
- c.setId(customerId);
-
- customerService.addCustomer(c);
- //插入 customerUserInfo
- customerUserService.addCustomerUserInfo(cui);
- //插入 customerOrganizationInfo
- customerOrganizationService.addCustomerOrganizationInfo(coi);
- //插入跟进表
- followUpService.addFollowUp(fur);
- //添加日志
- customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_CREATE,customerId);
- return res;
- }
-
-
- /**
- * 删除
- *
- * @return
- * @throws ParseException
- */
- @RequestMapping(value = "/deleteCustomer", method = RequestMethod.POST)
- public Result deleteCustomer(CustomerIn cusIn) throws ParseException {
- Result res=new Result();
- customerService.deleteCustomer(cusIn.getId());
- customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_DELETE,cusIn.getId());
- 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 pageNo){
- Result res = new Result();
- Pagination<CustomerOut> boList = customerService.getPrivateCustomer(cin, pageSize, pageNo);
- res.setData(boList);
- return res;
- }
-
-
- /**
- * 查询客户详情
- *
- * @return
- */
- @RequestMapping(value = "/findCustomerDetails", method = RequestMethod.POST)
- public Result findCustomerDetails(String id) {
- Result res=new Result();
- res.setData(customerService.findCustomerDetails(id));
- return res;
- }
-
- /**
- * 查询公司客户资料
- *
- * @return
- */
- @RequestMapping(value = "/findAllCustomerDetails", method = RequestMethod.POST)
- public Result findAllCustomerDetails(String id) {
- Result res=new Result();
- res.setData(customerService.findCustomerDetails(id));
- return res;
- }
-
- /**
- * 查询联系人姓名列表
- *
- * @return
- */
- @RequestMapping(value = "/findCustomerUserList", method = RequestMethod.POST)
- public Result findCustomerUserList (String cid) {
- Result res =new Result();
- res.setData(customerUserService.selectCustomerUserList(cid));
- return res;
- }
-
- /**
- * 添加联系人
- *
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/addContacter", method = RequestMethod.POST)
- public Result addContacter (CustomerUserInfo cui) throws IllegalAccessException, InvocationTargetException {
- Result res =new Result();
- cui.setId(UUID.randomUUID().toString());
- if(cui.getPrimaryFlg()==0) {//0:主要联系人,1-非主要联系人
- String primaryId = customerUserService.selectPrimaryFlgByCid(cui.getCid());
- if(StringUtils.isNoneBlank(primaryId)) {
- customerUserService.updatePrimaryFlg(primaryId);//把主要联系人状态给去掉
- }
- customerUserService.addCustomerUserInfo(cui);//再添加联系人
- }else {
- customerUserService.addCustomerUserInfo(cui);
- }
- return res;
- }
-
-
- /**
- * 修改客户信息
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/updateCustomer", method = RequestMethod.POST)
- public Result updateCustomer (CustomerIn cusIn,CustomerOrganizationInfo coi,HttpServletResponse rsp) throws IllegalAccessException, InvocationTargetException {
- Result res=new Result();
- Customer c =new Customer();
- BeanUtils.copyProperties(c, cusIn);
- c.setCustomerType(Integer.parseInt(cusIn.getCustomerType()));
- coi.setCid(cusIn.getId());
- //更新主表
- customerService.updateCustomer(c);
- //更新公司表
- customerOrganizationService.updateCustomerOrganizationInfo(coi);
- //插入日志表
- customerService.saveCustomerLog(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();
- c.setId(cusIn.getId());
- c.setAid(cusIn.getAid());
- c.setCreateTime(new Date());
- //更新主表
- customerService.updateCustomer(c);
- //插入日志表
- customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_TRANSFER,cusIn.getId());
- return res;
- }
-
- /**
- * 查询单个联系人信息
- * @return
- */
- @RequestMapping(value = "/findContactDetail", method = RequestMethod.GET)
- public Result findContactDetail (String contactId) {
- Result res=new Result();
- res.setData(customerUserService.findContactDetail(contactId));
- return res;
- }
-
- /**
- * 修改联系人信息
- * @return
- */
- @RequestMapping(value = "/updateContacter", method = RequestMethod.POST)
- public Result updateContacter (CustomerUserInfo cui) {
- Result res=new Result();
- if(cui.getPrimaryFlg() == 0){
- String primaryId = customerUserService.selectPrimaryFlgByCid(cui.getCid());
- if(StringUtils.isNoneBlank(primaryId)) {
- customerUserService.updatePrimaryFlg(primaryId);//把主要联系人状态给去掉
- }
- }
- customerUserService.updateContractById(cui);
- return res;
- }
-
- /**
- * 添加跟进记录
- * @param fur
- * @return
- * @throws ParseException
- */
- @RequestMapping(value = "/addFollowUpRecord", method = RequestMethod.POST)
- public Result addFollowUpRecord(FollowUpRecord fur, CustomerIn cusIn) throws ParseException{
- Result res = new Result();
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
- if(StringUtils.isNotBlank(cusIn.getFollowDates())) fur.setFollowDate(format.parse(cusIn.getFollowDates()));
- String followId = UUID.randomUUID().toString();
- fur.setId(followId);
- fur.setCid(cusIn.getId());
- fur.setEffective(0);
- cusIn.setFollowId(followId);
- followUpService.addFollowUp(fur);
- 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);
- customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_FOLLOW,cusIn.getId());
- 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;
- }
- /**
- * 查看公司客户跟进记录
- * @param customerId
- * @return
- */
- @RequestMapping(value = "/listAllFollowUpRecord" , method = RequestMethod.GET)
- public Result listAllFollowUpRecord(String customerId){
- Result res= new Result();
- res.setData(followUpService.listFollowUpRecord(customerId));
- return res;
- }
-
- /**
- * 删除联系人
- * @param customerId
- * @return
- */
- @RequestMapping(value = "/deleteContacter" , method = RequestMethod.GET)
- public Result deleteContacter(String contactId){
- Result res= new Result();
- CustomerUserInfo customerUserInfo = customerUserService.findContractById(contactId);
- if(customerUserInfo.getPrimaryFlg()==0) {
- res.getError().add(new Error("该联系人为主要联系人,不能进行删除操作!"));
- }else {
- customerUserService.deleteContractById(contactId);
- }
- return res;
- }
-
- /**
- * 营销员填写跟进记录上传文件
- * @param req
- * @param sign
- * @return
- */
- @RequestMapping(value = "/attachmentUpload" , method = RequestMethod.POST)
- public Result attachmentUpload(HttpServletRequest req, String sign){
- Result res= new Result();
- res.setData(handleFile(res, "/customer_sys_file/", true, req, sign));
- return res;
- }
-
- /**
- * 删除跟进记录
- * @param followId
- * @return
- */
- @RequestMapping(value = "/deleteFollowUpRecord", method = RequestMethod.GET)
- public Result deleteFollowUpRecord(String followId){
- Result res= new Result();
- followUpService.deleteFollowUpRecord(followId);
- return res;
- }
-
- /**
- * 查看公共客户
- * @param request
- * @return
- */
- @RequestMapping(value = "/listPublicCustomer", method = RequestMethod.POST)
- public Result listPublicCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
- Result res = new Result();
- Pagination<CustomerOut> boList = customerService.getPublicCustomer(cin, pageSize, pageNo);
- res.setData(boList);
- return res;
- }
-
- /**
- * 领取
- * @param cusIn
- * @return
- * @throws IllegalAccessException
- * @throws InvocationTargetException
- */
- @RequestMapping(value = "/receivePublicCustomer", method = RequestMethod.GET)
- public Result receivePublicCustomer(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException{
- Result res=new Result();
- Customer c =new Customer();
- c.setId(cusIn.getId());
- c.setAid(TokenManager.getAdminId());
- c.setShareType(0);
- //更新主表
- customerService.updateCustomer(c);
- //插入日志表
- customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_RECEIVE,cusIn.getId());
- return res;
- }
-
- /**
- * 查看公共客户
- * @param request
- * @return
- */
- @RequestMapping(value = "/listTeamCustomer", method = RequestMethod.POST)
- public Result listTeamCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
- Result res = new Result();
- Pagination<CustomerOut> boList = customerService.getTeamCustomer(cin, pageSize, pageNo);
- res.setData(boList);
- return res;
- }
-
- /**
- * 转为公共客户
- * @return
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- */
- @RequestMapping(value = "/transferToPublic" , method = RequestMethod.POST)
- public Result transferToPublic(CustomerIn cusIn) throws IllegalAccessException, InvocationTargetException{
- Result res=new Result();
- Customer c = new Customer();
- c.setId(cusIn.getId());
- c.setAid("");
- c.setShareType(1);
- c.setCreateTime(new Date());
- //更新主表
- customerService.updateCustomer(c);
- //插入日志表
- customerService.saveCustomerLog(cusIn, AFTConstants.CUSTOMER_TO_PUBLIC,cusIn.getId());
- return res;
- }
-
- /**
- * 查看公司客户
- * @param request
- * @return
- */
- @RequestMapping(value = "/listCompanyCustomer", method = RequestMethod.POST)
- public Result listCompanyCustomer(HttpServletRequest request,CustomerIn cin,Integer pageSize, Integer pageNo){
- Result res = new Result();
- Pagination<CustomerOut> boList = customerService.getCompanyCustomer(cin, pageSize, pageNo);
- res.setData(boList);
- return res;
- }
- /**
- * 查看日志信息
- * @param customerId
- * @return
- */
- @RequestMapping(value = "/listCustomerLog",method = RequestMethod.GET)
- public Result listCustomerLog(String customerId){
- Result res = new Result();
- res.setData(customerService.listCustomerLog(customerId));
- return res;
- }
-
- /**
- * 客户详情-操作记录
- * @return
- */
- @RequestMapping(value = "/findCustomerHistory",method = RequestMethod.GET)
- public Result findCustomerHistory(String customerId){
- Result res = new Result();
- res.setData(customerService.findCustomerHistory(customerId));
- return res;
- }
- }
|