| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157 |
- package com.goafanti.customer.service.impl;
- import com.goafanti.admin.bo.AdminListBo;
- import com.goafanti.common.bo.Error;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.bo.userDaysBo;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.dao.*;
- import com.goafanti.common.enums.*;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.*;
- import com.goafanti.common.utils.*;
- import com.goafanti.common.utils.excel.NewExcelUtil;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.core.websocket.SystemWebSocketHandler;
- import com.goafanti.customer.bo.*;
- import com.goafanti.customer.service.CustomerService;
- import com.goafanti.order.bo.TOrderNewBo;
- import com.goafanti.user.bo.OutUserChannel;
- import org.apache.commons.beanutils.BeanUtils;
- import org.apache.commons.beanutils.PropertyUtils;
- import org.apache.ibatis.builder.BuilderException;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.socket.TextMessage;
- import javax.annotation.Resource;
- import java.lang.reflect.InvocationTargetException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- @Service
- public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements CustomerService {
- @Autowired
- private UserMapper userMapper;
- @Autowired
- private UserIdentityMapper userIdentityMapper;
- @Autowired
- private OrganizationIdentityMapper organizationIdentityMapper;
- @Autowired
- private OrganizationContactBookMapper organizationContactBookMapper;
- @Resource(name = "passwordUtil")
- private PasswordUtil passwordUtil;
- @Value(value = "${user_remind_days}")
- private Integer USER_REMIND_DAYS = null;
- @Value(value = "${user_channel_days}")
- private Integer USER_CHANNEL_DAYS= null;
- @Value(value = "${user.receive.max}")
- private Integer USER_RECEIVE_MAX = null;
- @Value(value = "${yxzj_max}")
- private Integer YXZJ_MAX = null;
- @Value(value = "${yxy_max}")
- private Integer YXY_MAX = null;
- @Value(value = "${yxjl_max}")
- private Integer YXJL_MAX = null;
- @Resource
- private UserFollowMapper userFollowMapper;
- @Resource
- private UserBusinessMapper userBusinessMapper;
- @Resource
- private UserFollowBusinessMapper userFollowBusinessMapper;
- @Resource
- private BusinessProjectMapper businessProjectMapper;
- @Resource
- private UserLockReleaseMapper userLockReleaseMapper;
- @Resource
- private AdminMapper adminMapper;
- @Resource
- private OrganizationApplicationInfoMapper organizationApplicationInfoMapper;
- @Resource
- private OrganizationAnnualReportMapper organizationAnnualReportMapper;
- @Resource
- private OrganizationBusinessScopeMapper organizationBusinessScopeMapper;
- @Resource
- private OrganizationSalesTargetMapper organizationSalesTargetMapper;
- @Resource
- private UserTransferLogMapper userTransferLogMapper;
- @Resource
- private UserChannelMapper userChannelMapper;
- @Resource
- private UserNamesMapper userNamesMapper;
- @Resource
- private UserMidMapper userMidMapper;
- @Resource
- private UserDataLogMapper userDataLogMapper;
- @Resource
- private TOrderNewMapper tOrderNewMapper;
- @Resource
- private TOrderMidMapper tOrderMidMapper;
- @Resource
- private TOrderLogMapper tOrderLogMapper;
- @Resource
- private PublicExamineMapper publicExamineMapper;
- @Resource
- private PublicReleaseLogMapper publicReleaseLogMapper;
- @Resource
- private PublicReleaseMapper publicReleaseMapper;
- @Autowired
- private SystemWebSocketHandler systemWebSocketHandler;
- @Autowired
- private AdminUserCountMapper adminUserCountMapper;
- @Autowired
- private RestrictProjectMapper restProjectMapper;
- @Autowired
- private AsyncUtils asyncUtils;
- @Value(value = "${upload.path}")
- private String uploadPath = null;
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listPrivatePersonalCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- cli.setAid(TokenManager.getAdminId());
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPrivatePersonalCustomerList",
- "selectPrivatePersonalCustomerCount", params, pageNo, pageSize);
- List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
- setCustomerList(tmpList, 0, null);
- list.setList(tmpList);
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listPublicPersonalCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPublicPersonalCustomerList",
- "selectPublicPersonalCustomerCount", params, pageNo, pageSize);
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listAllPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectPersonalCustomerList",
- "selectPersonalCustomerCount", params, pageNo, pageSize);
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listAllManagePersonalCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_PERSONAL);
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectManagePersonalCustomerList",
- "selectManagePersonalCustomerCount", params, pageNo, pageSize);
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listPrivateOrganizationCustomer(CustomerListIn cli, Integer sort,
- Integer sortType, Integer power, Integer pageNo, Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setAid(TokenManager.getAdminId());
- // cli.setAid("1");
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
- Map<String, Object> params = disposeParams(cli);
- params.put("sort", sort);
- params.put("sortType", sortType);
- List<String> alist = new ArrayList<>();
- if (power == 0 || TokenManager.hasRole(AFTConstants.SALESMAN)) {
- params.put("power", 0);
- } else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)) {
- params.put("power", 1);
- alist = adminMapper.selectBySuperId(cli.getAid());
- } else if (TokenManager.hasRole(AFTConstants.SALESMAN_DIRECTOR)) {
- params.put("power", 2);
- alist = adminMapper.selectBySuperId(cli.getAid());
- List<String> alist2 = new ArrayList<>();
- if (!alist.isEmpty()) {
- for (String string : alist) {
- alist2.addAll(adminMapper.selectBySuperId(string));
- }
- alist.addAll(alist2);
- }
- } else if (TokenManager.hasRole(AFTConstants.CED)) {
- params.put("power", 3);
- }
- params.put("alist", alist);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage(
- "selectPrivateOrganizationCustomerList", "selectPrivateOrganizationCustomerCount", params, pageNo,
- pageSize);
- List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
- if(!tmpList.isEmpty()){
- setCustomerList(tmpList, 0, power);
- list.setList(tmpList);
- }
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listPublicOrganizationCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PUBLIC));
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> p = (Pagination<CustomerListOut>) findPage("selectPublicOrganizationCustomerList",
- "selectPublicOrganizationCustomerCount", params, pageNo, pageSize);
- return p;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listAllOrganizationCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- String name=null;
- String orgCode=null;
- if (StringUtils.isContainChinese(cli.getName())){
- name= cli.getName();
- }else {
- orgCode= cli.getName();
- cli.setName(null);
- }
- Map<String, Object> params = disposeParams(cli);
- if (TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)) {
- params.put("role", 1);
- if (name!=null)params.put("name",name);
- else params.put("orgCode",orgCode);
- } else {
- //处理为空报错
- params.put("role", 0);
- if (orgCode!=null) {
- params.put("orgCode",orgCode);
- }else {
- String [] names =pushNames(name);
- if (names.length>0){
- params.put("names", names);
- }else {
- return new Pagination<>();
- }
- }
- }
- Pagination<CustomerListOut> p = (Pagination<CustomerListOut>) findPage("selectOrganizationCustomerList",
- "selectOrganizationCustomerCount", params, pageNo, pageSize);
- List<CustomerListOut> l = (List<CustomerListOut>) p.getList();
- for (CustomerListOut c : l) {
- if (null != c) {
- if (null != c.getAid())
- c.setAdminName(adminMapper.selectNameByid(c.getAid()));
- if (null != c.getShareType() && c.getShareType().equals("1"))
- c.setAdminName("暂无");
- if (null != c.getMid())
- c.setInformationMaintainer(adminMapper.selectNameByid(c.getMid()));
- }
- }
- return p;
- }
- private String[] pushNames(String name) {
- if (name==null)name="";
- String newstr1=name.replaceAll(" ",","); //先把所有空格替换成 逗号。
- String newstr2=newstr1.replaceAll("\t",","); //再把所有的制表符替换成逗号。
- String newstr3=newstr2.replaceAll(",+", ","); //把所有重复的逗号合并成一个逗号。
- String[] strings=newstr3.split(","); //按逗号分解该字符串。
- return strings;
- }
- @Override
- public Pagination<CustomerListOut> listAllManageOrganizationCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
- cli.setAid(TokenManager.getAdminId());
- Map<String, Object> params = disposeParams(cli);
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage(
- "selectManageOrganizationCustomerList", "selectManageOrganizationCustomerCount", params, pageNo,
- pageSize);
- return list;
- }
- private Map<String, Object> disposeParams(CustomerListIn cli) {
- Map<String, Object> params = new HashMap<String, Object>();
- if (StringUtils.isNotBlank(cli.getType()))
- params.put("type", Integer.parseInt(cli.getType()));
- if (StringUtils.isNotBlank(cli.getName()))
- params.put("name", cli.getName());
- if (StringUtils.isNotBlank(cli.getProvince()))
- params.put("province", Integer.parseInt(cli.getProvince()));
- if (StringUtils.isNotBlank(cli.getCity()))
- params.put("city", Integer.parseInt(cli.getCity()));
- if (StringUtils.isNotBlank(cli.getArea()))
- params.put("area", Integer.parseInt(cli.getArea()));
- if (StringUtils.isNotBlank(cli.getStartDate()))
- params.put("startDate", cli.getStartDate());
- if (StringUtils.isNotBlank(cli.getEndDate()))
- params.put("endDate", cli.getEndDate()+" 23:59:59");
- if (StringUtils.isNotBlank(cli.getIndustry()))
- params.put("industry", Integer.parseInt(cli.getIndustry()));
- if (StringUtils.isNotBlank(cli.getAid()))
- params.put("aid", cli.getAid());
- if (StringUtils.isNotBlank(cli.getDepartmentId()))
- params.put("departmentId", cli.getDepartmentId());
- if (StringUtils.isNotBlank(cli.getStatus()))
- params.put("status", Integer.parseInt(cli.getStatus()));
- if (StringUtils.isNotBlank(cli.getSocietyTag()))
- params.put("societyTag", cli.getSocietyTag());
- if (StringUtils.isNotBlank(cli.getFollow()))
- params.put("follow", cli.getFollow());
- if (null != cli.getDataGrade())
- params.put("dataGrade", cli.getDataGrade());
- if (null != cli.getLevel())
- params.put("level", cli.getLevel());
- if (null != cli.getSort())
- params.put("sort", cli.getSort());
- if (null != cli.getChannel())
- params.put("channel", cli.getChannel());
- if (null != cli.getBusinessScope())
- params.put("businessScope", cli.getBusinessScope());
- return params;
- }
- @Override
- public List<CustomerSimpleBo> findCustomerByName(String name) {
- return userMapper.findCustomerByName(name);
- }
- @Override
- public int judgeCustomerByName(String name) {
- return userMapper.judgeCustomerByName(name);
- }
- @Override
- @Transactional
- public int addCustomer(InputAddCustomer in) throws BusinessException {
- User user = new User();
- Date now = new Date();
- String aid=TokenManager.getAdminId();
- String uid = UUID.randomUUID().toString();
- String identifyId = UUID.randomUUID().toString();
- user.setId(uid);
- user.setSource(1);// 客户来源为录入
- user.setIdentifyName(in.getName());
- user.setNickname(in.getName());
- user.setUsername(in.getName());
- user.setStatus(AFTConstants.USER_STATUS_NORMAL);
- user.setShareType(in.getShareType());
- user.setAid(TokenManager.getAdminId());
- // user.setAid("1");
- user.setType(in.getType());
- user.setLvl(UserLevel.CERTIFIED.getCode());
- user.setSocietyTag(in.getSocietyTag());
- user.setCreateTime(now);
- user.setTransferTime(now);
- user.setUpdateTime(now);
- user.setSignBills(0);
- user.setNewChannel(0);
- if(StringUtils.isNotBlank(in.getIntroduction()))user.setIntroduction(in.getIntroduction());
- user.setMobile(in.getContactMobile());
- user.setPassword(AFTConstants.INITIALPASSWORD);
- user.setInformationMaintainer(TokenManager.getAdminId());
- double f = 0;
- user.setIntegrity(f);
- // user.setInformationMaintainer("1");
- if(in.getNewChannel()!=null)user.setNewChannel(in.getNewChannel());
- user.setChannel(0);
- passwordUtil.encryptPassword(user);
- String aname = adminMapper.selectByPrimaryKey(TokenManager.getAdminId()).getName();
- if (Objects.equals(in.getType(), UserType.PERSONAL.getCode())) {
- if (!userMapper.checkUser("", "", in.getContactMobile(), in.getType(), null, null).isEmpty())
- throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, in.getName(), ""));
- UserIdentity ui = new UserIdentity();
- ui.setId(identifyId);
- ui.setUid(uid);
- ui.setContacts(in.getContacts());
- ui.setContactMobile(in.getContactMobile());
- ui.setUsername(in.getName());
- ui.setProvince(in.getProvince());
- ui.setCity(in.getCity());
- ui.setArea(in.getArea());
- ui.setExpert(AFTConstants.NO);
- ui.setCelebrity(AFTConstants.NO);
- ui.setInternational(AFTConstants.NO);
- ui.setAuditStatus(IdentityProcess.SUCCESS.getCode());// 认证个人
- userIdentityMapper.insert(ui);
- } else if (Objects.equals(in.getType(), UserType.ORGANIZATION.getCode())) {
- checkUserName(in);
- UserMid um=new UserMid();
- um.setAid(user.getAid());
- um.setUid(uid);
- um.setChannelType(in.getChannelType());
- userMidMapper.insertSelective(um);
- // 创建企业认证信息
- OrganizationIdentity oi = new OrganizationIdentity();
- oi.setUnitName(in.getName());
- oi.setId(identifyId);
- oi.setUid(uid);
- oi.setOrgCode(in.getOrgCode());
- oi.setContacts(in.getContacts());
- oi.setContactMobile(in.getContactMobile());
- oi.setContactsPosition(in.getPosition());
- oi.setLocationProvince(in.getProvince());
- oi.setLocationCity(in.getCity());
- oi.setLocationArea(in.getArea());
- oi.setHighTechZone(AFTConstants.NO);
- oi.setInternational(AFTConstants.NO);
- oi.setListed(AFTConstants.NO);
- oi.setAuditStatus(IdentityProcess.SUCCESS.getCode()); // 实名企业
- oi.setBusinessScope(in.getBusinessScope());
- if(in.getBusinessScope()!=null){
- updateBusinessScope(uid,in.getBusinessScope(),null,now);
- }
- oi.setIntendedProject(in.getIntendedProject());
- // oi.setIndustry(in.getIndustry());
- organizationIdentityMapper.insert(oi);
- }
- userMapper.insertSelective(user);
- UserNames un=new UserNames();
- un.setUid(uid);
- un.setAid(aid);
- un.setName(user.getNickname());
- userNamesMapper.insertSelective(un);
- // 新增企业联系人
- OrganizationContactBook cob = new OrganizationContactBook();
- cob.setAid(TokenManager.getAdminId());
- cob.setAname(aname);
- cob.setId(UUID.randomUUID().toString());
- cob.setPosition(in.getPosition());
- cob.setUid(uid);
- cob.setName(in.getContacts());
- cob.setMobile(in.getContactMobile());
- cob.setMajor(AFTConstants.YES);
- organizationContactBookMapper.insert(cob);
- // 新增锁定数据
- boolean isUs = false;
- if (uid.contains(",")) {
- isUs = true;
- }
- List<String> uList = new ArrayList<>();
- if (isUs) {
- uList = Arrays.asList(uid.split(","));
- }
- addUserLock(uid, TokenManager.getAdminId(), now, uList);
- addUserTransferLog(uid, TokenManager.getAdminId(), null,0, null, now, uList);
- updateAdminUserCount(user.getAid(),user.getTransferTime());
- return 1;
- }
- /**
- *
- * @param aid 管理员编号
- * @param transferTime 客户转换时间
- */
- @Override
- public void updateAdminUserCount(String aid ,Date transferTime) {
- String startTime=DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
- String endTime=startTime+" 23:59:59";
- AdminUserCount adminUserCount=getAdminUserCount(aid,startTime);
- if (adminUserCount==null){
- AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
- if(selectAUC!=null) adminUserCountMapper.insertSelective(selectAUC);
- }else {
- AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
- AdminUserCount newAUC=new AdminUserCount();
- newAUC.setId(adminUserCount.getId());
- if (selectAUC==null){
- newAUC.setPrivateCount(0);
- newAUC.setChannelCount(0);
- newAUC.setSignCount(0);
- }else {
- if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
- if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
- if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
- newAUC.setPrivateCount(selectAUC.getPrivateCount());
- newAUC.setChannelCount(selectAUC.getChannelCount());
- newAUC.setSignCount(selectAUC.getSignCount());
- }
- adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
- }
- }
- /**
- * 用于处理异常多产生数据,删除多余数据修改原本数据
- * @param aid
- * @param startTime
- * @return
- */
- @Override
- public AdminUserCount getAdminUserCount(String aid, String startTime) {
- List<AdminUserCount> selectList = adminUserCountMapper.selectByaidAndDate(aid, startTime);
- AdminUserCount selectAUC=null;
- if(!selectList.isEmpty())selectAUC=selectList.get(0);
- if (selectList.size()>1){
- for (int i=1;i<selectList.size();i++){
- Integer id = selectList.get(i).getId();
- if(id!=null) adminUserCountMapper.deleteByPrimaryKey(id);
- }
- }
- return selectAUC;
- }
- private void checkUserName(InputAddCustomer in) {
- if (!userMapper.checkUser("", in.getName(), "", in.getType(), null, null).isEmpty())
- throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, in.getName(), ""));
- String name2=null;
- if (in.getName().contains("(")){
- name2=in.getName().replace("(","(").replace(")",")");
- }else if (in.getName().contains("(")){
- name2=in.getName().replace("(","(").replace(")",")");
- }
- if (name2!=null){
- if (!userMapper.checkUser("", name2, "", in.getType(), null, null).isEmpty())
- throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, name2, ""));
- }
- }
- @Override
- public CustomerPersonalDetailBo findPersonalCustomerDetail(String uid) {
- return userMapper.findPersonalCustomerDetail(uid);
- }
- @Override
- public CustomerOrganizationDetailBo findOrganizationCustomerDetail(String uid) {
- return userMapper.findOrganizationCustomerDetail(uid);
- }
- @Override
- @Transactional
- public int updateOrganizationCustomer(CustomerOrganizationDetailBo bo) {
- OrganizationIdentity oi = new OrganizationIdentity();
- User user = new User();
- Date date = new Date();
- OrganizationApplicationInfo oa = new OrganizationApplicationInfo();
- try {
- BeanUtilsExt.copyProperties(oi, bo);
- user.setId(bo.getUid());
- user.setSocietyTag(bo.getSocietyTag());
- user.setCompanyLogoUrl(bo.getCompanyLogoUrl());
- user.setIntroduction(bo.getIntroduction());
- user.setUpdateTime(date);
- user.setInformationMaintainer(bo.getInformationMaintainer());
- user.setCoreTechnology(bo.getCoreTechnology());
- user.setAccomplishSituation(bo.getAccomplishSituation());
- user.setIntellectualProperty(bo.getIntellectualProperty());
- user.setCreditRating(bo.getCreditRating());
- user.setIntegrity(countIntegrity(bo));
- if (StringUtils.isNotBlank(bo.getPojectApplicationUrl())) {
- List<OrganizationApplicationInfo> l = organizationApplicationInfoMapper.selectByUid(bo.getUid());
- if (l.size() > 0) {
- oa = l.get(0);
- oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
- organizationApplicationInfoMapper.updateByPrimaryKey(oa);
- } else {
- oa.setId(UUID.randomUUID().toString());
- oa.setCreateTime(date);
- oa.setUid(bo.getUid());
- oa.setPojectApplicationUrl(bo.getPojectApplicationUrl());
- organizationApplicationInfoMapper.insert(oa);
- }
- }
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- if (bo.getBusinessScope() != null) {
- OrganizationIdentity use=organizationIdentityMapper.selectByPrimaryKey(bo.getId());
- if (!bo.getBusinessScope().equals(use.getBusinessScope())){
- updateBusinessScope(bo.getUid(),bo.getBusinessScope() ,use.getBusinessScope(), date);
- }
- }
- organizationSalesTargetMapper.deleteByUid(bo.getUid());
- if (bo.getSalesTarget() != null) {
- if (bo.getSalesTarget().contains(",")) {
- String[] ss = bo.getSalesTarget().split(",");
- List<OrganizationSalesTarget> list = new ArrayList<>();
- for (int i = 0; i < ss.length; i++) {
- String string = ss[i];
- OrganizationSalesTarget obs = new OrganizationSalesTarget();
- obs.setUid(bo.getUid());
- obs.setKeyword(string);
- list.add(obs);
- }
- organizationSalesTargetMapper.insertBatch(list);
- } else {
- OrganizationSalesTarget obs = new OrganizationSalesTarget();
- obs.setUid(bo.getUid());
- obs.setKeyword(bo.getSalesTarget());
- organizationSalesTargetMapper.insertSelective(obs);
- }
- }
- organizationIdentityMapper.updateByPrimaryKeySelective(oi);
- userMapper.updateByPrimaryKeySelective(user);
- return 1;
- }
- /**
- *
- * @param uid
- * @param businnessScope
- * @param useBusinnessScope
- * @param date
- */
- private void updateBusinessScope( String uid, String businnessScope,String useBusinnessScope, Date date) {
- if(date==null)date=new Date();
- organizationBusinessScopeMapper.deleteByUid(uid);
- if (businnessScope.contains(",")) {
- String[] ss = businnessScope.split(",");
- List<OrganizationBusinessScope> list = new ArrayList<>();
- for (int i = 0; i < ss.length; i++) {
- String string = ss[i];
- OrganizationBusinessScope obs = new OrganizationBusinessScope();
- obs.setUid(uid);
- obs.setKeyword(string);
- list.add(obs);
- }
- organizationBusinessScopeMapper.insertBatch(list);
- } else {
- OrganizationBusinessScope obs = new OrganizationBusinessScope();
- obs.setUid(uid);
- obs.setKeyword(businnessScope);
- organizationBusinessScopeMapper.insertSelective(obs);
- }
- UserMid um=new UserMid();
- um.setDateUpdateTime(date);
- um.setUid(uid);
- String aid=TokenManager.getAdminId();
- um.setUpdateAid(aid);
- Admin a=adminMapper.selectByPrimaryKey(aid);
- um.setUpdateName(a.getName());
- int i=userMidMapper.updateByUid(um);
- if (i==0) {
- um.setAid(aid);
- userMidMapper.insertSelective(um);
- }
- StringBuffer str=new StringBuffer(a.getName()).append("修改了主营产品");
- if (useBusinnessScope==null){useBusinnessScope="无";}
- str.append("[").append(useBusinnessScope).append("=> ").append(businnessScope).append("]");
- userDataLogMapper.insertSelective(new UserDataLog(uid,str.toString()));
- }
- public Double countIntegrity(CustomerOrganizationDetailBo bo) {
- // 完整资料总数
- int max = 10;
- int number = 0;
- if (null != bo.getIndustry())
- number += 1;
- if (bo.getLocationProvince() != null)
- number += 1;
- if (StringUtils.isNotBlank(bo.getBusinessScope()))
- number += 1;
- if (bo.getRegisteredCapital() != null)
- number += 1;
- if (StringUtils.isNotBlank(bo.getCooperationSituation()))
- number += 1;
- if (StringUtils.isNotBlank(bo.getQualification()))
- number += 1;
- if (organizationAnnualReportMapper.selectOrgAnnualCount(bo.getUid()) > 0)
- number += 1;
- if (organizationAnnualReportMapper.selectOrgYearProjectCount(bo.getUid()) > 0)
- number += 1;
- if (StringUtils.isNotBlank(bo.getCoreTechnology()))
- number += 1;
- if (bo.getCreditRating() != null)
- number += 1;
- Double d = (double) number / max;
- return d;
- }
- @Override
- public int updatePersonalCustomer(CustomerPersonalDetailBo bo) {
- UserIdentity ui = new UserIdentity();
- User user = new User();
- try {
- try {
- PropertyUtils.copyProperties(ui, bo);
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
- }
- user.setId(bo.getUid());
- user.setSocietyTag(bo.getSocietyTag());
- user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
- user.setIntroduction(bo.getIntroduction());
- user.setUpdateTime(new Date());
- if (null == bo.getExpertAudit() && bo.getExpert() == 1)
- ui.setExpertAudit(2);
- } catch (InvocationTargetException | IllegalAccessException e) {
- e.printStackTrace();
- }
- userIdentityMapper.updateByPrimaryKeySelective(ui);
- userMapper.updateByPrimaryKeySelective(user);
- return 1;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<FollowListBo> listFollowHistory(Integer pageNo, Integer pageSize, String uid,
- String businessProjectId, Integer type) {
- Map<String, Object> params = new HashMap<String, Object>();
- if (StringUtils.isNotBlank(uid))
- params.put("uid", uid);
- if (StringUtils.isNotBlank(businessProjectId))
- params.put("businessProjectId", businessProjectId);
- Pagination<FollowListBo> page = (Pagination<FollowListBo>) findPage("selectFollowHistoryList",
- "selectFollowHistoryCount", params, pageNo, pageSize);
- List<FollowListBo> list = (List<FollowListBo>) page.getList();
- for (FollowListBo bo : list) {
- if (bo.getAid().equals(TokenManager.getAdminId())) {
- bo.setReadOnly(AFTConstants.NO);
- } else {
- bo.setContactMobile("***");
- bo.setContacts("***");
- bo.setReadOnly(AFTConstants.YES);
- }
- }
- page.setList(list);
- return page;
- }
- /**
- * 推动指导已读
- *
- * @param uid
- */
- @Override
- public int pushGuidance(String uid) {
- User u = userMapper.findUserAccountDetail(uid);
- if (u != null && u.getGuidance() != 0) {
- return userMapper.pushUserGuidance(uid, 2);
- }
- return 0;
- }
- @Override
- public User findUserAccountDetail(String uid) {
- return userMapper.findUserAccountDetail(uid);
- }
- @Override
- public int updateUserAccount(User user) {
- return userMapper.updateByPrimaryKeySelective(user);
- }
- @Override
- public List<OrganizationContactBook> findCustomerContacts(String uid) {
- List<OrganizationContactBook> list = userMapper.findCustomerContacts(uid, null);
- for (OrganizationContactBook ob : list) {
- if (!ob.getAid().equals(TokenManager.getAdminId())){
- ob.setName("***");
- ob.setMobile("***");
- }
- }
- return list;
- }
- @Transactional
- @Override
- public int addFollow(FollowBusinessBo fbb,String ufid,Integer mainStatus,Integer type,String pid) throws BusinessException {
- // 更新跟进记录表
- Date followTime=DateUtils.StringToDate(fbb.getFollowTime(),AFTConstants.YYYYMMDDHHMMSS);
- UserFollow userFollow = new UserFollow();
- String followId = ufid==null?UUID.randomUUID().toString():ufid;
- userFollow.setId(followId);
- String aid=TokenManager.getAdminId();
- userFollow.setAid(aid);
- AdminListBo a=adminMapper.getDeptNameByAid(aid);
- userFollow.setFollowName(a.getName());
- userFollow.setFollowDep(a.getDepartmentName());
- userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
- userFollow.setEffective(DeleteStatus.UNDELETE.getCode());
- userFollow.setCreateTime(followTime);
- userFollow.setOcbId(fbb.getOcbId());
- userFollow.setResult(fbb.getResult());
- userFollow.setUid(fbb.getUid());
- int followCount = userBusinessMapper.selectFollowCountByUAid(fbb.getUid(), null) + 1;
- userFollow.setFollowCount(followCount);
- userFollow.setType(type);
- if (StringUtils.isNotBlank(pid))userFollow.setPid(pid);
- userFollowMapper.insert(userFollow);
- if (type==0){
- //处理中间表
- UserMid um =new UserMid();
- um.setUid(userFollow.getUid());
- //检查客户,修改小程序打卡,如果负责人和跟进人是同一个,则刷新最后跟进时间
- User user = userMapper.selectByPrimaryKey(fbb.getUid());
- if (aid.equals(user.getAid())){
- um.setLastFollowTime(userFollow.getCreateTime());
- }
- um.setFollowNumber(followCount);
- um.setFollowExplain(userFollow.getResult());
- um.setFollowDep(userFollow.getFollowDep());
- um.setLastFollowType(userFollow.getContactType());
- um.setFollowAname(a.getName());
- userMidMapper.updateByUid(um);
- addUserFllow( fbb, ufid, mainStatus,followTime,followId);
- }else if (type==1){
- addRestrictProject(fbb,followTime,followId);
- }
- return 1;
- }
- private void addRestrictProject(FollowBusinessBo fbb, Date followTime, String followId) {
- String businessName = "";
- String ufbId = "";
- UserBusiness userBusiness = null;
- UserFollowBusiness userFollowBusiness = null;
- for (BusinessListBo ub : fbb.getUserBusinessList()) {
- userBusiness = new UserBusiness();
- userFollowBusiness = new UserFollowBusiness();
- ufbId = UUID.randomUUID().toString();
- businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
- UserBusiness us = userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
- if (StringUtils.isNotBlank(ub.getBusinessId())) {
- // 更新业务表
- userBusiness.setId(ub.getBusinessId());
- if (us.getFollowSituation() == 5) {// 如果已签合同,则不允许变更
- if (ub.getCustomerStatus() != us.getCustomerStatus() && ub.getFollowSituation() != 5) {
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
- }
- }
- userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
- userBusiness.setCustomerStatus(ub.getCustomerStatus());
- userBusiness.setFollowSituation(ub.getFollowSituation());
- userBusiness.setRemarks(ub.getRemarks());
- userBusiness.setUid(fbb.getUid());
- userBusiness.setUpdateTime(followTime);
- userBusiness.setAid(TokenManager.getAdminId());
- userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
- // 更新业务中间表
- addUserFollowBusiness(userFollowBusiness, ub.getBusinessProjectId(), ub, ufbId, followId);
- } else {
- if (userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "") > 0) {
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST, businessName, ""));
- }
- String ubId = UUID.randomUUID().toString();
- // 更新业务表
- userBusiness.setId(ubId);
- userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
- userBusiness.setCreateTime(followTime);
- userBusiness.setUpdateTime(followTime);
- userBusiness.setCustomerStatus(ub.getCustomerStatus());
- userBusiness.setFollowSituation(ub.getFollowSituation());
- userBusiness.setUid(fbb.getUid());
- userBusiness.setAid(TokenManager.getAdminId());
- userBusiness.setRemarks(ub.getRemarks());
- userBusinessMapper.insert(userBusiness);
- // 更新业务中间表
- addUserFollowBusiness(userFollowBusiness, ubId, ub, ufbId, followId);
- }
- restProjectMapper.updateRefreshLockTime(fbb.getUid(),ub.getBusinessProjectId(),TokenManager.getAdminId());
- }
- }
- private void addUserFllow(FollowBusinessBo fbb,String ufid,Integer mainStatus,Date followTime,String followId) {
- boolean isUserOwner = false;
- // 检查客户锁定情况
- if (fbb.getUserBusinessList()!=null&& !fbb.getUserBusinessList().isEmpty()) {
- List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(),
- TokenManager.getAdminId(), null, 0, UserLockReleaseStatus.LOCKED.getCode());
- if (!userLockedList.isEmpty()) {
- isUserOwner = true;
- }
- boolean isBusinessOwner = false;
- List<LockingReleaseBo> businessLockedList = null;
- String businessName = "";
- String ufbId = "";
- UserBusiness userBusiness = null;
- UserFollowBusiness userFollowBusiness = null;
- for (BusinessListBo ub : fbb.getUserBusinessList()) {
- userBusiness = new UserBusiness();
- userFollowBusiness = new UserFollowBusiness();
- ufbId = UUID.randomUUID().toString();
- businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
- UserBusiness us = userBusinessMapper.selectByPrimaryKey(ub.getBusinessId());
- if (StringUtils.isNotBlank(ub.getBusinessId())) {
- // 更新业务表
- userBusiness.setId(ub.getBusinessId());
- if (us.getFollowSituation() == 5) {// 如果已签合同,则不允许变更
- if (ub.getCustomerStatus() != us.getCustomerStatus() && ub.getFollowSituation() != 5) {
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
- }
- }
- // 检查业务锁定情况
- businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
- 1, UserLockReleaseStatus.LOCKED.getCode());
- if (businessLockedList.size() > 0) {
- for (LockingReleaseBo bo : businessLockedList) {
- if (!bo.getAid().equals(TokenManager.getAdminId()))
- isBusinessOwner = true;
- }
- if (isBusinessOwner)
- throw new BusinessException(
- new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, businessName, ""));
- } else {
- if (!isUserOwner)
- throw new BusinessException(
- new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
- }
- // if (us.getFollowSituation()!=5&&ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
- // if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
- // lockProject(ub);//锁定客户业务
- // x=1;
- // }
- userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
- userBusiness.setCustomerStatus(ub.getCustomerStatus());
- userBusiness.setFollowSituation(ub.getFollowSituation());
- userBusiness.setRemarks(ub.getRemarks());
- userBusiness.setUid(fbb.getUid());
- userBusiness.setUpdateTime(followTime);
- userBusiness.setAid(TokenManager.getAdminId());
- userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
- // 更新业务中间表
- addUserFollowBusiness(userFollowBusiness, ub.getBusinessProjectId(), ub, ufbId, followId);
- } else {
- // 检查业务锁定情况
- businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
- 1, UserLockReleaseStatus.LOCKED.getCode());
- if (!businessLockedList.isEmpty()) {
- for (LockingReleaseBo bo : businessLockedList) {
- if (bo.getAid().equals(TokenManager.getAdminId()))
- isBusinessOwner = true;
- }
- if (!isBusinessOwner)
- throw new BusinessException(
- new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, businessName, ""));
- } else {
- if (!isUserOwner)
- throw new BusinessException(
- new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
- }
- if (userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "") > 0) {
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST, businessName, ""));
- }
- // if (ub.getFollowSituation()==5) {//如果改成已签合同,则锁定业务
- // if (StringUtils.isNotBlank(fbb.getUid())) ub.setUid(fbb.getUid());
- // lockProject(ub);//锁定客户业务
- // x=1;
- // }
- String ubId = UUID.randomUUID().toString();
- // 更新业务表
- userBusiness.setId(ubId);
- userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
- userBusiness.setCreateTime(followTime);
- userBusiness.setUpdateTime(followTime);
- userBusiness.setCustomerStatus(ub.getCustomerStatus());
- userBusiness.setFollowSituation(ub.getFollowSituation());
- userBusiness.setUid(fbb.getUid());
- userBusiness.setAid(TokenManager.getAdminId());
- userBusiness.setRemarks(ub.getRemarks());
- userBusinessMapper.insert(userBusiness);
- // 更新业务中间表
- addUserFollowBusiness(userFollowBusiness, ubId, ub, ufbId, followId);
- }
- }
- }
- if (mainStatus==1){
- followProject(fbb.getUid());
- }
- updateADminUserCountFollow(TokenManager.getAdminId(),followTime);
- }
- private void addUserFollowBusiness(UserFollowBusiness userFollowBusiness, String ub, BusinessListBo ub1, String ufbId, String followId) {
- userFollowBusiness.setBusinessId(ub);
- userFollowBusiness.setCustomerStatus(ub1.getCustomerStatus());
- userFollowBusiness.setFollowSituation(ub1.getFollowSituation());
- userFollowBusiness.setId(ufbId);
- userFollowBusiness.setFollowId(followId);
- userFollowBusiness.setRemarks(ub1.getRemarks());
- userFollowBusiness.setBusinessProjectId(ub1.getBusinessProjectId());
- userFollowBusinessMapper.insert(userFollowBusiness);
- }
- private void updateADminUserCountFollow(String aid, Date transferTime) {
- {
- String startTime= DateUtils.formatDate(transferTime,AFTConstants.YYYYMMDD);
- String endTime=startTime+" 23:59:59";
- AdminUserCount adminUserCount = getAdminUserCount(aid,startTime);
- Integer count = userFollowMapper.selectByaidAndDate(aid, startTime, endTime);
- if (adminUserCount==null){
- AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
- if (selectAUC==null)selectAUC=new AdminUserCount();
- selectAUC.setFollowCount(count);
- selectAUC.setAid(aid);
- selectAUC.setDateTime(transferTime);
- adminUserCountMapper.insertSelective(selectAUC);
- }else {
- AdminUserCount selectAUC=userMapper.selectByaidAndDate(aid,startTime,endTime);
- AdminUserCount newAUC=new AdminUserCount();
- newAUC.setId(adminUserCount.getId());
- newAUC.setFollowCount(count);
- if (selectAUC==null){
- newAUC.setPrivateCount(0);
- newAUC.setChannelCount(0);
- newAUC.setSignCount(0);
- }else {
- if (selectAUC.getPrivateCount()==null)selectAUC.setPrivateCount(0);
- if (selectAUC.getChannelCount()==null)selectAUC.setChannelCount(0);
- if (selectAUC.getSignCount()==null)selectAUC.setSignCount(0);
- newAUC.setPrivateCount(selectAUC.getPrivateCount());
- newAUC.setChannelCount(selectAUC.getChannelCount());
- newAUC.setSignCount(selectAUC.getSignCount());
- }
- adminUserCountMapper.updateByPrimaryKeySelective(newAUC);
- }
- }
- }
- /**
- * 跟进更新用户中间表
- *
- */
- private void followProject(String uid) {
- Date date = new Date();
- String aid = TokenManager.getAdminId();
- UserMid um=new UserMid();
- um.setUid(uid);
- um.setAid(aid);
- um.setLastFollowTime(date);
- int x=userMidMapper.updateByUid(um);
- if (x==0){
- userMidMapper.insertSelective(um);
- }
- }
- @SuppressWarnings("unused")
- private void releaseProject(List<LockingReleaseBo> businessLockedList) {
- if (businessLockedList != null && businessLockedList.size() > 0) {
- UserLockRelease ulr = null;
- for (LockingReleaseBo bo : businessLockedList) {
- ulr = new UserLockRelease();
- ulr.setId(bo.getId());
- ulr.setStatus(UserLockReleaseStatus.RELEASE.getCode());
- userLockReleaseMapper.updateByPrimaryKeySelective(ulr);
- }
- }
- }
- @Override
- public FollowBusinessBo findFollowById(String followId) {
- return userMapper.findFollowById(followId);
- }
- @Override
- public List<BusinessListBo> findBusinessByFollowId(String followId) {
- return userMapper.findBusinessByFollowId(followId);
- }
- @Override
- @Transactional
- public int updateFollow(FollowBusinessBo fbb) throws BusinessException {
- UserFollow userFollow = new UserFollow();
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
- userFollow.setId(fbb.getFollowId());
- if (StringUtils.isNotBlank(fbb.getOcbId()))
- userFollow.setOcbId(fbb.getOcbId());
- userFollow.setResult(fbb.getResult());
- userFollow.setContactType(Integer.parseInt(fbb.getContactType()));
- userFollowMapper.updateByPrimaryKeySelective(userFollow); // 修改拜访记录表
- if (fbb.getUserBusinessList().size() > 0) {
- // 检查客户锁定情况
- boolean isUserOwner = false;
- List<LockingReleaseBo> userLockedList = userMapper.selectLockedProject(fbb.getUid(),
- TokenManager.getAdminId(), null, 0, UserLockReleaseStatus.LOCKED.getCode());
- if (userLockedList.size() > 0) {
- isUserOwner = true;
- }
- boolean isBusinessOwner = false;
- List<LockingReleaseBo> businessLockedList = null;
- String businessName = "";
- UserFollowBusiness userFollowBusiness = null;
- for (BusinessListBo ub : fbb.getUserBusinessList()) {
- userFollowBusiness = new UserFollowBusiness();
- businessName = businessProjectMapper.selectByPrimaryKey(ub.getBusinessProjectId()).getBname();
- if (StringUtils.isNotBlank(ub.getUfbId())) {
- userFollowBusiness.setId(ub.getUfbId());
- userFollowBusiness.setFollowSituation(ub.getFollowSituation());
- userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
- userFollowBusiness.setRemarks(ub.getRemarks());
- userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness); // 修改拜访记录中间表
- } else {
- // 检查业务锁定情况
- businessLockedList = userMapper.selectLockedProject(fbb.getUid(), null, ub.getBusinessProjectId(),
- 1, UserLockReleaseStatus.LOCKED.getCode());
- if (businessLockedList.size() > 0) {
- for (LockingReleaseBo bo : businessLockedList) {
- if (bo.getAid().equals(TokenManager.getAdminId()))
- isBusinessOwner = true;
- }
- if (!isBusinessOwner)
- throw new BusinessException(
- new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, businessName, ""));
- } else {
- if (!isUserOwner)
- throw new BusinessException(
- new Error(ErrorConstants.CUSTOMER_ALREADY_LOCKED, businessName, ""));
- }
- if (userBusinessMapper.judgeBusiness(fbb.getUid(), ub.getBusinessProjectId(), "") > 0) {
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_EXIST, businessName, ""));
- }
- String ubId = UUID.randomUUID().toString();
- UserBusiness userBusiness = new UserBusiness();
- // 更新业务表
- userBusiness.setId(ubId);
- userBusiness.setBusinessProjectId(ub.getBusinessProjectId());
- try {
- userBusiness.setCreateTime(format.parse(fbb.getFollowTime()));
- userBusiness.setUpdateTime(format.parse(fbb.getFollowTime()));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- userBusiness.setCustomerStatus(ub.getCustomerStatus());
- userBusiness.setFollowSituation(ub.getFollowSituation());
- userBusiness.setUid(fbb.getUid());
- userBusiness.setAid(TokenManager.getAdminId());
- userBusinessMapper.insert(userBusiness);
- // 更新业务中间表
- String ufbId = UUID.randomUUID().toString();
- userFollowBusiness.setId(ufbId);
- userFollowBusiness.setFollowId(fbb.getFollowId());
- userFollowBusiness.setBusinessId(ubId);
- userFollowBusiness.setCustomerStatus(ub.getCustomerStatus());
- userFollowBusiness.setFollowSituation(ub.getFollowSituation());
- userFollowBusiness.setRemarks(ub.getRemarks());
- userFollowBusiness.setBusinessProjectId(ub.getBusinessProjectId());
- userFollowBusinessMapper.insert(userFollowBusiness);
- }
- }
- }
- return 1;
- }
- @Override
- public Set<OrganizationContactBook> findAllContacts(String uid) {
- Set<OrganizationContactBook> result = new HashSet<OrganizationContactBook>();
- result.addAll(userMapper.findAllContacts(uid));
- return result;
- }
- @Override
- public int updateCustomerContacts(List<OrganizationContactBook> ocbList, String uid) {
- if (ocbList.size() > 0) {
- OrganizationContactBook ocb = null;
- for (OrganizationContactBook item : ocbList) {
- if (item != null && item.getMajor() != null && item.getMajor() == 1) {
- // 改变用户原本的联系人
- OrganizationIdentity oi = new OrganizationIdentity();
- oi.setContacts(item.getName());
- oi.setContactMobile(item.getMobile());
- oi.setUid(uid);
- organizationIdentityMapper.updateServiceByUid(oi);
- }
- ocb = new OrganizationContactBook();
- try {
- BeanUtils.copyProperties(ocb, item);
- if (StringUtils.isBlank(ocb.getId())) {
- ocb.setId(UUID.randomUUID().toString());
- ocb.setUid(uid);
- ocb.setAid(TokenManager.getAdminId());
- Admin ad = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
- ocb.setAname(ad.getName());
- organizationContactBookMapper.insert(ocb);
- } else {
- organizationContactBookMapper.updateByPrimaryKeySelective(ocb);
- }
- } catch (IllegalAccessException | InvocationTargetException e) {
- e.printStackTrace();
- }
- }
- }
- return 1;
- }
- @Override
- public int deleteFollow(String followId) {
- UserFollow uf = new UserFollow();
- List<BusinessListBo> list = userMapper.findBusinessByFollowId(followId);
- for (BusinessListBo b : list) {
- if (b.getFollowSituation() == 5)
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
- ;
- }
- uf.setId(followId);
- uf.setEffective(DeleteStatus.DELETED.getCode());
- return userFollowMapper.updateByPrimaryKeySelective(uf);
- }
- @Override
- public void checkCustomer(Set<CustomerExcelBo> boSet, Set<Integer> existRows, Set<Integer> filterRows) {
- List<User> list = null;
- CustomerExcelBo[] bos = boSet.toArray(new CustomerExcelBo[] {});
- for (int i = 0; i < bos.length; i++) {
- CustomerExcelBo bo = bos[i];
- CustomerExcelBo ceb = null;
- for (int j = 0; j < i; j++) {
- ceb = bos[j];
- if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)) { // 个人
- if (ceb.getMobile().equals(bo.getMobile()) && ceb.getCustomerType().equals(bo.getCustomerType())) {
- bo.setUid(ceb.getUid());
- bo.setNewData(false);
- filterRows.add(bo.getRowNumber());
- break;
- }
- } else if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)) { // 单位
- if (ceb.getIdentifyName().equals(bo.getIdentifyName())
- && ceb.getCustomerType().equals(bo.getCustomerType())) {
- bo.setUid(ceb.getUid());
- bo.setNewData(false);
- filterRows.add(bo.getRowNumber());
- break;
- }
- }
- }
- if (StringUtils.isBlank(bo.getUid())) { // 是否已经存在
- if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_PERSONAL)) {
- list = userMapper.checkUser("", "", bo.getMobile(), Integer.parseInt(bo.getCustomerType()), null,
- null);
- } else if (bo.getCustomerType().equals(AFTConstants.USER_TYPE_ORGANIZATION)) {
- list = userMapper.checkUser("", bo.getIdentifyName(), "", Integer.parseInt(bo.getCustomerType()),
- null, null);
- }
- if (list.size() > 0) {
- bo.setUid(list.get(0).getId());
- bo.setNewData(false);
- List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,
- bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
- if (businessLockedList.size() > 0) {
- existRows.add(bo.getRowNumber());
- }
- } else {
- bo.setUid(UUID.randomUUID().toString());
- bo.setNewData(true);
- }
- } else {
- List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(bo.getUid(), null,
- bo.getBusinessProjectId(), 1, UserLockReleaseStatus.LOCKED.getCode());
- if (businessLockedList.size() > 0) {
- existRows.add(bo.getRowNumber());
- }
- }
- }
- }
- @Override
- @Transactional
- public int saveUploadData(Set<CustomerExcelBo> boSet) {
- Date now = new Date();
- String uid = "";
- for (CustomerExcelBo bo : boSet) {
- uid = bo.getUid();
- if (bo.isNewData()) { // 新建客户
- createUser(bo, uid, now);
- createIdentity(bo, bo.getCustomerType(), uid);
- createBusiness(bo, uid, now);
- createContacts(bo, uid);
- } else { // 新建业务
- createBusiness(bo, uid, now);
- if (organizationContactBookMapper.checkContacts(uid, bo.getMobile(), TokenManager.getAdminId()) <= 0) {
- createContacts(bo, uid);
- }
- }
- }
- return 1;
- }
- private void createUser(CustomerExcelBo bo, String uid, Date now) {
- User user = new User();
- user.setId(uid);
- user.setIdentifyName(bo.getIdentifyName());
- user.setSource(AFTConstants.USER_SOURCE_CREATE);
- user.setNickname(bo.getIdentifyName());
- user.setStatus(AFTConstants.USER_STATUS_NORMAL);
- user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
- user.setAid(TokenManager.getAdminId());
- user.setType(Integer.parseInt(bo.getCustomerType()));
- user.setLvl(UserLevel.CERTIFIED.getCode());
- user.setCreateTime(now);
- user.setUpdateTime(now);
- user.setMobile(bo.getMobile());
- user.setPassword(AFTConstants.INITIALPASSWORD);
- passwordUtil.encryptPassword(user);
- userMapper.insert(user);
- }
- private void createIdentity(CustomerExcelBo bo, String type, String uid) {
- String identifyId = UUID.randomUUID().toString();
- if (type.equals(AFTConstants.USER_TYPE_PERSONAL)) {
- // 新增个人认证信息
- UserIdentity ui = new UserIdentity();
- ui.setId(identifyId);
- ui.setUid(uid);
- ui.setContacts(bo.getContacts());
- ui.setContactMobile(bo.getMobile());
- ui.setUsername(bo.getIdentifyName());
- ui.setExpert(AFTConstants.NO);
- ui.setCelebrity(AFTConstants.NO);
- ui.setInternational(AFTConstants.NO);
- ui.setAuditStatus(5);
- userIdentityMapper.insert(ui);
- } else if (type.equals(AFTConstants.USER_TYPE_ORGANIZATION)) {
- // 创建企业认证信息
- OrganizationIdentity oi = new OrganizationIdentity();
- oi.setId(identifyId);
- oi.setUnitName(bo.getIdentifyName());
- oi.setUid(uid);
- oi.setContacts(bo.getContacts());
- oi.setContactMobile(bo.getMobile());
- oi.setHighTechZone(AFTConstants.NO);
- oi.setInternational(AFTConstants.NO);
- oi.setListed(AFTConstants.NO);
- oi.setAuditStatus(5); // 实名企业
- organizationIdentityMapper.insert(oi);
- }
- }
- private void createContacts(CustomerExcelBo bo, String uid) {
- // 新增企业联系人
- OrganizationContactBook cob = new OrganizationContactBook();
- cob.setAid(TokenManager.getAdminId());
- cob.setId(UUID.randomUUID().toString());
- cob.setUid(uid);
- cob.setName(bo.getContacts());
- cob.setMobile(bo.getMobile());
- cob.setMajor(AFTConstants.NO);
- organizationContactBookMapper.insert(cob);
- }
- private void createBusiness(CustomerExcelBo bo, String uid, Date now) {
- // 新增业务
- UserBusiness ub = new UserBusiness();
- ub.setId(UUID.randomUUID().toString());
- ub.setAid(TokenManager.getAdminId());
- ub.setBusinessProjectId(bo.getBusinessProjectId());
- ub.setUid(uid);
- ub.setCreateTime(now);
- ub.setUpdateTime(now);
- ub.setCustomerStatus(Integer.parseInt(bo.getCustomerStatus()));
- ub.setFollowSituation(Integer.parseInt(bo.getFollowSituation()));
- userBusinessMapper.insert(ub);
- }
- @Override
- @Transactional
- public List<String> updateByOperatorType(String uid,String aid, String oldAid, Integer operatorType,Integer data) {
- User user = new User();
- Date now = new Date();
- List<String> errors=new ArrayList<>();
- if(aid==null)aid=TokenManager.getAdminId();
- if(data==null)data=0;
- // 是否多个客户
- boolean isUs = false;
- if (uid.contains(",")) {
- isUs = true;
- }
- List<String> uList = new ArrayList<>();
- if (isUs) {
- uList = Arrays.asList(uid.split(","));
- }
- user.setId(uid);
- user.setTransferTime(now);
- int flag = 0;
- //记录旧数据值,与新数据值 将旧数据与新数据都需要更新
- List<User> useList=new ArrayList<>();
- List<User> newList=new ArrayList<>();
- //领取
- if (AFTConstants.USER_RECEIVE.equals(operatorType)) {
- User use = userMapper.selectByPrimaryKey(uid);
- user.setAid(TokenManager.getAdminId());
- if (use.getSignBills()==0){
- user.setShareType(AFTConstants.USER_SHARE_PRIVATE);
- }else if (use.getSignBills()==1){
- user.setShareType(AFTConstants.USER_SHARE_SIGN);
- }
- user.setInformationMaintainer(TokenManager.getAdminId());
- user.setSource(2);// 客户来源设置为领取
- flag = addUserLock(uid, TokenManager.getAdminId(), now, uList); // 指定用户锁定客户
- addUserTransferLog(uid, TokenManager.getAdminId(), null,1, null, now, uList);
- updateUserMid(aid,uid,0,null);
- organizationContactBookMapper.updateAdmin(uid,aid);
- //转交
- } else if (AFTConstants.USER_TRANSFER_TO_OTHER.equals(operatorType)
- || AFTConstants.SIGN_USER_TRANSFER_TO_OTHER .equals(operatorType)
- || AFTConstants.CHANNEL_USER_TRANSFER_TO_OTHER .equals(operatorType)) {
- if (!isUs) {
- user.setAid(aid);
- if (data==1||data==3){
- informationMaintainerHandOver(uid, aid, oldAid, errors);
- }
- if (data==2||data==3){
- updateOrderHandOver(uid,aid,oldAid);
- }
- user.setSource(3);// 客户来源设置为转交
- //私有和渠道有客户锁操作
- if (AFTConstants.USER_TRANSFER_TO_OTHER == operatorType||AFTConstants.CHANNEL_USER_TRANSFER_TO_OTHER == operatorType) {
- // 查询这个客户是否是登陆人的客户
- if (userMapper.getAidAndUser(uid, TokenManager.getAdminId()) <= 0)
- throw new BusinessException(new Error("请勿非法操作!", "请勿非法操作!"));
- flag = updateUserLock(uid, oldAid, UserLockReleaseStatus.LOCKED.getCode(),
- UserLockReleaseStatus.RELEASE.getCode()); // 原用户释放客户
- if (flag > 0)
- flag = addUserLock(uid,aid, now, uList); // 指定用户锁定客户
- if (flag <= 0)
- throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL, ""));
- }
- updateUserMid(aid,uid,0,null);
- //单客户转交,需要将客户原来得数据修改,需要将新数据刷新
- User use = userMapper.selectByPrimaryKey(uid);
- useList.add(use);
- User newUser=new User();
- newUser.setAid(aid);
- newUser.setTransferTime(now);
- newUser.setShareType(use.getShareType());
- newList.add(newUser);
- } else {
- for (String us : uList) {
- if (userMapper.getAidAndUser(us, TokenManager.getAdminId()) <= 0){
- throw new BusinessException(new Error("请勿非法操作!", "请勿非法操作!"));
- }
- if (data==1||data==3){
- informationMaintainerHandOver(us, aid, oldAid, errors);
- }
- if (data==2||data==3){
- updateOrderHandOver(uid,aid,oldAid);
- }
- //单客户转交,需要将客户原来得数据修改,需要将新数据刷新
- User use = userMapper.selectByPrimaryKey(us);
- useList.add(use);
- User newUser=new User();
- newUser.setAid(aid);
- newUser.setTransferTime(use.getTransferTime());
- newUser.setShareType(use.getShareType());
- newList.add(newUser);
- }
- if (AFTConstants.USER_TRANSFER_TO_OTHER == operatorType) {
- flag = updateUsersLock(uList, oldAid, UserLockReleaseStatus.LOCKED.getCode(),
- UserLockReleaseStatus.RELEASE.getCode()); // 原用户释放客户
- if (flag > 0){
- flag = addUserLock(uid, aid, now, uList); // 指定用户锁定客户
- }
- if (flag <= 0)
- throw new BusinessException(new Error(ErrorConstants.CUSTOMER_TRANSFER_FAIL, ""));
- }
- }
- Integer type = 2;
- if (AFTConstants.SIGN_USER_TRANSFER_TO_OTHER == operatorType)type = 7;
- addUserTransferLog(uid, aid,oldAid, type, null, now, uList);
- //转交客户后公出审核人也切换
- transferUser(uList,aid,uid);
- }
- if (isUs) {
- if (AFTConstants.USER_RECEIVE == operatorType) {
- userMapper.updateList(aid, null, 3, null, 2, uList,null);
- } else {
- userMapper.updateList(aid, null, 3, null, null, uList,data);
- }
- } else {
- userMapper.updateByPrimaryKeySelective(user);
- }
- //处理用户客户统计
- if (AFTConstants.USER_RECEIVE.equals(operatorType)){
- updateAdminUserCount(user.getAid(),user.getTransferTime());
- }
- if (AFTConstants.USER_TRANSFER_TO_OTHER.equals(operatorType)
- || AFTConstants.SIGN_USER_TRANSFER_TO_OTHER .equals(operatorType)
- || AFTConstants.CHANNEL_USER_TRANSFER_TO_OTHER .equals(operatorType)) {
- updateAdminUserCountTransfer(useList,newList);
- }
- return errors;
- }
- /**
- *
- * @param useList
- * @param newList
- */
- private void updateAdminUserCountTransfer(List<User> useList, List<User> newList) {
- for (User u : useList) {
- updateAdminUserCount(u.getAid(),u.getTransferTime());
- }
- for (User u : newList) {
- updateAdminUserCount(u.getAid(),u.getTransferTime());
- }
- }
- @Override
- public void transferUser(List<String> uList, String aid, String uid) {
- if(uList.isEmpty())uList.add(uid);
- //先查出所有在其他审核的公出
- List<PublicReleaseTransferUserBo> list=publicExamineMapper.selectByuList(uList);
- Admin admin = adminMapper.selectByPrimaryKey(aid);
- Integer logStatus=null;
- String logMsg=null;
- StringBuffer content=null;
- String noticeAid=null;
- for (PublicReleaseTransferUserBo e : list) {
- PublicExamine pe=new PublicExamine();
- pe.setPrid(e.getId());
- if (e.getAid().equals(aid)){
- content=new StringBuffer().append("[").append(e.getUserNames()).append("]公司的外出申请已发起,请尽快审核。");
- //再查比对和发起者一致的全部走入下一个审核流程
- PublicRelease pr=new PublicRelease();
- pr.setId(e.getId());
- pr.setPublicType(0);
- publicReleaseMapper.updateByPrimaryKeySelective(pr);
- Admin sendAdmin=adminMapper.selectByPrimaryKey(admin.getReviewer());
- noticeAid=sendAdmin.getId();
- logStatus=2;
- logMsg="转交客户到发起公出审核人,自动审核通过。";
- pe.setAid(sendAdmin.getId());
- pe.setAname(sendAdmin.getName());
- pe.setCreateTime(new Date());
- }else {
- //与发起者不一致的就需要修改审核人员
- pe.setAid(aid);
- pe.setAname(admin.getName());
- //给新的审核人发送消息
- logStatus=5;
- logMsg="转交客户归属人到["+admin.getName()+"]。";
- content=new StringBuffer().append("[").append(e.getUserNames()).append("]公司已转交给您,相关公出请尽快审核。");
- noticeAid=aid;
- }
- PublicReleaseLog log = new PublicReleaseLog(e.getId(), TokenManager.getAdminId(), logStatus, logMsg, new Date());
- publicReleaseLogMapper.insertSelective(log);
- systemWebSocketHandler.sendMessageToUser(noticeAid, new TextMessage("unread"));
- Notice n =new Notice();
- n.setId(UUID.randomUUID().toString());
- n.setAid(noticeAid);
- n.setNoticeType(NoticeStatus.PUBLIC_RELEASE_START.getCode());
- n.setContent(content.toString());
- n.setReaded(0);//未读
- asyncUtils.addNotice(n);
- publicExamineMapper.updateByPridSelective(pe);
- }
- }
- private void updateOrderHandOver(String uid, String aid, String oldAid) {
- List<TOrderNewBo> list = tOrderNewMapper.selectByuidandAid(uid, oldAid);
- for (TOrderNewBo bo : list) {
- bo.setSalesmanId(aid);
- bo.setOldSalesmanId(oldAid);
- tOrderNewMapper.updateByPrimaryKeySelective(bo);
- TOrderMid mid=new TOrderMid();
- mid.setOrderNo(bo.getOrderNo());
- Admin admin = adminMapper.selectByPrimaryKey(aid);
- Admin oldadmin = adminMapper.selectByPrimaryKey(oldAid);
- mid.setSalesmanName(admin.getName());
- tOrderMidMapper.updateByOrderNo(mid);
- TOrderLog log=new TOrderLog();
- log.setProcess(OrderLogProcess.DDZJ.getCode());
- log.setAid(oldAid);
- log.setOrderNo(bo.getOrderNo());
- log.setCreateTime(new Date());
- log.setRemarks("订单转交:"+oldadmin.getName()+"=>"+admin.getName());
- tOrderLogMapper.insert(log);
- }
- }
- private void informationMaintainerHandOver(String uid, String aid, String oldAid, List<String> errors) {
- User useUser = userMapper.selectByPrimaryKey(uid);
- if (useUser.getInformationMaintainer().equals(oldAid)){
- organizationContactBookMapper.updateAdmin(uid, aid);
- }else {
- errors.add("客户["+useUser.getNickname()+"]归属不正确,资料转交失败。");
- }
- }
- @Override
- public Integer receiveEveryDay(String uid) {
- if (uid !=null ){
- User u=userMapper.selectByPrimaryKey(uid);
- if (u.getShareType()!=1)return -1;
- if (u.getNewChannel()==1)return 0;
- }
- if (userMapper.UserReceiveCount(TokenManager.getAdminId()) >= USER_RECEIVE_MAX)return -2;
- if(checkMax(uid,TokenManager.getAdminId()))return -3;
- if(checkBeforeChannel(uid)) return -4;
- return 0;
- }
- @Override
- public int pushReceiveAsChannel(String uid) {
- Date date = new Date();
- User use=userMapper.selectByPrimaryKey(uid);
- User u =new User();
- String aid=TokenManager.getAdminId();
- u.setId(uid);
- u.setChannel(0);
- u.setSource(2);
- u.setShareType(0);
- u.setTransferTime(date);
- u.setNewChannel(1);
- u.setAid(aid);
- u.setInformationMaintainer(aid);
- addUserLock(uid,aid, date, null); // 指定用户锁定客户
- updateUserMid(aid,uid,0,null);
- addUserTransferLog(uid, aid,null, 15, null, date, null);
- userMapper.updateByPrimaryKeySelective(u);
- updateAdminUserCount(use.getAid(),use.getTransferTime());
- return 1;
- }
- @Override
- public boolean checkOrgCode(String orgCode) {
- OrganizationIdentity organizationIdentity = organizationIdentityMapper.selectByOrgCode(orgCode);
- if (organizationIdentity!=null)return true;
- return false;
- }
- @Override
- public Integer queryUserMax() {
- String aid=TokenManager.getAdminId();
- int limitmax = 0;
- int mymax = userMapper.checkUserMax(aid);
- List<String > roles=adminMapper.getAdminRoleListByAid(aid);
- for (String role : roles) {
- if (role.equals(AFTConstants.SALESMAN_DIRECTOR)){
- if(limitmax<YXZJ_MAX)limitmax = YXZJ_MAX;
- continue;
- } else if (role.equals(AFTConstants.SALESMAN_MANAGER)){
- if(limitmax<YXJL_MAX)limitmax = YXJL_MAX;
- continue;
- } else if (role.equals(AFTConstants.SALESMAN)){
- if(limitmax<YXY_MAX)limitmax = YXY_MAX;
- continue;
- }
- }
- if (mymax==limitmax){
- return 1;
- }else {
- return 0;
- }
- }
- /**
- * 处理中间表
- * @param aid
- * @param uid
- * @param type 0单个 1批量
- */
- private void updateUserMid(String aid, String uid,Integer type,List<String> list){
- if (type==0){
- UserMid um=new UserMid();
- um.setAid(aid);
- um.setUid(uid);
- um.setLastFollowTime(null);
- userMidMapper.updateByUid(um);
- }else{
- if (!list.isEmpty())userMidMapper.updateListByUid(aid,1,list);
- }
- }
- /**
- *
- * @param uid 客户id
- * @param aid 接受者id
- * @param lockTime 时间
- * @param uList 是不是多人客户
- * @return
- */
- private int addUserLock(String uid, String aid, Date lockTime, List<String> uList) {
- if (uList ==null|| uList.isEmpty()) {
- UserLockRelease ulr = new UserLockRelease();
- ulr.setId(UUID.randomUUID().toString());
- ulr.setType(0);
- ulr.setAid(aid);
- ulr.setLockTime(lockTime);
- ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
- ulr.setUid(uid);
- userLockReleaseMapper.insert(ulr);
- } else {
- List<UserLockRelease> ulrList = new ArrayList<>();
- for (String s : uList) {
- UserLockRelease ulr = new UserLockRelease();
- ulr.setId(UUID.randomUUID().toString());
- ulr.setType(0);
- ulr.setAid(aid);
- ulr.setLockTime(lockTime);
- ulr.setStatus(UserLockReleaseStatus.LOCKED.getCode());
- ulr.setUid(s);
- ulrList.add(ulr);
- }
- userLockReleaseMapper.insertList(ulrList);
- }
- return 1;
- }
- /**
- *
- * @param type 类型 0录入 1 领取 2 转交私有客户 3转交业务 4 未跟进丢失(30) 5未签单丢失(270天)6释放 7转交签单客户 8渠道录入 9渠道客户总监分配 10 渠道客户经理分配 11渠道释放 12回收 13离职客户转交 14离职签单业务转交
- * 15 领取为私有渠道
- */
- private void addUserTransferLog(String uid, String aid,String oldAid, Integer type, String pid,
- Date lockTime, List<String> uList) {
- if (uList ==null || uList.isEmpty()) {
- UserTransferLog utl = new UserTransferLog();
- if (type == 0 || type == 1 ||type ==15)
- utl.setAid(aid);
- else if (type == 2 || type == 3 || type == 7) {
- utl.setAid(TokenManager.getAdminId());
- utl.setTakeAid(aid);
- if (type == 3) utl.setPid(pid);
- }
- utl.setType(type);
- utl.setCreateTime(lockTime);
- utl.setUid(uid);
- userTransferLogMapper.insertSelective(utl);
- } else {
- List<String> ulist = Arrays.asList(uid.split(","));
- List<UserTransferLog> utlList = new ArrayList<>();
- for (String string : ulist) {
- UserTransferLog utl = new UserTransferLog();
- if (type == 0 || type == 1)
- utl.setAid(aid);
- else if (type == 2 || type == 3 || type == 7) {
- utl.setAid(TokenManager.getAdminId());
- utl.setTakeAid(aid);
- }
- if (type == 3) utl.setPid(pid);
- utl.setCreateTime(lockTime);
- utl.setUid(string);
- utl.setType(type);
- utlList.add(utl);
- }
- userTransferLogMapper.insertList(utlList);
- }
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<StatisticBo> customerStatistics(Date sDate, Date eDate, String depNo, String businessGlossoryId,
- Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if (null != sDate)
- params.put("sDate", sDate);
- if (null != eDate)
- params.put("eDate", eDate);
- if (StringUtils.isNotBlank(depNo))
- params.put("depNo", depNo);
- if (StringUtils.isNotBlank(businessGlossoryId))
- params.put("businessGlossoryId", businessGlossoryId);
- Pagination<StatisticBo> page = (Pagination<StatisticBo>) findPage("customerStatisticsList",
- "customerStatisticsCount", params, pageNo, pageSize);
- return page;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<StatisticBo> businessStatistic(Date sDate, Date eDate, String depNo, String businessGlossoryId,
- Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if (null != sDate)
- params.put("sDate", sDate);
- if (null != eDate)
- params.put("eDate", eDate);
- if (StringUtils.isNotBlank(depNo))
- params.put("depNo", depNo);
- if (StringUtils.isNotBlank(businessGlossoryId))
- params.put("businessGlossoryId", businessGlossoryId);
- Pagination<StatisticBo> page = (Pagination<StatisticBo>) findPage("businessStatisticList",
- "businessStatisticCount", params, pageNo, pageSize);
- return page;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<StatisticBo> followStatistic(Date sDate, Date eDate, String depNo, Integer pageNo,
- Integer pageSize) {
- Map<String, Object> params = new HashMap<String, Object>();
- if (null != sDate)
- params.put("sDate", sDate);
- if (null != eDate)
- params.put("eDate", eDate);
- if (StringUtils.isNotBlank(depNo))
- params.put("depNo", depNo);
- Pagination<StatisticBo> page = (Pagination<StatisticBo>) findPage("followStatisticList", "followStatisticCount",
- params, pageNo, pageSize);
- return page;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BusinessListBo> listBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
- blo.setAid(TokenManager.getAdminId());
- return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo),
- pageNo, pageSize);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BusinessListBo> listAllBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
- return (Pagination<BusinessListBo>) findPage("selectBusinessList", "selectBusinessCount", disposeParams(blo),
- pageNo, pageSize);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<BusinessListBo> listManageBusiness(BusinessListBo blo, Integer pageNo, Integer pageSize) {
- blo.setAid(TokenManager.getAdminId());
- return (Pagination<BusinessListBo>) findPage("selectBusinessManageList", "selectBusinessManageCount",
- disposeParams(blo), pageNo, pageSize);
- }
- private Map<String, Object> disposeParams(BusinessListBo blo) {
- Map<String, Object> params = new HashMap<String, Object>();
- if (StringUtils.isNotBlank(blo.getUid()))
- params.put("uid", blo.getUid());
- if (StringUtils.isNotBlank(blo.getAid()))
- params.put("aid", blo.getAid());
- if (StringUtils.isNotBlank(blo.getAdminName()))
- params.put("adminName", blo.getAdminName());
- 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("identifyName", blo.getIdentifyName());
- if (blo.getFollowSituation() != null)
- params.put("followSituation", blo.getFollowSituation());
- if (blo.getCustomerStatus() != null)
- params.put("customerStatus", blo.getCustomerStatus());
- return params;
- }
- @Override
- public List<BusinessListBo> findBusinessGlossory() {
- return userBusinessMapper.selectBusinessGlossory();
- }
- @Override
- public int judgeBusiness(String uid, String businessProjectId) {
- return userMapper.selectLockedProject(uid, null, businessProjectId, 1, UserLockReleaseStatus.LOCKED.getCode())
- .size();
- }
- @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.setBusinessProjectId(bfb.getBusinessProjectId());
- 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.selectFollowCountByUAid(bfb.getUid(), 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());
- ufb.setBusinessProjectId(bfb.getBusinessProjectId());
- userFollowBusinessMapper.insert(ufb);
- }
- }
- @Override
- public List<BusinessListBo> findBusinessByUAid(String uid, String aid) {
- return userBusinessMapper.selectBusinessByUAid(uid, aid);
- }
- @Override
- public List<BusinessListBo> findLockedBusinessByUAid(String uid, String aid) {
- return userBusinessMapper.selectLockedBusinessByUAid(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());
- return userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
- }
- @Override
- @Transactional
- public int addFollowOneBusiness(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.selectFollowCountByUAid(bfb.getUid(), 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());
- userFollow.setUid(bfb.getUid());
- userFollowMapper.insert(userFollow);
- UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
- String ufbId = UUID.randomUUID().toString();
- userFollowBusiness.setId(ufbId);
- userFollowBusiness.setFollowId(followId);
- userFollowBusiness.setBusinessProjectId(bfb.getBusinessProjectId());
- 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;
- }
- @Override
- public BussinessFollowBo findFollowOneBusiness(String ufbId) {
- return userBusinessMapper.findFollowOneBusiness(ufbId);
- }
- @Override
- public int updateFollowOneBusiness(BussinessFollowBo bfb) {
- // 修改业务跟进中间表
- UserFollowBusiness userFollowBusiness = new UserFollowBusiness();
- userFollowBusiness.setId(bfb.getUfbId());
- userFollowBusiness.setRemarks(bfb.getRemarks());
- userFollowBusiness.setCustomerStatus(Integer.parseInt(bfb.getCustomerStatus()));
- userFollowBusiness.setFollowSituation(Integer.parseInt(bfb.getFollowSituation()));
- userFollowBusinessMapper.updateByPrimaryKeySelective(userFollowBusiness);
- // 修改跟进记录表
- UserFollow userFollow = new UserFollow();
- userFollow.setId(bfb.getFollowId());
- userFollow.setContactType(Integer.parseInt(bfb.getContactType()));
- userFollow.setResult(bfb.getResult());
- if (StringUtils.isNotBlank(bfb.getOcbId()))
- userFollow.setOcbId(bfb.getOcbId());
- userFollowMapper.updateByPrimaryKeySelective(userFollow);
- return 1;
- }
- @Override
- public int addOneContact(OrganizationContactBook ocb) {
- ocb.setAid(TokenManager.getAdminId());
- ocb.setId(UUID.randomUUID().toString());
- Admin ad = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
- ocb.setAname(ad.getName());
- if (ocb.getMajor()==1){
- organizationContactBookMapper.updateSubContact(ocb.getUid());
- OrganizationIdentity n=new OrganizationIdentity();
- n.setUid(ocb.getUid());
- n.setContacts(ocb.getName());
- n.setContactMobile(ocb.getMobile());
- n.setContactsDep(ocb.getDepartment());
- n.setContactsPosition(ocb.getPosition());
- organizationIdentityMapper.updateServiceByUid(n);
- }
- return organizationContactBookMapper.insert(ocb);
- }
- @Override
- public int deleteBusiness(String businessId) {
- return userBusinessMapper.deleteByPrimaryKey(businessId);
- }
- @Override
- public int updateBusinessToStop(String businessId) {
- UserBusiness ub = new UserBusiness();
- ub.setId(businessId);
- ub.setCustomerStatus(CustomerStatusFiled.STATUS_STOP.getCode());
- return userBusinessMapper.updateByPrimaryKeySelective(ub);
- }
- @Override
- public int deleteFollowOneBusiness(String ufbId) {
- UserFollowBusiness ufb = userFollowBusinessMapper.selectByPrimaryKey(ufbId);
- if (ufb.getFollowSituation() == 5) {// 如果业务是已签合同则不允许删除
- throw new BusinessException(new Error(ErrorConstants.BUSINESS_ALREADY_LOCKED, ""));
- }
- return userFollowBusinessMapper.deleteByPrimaryKey(ufbId);
- }
- @Override
- public int deleteOneContact(String ocbId) {
- return organizationContactBookMapper.deleteByPrimaryKey(ocbId);
- }
- @Override
- public List<Admin> findAdminName() {
- String aid = TokenManager.getAdminId();
- return userMapper.findAdminName(aid);
- }
- @Override
- public int updatePersonalCustomerz(CustomerPersonalDetailBo bo) {
- UserIdentity ui = new UserIdentity();
- User user = new User();
- try {
- BeanUtilsExt.copyProperties(ui, bo);
- user.setId(bo.getUid());
- user.setSocietyTag(bo.getSocietyTag());
- user.setHeadPortraitUrl(bo.getHeadPortraitUrl());
- user.setIntroduction(bo.getIntroduction());
- user.setUpdateTime(new Date());
- if (!StringUtils.isBlank(bo.getAid())) {
- user.setAid(bo.getAid());
- user.setShareType(0);
- }
- } catch (InvocationTargetException | IllegalAccessException e) {
- e.printStackTrace();
- }
- userMapper.updateByPrimaryKeySelective(user);
- return 1;
- }
- @Override
- public Pagination<CustomerListOut> findEnteringAudit(CustomerListOut clo, Integer pageNo, Integer pageSize) {
- Map<String, Object> params = disposeParams(clo);
- if (!StringUtils.isBlank(clo.getAdminName()))
- params.put("adminName", clo.getAdminName());
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditList",
- "findEnteringAuditCount", params, pageNo, pageSize);
- return list;
- }
- @Override
- public Pagination<CustomerListOut> findEnteringAuditIsNo(CustomerListOut clo, Integer pageNo, Integer pageSize) {
- clo.setAid(TokenManager.getAdminId());
- Map<String, Object> params = disposeParams(clo);
- if (!StringUtils.isBlank(clo.getAdminName()))
- params.put("adminName", clo.getAdminName());
- @SuppressWarnings("unchecked")
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("findEnteringAuditIsNoList",
- "findEnteringAuditIsNoCount", params, pageNo, pageSize);
- return list;
- }
- @Override
- public int updateEnteringAudit(User bo) {
- String[] ary = bo.getId().split(",");
- for (String s : ary) {
- String id = s;
- Integer auditStatus = bo.getAuditStatus();
- String auditOpinion = bo.getAuditOpinion();
- userMapper.updateEnteringAudit(id, auditStatus, auditOpinion);
- }
- return 1;
- }
- @Override
- public int updateMainContact(String ocbId, String uid) {
- organizationContactBookMapper.updateSubContact(uid);
- OrganizationIdentity oi = new OrganizationIdentity();
- OrganizationContactBook ocb = organizationContactBookMapper.selectByPrimaryKey(ocbId);
- oi.setUid(uid);
- oi.setContacts(ocb.getName());
- oi.setContactMobile(ocb.getMobile());
- organizationIdentityMapper.updateServiceByUid(oi);
- organizationContactBookMapper.updateMainContact(ocbId);
- return 1;
- }
- @Override
- public int updateRefusedCustomer(String id, String nickname, String mobile, String societyTag) {
- User u = userMapper.selectByPrimaryKey(id);
- u.setNickname(nickname);
- u.setMobile(mobile);
- u.setSocietyTag(societyTag);
- return userMapper.updateRefusedCustomer(id, nickname, mobile, societyTag);
- }
- /**
- * 计算私有客户剩余时间
- * @param tmpList
- * @param i
- * @param power
- */
- private void setCustomerList(List<CustomerListOut> tmpList, int i, Integer power) {
- Date now = new Date();
- Date s1, s2;
- long l1, l2;
- int diff1 = 0, diff2 = 0;
- for (CustomerListOut clo : tmpList) {
- // 如果最近跟进为空直接取转换时间
- if (clo.getLastFollowTime()!=null) {
- // 如果最近跟进小于转换取转换时间
- if (clo.getTransferTime()!=null&&(clo.getLastFollowTime().getTime() > clo.getTransferTime().getTime())
- ) {
- s1 = clo.getLastFollowTime();
- } else {
- s1 = clo.getTransferTime();
- }
- } else {
- s1 = clo.getTransferTime();
- }
- // 另外一个时间取转换时间
- s2 = clo.getTransferTime();
- l1 = s1.getTime();
- l2 = s2.getTime();
- if (i == 0) {
- diff1 = (int) ((l1 + AFTConstants.USER_FOLLOW_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
- diff2 = (int) ((l2 + AFTConstants.USER_SIGN_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
- if (diff1 < 0)diff1 = 0;
- if (diff2 < 0)diff2 = 0;
- } else if (i == 1) {
- diff1 = (int) ((l1 + AFTConstants.PROJECT_FOLLOW_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
- // diff2 = (int) ((l2 + AFTConstants.PROJECT_SIGN_LIMIT_MS - now.getTime()) / (24 * 3600 * 1000));
- if (diff1 < 0)diff1 = 0;
- }
- clo.setSurplusFollowTime(diff1 + "");
- clo.setSurplusSignTime(diff2 + "");
- if (power!=null&&power == 1) {
- if (!clo.getAid().equals(TokenManager.getAdminId())) {
- clo.setContacts("***");
- clo.setContactMobile("***");
- }
- }
- }
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listSignOrganizationCustomer(CustomerListIn cli, Integer pageNo,
- Integer pageSize) {
- cli.setAid(TokenManager.getAdminId());
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignOrganizationCustomerList",
- "selectSignOrganizationCustomerCount", params, pageNo, pageSize);
- List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
- setCustomerList(tmpList, 1, null);
- list.setList(tmpList);
- return list;
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListOut> listSignPersonalCustomer(CustomerListIn cli, Integer pageNo, Integer pageSize) {
- cli.setAid(TokenManager.getAdminId());
- Map<String, Object> params = disposeParams(cli);
- Pagination<CustomerListOut> list = (Pagination<CustomerListOut>) findPage("selectSignPersonalCustomerList",
- "selectSignPersonalCustomerCount", params, pageNo, pageSize);
- List<CustomerListOut> tmpList = (List<CustomerListOut>) list.getList();
- setCustomerList(tmpList, 0, null);
- list.setList(tmpList);
- return list;
- }
- @Override
- public List<LockingReleaseBo> selectLockedProject(String uid) {
- List<LockingReleaseBo> list = userMapper.selectLockedProject(uid, null, null, 1, 0);
- for (LockingReleaseBo lrb : list) {
- if (lrb.getAid().equals(TokenManager.getAdminId())) {
- lrb.setMySign(1);
- } else {
- lrb.setMySign(0);
- }
- }
- return list;
- }
- @Override
- public List<CustomerSimpleBo> getPrivateCustomerByName(String name) {
- return userMapper.selectPrivateCustomerByName(name, TokenManager.getAdminId());
- }
- @Override
- public List<CustomerSimpleBo> getSignedCustomerByName(String name) {
- return userMapper.selectSignedCustomerByName(name, TokenManager.getAdminId(), 1);
- }
- @Override
- public List<CustomerSimpleBo> getChannelCustomerByName(String name) {
- return userMapper.selectSignedCustomerByName(name, TokenManager.getAdminId(), 2);
- }
- private int updateUserLock(String uid, String aid, Integer oldStatus, Integer newStatus) {
- return userLockReleaseMapper.updateUserLock(uid, aid, oldStatus, newStatus);
- }
- private int updateUsersLock(List<String> uList, String aid, Integer oldStatus, Integer newStatus) {
- return userLockReleaseMapper.updateUsersLock(uList, aid, oldStatus, newStatus);
- }
- @Override
- public List<LockingReleaseBo> selectWaitReleaseCustomer(String uid) {
- List<LockingReleaseBo> list = new ArrayList<>();
- List<LockingReleaseBo> lockingReleaseBos = userLockReleaseMapper.selectWaitReleaseCustomer(uid);
- for (LockingReleaseBo bo : lockingReleaseBos) {
- // 渠道为空或者不其他的需要处理
- if (bo.getChannelType()==null||bo.getChannelType()!=1){
- list.add(bo);
- }
- }
- return list;
- }
- /**
- * 查询需要释放的业务
- *
- * @param uid
- * @return
- */
- @Override
- public List<LockingReleaseBo> selectWaitReleaseBusiness(String uid) {
- return userLockReleaseMapper.selectWaitReleaseBusiness(uid);
- }
- /**
- * 处理需要释放
- *
- */
- @Override
- public void updateReleaseLock(Date releaseTime) {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = formatter.format(releaseTime);
- userMapper.updateReleaseLock(time);
- }
- @Override
- public int updateAgainProjectTask(String uid, String projectId, String aid) {
- List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, TokenManager.getAdminId(),
- projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
- // List<LockingReleaseBo> businessLockedList = userMapper.selectLockedProject(uid, aid, projectId, 1, UserLockReleaseStatus.LOCKED.getCode());
- UserLockRelease u = new UserLockRelease();
- if (businessLockedList.size() == 1) {
- for (LockingReleaseBo l : businessLockedList) {
- u.setId(l.getId());
- u.setLockTime(new Date());
- }
- return userLockReleaseMapper.updateByPrimaryKeySelective(u);
- }
- return 0;
- }
- @Override
- public int updateInformationMaintainerr(String id, String aid) {
- User u = new User();
- u.setId(id);
- u.setInformationMaintainer(aid);
- return userMapper.updateByPrimaryKeySelective(u);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListIn> listCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setAid(TokenManager.getAdminId());
- // cli.setAid("1");
- if (cli.getShareType()==null){
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
- }
- Map<String, Object> params = disposeParams(cli);
- return (Pagination<CustomerListIn>) findPage("selectCustomerInformationList", "selectCustomerInformationCount",
- params, pageNo, pageSize);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<CustomerListIn> listDepCustomerInformation(CustomerListIn cli, Integer pageNo, Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setAid(TokenManager.getAdminId());
- // cli.setAid("1");
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
- Map<String, Object> params = disposeParams(cli);
- return (Pagination<CustomerListIn>) findPage("selectDepCustomerInformationList",
- "selectDepCustomerInformationCount", params, pageNo, pageSize);
- }
- public boolean checkCustomerInformation(String uid) {
- int i = userMapper.checkCustomerInformation(uid);
- if (i < 1) {
- return true;
- }
- return false;
- }
- @Override
- public void updatePendingReleaseLock(List<LockingReleaseBo> newList) {
- String lockIds = "";
- for (LockingReleaseBo bo : newList) {
- lockIds += bo.getId() + ",";
- }
- if (lockIds.length() > 0) {
- lockIds = "'" + lockIds.substring(0, lockIds.length() - 1).replace(",", "','") + "'";
- userLockReleaseMapper.updatePendingReleaseLock(lockIds);
- }
- }
- @Override
- public List<LockingReleaseBo> selectPendinglockUserList() {
- return userLockReleaseMapper.selectPendinglockUserList();
- }
- @Override
- public int updateUserLevel(User u) {
- if (!u.getId().contains(",")) {
- userMapper.updateByPrimaryKeySelective(u);
- } else {
- List<String> ulist = Arrays.asList(u.getId().split(","));
- userMapper.updateList(null, u.getLevel(), null, null, null, ulist,null);
- }
- return 1;
- }
- @Override
- public XSSFWorkbook privateUnitCustomerOutXls(CustomerListIn cli, Integer sort, Integer sortType, Integer pageNo,
- Integer pageSize) {
- cli.setType(AFTConstants.USER_TYPE_ORGANIZATION);
- cli.setAid(TokenManager.getAdminId());
- // cli.setAid("1");
- cli.setShareType(String.valueOf(AFTConstants.USER_SHARE_PRIVATE));
- Map<String, Object> params = disposeParams(cli);
- params.put("sort", sort);
- params.put("sortType", sortType);
- List<CustomerListOut> list = userMapper.privateUnitCustomerList(params);
- setCustomerList(list, 0, 0);
- if (list == null || list.size() == 0)
- return null;
- String[] comment = { "客户名称", "地区", "联系人", "联系电话", "社会性质", "客户初始时间", "剩余私有天数", "最新跟进时间", "客户等级" };
- String filePath = uploadPath + "/privateUnitCustomer";
- XSSFWorkbook wb = ExportExcelUtil.exportSelectPrivateOrganizationCustomer(list, comment, filePath);
- return wb;
- }
- @Override
- public int customerHandOver(String userIds, String receiveId) {
- /*
- * String [] str=userIds.split(","); String aid=TokenManager.getAdminId();
- * List<String> uids=Arrays.asList(str);
- * userLockReleaseMapper.updateBatchReleaseProject(uids,receiveId,aid);
- * userLockReleaseMapper.updateBatchlockProject(uids,receiveId,aid);
- */
- return 0;
- }
- @Override
- public int updatePrivateBusinessTransfer(String inputId, String uid, String pid) {
- List<LockingReleaseBo> list = userLockReleaseMapper.checkUserProject(uid, pid, TokenManager.getAdminId());
- if (list.isEmpty()) {
- throw new BusinessException(new Error("客户归属错误", "客户归属错误"));
- }
- LockingReleaseBo l = list.get(0);
- UserLockRelease ul = new UserLockRelease();
- ul.setId(l.getId());
- ul.setAid(inputId);
- userLockReleaseMapper.updateByPrimaryKeySelective(ul);
- addtransferLog(uid, pid, TokenManager.getAdminId(), inputId, 3, false);
- List<BusinessListBo> bl = userBusinessMapper.selectBusinessProjectByUAPid(uid, TokenManager.getAdminId(), pid);
- if (bl.size() == 1) {
- UserBusiness ub = new UserBusiness();
- ub.setId(bl.get(0).getBusinessId());
- ub.setAid(inputId);
- ub.setRemarks("转交客户业务触发");
- userBusinessMapper.updateByPrimaryKeySelective(ub);
- }
- return 1;
- }
- private void addtransferLog(String uid, String pid, String aid, String takeAid, Integer type, boolean isUs) {
- if (!isUs) {
- UserTransferLog utl = new UserTransferLog();
- utl.setAid(aid);
- utl.setCreateTime(new Date());
- utl.setPid(pid);
- utl.setTakeAid(takeAid);
- utl.setType(type);
- utl.setUid(uid);
- userTransferLogMapper.insertSelective(utl);
- } else {
- List<String> ulist = Arrays.asList(uid.split(","));
- List<UserTransferLog> utfList = new ArrayList<>();
- for (String us : ulist) {
- UserTransferLog utl = new UserTransferLog();
- utl.setAid(aid);
- utl.setCreateTime(new Date());
- utl.setPid(pid);
- utl.setTakeAid(takeAid);
- utl.setType(type);
- utl.setUid(us);
- utfList.add(utl);
- }
- userTransferLogMapper.insertList(utfList);
- }
- }
- @Override
- public List<transferListBo> transferList(String uid) {
- return userTransferLogMapper.selectByUidGetList(uid);
- }
- @Override
- public int pushReleaseUser(String id) {
- Date date = new Date();
- String aid = TokenManager.getAdminId();
- if (!id.contains(",")) {
- User u = userMapper.selectByPrimaryKey(id);
- if (!u.getAid().equals(aid)) {
- throw new BuilderException("客户归属错误!");
- }
- UserTransferLog utl = new UserTransferLog();
- u.setTransferTime(date);
- u.setShareType(1);
- userMapper.updateByPrimaryKeySelective(u);
- utl.setAid(aid);
- utl.setCreateTime(date);
- utl.setType(6);
- utl.setUid(id);
- userTransferLogMapper.insertSelective(utl);
- userLockReleaseMapper.updateUserTypeLock(u.getId(), TokenManager.getAdminId(), 0, 2, date);
- //用户客户统计移除时修改
- updateAdminUserCount(u.getAid(),u.getTransferTime());
- } else {
- List<String> list = Arrays.asList(id.split(","));
- List<UserTransferLog> ulList = new ArrayList<UserTransferLog>();
- List<User> userList=new ArrayList<>();
- for (String str : list) {
- User u = userMapper.selectByPrimaryKey(str);
- if (!u.getAid().equals(TokenManager.getAdminId())) {
- throw new BuilderException("客户归属错误!");
- }
- UserTransferLog utl = new UserTransferLog();
- utl.setAid(aid);
- utl.setCreateTime(date);
- utl.setType(6);
- utl.setUid(str);
- ulList.add(utl);
- userList.add(u);
- }
- userTransferLogMapper.insertList(ulList);
- userMapper.updateList(null, null, null, date, 1, list,null);
- userLockReleaseMapper.updateUserTypeLockList(list, TokenManager.getAdminId(), 0, 2, date);
- //批量移除客户,需要单独处理客户每天得计算。
- updateAdminUserAllCount(userList);
- }
- return 1;
- }
- private void updateAdminUserAllCount(List<User> userList) {
- for (User user : userList) {
- updateAdminUserCount(user.getAid(),user.getTransferTime());
- }
- }
- @Override
- public List<userDaysBo> selectReleaseUserDays(String id) {
- //渠道
- Integer y = USER_CHANNEL_DAYS;
- y = y - USER_REMIND_DAYS;
- List<userDaysBo> list = userLockReleaseMapper.selectUserDays(id, y);
- return list;
- }
- @Override
- public List<userDaysBo> selectChannelUserDays(String id) {
- return userLockReleaseMapper.selectChannelUserDays(USER_CHANNEL_DAYS,id);
- }
- @Override
- public int addGuidance(String followId, String guidance) {
- UserFollow uf = new UserFollow();
- uf.setId(followId);
- uf.setGuidance(guidance);
- uf.setGuidanceTime(new Date());
- String aid=TokenManager.getAdminId();
- Admin a=adminMapper.selectByPrimaryKey(aid);
- uf.setGuidanceAid(a.getId());
- uf.setGuidanceName(a.getName());
- userFollowMapper.pushUserGuidance(followId, 1);
- return userFollowMapper.updateByPrimaryKeySelective(uf);
- }
- @Override
- public boolean checkMax(String uid,String aid) {
- boolean isUs = false;
- if (uid !=null &&uid.contains(",")) {
- isUs = true;
- }
- List<String> uList = new ArrayList<>();
- int x=0;
- if (isUs) {
- uList = Arrays.asList(uid.split(","));
- uid=uList.get(0);
- x=uList.size();
- }else {
- x=1;
- }
- int limitmax = 0;
- int i = userMapper.checkUserMax(aid);
- if (uid !=null){
- User user =userMapper.selectByPrimaryKey(uid);
- if (user.getNewChannel()==1){
- return false;
- }
- }
- List<String > roles=adminMapper.getAdminRoleListByAid(aid);
- for (String role : roles) {
- if (role.equals(AFTConstants.SALESMAN_DIRECTOR)){
- if(limitmax<YXZJ_MAX)limitmax = YXZJ_MAX;
- continue;
- } else if (role.equals(AFTConstants.SALESMAN_MANAGER)){
- if(limitmax<YXJL_MAX)limitmax = YXJL_MAX;
- continue;
- } else if (role.equals(AFTConstants.SALESMAN)){
- if(limitmax<YXY_MAX)limitmax = YXY_MAX;
- continue;
- }
- }
- i+=x;
- if (i >= limitmax) {
- return true;
- }
- return false;
- }
- @Override
- public void pushReleaseLog(List<LockingReleaseBo> list, Integer type) throws InterruptedException {
- Date date = new Date();
- List<LockingReleaseBo> newList = new ArrayList<LockingReleaseBo>();
- List<UserTransferLog> list3 = new ArrayList<UserTransferLog>();
- if (list != null && list.size() > 0) {
- for (int i = 0; i < list.size(); i++) {
- newList.add(list.get(i));
- if (50 == newList.size() || i == list.size() - 1) {
- if (newList.size() > 0) {
- // 处理日志
- for (LockingReleaseBo lrb : newList) {
- UserTransferLog utl = new UserTransferLog();
- utl.setAid(lrb.getAid());
- utl.setCreateTime(date);
- if (type == 0)
- utl.setType(4);
- else if (type == 1)
- utl.setType(5);
- utl.setUid(lrb.getUid());
- list3.add(utl);
- }
- userTransferLogMapper.insertList(list3);
- list3.clear();
- }
- newList.clear();
- Thread.sleep(2000);
- }
- }
- }
- }
- @Override
- public Object listChannelCustomer(InputListChannel in) {
- Map<String, Object> params = new HashMap<>();
- if (StringUtils.isNotBlank(in.getName()))
- params.put("name", in.getName());
- if (in.getProvince() != null)
- params.put("province", in.getProvince());
- if (in.getCity() != null)
- params.put("city", in.getCity());
- if (in.getStatus() != null)
- params.put("status", in.getStatus());
- params.put("type", in.getType() == null ? 0 : in.getType());
- if (StringUtils.isNotBlank(in.getStartTime()))
- params.put("startTime", in.getStartTime());
- if (StringUtils.isNotBlank(in.getEndTime()))
- params.put("endTime", in.getEndTime() + " 23:59:59");
- // 0营销员 1渠道专员 2营销总监 3营销经理 4释放 5未分配 6已分配 7已签单
- if (in.getType()==0) {
- if(StringUtils.isNotBlank(in.getAid()))params.put("aid", in.getAid());
- params.put("sid", TokenManager.getAdminId());
- } else if (in.getType()==1) {
- params.put("aid", in.getAid() == null ? TokenManager.getAdminId() : in.getAid());
- } else if (in.getType()==2) {
- if(StringUtils.isNotBlank(in.getAid()))params.put("aid", in.getAid());
- }else if (in.getType()==3) {
- params.put("maid", TokenManager.getAdminId());
- if(StringUtils.isNotBlank(in.getAid()))params.put("aid", in.getAid());
- } else {
- params.put("aid", in.getAid() == null ? TokenManager.getAdminId() : in.getAid());
- }
- Pagination<?> p=findPage("selectChannelCustomerList", "selectChannelCustomerCount", params, in.getPageNo(),
- in.getPageSize());
- @SuppressWarnings("unchecked")
- List<OutUserChannel> list=(List<OutUserChannel>) p.getList();
- Date date=new Date();
- for (OutUserChannel o : list) {
- if (o.getDistributionTime()!=null) {
- int days = (int) ((o.getDistributionTime().getTime() + AFTConstants.USER_CHENNL_LIMIT_MS - date.getTime()) / (24 * 3600 * 1000));
- o.setDays(days);
- }
- }
- return p;
- }
- @Override
- public Object pushChannelDeliver(List<String> uids, String receiveId, String remarks, Integer type) {
- Date date = new Date();
- Integer i = userMapper.updatechannelCustomerDeliver(uids, receiveId);
- Integer status = null;
- if (i > 0) {
- List<UserTransferLog> l = new ArrayList<UserTransferLog>();
- for (String string : uids) {
- UserTransferLog u = new UserTransferLog();
- u.setAid(TokenManager.getAdminId());
- u.setUid(string);
- if (type == 0) {
- u.setTakeAid(receiveId);
- u.setType(9);
- } else if (type == 1) {
- u.setTakeAid(receiveId);
- u.setType(10);
- } else if (type == 2) {
- u.setType(12);
- }
- u.setCreateTime(date);
- u.setRemarks(remarks);
- l.add(u);
- }
- userTransferLogMapper.insertList(l);
- }
- if (type != 2) {
- userLockReleaseMapper.insertChannelList(uids, receiveId);
- String role = userMapper.checkRoleMax(receiveId);
- if (role.equals(AFTConstants.SALESMAN_MANAGER)) {
- status = ChannelStatus.YFPJL.getCode();
- } else {
- status = ChannelStatus.YFPYXY.getCode();
- }
- } else {
- userLockReleaseMapper.updateChannelList(uids);
- status = ChannelStatus.HT.getCode();
- }
- if (type == 0) {
- userChannelMapper.updateByuids(uids, type, date, receiveId, status);
- } else {
- userChannelMapper.updateByuids(uids, type, date, null, status);
- }
- organizationContactBookMapper.updateByUids(uids, receiveId);
- return 1;
- }
- @Override
- public boolean checkChannel(List<String> uids) {
- for (String uid : uids) {
- List<UserFollow> list = userFollowMapper.selectbyUid(uid, TokenManager.getAdminId());
- if (!list.isEmpty()) {
- return true;
- }
- }
- return false;
- }
- @Override
- public boolean checkBeforeChannel(String uid) {
- String aid = userMapper.checkBeforeChannel(uid);
- if (aid != null && aid.equals(TokenManager.getAdminId())) {
- return true;
- }
- return false;
- }
- @Override
- public boolean checkRecovery(List<String> uids) {
- List<String> list = userChannelMapper.checkRecovery(uids);
- for (String string : list) {
- if (string.equals("1")) {
- return true;
- }
- }
- return false;
- }
- @Override
- public List<userDaysBo> selectChannelNotFollow(String aid) {
- Integer days = 15;
- return userLockReleaseMapper.selectChannelNotFollow(days,aid);
- }
- @Override
- public Object listChannelCounts(InputChannelCounts in) {
- Map<String, Object> params = new HashMap<>();
- params.put("type", in.getType() == null ? 0 : in.getType());
- if (StringUtils.isNotBlank(in.getStartTime()))
- params.put("startTime", in.getStartTime());
- if (StringUtils.isNotBlank(in.getEndTime()))
- params.put("endTime", in.getEndTime() + " 23:59:59");
- return findPage("selectChannelCountsList", "selectChannelCountsCount", params, in.getPageNo(),
- in.getPageSize());
- }
- @Override
- public Object getUserByName(String name) {
- return userMapper.getUserByName(name);
- }
- @Override
- public Object getUserByNames(String name, Integer type,Integer pageNo, Integer pageSize) {
- Map<String, Object> params = new HashMap<>();
- params.put("name", name);
- Pagination<?> page =findPage("getUserByNameList", "getUserByNameCount", params, pageNo, pageSize);
- return pushRetrun(page);
- }
- private Object pushRetrun(Pagination<?> page) {
- Admin admin = adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
- List<CustomerSimpleBo> list = (List<CustomerSimpleBo>) page.getList();
- //公出权限 0正常 1全部 =1的用户,公出status=0(应该是不用审核)
- //不然,就是 客户是公共客户 status=2
- //再不然就是 是我自己的客户就是 status=0
- //再不然就是status=1 (也就是不是公共客户,也不是我自己的客户,按理是需要审核)
- list.forEach(e ->{
- if (admin.getPublicPurview()==1){
- //如果是白名单不管是不是自己都可以公出
- e.setStatus(0);
- }else {
- //不是白名单不是自己的需要审核
- if (e.getShareType()==1){
- e.setStatus(2);
- }else if (admin.getId().equals(e.getAid())){
- e.setStatus(0);
- }else {
- e.setStatus(1);
- }
- }
- });
- return page;
- }
- @Override
- public int updateUserName(String uid, String userName) {
- userNamesMapper.updateAddUserName(uid,userName);
- UserNames un=new UserNames();
- un.setAid(TokenManager.getAdminId());
- un.setUid(uid);
- un.setName(userName);
- userNamesMapper.insertSelective(un);
- return 1;
- }
- @Override
- public boolean checkUserName(String uid,String userName) {
- String name2=null;
- if (userName.contains("(")){
- name2=userName.replace("(","(").replace(")",")");
- }else if (userName.contains("(")){
- name2=userName.replace("(","(").replace(")",")");
- }
- List<UserNamesListBo> list=userNamesMapper.checkUserName(userName);
- List<UserNamesListBo> list2=userNamesMapper.checkUserName(name2);
- int i=0;
- for (UserNamesListBo userNamesListBo : list) {
- if (!userNamesListBo.getUid().equals(uid)){
- i++;
- }
- }
- for (UserNamesListBo userNamesListBo : list2) {
- if (!userNamesListBo.getUid().equals(uid)){
- i++;
- }
- }
- return i > 0;
- }
- @Override
- public List<UserNamesListBo> listUserName(String uid) {
- List<UserNamesListBo> list=userNamesMapper.getUserList(uid);
- return list;
- }
- @Override
- public Pagination<OutUserMianProducts> mainProductsList( InputMainProductsList in) {
- Map<String,Object> map =new HashMap<>();
- map.put("aid",TokenManager.getAdminId());
- if(in.getUserName()!=null)map.put("userName",in.getUserName());
- if(in.getKey()!=null)map.put("key",in.getKey());
- if(in.getStartTime()!=null)map.put("startTime",in.getStartTime());
- if(in.getEndTime()!=null)map.put("endTime",in.getEndTime()+" 23:59:59");
- if(in.getShiroType()==null){in.setShiroType(0);}
- if(in.getShareType()!=null)map.put("shareType",in.getShareType());
- else if(in.getShiroType()==2){
- if(in.getAdminName()!=null)map.put("adminName",in.getAdminName());
- if(in.getDepId()!=null)map.put("depId",in.getDepId());
- }
- map.put("shiroType",in.getShiroType());
- return (Pagination<OutUserMianProducts>) findPage("findMainProductsList","findMainProductsCount",map,in.getPageNo(),in.getPageSize());
- }
- @Override
- public List<OutUserDateLogList> userDateLogList(String uid) {
- return userDataLogMapper.userDateLogList(uid);
- }
- @Override
- public int updateuserBusinessScope(String id, String businessScope) {
- Date date =new Date();
- OrganizationIdentity use=organizationIdentityMapper.selectByPrimaryKey(id);
- if(!businessScope.equals(use.getBusinessScope())){
- updateBusinessScope(use.getUid(),businessScope,use.getBusinessScope(),date);
- OrganizationIdentity oi=new OrganizationIdentity();
- oi.setId(id);
- oi.setBusinessScope(businessScope);
- return organizationIdentityMapper.updateByPrimaryKeySelective(oi);
- }
- return 0;
- }
- @Override
- public boolean checkData(String uid, String aid) {
- List<String> list=Arrays.asList(uid.split(","));
- for (String s : list) {
- User u=userMapper.selectByPrimaryKey(s);
- if (!u.getInformationMaintainer().equals(aid)){
- return true;
- }
- }
- return false;
- }
- @Override
- public int updateUserDate(String uid,Integer province, Integer city, Integer area, String businessScope, String intendedProject,
- String introduction,Integer channelType,String orgCode) {
- OrganizationIdentity oi =new OrganizationIdentity();
- oi.setUid(uid);
- if (province!=null ||city !=null ||area!=null|| businessScope!=null ||intendedProject!=null||orgCode!=null){
- if(province!=null)oi.setLocationProvince(province);
- if(city!=null)oi.setLocationCity(city);
- if(area!=null)oi.setLocationArea(area);
- if (orgCode!=null)oi.setOrgCode(orgCode);
- if (businessScope!=null){
- OrganizationIdentity use=organizationIdentityMapper.selectOrgIdentityByUserId(uid);
- updateBusinessScope(uid,businessScope,use.getBusinessScope(),new Date());
- oi.setBusinessScope(businessScope);
- }
- if(intendedProject!=null)oi.setIntendedProject(intendedProject);
- organizationIdentityMapper.updateServiceByUid(oi);
- }
- if (introduction!=null){
- User user=new User();
- user.setId(uid);
- user.setIntroduction(introduction);
- userMapper.updateByPrimaryKeySelective(user);
- }
- if (channelType !=null){
- UserMid um =new UserMid();
- um.setUid(uid);
- um.setChannelType(channelType);
- userMidMapper.updateByUid(um);
- }
- return 1;
- }
- @Override
- public Pagination<OutChannelListBo> channelUserList(InputChannelListBo in) {
- Map<String, Object> params = new HashMap<>();
- addParams(in, params);
- Pagination<OutChannelListBo> p = (Pagination<OutChannelListBo>) findPage(
- "channelUserList", "channelUserCout", params, in.getPageNo(),
- in.getPageSize());
- //只有私有客户才需要剩余时间
- if (in.getShareType()==null || in.getShareType()!=1){
- List<OutChannelListBo> list = (List<OutChannelListBo>) p.getList();
- for (OutChannelListBo out : list) {
- if(out.getType()!=null&&out.getType()==1){
- out.setaName(null);
- out.setCreateTime(null);
- out.setLastFollowTime(null);
- }else {
- out.setRemainingDays(getRemainingDays(out));
- }
- }
- }
- return p;
- }
- /**
- * 组装参数
- * @param in
- * @param params
- */
- private void addParams(InputChannelListBo in, Map<String, Object> params) {
- if (StringUtils.isNotBlank(in.getName())) params.put("name", in.getName());
- if (StringUtils.isNotBlank(in.getStartDate())) params.put("startDate", in.getStartDate());
- if (StringUtils.isNotBlank(in.getEndDate())) params.put("endDate", in.getEndDate()+" 23:59:59");
- if (null!= in.getProvince()) params.put("province", in.getProvince());
- if (null!= in.getArea()) params.put("area", in.getArea());
- if (null!= in.getCity()) params.put("city", in.getCity());
- if (null!= in.getType()) params.put("type", in.getType());
- if (null!= in.getShareType()) {
- params.put("shareType", in.getShareType());
- if(!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
- if (in.getShareType()==0){
- if (in.getAid()==null||in.getAid().equals(TokenManager.getAdminId())){
- params.put("aid", TokenManager.getAdminId());
- }else{
- params.put("aid", "");
- }
- }
- }else{
- if (null != in.getAid())params.put("aid", in.getAid());
- }
- }
- if (null != in.getNewChannel())params.put("newChannel", in.getNewChannel());
- }
- @Override
- public List<OutChannelListBo> selectChannelUserList(InputChannelListBo in) {
- Map<String, Object> params = new HashMap<>();
- addParams(in, params);
- return userMapper.channelUserList(params);
- }
- /**
- * 根据您 初始时间、最后跟进时间当前时间计算剩余天数
- * @param out
- * @return
- */
- private String getRemainingDays(OutChannelListBo out) {
- Date now = new Date();
- Long lastFollow=null,transfer=null,endLong = null;
- Integer diff1 = 0;
- // 如果最近跟进为空直接取转换时间
- try {
- if (StringUtils.isNotBlank(out.getLastFollowTime())) {
- lastFollow = DateUtils.parseDate(out.getLastFollowTime(), AFTConstants.YYYYMMDDHHMMSS).getTime();
- // 如果最近跟进小于转换取转换时间
- if (StringUtils.isNotBlank(out.getTransferTime())) {
- transfer = DateUtils.parseDate(out.getTransferTime(), AFTConstants.YYYYMMDDHHMMSS).getTime();
- }else {
- transfer=0L;
- }
- if (lastFollow > transfer) {
- endLong = lastFollow;
- } else {
- endLong = transfer;
- }
- } else {
- if (StringUtils.isNotBlank(out.getTransferTime())) {
- endLong = DateUtils.parseDate(out.getTransferTime(), AFTConstants.YYYYMMDDHHMMSS).getTime();
- } else {
- return "0";
- }
- }
- }catch (Exception e){
- throw new BusinessException("转换异常");
- }
- endLong=endLong+AFTConstants.USER_FOLLOW_LIMIT_MS;
- diff1 = (int) ((endLong - now.getTime()) / (24 * 3600 * 1000));
- return diff1.toString();
- }
- @Override
- public Pagination<OutUserLastSignBo> selectUserLastSign(InputSelectUserLastSignBo in) {
- Map<String, Object> param = addParam(in);
- Pagination<OutUserLastSignBo> p=(Pagination<OutUserLastSignBo>) findPage("selectUserLastSignList","selectUserLastSignCount",param,in.getPageNo(),in.getPageSize());
- pushDays(p);
- return p;
- }
- @Override
- public Result selectUserLastSignExport(InputSelectUserLastSignBo in) {
- Map<String, Object> param = addParam(in);
- List<OutUserLastSignBo> list = (List<OutUserLastSignBo>) findList("selectUserLastSignList", param, 1, 99999);
- pushDays(list);
- NewExcelUtil<OutUserLastSignBo> excelUtil=new NewExcelUtil<>(OutUserLastSignBo.class);
- return excelUtil.exportExcel(list,"用户最后跟进表",uploadPath);
- }
- @Override
- public boolean checkAid(String aid, Integer roleType) {
- List<Integer> roleTypes = adminMapper.selectRoleTypeByid(aid);
- for (Integer rt : roleTypes) {
- if (rt.equals(roleType))return true;
- }
- return false;
- }
- private void pushDays(Pagination<OutUserLastSignBo> p) {
- List<OutUserLastSignBo> list = (List<OutUserLastSignBo>) p.getList();
- pushDays(list);
- }
- private void pushDays(List<OutUserLastSignBo> list) {
- for (OutUserLastSignBo bo : list) {
- String dates=null;
- if (bo.getLastFollowTimeStr()!=null)dates=bo.getLastFollowTimeStr();
- else dates=bo.getTransferTimeStr();
- Integer days=DateUtils.sumDays(dates);
- bo.setDays(days);
- }
- }
- private Map<String, Object> addParam(InputSelectUserLastSignBo in) {
- Map<String,Object> param=new HashMap<>();
- Integer purview=null;
- if (TokenManager.hasRole(AFTConstants.SUPERADMIN)||TokenManager.hasRole(AFTConstants.SUPERADMIN_ASSISTANT)){
- purview=2;
- } else if (TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
- purview=0;
- } else if (TokenManager.hasRole(AFTConstants.APPROVAL_DECISION_ASSISTANT)) {
- purview = 1;
- }else {
- throw new BusinessException("权限异常");
- }
- param.put("purview",purview);
- if(in.getNickname()!=null)param.put("nickname",in.getNickname());
- if(in.getAid()!=null)param.put("aid",in.getAid());
- if(in.getShareType()!=null)param.put("shareType",in.getShareType());
- if (in.getDaysType()!=null){
- Calendar cal=Calendar.getInstance();
- cal=DateUtils.setMidnight(cal);
- if (in.getDaysType()==0)cal.add(Calendar.DATE,-14);
- else if (in.getDaysType()==1)cal.add(Calendar.DATE,-29);
- else if (in.getDaysType()==2)cal.add(Calendar.DATE,-59);
- else if (in.getDaysType()==3)cal.add(Calendar.DATE,-89);
- else if (in.getDaysType()==4)cal.add(Calendar.DATE,-179);
- else if (in.getDaysType()==5)cal.add(Calendar.DATE,-364);
- else if (in.getDaysType()==6)cal.add(Calendar.DATE,-729);
- param.put("lastTime",DateUtils.formatDate(cal.getTime(),AFTConstants.YYYYMMDDHHMMSS));
- }
- return param;
- }
- @Override
- public Object importExcel(MultipartFile file) {
- NewExcelUtil<InputExcelUser> newExcelUtil=new NewExcelUtil<>(InputExcelUser.class);
- List<InputExcelUser> list = null;
- try {
- list = newExcelUtil.importExcel(file.getInputStream(),0);
- } catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- return pushUserName(list);
- }
- @Override
- public List<CustomerSimpleBo> getRestrictCustomerByName(String name) {
- return userMapper.getRestrictCustomerByName(name,TokenManager.getAdminId());
- }
- private Object pushUserName(List<InputExcelUser> list) {
- List<InputExcelUser> res=new ArrayList<>();
- List<InputExcelUser> list2=new ArrayList<>();
- int i = 0;
- for (InputExcelUser e : list) {
- i++;
- list2.add(e);
- if (list2.size()==100||i==list.size()){
- List<UserNamesListBo> userNamesListBos = userNamesMapper.selectUserNameList(list2);
- if (!userNamesListBos.isEmpty()){
- for (InputExcelUser excelUser : list2) {
- for (UserNamesListBo ex2 : userNamesListBos) {
- if (ex2.getName().equals(excelUser.getName())){
- excelUser.setType(1);
- break;
- }
- }
- if(excelUser.getType()==null){
- excelUser.setType(0);
- }
- if (excelUser.getType()==1){
- res.add(excelUser);
- }
- }
- }
- list2.clear();
- }
- }
- return res;
- }
- }
|