| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- package com.goafanti.customer.controller;
- import java.lang.reflect.InvocationTargetException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.annotation.Resource;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.controller.BaseController;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.OrganizationContactBook;
- import com.goafanti.common.model.User;
- import com.goafanti.common.model.UserBusiness;
- import com.goafanti.common.utils.BeanUtilsExt;
- import com.goafanti.common.utils.StringUtils;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.customer.bo.CustomerListIn;
- import com.goafanti.customer.bo.CustomerOrganizationDetailBo;
- import com.goafanti.customer.bo.FollowBusinessBo;
- import com.goafanti.customer.bo.UserDetailBo;
- import com.goafanti.customer.service.BusinessService;
- import com.goafanti.customer.service.CustomerService;
- @RestController
- @RequestMapping("api/admin/customer")
- public class CustomerApiController extends BaseController{
- @Resource
- private CustomerService customerService;
- @Resource
- private BusinessService businessService;
- /** 私有个人客户列表 **/
- @RequestMapping(value = "/listPrivatePersonalCustomer" , method = RequestMethod.POST)
- public Result listPrivatePersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(customerService.listPrivatePersonalCustomer(cli, pageNo, pageSize));
- return res;
- }
-
- /** 公共个人客户列表 **/
- @RequestMapping(value = "/listPublicPersonalCustomer" , method = RequestMethod.POST)
- public Result listPublicPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(customerService.listPublicPersonalCustomer(cli, pageNo, pageSize));
- return res;
- }
- /** 个人客户查询 **/
- @RequestMapping(value = "/listAllPersonalCustomer" , method = RequestMethod.POST)
- public Result listAllPersonalCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(customerService.listAllPersonalCustomer(cli, pageNo, pageSize));
- return res;
- }
-
- /** 私有单位客户列表 **/
- @RequestMapping(value = "/listPrivateOrganizationCustomer" , method = RequestMethod.POST)
- public Result listPrivateOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(customerService.listPrivateOrganizationCustomer(cli, pageNo, pageSize));
- return res;
- }
-
- /** 公共单位客户列表 **/
- @RequestMapping(value = "/listPublicOrganizationCustomer" , method = RequestMethod.POST)
- public Result listPublicOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(customerService.listPublicOrganizationCustomer(cli, pageNo, pageSize));
- return res;
- }
- /** 单位客户查询 **/
- @RequestMapping(value = "/listAllOrganizationCustomer" , method = RequestMethod.POST)
- public Result listAllOrganizationCustomer(CustomerListIn cli,Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(customerService.listAllOrganizationCustomer(cli, pageNo, pageSize));
- return res;
- }
-
-
- /** 客户即时检索 **/
- @RequestMapping(value = "/findCustomerByName",method = RequestMethod.GET)
- public Result findCustomerByName(String name){
- Result res = new Result();
- res.setData(customerService.findCustomerByName(name));
- return res;
- }
-
- /** 添加客户基本信息
- * @throws Exception
- * @throws NumberFormatException **/
- @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
- public Result addCustomer(String name,String contacts,String contactMobile,String type) throws Exception{
- Result res = new Result();
- customerService.addCustomer(name, contacts, contactMobile, Integer.parseInt(type));
- return res;
- }
-
- /** 个人客户详情信息 **/
- @RequestMapping(value = "/findPersonalCustomerDetail" ,method = RequestMethod.GET)
- public Result findPersonalCustomerDetail(String uid){
- Result res = new Result();
- res.setData(customerService.findPersonalCustomerDetail(uid));
- return res;
- }
-
- /** 单位客户详情信息 **/
- @RequestMapping(value = "/findOrganizationCustomerDetail", method = RequestMethod.GET)
- public Result findOrganizationCustomerDetail(String uid){
- Result res = new Result();
- res.setData(customerService.findOrganizationCustomerDetail(uid));
- return res;
- }
-
- /** 修改单位客户信息 **/
- @RequestMapping(value = "/updateOrganizationCustomer", method = RequestMethod.POST)
- public Result updateOrganizationCustomer(CustomerOrganizationDetailBo bo){
- Result res = new Result();
- if(StringUtils.isBlank(bo.getId()) || StringUtils.isBlank(bo.getUid())){
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR,""));
- return res;
- }
- customerService.updateOrganizationCustomer(bo);
- return res;
- }
-
- /** 查看跟进记录 **/
- @RequestMapping(value = "/listFollowHistory", method = RequestMethod.GET)
- public Result listFollowHistory(Integer pageNo, Integer pageSize,String uid,String businessGlossoryId){
- Result res = new Result();
- res.setData(customerService.listFollowHistory(pageNo,pageSize,uid,businessGlossoryId));
- return res;
- }
-
- /** 查看客户账户信息 **/
- @RequestMapping(value = "/findUserAccountDetail", method = RequestMethod.GET)
- public Result findUserAcountDetail(String uid){
- Result res = new Result();
- UserDetailBo bo = new UserDetailBo();
- User user = customerService.findUserAccountDetail(uid);
- try {
- BeanUtilsExt.copyProperties(bo, user);
- } catch (InvocationTargetException | IllegalAccessException e) {
- e.printStackTrace();
- }
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
- bo.setCreateTimes(format.format(user.getCreateTime()));
- res.setData(bo);
- return res;
- }
-
- /** 修改客户账户信息 **/
- @RequestMapping(value = "/updateUserAccount", method = RequestMethod.POST)
- public Result updateUserAccount(User user){
- Result res = new Result();
- customerService.updateUserAccount(user);
- return res;
- }
- /** 查看客户联系人列表 **/
- @RequestMapping(value = "/findCustomerContacts", method = RequestMethod.GET)
- public Result findCustomerContacts(String uid){
- Result res = new Result();
- res.setData(customerService.findCustomerContacts(uid));
- return res;
- }
-
- /** 进入添加拜访记录 **/
- @RequestMapping(value = "/toAddFollow", method = RequestMethod.GET)
- public Result toAddFollow(String uid){
- Result res = new Result();
- if(StringUtils.isBlank(uid)){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,""));
- return res;
- }
- User user = customerService.findUserAccountDetail(uid);
- FollowBusinessBo fbb = new FollowBusinessBo();
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
- fbb.setFollowTime(format.format(new Date()));
- fbb.setIdentityName(user.getIdentifyName());
- fbb.setUid(uid);
- fbb.setUserBusinessList(businessService.findBusinessByUAid(uid, TokenManager.getAdminId()));
- res.setData(fbb);
- return res;
- }
-
- /** 添加拜访记录
- * @throws ParseException
- * @throws Exception **/
- @RequestMapping(value = "/addFollow", method = RequestMethod.POST)
- public Result addFollow(String userBusinessList,String uid,String ocbId,String contactType,String result,String followTime) throws BusinessException{
- Result res = new Result();
- if(StringUtils.isBlank(uid) || StringUtils.isBlank(ocbId)){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
- return res;
- }
- JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
- List<UserBusiness> list = new ArrayList<UserBusiness>();
- if (ja != null && !ja.isEmpty()) {
- UserBusiness userBusiness = null;
- for (int idx = 0; idx < ja.size(); idx++) {
- userBusiness = ja.getJSONObject(idx).toJavaObject(UserBusiness.class);
- for(UserBusiness ub:list){
- if(ub.getBusinessGlossoryId() == userBusiness.getBusinessGlossoryId()){
- res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
- return res;
- }
- }
- list.add(userBusiness);
- }
- }
- FollowBusinessBo fbb = new FollowBusinessBo();
- fbb.setOcbId(ocbId);
- fbb.setUid(uid);
- fbb.setContactType(contactType);
- fbb.setResult(result);
- fbb.setFollowTime(followTime);
- fbb.setUserBusinessList(list);
- customerService.addFollow(fbb);
- return res;
- }
-
- /** 进入修改拜访记录 **/
- @RequestMapping(value = "/toUpdateFollow", method = RequestMethod.GET)
- public Result toUpdateFollow(String followId){
- Result res = new Result();
- FollowBusinessBo fbb = customerService.findFollowById(followId);
- fbb.setUserBusinessList(customerService.findBusinessByFollowId(followId));
- res.setData(fbb);
- return res;
- }
-
- /** 修改拜访记录
- * @throws ParseException
- * @throws BusinessException
- */
- @RequestMapping(value = "/updateFollow", method = RequestMethod.POST)
- public Result updateFollow(String userBusinessList,String followId,String followTime,String uid,String contactType,String result) throws BusinessException{
- Result res = new Result();
- if(StringUtils.isBlank(uid) || StringUtils.isBlank(followId)){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
- return res;
- }
- JSONArray ja = (JSONArray) JSON.parse(userBusinessList);
- List<UserBusiness> list = new ArrayList<UserBusiness>();
- if (ja != null && !ja.isEmpty()) {
- UserBusiness userBusiness = null;
- for (int idx = 0; idx < ja.size(); idx++) {
- userBusiness = ja.getJSONObject(idx).toJavaObject(UserBusiness.class);
- for(UserBusiness ub:list){
- if(ub.getBusinessGlossoryId() == userBusiness.getBusinessGlossoryId()){
- res.getError().add(new com.goafanti.common.bo.Error("业务类型重复,请检查后重新提交!"));
- return res;
- }
- }
- list.add(userBusiness);
- }
- }
- FollowBusinessBo fbb = new FollowBusinessBo();
- fbb.setFollowTime(followTime);
- fbb.setUid(uid);
- fbb.setContactType(contactType);
- fbb.setResult(result);
- fbb.setUserBusinessList(list);
- fbb.setFollowId(followId);
- customerService.updateFollow(fbb);
- return res;
- }
-
- /** 查询客户的所有联系人 **/
- @RequestMapping(value = "/findAllContacts", method = RequestMethod.GET)
- public Result findAllContacts(String uid){
- Result res = new Result();
- res.setData(customerService.findAllContacts(uid));
- return res;
- }
-
- /** 修改企业联系人 **/
- @RequestMapping(value = "/updateCustomerContacts", method = RequestMethod.POST)
- public Result updateCustomerContacts(String contactList,String uid){
- Result res = new Result();
- if(StringUtils.isBlank(uid)){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, ""));
- return res;
- }
- JSONArray ja = (JSONArray) JSON.parse(contactList);
- List<OrganizationContactBook> ocbList = new ArrayList<OrganizationContactBook>();
- OrganizationContactBook ocb = null;
- if(ja != null & !ja.isEmpty()){
- for (int idx = 0; idx < ja.size(); idx++) {
- ocb = ja.getJSONObject(idx).toJavaObject(OrganizationContactBook.class);
- if(StringUtils.isBlank(ocb.getMobile()) || StringUtils.isBlank(ocb.getName())){
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "用户名和手机号码为必填"));
- return res;
- }
- if(StringUtils.isBlank(ocb.getUid())) ocb.setUid(uid);
- ocbList.add(ocb);
- }
- }
- customerService.updateCustomerContacts(ocbList,uid);
- return res;
- }
- }
|