package com.goafanti.customer.controller; import java.lang.reflect.InvocationTargetException; import java.text.ParseException; 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.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.Admin; 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 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); 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 fur.setAid(TokenManager.getUserId()); /*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 ParseException */ @RequestMapping(value = "/findAdmin", method = RequestMethod.POST) public Result selectAllAdmin() throws ParseException { Result res = new Result(); List selectAllAdmin = adminService.selectAllAdmin(); res.setData(selectAllAdmin); 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 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 = "/transferCsutomer", method = RequestMethod.POST) public Result transferCsutomer (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; } }