AdminServiceImpl.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. package com.goafanti.admin.service.impl;
  2. import com.goafanti.admin.bo.*;
  3. import com.goafanti.admin.service.AdminService;
  4. import com.goafanti.admin.service.DepartmentService;
  5. import com.goafanti.admin.service.NewAdminService;
  6. import com.goafanti.common.constant.AFTConstants;
  7. import com.goafanti.common.dao.*;
  8. import com.goafanti.common.error.BusinessException;
  9. import com.goafanti.common.model.*;
  10. import com.goafanti.common.utils.LoggerUtils;
  11. import com.goafanti.common.utils.PasswordUtil;
  12. import com.goafanti.common.utils.StringUtils;
  13. import com.goafanti.core.mybatis.BaseMybatisDao;
  14. import com.goafanti.core.mybatis.page.Pagination;
  15. import com.goafanti.core.shiro.token.TokenManager;
  16. import com.goafanti.customer.bo.BusinessListBo;
  17. import com.goafanti.organization.bo.OrganizationListOut;
  18. import org.springframework.beans.BeanUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import javax.annotation.Resource;
  22. import java.util.*;
  23. @Service
  24. public class AdminServiceImpl extends BaseMybatisDao<AdminMapper> implements AdminService {
  25. @Autowired
  26. private AdminMapper adminMapper;
  27. @Autowired
  28. private UserRoleMapper userRoleMapper;
  29. @Autowired
  30. private AdminLocationMapper adminLocationMapper;
  31. @Autowired
  32. private UserLockReleaseMapper userLockReleaseMapper;
  33. @Autowired
  34. private UserBusinessMapper userBusinessMapper;
  35. @Autowired
  36. private UserMapper userMapper;
  37. @Autowired
  38. private DepartmentMapper departmentMapper;
  39. @Autowired
  40. private DepartmentService departmentService;
  41. @Resource(name = "passwordUtil")
  42. private PasswordUtil passwordUtil;
  43. @Autowired
  44. private NewAdminService newAdminService;
  45. @Autowired
  46. private AdminUserCountMapper adminUserCountMapper;
  47. @Autowired
  48. private TOrderNewMapper TOrderNewMapper;
  49. @Autowired
  50. private ExpenseAccountMapper expenseAccountMapper;
  51. @Autowired
  52. private TOrderInvoiceMapper tOrderInvoiceMapper;
  53. @Autowired
  54. private TTaskMemberMapper tTaskMemberMapper;
  55. @Autowired
  56. private TOrderPaymentMapper tOrderPaymentMapper;
  57. @Autowired
  58. private FinanceCountMapper financeCountMapper;
  59. @Override
  60. public List<Admin> selectAllAdmin() {
  61. return adminMapper.selectAllAdmin(null);
  62. }
  63. @Override
  64. public Admin selectByMobile(String mobile) {
  65. return adminMapper.selectByMobile(mobile);
  66. }
  67. @Override
  68. public Admin selectByPrimaryKey(String key) {
  69. return adminMapper.selectByPrimaryKey(key);
  70. }
  71. @SuppressWarnings("unchecked")
  72. @Override
  73. public Pagination<AdminListBo> listAdmin(Integer province, Integer number, String mobile, String name,String roleName,Integer seniorStaff,
  74. Integer pageNo, Integer pageSize) {
  75. Map<String, Object> params = new HashMap<>();
  76. if (StringUtils.isNotBlank(roleName))params.put("roleName", roleName);
  77. if (StringUtils.isNotBlank(mobile))params.put("mobile", mobile);
  78. if (StringUtils.isNotBlank(name))params.put("name", name);
  79. if (null != number)params.put("number", number);
  80. if (null != seniorStaff)params.put("seniorStaff", seniorStaff);
  81. if (pageNo == null || pageNo < 0)pageNo = 1;
  82. if (pageSize == null || pageSize < 0 || pageSize > 10)pageSize = 10;
  83. if (province != null) params.put("province", province);
  84. return (Pagination<AdminListBo>) findPage("findAdminListByPage", "findAdminCount", params, pageNo,
  85. pageSize);
  86. }
  87. @Override
  88. public int insert(Admin ad) {
  89. return adminMapper.insert(ad);
  90. }
  91. @Override
  92. public int updateByPrimaryKeySelective(Admin ad, List<String> roleIds) {
  93. Map<String, Object> params = new HashMap<>();
  94. params.put("uid", ad.getId());
  95. params.put("roles", roleIds);
  96. if (ad.getId() != "1") {
  97. userRoleMapper.deleteByUserId(ad.getId());
  98. if (!roleIds.isEmpty()) {
  99. userRoleMapper.insertBatch(params);
  100. }
  101. TokenManager.clearUserAuthByUserId(ad.getId());
  102. }
  103. return adminMapper.updateByPrimaryKeySelective(ad);
  104. }
  105. @Override
  106. public int updateByPrimaryKey(Admin a) {
  107. return adminMapper.updateByPrimaryKeySelective(a);
  108. }
  109. @Override
  110. public AdminDetail selectAdminDetail(String id) {
  111. Admin a = adminMapper.selectByPrimaryKey(id);
  112. if (null == a) {
  113. return null;
  114. }
  115. AdminDetail ad = new AdminDetail();
  116. BeanUtils.copyProperties(a, ad);
  117. ad.setRoles(adminMapper.selectRolesByPrimaryKey(id));
  118. return null;
  119. }
  120. @Override
  121. public List<Admin> selectCognizanceConsultant() {
  122. return adminMapper.selectCognizanceConsultant();
  123. }
  124. @Override
  125. public List<Admin> selectPatentAuthor() {
  126. return adminMapper.selectPatentAuthor();
  127. }
  128. @Override
  129. public List<Admin> selectPatentPrincipal() {
  130. return adminMapper.selectPatentPrincipal();
  131. }
  132. @Override
  133. public List<Admin> selectCopyrightConsultant() {
  134. return adminMapper.selectCopyrightConsultant();
  135. }
  136. @Override
  137. public List<Admin> selectCognizancePrincipal() {
  138. return adminMapper.selectCognizancePrincipal();
  139. }
  140. @Override
  141. public List<Admin> selectCopyrightPrincipal() {
  142. return adminMapper.selectCopyrightPrincipal();
  143. }
  144. @Override
  145. public List<Admin> selectTechprojectConsultant() {
  146. return adminMapper.selectTechprojectConsultant();
  147. }
  148. @Override
  149. public List<Admin> selectTechprojectPrincipal() {
  150. return adminMapper.selectTechprojectPrincipal();
  151. }
  152. @Override
  153. public List<String> selectRoleByPrimaryKey(String uid) {
  154. return adminMapper.selectRoleByPrimaryKey(uid);
  155. }
  156. @Override
  157. public List<String> listAuditor() {
  158. return userRoleMapper.listAuditor();
  159. }
  160. @Override
  161. public Map<String, String> selectAccoutManager() {
  162. return disposeAdminList(adminMapper.selectAccoutManager());
  163. }
  164. @Override
  165. public Map<String, String> selectTechnician() {
  166. return disposeAdminList(adminMapper.selectTechnician());
  167. }
  168. @Override
  169. public Map<String, String> selectSalesman() {
  170. return disposeAdminList(adminMapper.selectSalesman());
  171. }
  172. @Override
  173. public Map<String, String> selectContractManager() {
  174. return disposeAdminList(adminMapper.selectContractManager());
  175. }
  176. @Override
  177. public Map<String, String> selectTechBroder() {
  178. return disposeAdminList(adminMapper.selectTechBroder());
  179. }
  180. @Override
  181. public int insertNewAdmin(Admin ad) {
  182. return adminMapper.insert(ad);
  183. }
  184. @Override
  185. public Map<String, String> listAdminSelect() {
  186. if (TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  187. return disposeAdminList(adminMapper.listAdminSelectBySuperAdmin());
  188. } else if (TokenManager.hasRole(AFTConstants.AREAADMIN)) {
  189. List<Integer> provinceList = adminLocationMapper
  190. .selectProvinceWhereCityIsNullByAdminId(TokenManager.getAdminId());
  191. List<Integer> cityList = adminLocationMapper.selectCityByAdminId(TokenManager.getAdminId());
  192. provinceList.addAll(cityList);
  193. return disposeAdminList(adminMapper.listAdminSelectByAreaAdmin(provinceList, cityList));
  194. }
  195. return null;
  196. }
  197. private Map<String, String> disposeAdminList(List<Admin> list) {
  198. Map<String, String> map = new TreeMap<String, String>();
  199. for (Admin o : list) {
  200. map.put(o.getId(), o.getName());
  201. }
  202. return map;
  203. }
  204. @Override
  205. public List<Admin> listAdminByName(String name,Integer status) {
  206. if(status==null)status=0;
  207. return adminMapper.listAdminByName(name,status);
  208. }
  209. @Override
  210. public List<AdminListBo> selectDepartmentStaff(String departmentId, String name) {
  211. return adminMapper.selectDepartmentStaff( departmentId, name);
  212. }
  213. @Override
  214. public int updateLockAdmin() {
  215. int count=0;
  216. List<Admin> list=adminMapper.selectAllAdmin(null);//获取所有用户
  217. List<List<Admin>>aList=groupList(list);//拆分成多个
  218. String lockIds = "";
  219. for(List<Admin> al:aList){
  220. for (Admin a : al) {
  221. String pwd=a.getPassword();
  222. a.setPassword("123456");
  223. String pwd2=passwordUtil.getEncryptPwd(a);
  224. if (pwd.equals(pwd2)) {
  225. lockIds += a.getId() + ",";
  226. }
  227. }
  228. if(lockIds.length()>0){
  229. try {
  230. lockIds = "'" + lockIds.substring(0,lockIds.length()-1).replace(",", "','") + "'";
  231. count+= adminMapper.updateLockIds(lockIds);
  232. lockIds = "";
  233. Thread.sleep(1000);
  234. } catch (InterruptedException e) {
  235. LoggerUtils.error(getClass(), "未修改管理员锁定失败", e);
  236. }
  237. }
  238. }
  239. return count;
  240. }
  241. /*
  242. * List分割
  243. */
  244. public List<List<Admin>> groupList(List<Admin> list) {
  245. List<List<Admin>> listGroup = new ArrayList<List<Admin>>();
  246. int listSize = list.size();
  247. //子集合的长度
  248. int toIndex = 100;
  249. for (int i = 0; i < list.size(); i += toIndex) {
  250. if (i + toIndex > listSize) {
  251. toIndex = listSize - i;
  252. }
  253. List<Admin> newList = list.subList(i, i + toIndex);
  254. listGroup.add(newList);
  255. }
  256. return listGroup;
  257. }
  258. @Override
  259. public List<Admin> getListDefaultPassword(String depId) {
  260. List<Admin> list=adminMapper.selectAllAdmin(depId);
  261. List<Admin> list2=new ArrayList<>();
  262. for (Admin a : list) {
  263. String pwd=a.getPassword();
  264. a.setPassword("123456");
  265. String pwd2=passwordUtil.getEncryptPwd(a);
  266. if (pwd.equals(pwd2)) {
  267. list2.add(a);
  268. }
  269. }
  270. return list2;
  271. }
  272. @Override
  273. public List<Admin> getAdminRoleList(String roleName) {
  274. return adminMapper.getAdminRoleNameList(roleName);
  275. }
  276. @Override
  277. public int addFrequentContacts(String id) {
  278. String []ss=id.split(",");
  279. List<String> list=adminMapper.getaidFrequentContacts(TokenManager.getAdminId()==null?"1":TokenManager.getAdminId());
  280. for (String s : ss) {
  281. boolean flag=true;
  282. for (String s2 : list) {
  283. if (s.equals(s2)) {
  284. flag=false;
  285. }
  286. }
  287. if (flag) {
  288. AdminContacts a=new AdminContacts();
  289. a.setId(UUID.randomUUID().toString());
  290. a.setAid(TokenManager.getAdminId()==null?"1":TokenManager.getAdminId());
  291. a.setContactsId(s);
  292. adminMapper.addAdminContacts(a);
  293. }
  294. }
  295. return 1;
  296. }
  297. @SuppressWarnings("unchecked")
  298. @Override
  299. public Pagination<AdminListBo> frequentContactsList(String deps, String name,String roleName, Integer pageSize, Integer pageNo) {
  300. Map<String, Object> params = new HashMap<String, Object>();
  301. if(pageSize==null||pageSize<0)pageSize=10;
  302. if(pageNo==null||pageNo<0)pageNo=1;
  303. if (StringUtils.isNotBlank(deps)){
  304. params.put("depId", departmentService.parseArray(deps));
  305. }
  306. if (StringUtils.isNotBlank(name)) params.put("name", name);
  307. if (StringUtils.isNotBlank(roleName)) params.put("roleName", roleName);
  308. params.put("aid", TokenManager.getAdminId()==null?"1":TokenManager.getAdminId());
  309. Pagination<AdminListBo> p = (Pagination<AdminListBo>)findPage("frequentContactsList", "frequentContactsCount", params, pageNo, pageSize);
  310. List<AdminListBo> list=(List<AdminListBo>)p.getList();
  311. for(AdminListBo i:list){
  312. newAdminService.pushRolesName(i);
  313. }
  314. return p;
  315. }
  316. @Override
  317. public int deleteFrequentContacts(String id) {
  318. return adminMapper.deleteFrequentContacts(id);
  319. }
  320. @SuppressWarnings("unchecked")
  321. @Override
  322. public Pagination<AdminCustomerBo> selectAdminCustomerStatistics(String depId, String startTime, String endTime, Integer pageSize, Integer pageNo) {
  323. Map<String, Object> params = new HashMap<String, Object>();
  324. if(pageSize==null||pageSize<0)pageSize=10;
  325. if(pageNo==null||pageNo<0)pageNo=1;
  326. if (StringUtils.isNotBlank(depId)) params.put("depId", depId);
  327. if (StringUtils.isNotBlank(startTime)) params.put("startTime", startTime);
  328. if (StringUtils.isNotBlank(endTime)) params.put("endTime", endTime+" 23:59:59");
  329. return (Pagination<AdminCustomerBo>)findPage("selectAdminCustomerList", "selectAdminCustomerCount", params, pageNo, pageSize);
  330. }
  331. @Override
  332. public DepCountBo selectAllUser(String depId, String startTime, String endTime,String aName) {
  333. DepCountBo acb=new DepCountBo();
  334. if (endTime!=null)endTime=endTime+" 23:59:59";
  335. List<DepCountBo >deps=new ArrayList<>();
  336. List<Department> depIds=new ArrayList<>();
  337. //总裁助力不查看老员工
  338. Integer seniorstaff = null;
  339. if (TokenManager.hasRole(AFTConstants.CED_ASSISTANT)){
  340. seniorstaff=0;
  341. }
  342. if (depId==null) {
  343. acb.setName("科德集团");
  344. deps=departmentMapper.selectBysuperName("科德集团");
  345. }else {
  346. OrganizationListOut oo=departmentMapper.selectAllById(depId);
  347. acb.setName(oo.getName());
  348. acb.setId(depId);
  349. if(TokenManager.hasRole(AFTConstants.OPERATION_MANAGER)){
  350. List<String> myShiroDep = departmentService.selectMyDeps();
  351. if (!myShiroDep.contains(depId))throw new BusinessException("无权查看此部门信息");
  352. }
  353. depIds =departmentService.selectSubordinateDeps(depId);
  354. Department department = new Department();
  355. department.setId(depId);
  356. depIds.add(department);
  357. deps=departmentMapper.selectBysuperId(oo.getId());
  358. }
  359. List<AdminCustomerBo> list =null;
  360. //原sql计算
  361. // list=departmentMapper.AlldepCount(depIds,startTime, endTime);
  362. //新java计算
  363. list=AllDepCount(depIds,startTime,endTime,seniorstaff);
  364. for (AdminCustomerBo ad : list) {
  365. if (acb.getId().equals(ad.getDepId())){
  366. acb.getaList().add(ad);
  367. }
  368. }
  369. for (DepCountBo dep : deps) {
  370. dep.setList(iterationDeps(dep.getId(),list));
  371. for (AdminCustomerBo ad : list) {
  372. if (dep.getId().equals(ad.getDepId())){
  373. dep.getaList().add(ad);
  374. }
  375. sumCount(dep);
  376. }
  377. }
  378. acb.setList(deps);
  379. sumCount(acb);
  380. return acb;
  381. }
  382. private List<AdminCustomerBo> AllDepCount(List<Department> depIds, String startTime, String endTime,Integer seniorStaff) {
  383. List<AdminCustomerBo> admins = adminMapper.selectByDeps(depIds,seniorStaff);
  384. if(!admins.isEmpty()){
  385. List<AdminCustomerBo> users = userMapper.selectNoChannelByaids(admins,startTime,endTime);
  386. List<AdminCustomerBo> users2 = userMapper.selectChannelByaids(admins,startTime,endTime);
  387. for (AdminCustomerBo admin : admins) {
  388. for (AdminCustomerBo user : users) {
  389. if (admin.getAid().equals(user.getAid())){
  390. admin.setUserCount(user.getUserCount());
  391. admin.setChannelCount(user.getChannelCount());
  392. admin.setSignCount(user.getSignCount());
  393. admin.setNewCount(user.getNewCount());
  394. admin.setChannelNewCount(user.getChannelNewCount());
  395. admin.setReceiveCount(user.getReceiveCount());
  396. admin.setTransferCount(user.getTransferCount());
  397. break;
  398. }
  399. }
  400. for (AdminCustomerBo user : users2) {
  401. if (admin.getAid().equals(user.getAid())){
  402. admin.setCompleteCount(user.getCompleteCount());
  403. admin.setChannelCompleteCount(user.getChannelCompleteCount());
  404. break;
  405. }
  406. }
  407. pushAdminCount(admin);
  408. }
  409. }
  410. return admins;
  411. }
  412. private void pushAdminCount(AdminCustomerBo admin) {
  413. if (admin.getUserCount()==null) admin.setUserCount(0);
  414. if (admin.getChannelCount()==null) admin.setChannelCount(0);
  415. if (admin.getSignCount()==null) admin.setSignCount(0);
  416. if (admin.getNewCount()==null) admin.setNewCount(0);
  417. if (admin.getChannelNewCount()==null) admin.setChannelNewCount(0);
  418. if (admin.getReceiveCount()==null) admin.setReceiveCount(0);
  419. if (admin.getCompleteCount()==null) admin.setCompleteCount(0);
  420. if (admin.getChannelCompleteCount()==null) admin.setChannelCompleteCount(0);
  421. if (admin.getTransferCount()==null)admin.setTransferCount(0);
  422. }
  423. //迭代获取所有部门与部门员工并计算出部门数量
  424. public List<DepCountBo> iterationDeps(String id,List<AdminCustomerBo> list) {
  425. List<DepCountBo> deps =departmentMapper.selectBysuperId(id);
  426. for (DepCountBo dep : deps) {
  427. dep.setList(iterationDeps(dep.getId(),list));
  428. for (AdminCustomerBo ad : list) {
  429. if (dep.getId().equals(ad.getDepId())){
  430. dep.getaList().add(ad);
  431. }
  432. }
  433. sumCount(dep);
  434. }
  435. return deps;
  436. }
  437. /**
  438. *
  439. * @param ab
  440. */
  441. public void sumCount(DepCountBo ab) {
  442. int completeCount=0,receiveCount=0,userCount=0,signCount=0,channelCount=0,newCount=0,channelNewCount=0,channelCompleteCount=0,transferCount=0;
  443. if (ab.getList()!=null&&!ab.getList().isEmpty()) {
  444. for (DepCountBo a : ab.getList()) {
  445. if (a.getCompleteCount()!=null&& a.getCompleteCount()!=0) completeCount+=a.getCompleteCount();
  446. if (a.getReceiveCount()!=null&& a.getReceiveCount()!=0) receiveCount+=a.getReceiveCount();
  447. if (a.getUserCount()!=null&& a.getUserCount()!=0) userCount+=a.getUserCount();
  448. if (a.getSignCount()!=null&& a.getSignCount()!=0) signCount+=a.getSignCount();
  449. if (a.getChannelCount()!=null&& a.getChannelCount()!=0) channelCount+=a.getChannelCount();
  450. if (a.getNewCount()!=null&& a.getNewCount()!=0) newCount+=a.getNewCount();
  451. if (a.getChannelNewCount()!=null&& a.getChannelNewCount()!=0) channelNewCount+=a.getChannelNewCount();
  452. if (a.getChannelCompleteCount()!=null&& a.getChannelCompleteCount()!=0) channelCompleteCount+=a.getChannelCompleteCount();
  453. if (a.getTransferCount()!=null&& a.getTransferCount()!=0)transferCount+=a.getTransferCount();
  454. }
  455. }
  456. if (ab.getaList()!=null&&!ab.getaList().isEmpty()) {
  457. for (AdminCustomerBo a : ab.getaList()) {
  458. if (a.getCompleteCount()!=null&& a.getCompleteCount()!=0) completeCount+=a.getCompleteCount();
  459. if (a.getReceiveCount()!=null&& a.getReceiveCount()!=0) receiveCount+=a.getReceiveCount();
  460. if (a.getUserCount()!=null&& a.getUserCount()!=0) userCount+=a.getUserCount();
  461. if (a.getSignCount()!=null&& a.getSignCount()!=0) signCount+=a.getSignCount();
  462. if (a.getChannelCount()!=null&& a.getChannelCount()!=0) channelCount+=a.getChannelCount();
  463. if (a.getNewCount()!=null&& a.getNewCount()!=0) newCount+=a.getNewCount();
  464. if (a.getChannelNewCount()!=null&& a.getChannelNewCount()!=0) channelNewCount+=a.getChannelNewCount();
  465. if (a.getChannelCompleteCount()!=null&& a.getChannelCompleteCount()!=0) channelCompleteCount+=a.getChannelCompleteCount();
  466. if (a.getTransferCount()!=null&& a.getTransferCount()!=0)transferCount+=a.getTransferCount();
  467. }
  468. }
  469. ab.setCompleteCount(completeCount);
  470. ab.setReceiveCount(receiveCount);
  471. ab.setUserCount(userCount);
  472. ab.setSignCount(signCount);
  473. ab.setChannelCount(channelCount);
  474. ab.setNewCount(newCount);
  475. ab.setChannelNewCount(channelNewCount);
  476. ab.setChannelCompleteCount(channelCompleteCount);
  477. ab.setTransferCount(transferCount);
  478. }
  479. @SuppressWarnings("unchecked")
  480. @Override
  481. public Pagination<AdminCustomerDetailBo> selectAdminCustomerList(String aid, String startTime, String endTime,Integer type,
  482. Integer pageSize, Integer pageNo) {
  483. Map<String, Object> params = new HashMap<String, Object>();
  484. if(pageSize==null||pageSize<0)pageSize=10;
  485. if(pageNo==null||pageNo<0)pageNo=1;
  486. if (StringUtils.isNotBlank(aid)) params.put("aid", aid);
  487. if (type==null) params.put("type", 0);
  488. else params.put("type", type);
  489. if (StringUtils.isNotBlank(startTime)) params.put("startTime", startTime);
  490. if (StringUtils.isNotBlank(endTime)) params.put("endTime", endTime+" 23:59:59");
  491. Pagination<AdminCustomerDetailBo> p =(Pagination<AdminCustomerDetailBo>)findPage("selectAdminCustomerDetailList", "selectAdminCustomerDetailCount", params, pageNo, pageSize);
  492. if (type == 2&& !TokenManager.hasRole(AFTConstants.SUPERADMIN)) {
  493. List<AdminCustomerDetailBo> list = (List<AdminCustomerDetailBo>) p.getList();
  494. for (AdminCustomerDetailBo out : list) {
  495. out.setContacts("***");
  496. out.setContactMobile("***");
  497. }
  498. }
  499. return p;
  500. }
  501. @Override
  502. public int updatePrivateBusinessTransfer(String inputId, String uid, String pid) {
  503. String aid=TokenManager.getAdminId();
  504. int i=userLockReleaseMapper.updatePrivateBusinessTransfer( inputId, uid, pid,aid);
  505. if (i>0) {
  506. List<BusinessListBo> l=userBusinessMapper.selectBusinessProjectByUAPid(uid, inputId, pid);
  507. if (l.isEmpty()) {
  508. UserBusiness ub=new UserBusiness();
  509. ub.setId(UUID.randomUUID().toString());
  510. ub.setAid(inputId);
  511. ub.setUid(uid);
  512. ub.setBusinessProjectId(pid);
  513. ub.setCustomerStatus(4);
  514. ub.setFollowSituation(5);
  515. ub.setRemarks("转交客户业务触发");
  516. userBusinessMapper.insertSelective(ub);
  517. }
  518. }
  519. return i;
  520. }
  521. @Override
  522. public Object pushStatistics() {
  523. //营销统计处理
  524. // List<String> roles=new ArrayList<>();
  525. // roles.add(AFTConstants.SALESMAN);
  526. // roles.add(AFTConstants.SALESMAN_MANAGER);
  527. // List<Admin> adminList = adminMapper.getAdminRoleTypesList(roles);
  528. // for (Admin admin : adminList) {
  529. // List<AdminUserCount> list =adminMapper.selectAdminPublicRelease(admin.getId());
  530. // List<AdminUserCount> list2 =adminMapper.selectAdminUserFollow(admin.getId());
  531. // List<AdminUserCount> list3 =adminMapper.selectAdminOrder(admin.getId());
  532. // if (list.isEmpty())list=new ArrayList<>();
  533. // if (!list.isEmpty())list.addAll(list2);
  534. // if (!list.isEmpty())list.addAll(list3);
  535. // publiAdminUserCount(list);
  536. // System.out.println("list="+list.size());
  537. // }
  538. //咨询师统计处理
  539. // List<TOrderTask> allTimeRecord = taskTimeMapper.getAllTimeRecord();
  540. // List<TaskTime> list=new ArrayList<>();
  541. // for (TOrderTask e : allTimeRecord) {
  542. // String timeRecord = e.getTimeRecord();
  543. // System.out.println(e.getTimeRecord());
  544. // if (StringUtils.isNotBlank(e.getTimeRecord())){
  545. // Map<String,Object> map = JSON.parseObject(timeRecord, Map.class);
  546. // for (String s : map.keySet()) {
  547. // if (s.equals("2")||s.equals("3")||s.equals("29")||s.equals("19")||(s.equals("27"))){
  548. // JSONObject js = JSON.parseObject(map.get(s).toString());
  549. // Object date = js.get("date");
  550. // Object suspendImg = js.get("suspendImg") ;
  551. // Object title = js.get("title") ;
  552. // Object certificateNumber = js.get("certificateNumber") ;
  553. // Object setUpAmount = js.get("setUpAmount") ;
  554. // Object appropriation = js.get("appropriation") ;
  555. // TaskTime tt=new TaskTime();
  556. // tt.setTid(e.getId());
  557. // tt.setProjectStatus(Integer.parseInt(s));
  558. // if (!Objects.isNull(date)){
  559. // String dates=date.toString();
  560. // if (StringUtils.isNotBlank(dates)){
  561. // Date date1 = DateUtils.StringToDate(dates, AFTConstants.YYYYMMDD);
  562. // tt.setDateTime(date1);
  563. // }
  564. // }
  565. // if (!Objects.isNull(setUpAmount))tt.setSetUpAmount(setUpAmount.toString());
  566. // if (!Objects.isNull(suspendImg))tt.setSuspendImg(suspendImg.toString());
  567. // if (!Objects.isNull(title))tt.setTitle(title.toString());
  568. // if (!Objects.isNull(certificateNumber))tt.setCertificateNumber(certificateNumber.toString());
  569. // if (!Objects.isNull(appropriation))tt.setAppropriation(appropriation.toString());
  570. // list.add(tt);
  571. //// taskTimeMapper.insertSelective(tt);
  572. // }
  573. // }
  574. // }
  575. // }
  576. // List<TaskTime> addList = new ArrayList<>();
  577. // for (int i = 0; i <list.size(); i++) {
  578. // addList.add(list.get(i));
  579. // if (addList.size()==50|| i==list.size() -1){
  580. // taskTimeMapper.insertBatch(addList);
  581. // try {
  582. // addList.clear();
  583. // Thread.sleep(500);
  584. // } catch (InterruptedException exception) {
  585. // exception.printStackTrace();
  586. // }
  587. // }
  588. // }
  589. List<String> roles=new ArrayList<>();
  590. roles.add(AFTConstants.FINANCE);
  591. roles.add(AFTConstants.FINANCE_MANAGER);
  592. List<Admin> admins = adminMapper.selectAdminByRoleTypes(roles);
  593. List<FinanceCount> list=new ArrayList<>();
  594. for (Admin admin : admins){
  595. List<FinanceCount> aList=new ArrayList<>();
  596. List<FinanceCount> orderList = TOrderNewMapper.selectCountByFinance(admin.getId());
  597. if (!orderList.isEmpty()){
  598. aList.addAll(orderList);
  599. }
  600. List<FinanceCount> expenseList = expenseAccountMapper.selectCountByFinance(admin.getId());
  601. pushFinanceList(aList, expenseList,0);
  602. List<FinanceCount> invoiceList =tOrderInvoiceMapper.selectCountByFinance(admin.getId());
  603. pushFinanceList(aList, invoiceList,1);
  604. List<FinanceCount> memberList =tTaskMemberMapper.selectCountByFinance(admin.getId());
  605. pushFinanceList(aList, memberList,2);
  606. List<FinanceCount> paymentList =tOrderPaymentMapper.selectCountByFinance(admin.getId());
  607. pushFinanceList(aList, paymentList,3);
  608. if (!aList.isEmpty()){
  609. for (FinanceCount financeCount : aList) {
  610. if (financeCount.getExpenseCount()!=null&&financeCount.getExpenseCount()>0){
  611. financeCount.toString();
  612. }
  613. }
  614. }
  615. list.addAll(aList);
  616. }
  617. List<FinanceCount> addList=new ArrayList<>();
  618. for (int i = 0; i <list.size(); i++) {
  619. FinanceCount financeCount = list.get(i);
  620. FinanceCount newFc=FinanceCount.initialization(financeCount);
  621. addList.add(newFc);
  622. if (addList.size()==50||i==list.size()-1){
  623. financeCountMapper.insetBatch(addList);
  624. addList.clear();
  625. try {
  626. Thread.sleep(500);
  627. } catch (InterruptedException exception) {
  628. exception.printStackTrace();
  629. }
  630. }
  631. }
  632. return 1;
  633. }
  634. /**
  635. *
  636. * @param list
  637. * @param minList
  638. * @param type
  639. */
  640. private void pushFinanceList(List<FinanceCount> list, List<FinanceCount> minList,Integer type) {
  641. if (!minList.isEmpty()){
  642. for (FinanceCount expense : minList) {
  643. boolean flag=true;
  644. for (FinanceCount e : list) {
  645. if (e.getDateTime().getTime()==expense.getDateTime().getTime()){
  646. if (type==0){
  647. e.setExpenseCount(expense.getExpenseCount());
  648. e.setExpenseUnauditedCount(expense.getExpenseUnauditedCount());
  649. }else if (type==1){
  650. e.setInvoiceCount(expense.getInvoiceCount());
  651. e.setInvoiceUnauditedCount(expense.getInvoiceUnauditedCount());
  652. }else if (type==2){
  653. e.setMemberCount(expense.getMemberCount());
  654. e.setMemberUnauditedCount(expense.getMemberUnauditedCount());
  655. }else if (type==3){
  656. e.setPaymentCount(expense.getPaymentCount());
  657. e.setPaymentUnauditedCount(expense.getPaymentUnauditedCount());
  658. }
  659. flag=false;
  660. }
  661. }
  662. if (flag){
  663. list.add(expense);
  664. }
  665. }
  666. }
  667. }
  668. private void publiAdminUserCount(List<AdminUserCount> list) {
  669. for (AdminUserCount e : list) {
  670. int i=adminUserCountMapper.updateByAidAndDateSelective(e);
  671. if (i==0){
  672. adminUserCountMapper.insertSelective(e);
  673. }
  674. }
  675. }
  676. }