package com.goafanti.customer.service.impl; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.goafanti.common.constant.AFTConstants; import com.goafanti.common.dao.UserBusinessMapper; import com.goafanti.common.dao.UserFollowBusinessMapper; import com.goafanti.common.dao.UserFollowMapper; import com.goafanti.common.model.UserBusiness; import com.goafanti.common.model.UserFollow; import com.goafanti.common.model.UserFollowBusiness; import com.goafanti.common.utils.StringUtils; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.customer.bo.BusinessListBo; import com.goafanti.customer.bo.BussinessFollowBo; import com.goafanti.customer.service.BusinessService; @Service public class BusinessServiceImpl extends BaseMybatisDao implements BusinessService { @Autowired private UserBusinessMapper userBusinessMapper; @Autowired private UserFollowMapper userFollowMapper; @Autowired private UserFollowBusinessMapper userFollowBusinessMapper; @SuppressWarnings("unchecked") @Override public Pagination listBusiness(BusinessListBo blo,Integer pageNo,Integer pageSize) { blo.setAid(TokenManager.getAdminId()); return (Pagination) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo), pageNo, pageSize); } private Map disposeParams(BusinessListBo blo){ Map params = new HashMap(); if(StringUtils.isNotBlank(blo.getAid())) params.put("aid", blo.getAid()); if(StringUtils.isNotBlank(blo.getAdminName())) params.put("adminName", blo.getAdminName()); if(StringUtils.isNotBlank(blo.getBusinessId())) params.put("businessId", blo.getBusinessId()); if(StringUtils.isNotBlank(blo.getStartDate())) params.put("startDate", blo.getStartDate()+" 00:00:00"); if(StringUtils.isNotBlank(blo.getEndDate())) params.put("endDate", blo.getEndDate()+ " 23:59:59"); if(StringUtils.isNotBlank(blo.getIdentifyName())) params.put("identity", blo.getIdentifyName()); if(StringUtils.isNoneBlank(blo.getFollowSituation())) params.put("followSituation", blo.getFollowSituation()); if(StringUtils.isNotBlank(blo.getCustomerStatus())) params.put("customerStatus", blo.getCustomerStatus()); return params; } @Override public List findBusinessGlossory() { return userBusinessMapper.findBusinessGlossory(); } @Override public int judgeBusiness(String uid, Integer businessGlossoryId) { return userBusinessMapper.judgeBusiness(uid,businessGlossoryId,""); } @Override @Transactional public void addBusinessAndFollow(BussinessFollowBo bfb) throws ParseException { UserBusiness ub = new UserBusiness(); String ubId = UUID.randomUUID().toString(); SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS); ub.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); ub.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); ub.setId(ubId); ub.setUid(bfb.getUid()); ub.setAid(TokenManager.getAdminId()); ub.setRemarks(bfb.getRemarks()); ub.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId())); ub.setUpdateTime(format.parse(bfb.getCreateTime())); ub.setCreateTime(format.parse(bfb.getCreateTime())); userBusinessMapper.insert(ub); if (StringUtils.isNotBlank(bfb.getOcbId())) { // 跟进联系人不为空则添加跟进记录 UserFollow uf = new UserFollow(); String ufId = UUID.randomUUID().toString(); uf.setId(ufId); uf.setUid(bfb.getUid()); uf.setCreateTime(format.parse(bfb.getFollowTime())); uf.setOcbId(bfb.getOcbId()); uf.setResult(bfb.getResult()); uf.setContactType(Integer.parseInt(bfb.getContactType())); uf.setAid(TokenManager.getAdminId()); uf.setEffective(0); int followCount = userBusinessMapper.judgeBusiness(bfb.getUid(), null, TokenManager.getAdminId()) + 1; uf.setFollowCount(followCount); userFollowMapper.insert(uf); UserFollowBusiness ufb = new UserFollowBusiness(); ufb.setId(UUID.randomUUID().toString()); ufb.setBusinessId(ubId); ufb.setFollowId(ufId); ufb.setCustomerStatus(ub.getCustomerStatus()); ufb.setFollowSituation(ub.getFollowSituation()); userFollowBusinessMapper.insert(ufb); } } @Override public List findBusinessByUAid(String uid, String aid) { return userBusinessMapper.findBusinessByUAid(uid,aid); } @Override public BussinessFollowBo findBusinessDetail(String businessId) { return userBusinessMapper.findBusinessDetail(businessId); } @Override public int updateBusiness(BussinessFollowBo bfb) { UserBusiness userBusiness = new UserBusiness(); userBusiness.setId(bfb.getBusinessId()); userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userBusiness.setRemarks(bfb.getRemarks()); userBusiness.setUpdateTime(new Date()); userBusinessMapper.updateByPrimaryKeySelective(userBusiness); return 1; } @Override @Transactional public int followOneBusiness(BussinessFollowBo bfb) throws ParseException { Date updateTime = new Date(); SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS); UserBusiness userBusiness = new UserBusiness(); userBusiness.setId(bfb.getBusinessId()); userBusiness.setUpdateTime(updateTime); userBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userBusinessMapper.updateByPrimaryKeySelective(userBusiness); UserFollow userFollow = new UserFollow(); String followId = UUID.randomUUID().toString(); int followCount = userBusinessMapper.judgeBusiness(bfb.getUid(), null, TokenManager.getAdminId()) + 1; userFollow.setId(followId); userFollow.setResult(bfb.getResult()); userFollow.setCreateTime(format.parse(bfb.getFollowTime())); userFollow.setEffective(0); userFollow.setOcbId(bfb.getOcbId()); userFollow.setFollowCount(followCount); userFollow.setContactType(Integer.parseInt(bfb.getContactType())); userFollow.setAid(TokenManager.getAdminId()); userFollowMapper.insert(userFollow); UserFollowBusiness userFollowBusiness = new UserFollowBusiness(); String ufbId = UUID.randomUUID().toString(); userFollowBusiness.setId(ufbId); userFollowBusiness.setFollowId(followId); userFollowBusiness.setBusinessGlossoryId(Integer.parseInt(bfb.getBusinessGlossoryId())); userFollowBusiness.setBusinessId(bfb.getBusinessId()); userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus())); userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation())); userFollowBusiness.setRemarks(bfb.getRemarks()); userFollowBusinessMapper.insert(userFollowBusiness); return 1; } }