RestrictProjectServiceImpl.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package com.goafanti.business.service.impl;
  2. import com.goafanti.business.bo.InputRestrictProject;
  3. import com.goafanti.business.bo.OutRestrictProject;
  4. import com.goafanti.business.bo.RestrictProjectPageList;
  5. import com.goafanti.business.service.RestrictProjectService;
  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.core.mybatis.BaseMybatisDao;
  11. import com.goafanti.core.mybatis.page.Pagination;
  12. import com.goafanti.core.shiro.token.TokenManager;
  13. import com.goafanti.customer.bo.BusinessListBo;
  14. import com.goafanti.customer.bo.FollowBusinessBo;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.text.SimpleDateFormat;
  18. import java.time.LocalDateTime;
  19. import java.time.temporal.ChronoUnit;
  20. import java.util.*;
  21. @Service
  22. public class RestrictProjectServiceImpl extends BaseMybatisDao<RestrictProjectMapper> implements RestrictProjectService {
  23. @Resource
  24. private RestrictProjectMapper restrictProjectMapper;
  25. @Resource
  26. private UserTransferLogMapper userTransferLogMapper;
  27. @Resource
  28. private UserBusinessMapper userBusinessMapper;
  29. @Resource
  30. private UserMapper userMapper;
  31. @Resource
  32. private AdminMapper adminMapper;
  33. @Override
  34. public int add(InputRestrictProject in) {
  35. String aid = TokenManager.getAdminId();
  36. in.setAid(aid);
  37. in.setType(1);
  38. in.setLockTime(new Date());
  39. RestrictProject use = restrictProjectMapper.selectByPid(in);
  40. if (use != null && use.getType() != 0){
  41. throw new BusinessException("该项目已存在");
  42. }
  43. if(use ==null){
  44. restrictProjectMapper.insertSelective(in);
  45. }else if (use.getType() == 0){
  46. in.setId(use.getId());
  47. restrictProjectMapper.updateByPrimaryKeySelective(in);
  48. }
  49. UserBusiness ub=new UserBusiness();
  50. ub.setId(UUID.randomUUID().toString());
  51. ub.setAid(aid);
  52. ub.setUid(in.getUid());
  53. ub.setBusinessProjectId(in.getPid());
  54. ub.setCustomerStatus(in.getCustomerStatus());
  55. ub.setFollowSituation(in.getFollowSituation());
  56. ub.setRemarks("领取限定项目触发");
  57. userBusinessMapper.insertSelective(ub);
  58. addUserLog(in,0);
  59. return 1;
  60. }
  61. /**
  62. *
  63. * @param i 0=新增 1=移除
  64. */
  65. private void addUserLog(RestrictProject in, int i) {
  66. addUserLog(in,i,null);
  67. }
  68. @Override
  69. public Object list(InputRestrictProject in) {
  70. in.setAid(TokenManager.getAdminId());
  71. String aname=null;
  72. List<OutRestrictProject> list = restrictProjectMapper.selectByUidAndAid(in);
  73. User u = userMapper.selectByPrimaryKey(in.getUid());
  74. for (OutRestrictProject e : list) {
  75. if (e.getType()==null){
  76. e.setType(0);
  77. }
  78. if (u.getType()==0&&u.getAid()!=null&&u.getAid().equals(AFTConstants.CAOJIN_AID)){
  79. e.setType(1);
  80. if (aname==null){
  81. Admin admin = adminMapper.selectByPrimaryKey(AFTConstants.CAOJIN_AID);
  82. aname =admin.getName();
  83. }
  84. e.setAdminName(aname);
  85. }
  86. }
  87. return list;
  88. }
  89. @Override
  90. public Object update(String ids,Integer type,String takeAid) {
  91. String[] split = ids.split(",");
  92. Date date = new Date();
  93. for (String s : split) {
  94. Integer id = Integer.parseInt(s);
  95. RestrictProject in = new RestrictProject();
  96. RestrictProject use = restrictProjectMapper.selectByPrimaryKey(id);
  97. in.setId(id);
  98. if (type==0){
  99. in.setReleaseTime(date);
  100. in.setType(0);
  101. addUserLog(use,1);
  102. }else if (type==1){
  103. in.setLockTime(date);
  104. in.setAid(takeAid);
  105. in.setPid(use.getPid());
  106. in.setUid(use.getUid());
  107. addUserLog(use,2,takeAid);
  108. }
  109. int i = restrictProjectMapper.updateByPrimaryKeySelective(in);
  110. }
  111. return 1;
  112. }
  113. @Override
  114. public Object pageList(InputRestrictProject in) {
  115. Map<String,Object> param = new HashMap<>();
  116. if (in.getUserName()!=null)param.put("userName",in.getUserName());
  117. if (in.getType()!=null)param.put("type",in.getType());
  118. if (in.getStartTime()!=null)param.put("startTime",in.getStartTime());
  119. if (in.getEndTime()!=null)param.put("endTime",in.getEndTime()+" 23:59:59");
  120. if (in.getProjectName()!=null)param.put("projectName",in.getProjectName());
  121. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  122. param.put("aid",TokenManager.getAdminId());
  123. }
  124. Pagination<RestrictProjectPageList> page =
  125. (Pagination<RestrictProjectPageList>) findPage("RestrictProjectList", "RestrictProjectCount",
  126. param, in.getPageNo(), in.getPageSize());
  127. pushPageList((List<RestrictProjectPageList>)page.getList());
  128. return page;
  129. }
  130. @Override
  131. public Object getFollowDetails(String uid) {
  132. User user = userMapper.findUserAccountDetail(uid);
  133. FollowBusinessBo fbb = new FollowBusinessBo();
  134. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  135. fbb.setFollowTime(format.format(new Date()));
  136. fbb.setIdentifyName(user.getIdentifyName());
  137. fbb.setUid(uid);
  138. List<BusinessListBo> businessListBos = userBusinessMapper.selectBusinessByUAid(uid, TokenManager.getAdminId());
  139. fbb.setUserBusinessList(businessListBos);
  140. return fbb;
  141. }
  142. private void pushPageList(List<RestrictProjectPageList> list) {
  143. LocalDateTime now = LocalDateTime.now();
  144. now=now.withHour(0).withMinute(0).withSecond(0).withNano(0);
  145. for (RestrictProjectPageList e : list) {
  146. LocalDateTime lockTime = e.getLockTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime();
  147. lockTime=lockTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
  148. if (e.getType()==1){
  149. LocalDateTime endTime = lockTime.plusDays(30);
  150. long between = ChronoUnit.DAYS.between(now, endTime);
  151. e.setPrivateDays(between>0?(int)between:0);
  152. }else if (e.getType()==2){
  153. LocalDateTime endTime = lockTime.plusDays(270);
  154. long between = ChronoUnit.DAYS.between(now, endTime);
  155. e.setSignDays(between>0?(int)between:0);
  156. }
  157. }
  158. }
  159. private void addUserLog(RestrictProject in, int i, String takeAid) {
  160. UserTransferLog log = new UserTransferLog();
  161. log.setUid(in.getUid());
  162. log.setPid(in.getPid());
  163. if (i == 0){
  164. log.setAid(in.getAid());
  165. log.setType(15);
  166. } else if (i == 1) {
  167. log.setAid(in.getAid());
  168. log.setType(16);
  169. }else if (i == 2) {
  170. log.setAid(TokenManager.getAdminId());
  171. log.setTakeAid(takeAid);
  172. log.setType(17);
  173. }
  174. userTransferLogMapper.insertSelective(log);
  175. }
  176. }