RestrictProjectServiceImpl.java 9.1 KB

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