CustomInfoServiceImpl.java 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. package com.crm.custom.service.impl;
  2. import com.crm.custom.dao.mapper.CustomFileDao;
  3. import com.crm.custom.dao.mapper.CustomInfoDao;
  4. import com.crm.custom.dao.repository.CustomInfoRepository;
  5. import com.crm.custom.dao.repository.CustomLoginHistoryRepository;
  6. import com.crm.custom.dao.repository.UserInfoRepository;
  7. import com.crm.custom.service.*;
  8. import com.crm.custom.service.impl.base.BaseUploadServiceImpl;
  9. import com.crm.rely.backend.configuration.LocaleMessage;
  10. import com.crm.rely.backend.core.constant.*;
  11. import com.crm.rely.backend.core.entity.base.LongEntitys;
  12. import com.crm.rely.backend.core.entity.system.email.SysEmailSendEntity;
  13. import com.crm.rely.backend.core.entity.web.notice.record.WebNoticeRecordAndEmailMqEntity;
  14. import com.crm.rely.backend.core.exception.ServiceException;
  15. import com.crm.rely.backend.core.pojo.table.CustomLoginHistoryTable;
  16. import com.crm.rely.backend.core.pojo.table.SysConfigTable;
  17. import com.crm.rely.backend.core.pojo.table.SysCountryTable;
  18. import com.crm.rely.backend.model.constant.ConfigConstants;
  19. import com.crm.rely.backend.model.constant.CustomConstants;
  20. import com.crm.rely.backend.model.entity.custom.bank.CustomBankAddEntity;
  21. import com.crm.rely.backend.model.entity.custom.fund.history.CustomFundHistoryAddEntity;
  22. import com.crm.rely.backend.model.entity.custom.info.*;
  23. import com.crm.rely.backend.model.entity.user.info.UserInfoEntity;
  24. import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
  25. import com.crm.rely.backend.model.pojo.table.UserInfoTable;
  26. import com.crm.rely.backend.model.util.CustomInfoUtil;
  27. import com.crm.rely.backend.service.EmailService;
  28. import com.crm.rely.backend.service.MqSendService;
  29. import com.crm.rely.backend.service.RedisService;
  30. import com.crm.rely.backend.util.*;
  31. import com.google.common.base.Strings;
  32. import lombok.extern.log4j.Log4j;
  33. import org.springframework.beans.BeanUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.stereotype.Service;
  36. import org.springframework.transaction.annotation.Transactional;
  37. import org.springframework.web.multipart.MultipartFile;
  38. import java.math.BigDecimal;
  39. import java.util.*;
  40. /**
  41. * @program: crm-backend
  42. * @description:
  43. * @author: houn
  44. * @create: 2019-07-25 16:14
  45. */
  46. @SuppressWarnings("SpringJavaAutowiringInspection")
  47. @Log4j
  48. @Service
  49. public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements CustomInfoService {
  50. @Autowired
  51. private CustomInfoRepository customInfoRepository;
  52. @Autowired
  53. private UserInfoRepository userInfoRepository;
  54. @Autowired
  55. private CustomLoginHistoryRepository customLoginHistoryRepository;
  56. @Autowired
  57. private SysCountryService sysCountryService;
  58. @Autowired
  59. private EmailService emailService;
  60. @Autowired
  61. private RedisService redisService;
  62. @Autowired
  63. private MqSendService mqSendService;
  64. @Autowired
  65. private CustomInfoDao customInfoDao;
  66. @Autowired
  67. private CustomFileDao customFileDao;
  68. @Autowired
  69. private SysConfigService sysConfigService;
  70. @Autowired
  71. private CustomBankService customBankService;
  72. @Autowired
  73. private CustomLoginService customLoginService;
  74. @Autowired
  75. private CustomLoginDemoService customLoginDemoService;
  76. @Autowired
  77. private CustomLoginFirmOfferService customLoginFirmOfferService;
  78. @Autowired
  79. private CustomLoginAssetManagementService customLoginAssetManagementService;
  80. @Autowired
  81. private CustomFundHistoryService customFundHistoryService;
  82. @Autowired
  83. private LocaleMessage localeMessage;
  84. /**
  85. * 用户登录
  86. *
  87. * @param entity
  88. * @return
  89. * @throws ServiceException
  90. */
  91. @Override
  92. @Transactional(rollbackFor = Exception.class)
  93. public CustomInfoEntity login(CustomInfoLoginEntity entity) throws ServiceException {
  94. //首先用邮箱和密码验证账号
  95. CustomInfoTable customInfoTable = customInfoRepository.findFirstByEmailAndPassword(entity.getLoginName(),
  96. entity.getPassword());
  97. //如果不存在则判断 输入的是否为id
  98. if (customInfoTable == null) {
  99. Long id = null;
  100. try {
  101. //将登陆输入的账号转为id
  102. id = Long.parseLong(entity.getLoginName());
  103. customInfoTable = customInfoRepository.findFirstByIdAndPassword(id, entity.getPassword());
  104. } finally {
  105. //如果转化id异常或者id和密码不匹配 这提示用户名或密码错误
  106. if (customInfoTable == null || id == null) {
  107. throw new ServiceException(Constants.LOGIN_FAIL);
  108. }
  109. }
  110. }
  111. if (customInfoTable.getValid() == null || !customInfoTable.getValid().equals(1)) {
  112. throw ServiceException.exception(Constants.RESTRICTED_LOGIN);
  113. }
  114. /*
  115. 获取ib信息
  116. */
  117. //List<CustomFileDto> fileDtos = customFileService.getAllFiles(customInfoTable.getId());
  118. //CustomBankTable customBankTable = customBankService.getByCustomId(customInfoTable.getId());
  119. CustomInfoEntity transform = transform(customInfoTable, null, entity);
  120. /**
  121. * 更新登录信息
  122. */
  123. customInfoTable.setLastAddress(entity.getAddress());
  124. customInfoTable.setLastIp(entity.getIp());
  125. customInfoTable.setLastTime(entity.getTime());
  126. customInfoTable.setModifyUser(customInfoTable.getId());
  127. customInfoTable.setModifyIp(entity.getIp());
  128. customInfoTable.setModifyTime(entity.getTime());
  129. customInfoRepository.save(customInfoTable);
  130. //添加登录记录
  131. CustomLoginHistoryTable customLoginHistoryTable = new CustomLoginHistoryTable();
  132. customLoginHistoryTable.setAddress(entity.getAddress());
  133. customLoginHistoryTable.setLoginIp(entity.getIp());
  134. customLoginHistoryTable.setLoginTime(entity.getTime());
  135. customLoginHistoryTable.setCustomId(customInfoTable.getId());
  136. customLoginHistoryTable.setName(CustomInfoUtil.getName(customInfoTable));
  137. customLoginHistoryTable.setAddUser(customInfoTable.getId());
  138. customLoginHistoryTable.setAddIp(entity.getIp());
  139. customLoginHistoryTable.setAddTime(entity.getTime());
  140. customLoginHistoryRepository.save(customLoginHistoryTable);
  141. return transform;
  142. }
  143. /**
  144. * 注册发送邮箱验证码
  145. *
  146. * @param entity
  147. * @throws ServiceException
  148. */
  149. @Override
  150. public void registerSendEmailCode(CustomInfoRegisterSendEmailCodeEntity entity) throws ServiceException {
  151. //验证邮箱是否存在
  152. existByEmail(entity.getEmail());
  153. //构建实体
  154. SysEmailSendEntity sysEmailSendEntity = createRegisterSendEmailCodeSysEmailEntity(entity);
  155. //发送收据
  156. emailService.sendCode(sysEmailSendEntity, sysEmailSendEntity.getMap().get(MapConstants.CODE),
  157. Constants.EMAIL_REGISTER_VALIDATECODE_TIME * 60 * 1000);
  158. }
  159. @Override
  160. @Transactional(rollbackFor = Exception.class)
  161. public CustomInfoTable applyReal(CustomApplyRealEntity entity) throws ServiceException {
  162. CustomInfoTable customInfoTable = findFirstById(entity.getCustomId());
  163. if (StatusConstants.PASSED_STATUS.equals(customInfoTable.getApplyRealStatus())
  164. && StatusConstants.PASSED_STATUS.equals(customInfoTable.getStatus())) {
  165. return customInfoTable;
  166. } else {
  167. customInfoTable.setStatus(StatusConstants.APPLY_STATUS);
  168. customInfoTable.setApplyRealStatus(StatusConstants.APPLY_STATUS);
  169. }
  170. entity.setId(customInfoTable.getId());
  171. BeanUtils.copyProperties(entity, customInfoTable);
  172. customInfoRepository.save(customInfoTable);
  173. sendCustomApplyVerificationSysEmailEntity(customInfoTable);
  174. sendCustomApplyVerificationToCustom(customInfoTable);
  175. return customInfoTable;
  176. }
  177. @Override
  178. public void updateEmailSendEmailCode(CustomInfoUpdateEmailSendEmailCodeEntity entity) throws ServiceException {
  179. //验证邮箱是否存在
  180. existByEmail(entity.getEmail());
  181. //构建实体
  182. SysEmailSendEntity sysEmailSendEntity = createUpdateEmailSendEmailSysEmailEntity(entity);
  183. //发送收据
  184. emailService.sendCode(sysEmailSendEntity, sysEmailSendEntity.getMap().get(MapConstants.CODE));
  185. }
  186. /**
  187. * 添加用户信息
  188. *
  189. * @param entity
  190. * @throws ServiceException
  191. */
  192. @Override
  193. @Transactional(rollbackFor = Exception.class)
  194. public void add(CustomInfoRegisterEntity entity) throws ServiceException, InterruptedException {
  195. //打印注册信息日志
  196. String registerString = String.format("register email:%s,emailCode:%s,agentId:%d",entity.getEmail(),entity.getEmailCode(), entity.getAgentId());
  197. log.info(registerString);
  198. //emailService.validateCode(entity.getEmail(), entity.getEmailCode());
  199. //验证邮箱是否存在
  200. existByEmail(entity.getEmail());
  201. /*if (entity.getAgentId() != null) {
  202. UserInfoTable agent = userInfoRepository.getFirstById(entity.getAgentId());
  203. //不存在代理设置为null 外佣设置为0
  204. if (agent == null) {
  205. log.error("get agent is null,agentId:" + entity.getAgentId());
  206. entity.setAgentId(null);
  207. } else {
  208. }
  209. }
  210. //如果代理链接错误或者没有代理 则将客户挂在公司名下
  211. if (entity.getAgentId() == null) {
  212. SysConfigTable sysConfigTable = sysConfigService.getByCode(GlobalConfigConstants.COMPANY_ACCOUNT_SUPER);
  213. if (sysConfigTable != null) {
  214. Long agentId = Long.parseLong(sysConfigTable.getValue());
  215. entity.setAgentId(agentId);
  216. }
  217. }*/
  218. //获取国家信息
  219. SysCountryTable sysCountryTable = sysCountryService.getByCode(entity.getCountry());
  220. CustomInfoTable customInfoTable = new CustomInfoTable();
  221. BeanUtils.copyProperties(entity, customInfoTable);
  222. //设置国家信息
  223. customInfoTable.setCountryEnName(sysCountryTable.getEnName());
  224. customInfoTable.setCountryName(sysCountryTable.getName());
  225. customInfoTable.setAreaCode(sysCountryTable.getCallingCode());
  226. customInfoTable.setPayStatus(0);
  227. //获取和设置c_id
  228. customInfoTable.setCId(CidUtil.getCid().longValue());
  229. customInfoRepository.save(customInfoTable);
  230. customInfoTable.setAddUser(customInfoTable.getId());
  231. //
  232. // //构建实体
  233. // SysEmailSendEntity sysEmailSendEntity = createRegisterCompleteSysEmailEntity(customInfoTable);
  234. //
  235. // //发送收据
  236. // emailService.sendEmail(sysEmailSendEntity);
  237. //
  238. // WebNoticeRecordAndEmailMqEntity mqEntity = new WebNoticeRecordAndEmailMqEntity(sysEmailSendEntity,
  239. // customInfoTable.getCId(), customInfoTable.getId());
  240. // mqSendService.send(Constants.WEB_NOTICE_PUT_RECORD, mqEntity);
  241. //
  242. // //构建实体
  243. // SysEmailSendEntity sysEmailSendEntityToManger = createRegisterCompleteToMangerSysEmailEntity(customInfoTable);
  244. //
  245. // //发送收据
  246. // emailService.sendEmail(sysEmailSendEntityToManger);
  247. }
  248. /**
  249. * 修改用户信息
  250. *
  251. * @param entity
  252. * @throws ServiceException
  253. */
  254. @Override
  255. @Transactional(rollbackFor = Exception.class)
  256. public void update(CustomInfoUpdateEntity entity) throws ServiceException {
  257. CustomInfoTable customInfoTable = findFirstById(entity.getId());
  258. if (Strings.isNullOrEmpty(entity.getSno())) {
  259. entity.setSno(customInfoTable.getSno());
  260. } else {
  261. if (!entity.getSno().equals(customInfoTable.getSno())) {
  262. existBySno(entity.getSno());
  263. }
  264. }
  265. if (!Strings.isNullOrEmpty(entity.getIdentity()) && !entity.getIdentity().equals(customInfoTable.getIdentity())) {
  266. existByIdentity(entity.getIdentity());
  267. }
  268. BeanUtils.copyProperties(entity, customInfoTable);
  269. //获取国家信息
  270. SysCountryTable sysCountryTable = sysCountryService.getByCode(entity.getCountry());
  271. //设置国家信息
  272. customInfoTable.setCountryEnName(sysCountryTable.getEnName());
  273. customInfoTable.setCountryName(sysCountryTable.getName());
  274. if (entity.getAddressLines() != null) {
  275. customInfoTable.setAddressLine(String.join("@#", entity.getAddressLines()));
  276. } else {
  277. customInfoTable.setAddressLine(null);
  278. }
  279. customInfoRepository.save(customInfoTable);
  280. CustomBankAddEntity customBankAddEntity = new CustomBankAddEntity();
  281. BeanUtils.copyProperties(entity, customBankAddEntity);
  282. customBankAddEntity.setCustomId(entity.getId());
  283. customBankService.add(customBankAddEntity);
  284. }
  285. @Override
  286. @Transactional(rollbackFor = Exception.class)
  287. public void updateEmail(CustomInfoUpdateEmailEntity entity) throws ServiceException {
  288. emailService.validateCode(entity.getEmail(), entity.getEmailCode());
  289. //邮箱
  290. existByEmail(entity.getEmail());
  291. CustomInfoTable customInfoTable = customInfoRepository.findFirstById(entity.getCustomId());
  292. customInfoTable.setEmail(entity.getEmail());
  293. customInfoRepository.save(customInfoTable);
  294. }
  295. @Override
  296. @Transactional(rollbackFor = Exception.class)
  297. public String updateHeadPicture(CustomInfoUpdateHeadPictureEntity entity, MultipartFile file) throws Exception {
  298. CustomInfoTable customInfoTable = customInfoRepository.findFirstById(entity.getCustomId());
  299. if (customInfoTable == null) {
  300. throw ServiceException.exception(Constants.SYSTEM_ERROR);
  301. }
  302. //保存头像
  303. String path = saveFile((entity.getCustomId() == null ? "" : entity.getCustomId().toString()) + "/headPicture"
  304. , file);
  305. customInfoTable.setHeadPicture(path);
  306. customInfoTable.setModifyUser(entity.getUser());
  307. customInfoTable.setModifyTime(entity.getTime());
  308. customInfoTable.setModifyIp(entity.getIp());
  309. customInfoRepository.save(customInfoTable);
  310. return path;
  311. }
  312. @Override
  313. @Transactional(rollbackFor = Exception.class)
  314. public void updatePassword(CustomUpdateLoginPasswordEntity entity) throws ServiceException {
  315. CustomInfoTable customInfoTable = findFirstById(entity.getId());
  316. //验证密码是否正确
  317. if (!entity.getOldPassword().equals(customInfoTable.getPassword())) {
  318. throw new ServiceException(Constants.PASSWORD_ERROR);
  319. }
  320. /**
  321. * 填写修改时间和密码
  322. */
  323. customInfoTable.setPassword(entity.getNewPassword());
  324. customInfoTable.setModifyIp(entity.getModifyIp());
  325. customInfoTable.setModifyTime(entity.getModifyTime());
  326. customInfoTable.setModifyUser(entity.getModifyUser());
  327. customInfoRepository.save(customInfoTable);
  328. sendUpdatePasswordCompleteSendEmailSysEmailEntity(customInfoTable);
  329. }
  330. @Override
  331. public void updatePasswordSendEmail(CustomUpdatePasswordSendEmailEntity entity) throws ServiceException {
  332. CustomInfoTable customInfoTable = customInfoRepository.getFirstByEmailNotNullAndEmail(entity.getEmail());
  333. if (customInfoTable == null) {
  334. return;
  335. // throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
  336. }
  337. SysEmailSendEntity sysEmailSendEntity = createUpdatePasswordSendEmailSysEmailEntity(entity, customInfoTable);
  338. redisService.save(sysEmailSendEntity.getMap().get(MapConstants.TOKEN), customInfoTable.getId(),
  339. Constants.EMAIL_TOKEN_TIME * 60 * 1000);
  340. mqSendService.send("ACTIVEMQ_JMS_URL_EMAILSS", sysEmailSendEntity);
  341. //系统内部通知
  342. /*WebNoticeRecordAndEmailMqEntity mqEntity = new WebNoticeRecordAndEmailMqEntity(sysEmailSendEntity,
  343. customInfoTable.getCId(), customInfoTable.getId());
  344. mqSendService.send(Constants.WEB_NOTICE_PUT_RECORD, mqEntity);*/
  345. }
  346. @Override
  347. @Transactional(rollbackFor = Exception.class)
  348. public void updatePassword(CustomUpdateEmailPasswordEntity entity) throws ServiceException {
  349. Long id = redisService.getEntity(entity.getToken(), Long.class);
  350. if (id == null) {
  351. throw new ServiceException(Constants.EMAIL_EXPIRE);
  352. }
  353. CustomInfoTable customInfoTable = customInfoRepository.findFirstById(id);
  354. if (customInfoTable == null) {
  355. throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
  356. }
  357. /**
  358. * 填写修改时间和密码
  359. */
  360. customInfoTable.setPassword(entity.getPassword());
  361. customInfoTable.setModifyIp(entity.getModifyIp());
  362. customInfoTable.setModifyTime(entity.getModifyTime());
  363. customInfoTable.setModifyUser(customInfoTable.getModifyUser());
  364. customInfoRepository.save(customInfoTable);
  365. redisService.remove(entity.getToken());
  366. sendUpdatePasswordCompleteSendEmailSysEmailEntity(customInfoTable);
  367. }
  368. private void addHistory(CustomInfoTable customInfoTable, Integer sourceType, BigDecimal amount, String remarks) throws ServiceException {
  369. CustomFundHistoryAddEntity entity = new CustomFundHistoryAddEntity();
  370. entity.setCustomId(customInfoTable.getId());
  371. entity.setCId(customInfoTable.getCId());
  372. entity.setAgentId(customInfoTable.getAgentId());
  373. entity.setAmount(amount);
  374. entity.setRemarks(remarks);
  375. entity.setSourceType(sourceType);
  376. customFundHistoryService.add(entity);
  377. }
  378. @Override
  379. @Transactional(rollbackFor = Exception.class)
  380. public void updateAgentId(CustomInfoUpdateAgentEntity entity) throws ServiceException {
  381. CustomInfoTable customInfoTable = customInfoRepository.findFirstById(entity.getId());
  382. if (customInfoTable == null) {
  383. throw ServiceException.exception(Constants.INFO_NOT_FOUND);
  384. }
  385. if (!entity.getAgentId().equals(customInfoTable.getAgentId())) {
  386. BeanUtils.copyProperties(entity, customInfoTable);
  387. customInfoRepository.save(customInfoTable);
  388. customLoginService.updateAgentId(entity);
  389. customLoginDemoService.updateAgentId(entity);
  390. customLoginFirmOfferService.updateAgentId(entity);
  391. customLoginAssetManagementService.updateAgentId(entity);
  392. UserInfoTable userInfoTable = userInfoRepository.findFirstById(customInfoTable.getIbId());
  393. if (userInfoTable != null) {
  394. userInfoTable.setPid(entity.getAgentId());
  395. userInfoTable.setPStamp(entity.getPStamp());
  396. userInfoTable.setStamp(entity.getStamp());
  397. userInfoTable.setSalesId(entity.getSalesId());
  398. userInfoRepository.save(userInfoTable);
  399. }
  400. }
  401. }
  402. /**
  403. * 根据id获取用户信息
  404. *
  405. * @param id
  406. * @return
  407. */
  408. private CustomInfoTable findFirstById(Long id) throws ServiceException {
  409. CustomInfoTable customInfoTable = customInfoRepository.findFirstById(id);
  410. if (customInfoTable == null) {
  411. throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
  412. }
  413. return customInfoTable;
  414. }
  415. /**
  416. * 验证邮箱是否已存在
  417. *
  418. * @param email
  419. * @throws ServiceException
  420. */
  421. private void existByEmail(String email) throws ServiceException {
  422. boolean existByEmail = customInfoRepository.existsByEmail(email);
  423. if (existByEmail) {
  424. throw new ServiceException(Constants.EMAIL_IS_EXIST_ERROR);
  425. }
  426. }
  427. /**
  428. * 验证证件是否已存在
  429. *
  430. * @param identity
  431. * @throws ServiceException
  432. */
  433. private void existByIdentity(String identity) throws ServiceException {
  434. //如果为空 则直接返回
  435. if (Strings.isNullOrEmpty(identity)) {
  436. return;
  437. }
  438. boolean existsByIdentity = customInfoRepository.existsByIdentity(identity);
  439. if (existsByIdentity) {
  440. throw new ServiceException(Constants.IDENTITY_IS_EXIST_ERROR);
  441. }
  442. }
  443. private void existBySno(String sno) throws ServiceException {
  444. //如果为空 则直接返回
  445. if (Strings.isNullOrEmpty(sno)) {
  446. return;
  447. }
  448. CustomInfoTable customInfoTable = customInfoRepository.getFirstBySno(sno);
  449. if (customInfoTable != null) {
  450. throw new ServiceException(String.format(localeMessage.getMessage("sno_is_exist_error"),
  451. customInfoTable.getSno(), customInfoTable.getEmail()));
  452. }
  453. }
  454. /**
  455. * 构建注册发送邮件实体
  456. *
  457. * @param entity
  458. * @return
  459. */
  460. private SysEmailSendEntity createRegisterSendEmailCodeSysEmailEntity(CustomInfoRegisterSendEmailCodeEntity entity) {
  461. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  462. Map<String, String> map = new HashMap<>(4);
  463. String code = GetRandom.getRandom(6);
  464. map.put(MapConstants.CODE, code);
  465. Date time = DateUtil.operationMinute(new Date(), Constants.EMAIL_REGISTER_VALIDATECODE_TIME);
  466. map.put(MapConstants.EXPIRE_TIME, DateUtil.formatTime(time));
  467. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  468. sysEmailSendEntity.setAddIp(entity.getIp());
  469. sysEmailSendEntity.setAddTime(entity.getTime());
  470. sysEmailSendEntity.setUsers(entity.getEmail());
  471. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.REGISTER_CODE);
  472. sysEmailSendEntity.setTemplateName(GlobalSystemEmailCodeConstants.CUSTOM_REGISTER_SEND_EMAIL_CODE_CN);
  473. sysEmailSendEntity.setMap(map);
  474. sysEmailSendEntity.setMap(map);
  475. return sysEmailSendEntity;
  476. }
  477. private SysEmailSendEntity createRegisterCompleteSysEmailEntity(CustomInfoTable entity) {
  478. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  479. Map<String, String> map = new HashMap<>(3);
  480. map.put(MapConstants.C_ID, entity.getCId() + "");
  481. map.put(MapConstants.EMAIL, entity.getEmail());
  482. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  483. sysEmailSendEntity.setAddIp(entity.getAddIp());
  484. sysEmailSendEntity.setAddTime(entity.getAddTime());
  485. sysEmailSendEntity.setUsers(entity.getEmail());
  486. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.REGISTER_COMPLETE);
  487. sysEmailSendEntity.setTemplateName(GlobalSystemEmailCodeConstants.CUSTOM_REGISTER_COMPLETE_SEND_CN);
  488. sysEmailSendEntity.setMap(map);
  489. return sysEmailSendEntity;
  490. }
  491. // private SysEmailSendEntity createRegisterCompleteToMangerSysEmailEntity(CustomInfoTable entity) throws
  492. // ServiceException {
  493. // SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  494. //
  495. // Map<String, String> map = new HashMap<>(3);
  496. //
  497. // map.put(MapConstants.C_ID, entity.getCId() + "");
  498. // map.put(MapConstants.EMAIL, entity.getEmail());
  499. //
  500. // map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  501. //
  502. // sysEmailSendEntity.setAddIp(entity.getAddIp());
  503. // sysEmailSendEntity.setAddTime(entity.getAddTime());
  504. //
  505. // SysConfigTable sysConfigTable = sysConfigService.getByCode(GlobalConfigConstants.REGISTER_EMAIL_NOTICE);
  506. // if (sysConfigTable != null) {
  507. // sysEmailSendEntity.setUsers(sysConfigTable.getValue());
  508. // }
  509. //
  510. // sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.REGISTER_COMPLETE_MANAGER);
  511. //
  512. // sysEmailSendEntity.setTemplateName(SystemEmailCodeConstants.REGISTER_COMPLETE_NOTICE_NAME);
  513. //
  514. // sysEmailSendEntity.setMap(map);
  515. //
  516. // return sysEmailSendEntity;
  517. // }
  518. private SysEmailSendEntity createUpdateEmailSendEmailSysEmailEntity(CustomInfoUpdateEmailSendEmailCodeEntity entity) {
  519. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  520. Map<String, String> map = new HashMap<>(2);
  521. String code = GetRandom.getRandom(6);
  522. map.put(MapConstants.CODE, code);
  523. Date time = DateUtil.operationMinute(new Date(), Constants.EMAIL_VALIDATECODE_TIME);
  524. map.put(MapConstants.EXPIRE_TIME, DateUtil.formatTime(time));
  525. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  526. sysEmailSendEntity.setAddIp(entity.getIp());
  527. sysEmailSendEntity.setAddTime(entity.getTime());
  528. sysEmailSendEntity.setUsers(entity.getEmail());
  529. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.UPDATE_EMAIL_CODE);
  530. sysEmailSendEntity.setTemplateName(GlobalSystemEmailCodeConstants.CUSTOM_UPDATE_EMAIL_CODE_SEND_CN);
  531. sysEmailSendEntity.setMap(map);
  532. return sysEmailSendEntity;
  533. }
  534. /**
  535. * 发送后台申请核验发送邮件实体
  536. *
  537. * @param customInfoTable
  538. * @return
  539. * @throws ServiceException
  540. */
  541. private void sendCustomApplyVerificationSysEmailEntity(CustomInfoTable customInfoTable) throws ServiceException {
  542. if (customInfoTable == null) {
  543. throw ServiceException.exception(Constants.SYSTEM_ERROR);
  544. }
  545. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  546. SysConfigTable sysConfigTable =
  547. sysConfigService.getByCode(ConfigConstants.CUSTOM_SUBMIT_VERIFICATION_MANAGER_EMAIL);
  548. if (sysConfigTable != null) {
  549. sysEmailSendEntity.setUsers(sysConfigTable.getValue());
  550. }
  551. Map<String, String> map = new HashMap<>(6);
  552. String name = CustomInfoUtil.getName(customInfoTable);
  553. map.put(MapConstants.NAME, name);
  554. map.put(MapConstants.C_ID, String.valueOf(customInfoTable.getCId()));
  555. map.put(MapConstants.EMAIL, customInfoTable.getEmail());
  556. map.put(MapConstants.APPLY_TIME, DateUtil.formatTime());
  557. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  558. sysEmailSendEntity.setAddIp(customInfoTable.getModifyIp());
  559. sysEmailSendEntity.setAddTime(new Date());
  560. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.SUBMIT_VERIFICATION);
  561. String templateName = GlobalSystemEmailCodeConstants.SUBMIT_VERIFICATION_NOTICE_NAME;
  562. sysEmailSendEntity.setTemplateName(templateName);
  563. sysEmailSendEntity.setMap(map);
  564. emailService.sendEmail(sysEmailSendEntity);
  565. }
  566. /**
  567. * 发送到客户提交核验
  568. *
  569. * @param customInfoTable
  570. * @throws ServiceException
  571. */
  572. private void sendCustomApplyVerificationToCustom(CustomInfoTable customInfoTable) throws ServiceException {
  573. if (customInfoTable == null) {
  574. throw ServiceException.exception(Constants.SYSTEM_ERROR);
  575. }
  576. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  577. sysEmailSendEntity.setUsers(customInfoTable.getEmail());
  578. Map<String, String> map = new HashMap<>(3);
  579. String name = CustomInfoUtil.getName(customInfoTable);
  580. map.put(MapConstants.NAME, name);
  581. map.put(MapConstants.C_ID, String.valueOf(customInfoTable.getCId()));
  582. map.put(MapConstants.EMAIL, customInfoTable.getEmail());
  583. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  584. sysEmailSendEntity.setAddIp(customInfoTable.getModifyIp());
  585. sysEmailSendEntity.setAddTime(new Date());
  586. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.CUSTOM_SUBMIT_VERIFICATION);
  587. String templateName;
  588. templateName = GlobalSystemEmailCodeConstants.CUSTOM_SUBMIT_VERIFICATION_NOTICE_NAME_CN;
  589. sysEmailSendEntity.setTemplateName(templateName);
  590. sysEmailSendEntity.setMap(map);
  591. emailService.sendEmail(sysEmailSendEntity);
  592. WebNoticeRecordAndEmailMqEntity mqEntity = new WebNoticeRecordAndEmailMqEntity(sysEmailSendEntity,
  593. customInfoTable.getCId(), customInfoTable.getId());
  594. mqSendService.send(Constants.WEB_NOTICE_PUT_RECORD, mqEntity);
  595. }
  596. /**
  597. * 构建修改密码发送邮件实体
  598. *
  599. * @param entity
  600. * @param customInfoTable
  601. * @return
  602. */
  603. private SysEmailSendEntity createUpdatePasswordSendEmailSysEmailEntity(CustomUpdatePasswordSendEmailEntity entity
  604. , CustomInfoTable customInfoTable) {
  605. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  606. String token =
  607. MD5Util.getMD5(AESUtil.encrypt(entity.getEmail() + Constants.LOGIN_LINK + UUIDUtil.getUUID() + Constants.LOGIN_LINK + customInfoTable.getId()));
  608. Date time = DateUtil.operationMinute(new Date(), Constants.EMAIL_TOKEN_TIME);
  609. Map<String, String> map = new HashMap<>(4);
  610. String name = CustomInfoUtil.getName(customInfoTable);
  611. map.put(MapConstants.TOKEN, token);
  612. map.put(MapConstants.EXPIRE_TIME, DateUtil.formatTime(time));
  613. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  614. map.put(MapConstants.NAME, name);
  615. sysEmailSendEntity.setAddIp(entity.getIp());
  616. sysEmailSendEntity.setAddTime(entity.getTime());
  617. sysEmailSendEntity.setAddUser(customInfoTable.getAddUser());
  618. sysEmailSendEntity.setUsers(entity.getEmail());
  619. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.FORGET_PASSWORD);
  620. if (CountryUtil.isCN(customInfoTable.getCountry())) {
  621. sysEmailSendEntity.setTemplateName(GlobalSystemEmailCodeConstants.CUSTOM_UPDATE_PASSWORD_SEND_CN);
  622. } else {
  623. sysEmailSendEntity.setTemplateName(GlobalSystemEmailCodeConstants.CUSTOM_UPDATE_PASSWORD_SEND_EN);
  624. }
  625. sysEmailSendEntity.setMap(map);
  626. return sysEmailSendEntity;
  627. }
  628. /**
  629. * @param customInfoTable
  630. */
  631. private void sendUpdatePasswordCompleteSendEmailSysEmailEntity(CustomInfoTable customInfoTable) throws ServiceException {
  632. SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
  633. Map<String, String> map = new HashMap<>(2);
  634. String name = CustomInfoUtil.getName(customInfoTable);
  635. map.put(MapConstants.NAME, name);
  636. map.put(MapConstants.DATE_TIME, DateUtil.formatTime());
  637. sysEmailSendEntity.setAddIp(customInfoTable.getModifyIp());
  638. sysEmailSendEntity.setAddTime(customInfoTable.getModifyTime());
  639. sysEmailSendEntity.setAddUser(customInfoTable.getAddUser());
  640. sysEmailSendEntity.setUsers(customInfoTable.getEmail());
  641. sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.FORGET_PASSWORD);
  642. sysEmailSendEntity.setTemplateName(GlobalSystemEmailCodeConstants.CUSTOM_UPDATE_PASSWORD_COMPLETE_SEND_CN);
  643. sysEmailSendEntity.setMap(map);
  644. emailService.sendEmail(sysEmailSendEntity);
  645. }
  646. private CustomInfoEntity transform(CustomInfoTable customInfoTable, UserInfoEntity ibInfoEntity,
  647. CustomInfoLoginEntity entity) {
  648. CustomInfoEntity infoEntity = new CustomInfoEntity();
  649. BeanUtils.copyProperties(customInfoTable, infoEntity);
  650. if (!Strings.isNullOrEmpty(customInfoTable.getAddressLine())) {
  651. infoEntity.setAddressLines(Arrays.asList(customInfoTable.getAddressLine().split("@#")));
  652. }
  653. infoEntity.setIbInfo(ibInfoEntity);
  654. /*infoEntity.setFiles(fileDtos);
  655. if (customBankTable != null) {
  656. infoEntity.setBankAddr(customBankTable.getBankAddr());
  657. infoEntity.setBankBack(customBankTable.getBankBack());
  658. infoEntity.setBankBranchName(customBankTable.getBankBranchName());
  659. infoEntity.setBankCode(customBankTable.getBankCode());
  660. infoEntity.setBankUname(customBankTable.getBankUname());
  661. infoEntity.setBankName(customBankTable.getBankName());
  662. infoEntity.setSwiftCode(customBankTable.getSwiftCode());
  663. infoEntity.setBankFront(customBankTable.getBankFront());
  664. infoEntity.setBankCardNum(customBankTable.getBankCardNum());
  665. }*/
  666. return infoEntity;
  667. }
  668. @Override
  669. @Transactional(rollbackFor = Exception.class)
  670. public void deleteInBatch(LongEntitys entitys) throws Exception {
  671. /*
  672. 删除基本信息
  673. */
  674. customInfoDao.deleteInBatch(entitys);
  675. /*
  676. 删除文件信息
  677. */
  678. List<String> files = customFileDao.getAllPathByCustomId(entitys);
  679. customFileDao.deleteInBatchByCustomId(entitys);
  680. /*
  681. 删除文件
  682. */
  683. FileProcessUtil.deleteFiles(files);
  684. }
  685. @Override
  686. public CustomInfoTable getById(Long id) throws ServiceException {
  687. CustomInfoTable customInfoTable = customInfoRepository.getFirstById(id);
  688. if (customInfoTable == null) {
  689. throw ServiceException.exception(Constants.INFO_NOT_FOUND);
  690. }
  691. return customInfoTable;
  692. }
  693. @Override
  694. @Transactional(rollbackFor = Exception.class)
  695. public void updatePosition(Long customId, Integer position) throws ServiceException {
  696. CustomInfoTable customInfoTable = customInfoRepository.findFirstById(customId);
  697. if (customInfoTable == null) {
  698. throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
  699. }
  700. customInfoTable.setPosition(position);
  701. customInfoRepository.save(customInfoTable);
  702. }
  703. @Override
  704. @Transactional(rollbackFor = Exception.class)
  705. public void validPosition(Long customId, Integer position) throws ServiceException {
  706. CustomInfoTable customInfoTable = customInfoRepository.getFirstById(customId);
  707. if (customInfoTable == null) {
  708. throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
  709. }
  710. if (customInfoTable.getPosition() == null) {
  711. customInfoTable.setPosition(CustomConstants.POSITION1);
  712. }
  713. if (!customInfoTable.getPosition().equals(position)) {
  714. throw new ServiceException(Constants.NOT_PERMIT);
  715. }
  716. }
  717. @Override
  718. public Integer getPosition(Long customId) throws ServiceException {
  719. CustomInfoTable customInfoTable = customInfoRepository.getFirstById(customId);
  720. if (customInfoTable == null) {
  721. throw new ServiceException(Constants.USER_NOT_EXIST_ERROR);
  722. }
  723. return customInfoTable.getPosition();
  724. }
  725. @Override
  726. public BigDecimal getBalance(Long id) throws ServiceException {
  727. CustomInfoTable customInfoTable = customInfoRepository.getFirstById(id);
  728. return customInfoTable.getBalance() == null ? BigDecimal.ZERO : customInfoTable.getBalance();
  729. }
  730. }