RestrictProjectServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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.enums.NoticeStatus;
  10. import com.goafanti.common.error.BusinessException;
  11. import com.goafanti.common.model.*;
  12. import com.goafanti.common.utils.AsyncUtils;
  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.customer.bo.FollowBusinessBo;
  18. import org.springframework.beans.factory.annotation.Value;
  19. import org.springframework.stereotype.Service;
  20. import javax.annotation.Resource;
  21. import java.text.SimpleDateFormat;
  22. import java.util.*;
  23. @Service
  24. public class RestrictProjectServiceImpl extends BaseMybatisDao<RestrictProjectMapper> implements RestrictProjectService {
  25. @Resource
  26. private RestrictProjectMapper restrictProjectMapper;
  27. @Resource
  28. private UserTransferLogMapper userTransferLogMapper;
  29. @Resource
  30. private UserBusinessMapper userBusinessMapper;
  31. @Resource
  32. private UserMapper userMapper;
  33. @Resource
  34. private AdminMapper adminMapper;
  35. @Resource
  36. private AsyncUtils asyncUtils;
  37. @Resource
  38. private BusinessProjectMapper businessProjectMapper;
  39. @Value(value = "${yxzj_max}")
  40. private Integer YXZJ_MAX = null;
  41. @Value(value = "${yxy_max}")
  42. private Integer YXY_MAX = null;
  43. @Value(value = "${yxjl_max}")
  44. private Integer YXJL_MAX = null;
  45. @Override
  46. public int add(InputRestrictProject in) {
  47. String aid = TokenManager.getAdminId();
  48. in.setAid(aid);
  49. in.setType(1);
  50. in.setLockTime(new Date());
  51. RestrictProject use = restrictProjectMapper.selectByParam(in);
  52. if (use != null && use.getType() != 0){
  53. throw new BusinessException("该项目已存在");
  54. }
  55. if(use ==null){
  56. restrictProjectMapper.insertSelective(in);
  57. }else if (use.getType() == 0){
  58. in.setId(use.getId());
  59. restrictProjectMapper.updateByPrimaryKeySelective(in);
  60. }
  61. UserBusiness ub=new UserBusiness();
  62. ub.setId(UUID.randomUUID().toString());
  63. ub.setAid(aid);
  64. ub.setUid(in.getUid());
  65. ub.setBusinessProjectId(in.getPid());
  66. ub.setCustomerStatus(in.getCustomerStatus());
  67. ub.setFollowSituation(in.getFollowSituation());
  68. ub.setCreateTime(new Date());
  69. ub.setRemarks("领取限定项目触发");
  70. userBusinessMapper.insertSelective(ub);
  71. addUserLog(in,0);
  72. User user = userMapper.selectByPrimaryKey(in.getUid());
  73. BusinessProject businessProject = businessProjectMapper.selectByPrimaryKey(in.getPid());
  74. String str =String.format("客户:%s,已被营销员%s领取了【限定项目:%s】",user.getNickname(),TokenManager.getAdminToken().getName(),businessProject.getBname());
  75. //如果客户是当事人的不提示消息
  76. if (user.getAid()!=null&&!user.getAid().equals(aid)){
  77. asyncUtils.addNoticAndEmail(new Notice(user.getAid(), NoticeStatus.RECEIVE_RESTRICT_PROJECT.getCode(),str));
  78. }
  79. return 1;
  80. }
  81. /**
  82. *
  83. * @param i 0=新增 1=移除
  84. */
  85. private void addUserLog(RestrictProject in, int i) {
  86. addUserLog(in,i,null);
  87. }
  88. @Override
  89. public Object list(InputRestrictProject in) {
  90. in.setAid(TokenManager.getAdminId());
  91. String aname=null;
  92. List<OutRestrictProject> list = restrictProjectMapper.selectByUidAndAid(in);
  93. User u = userMapper.selectByPrimaryKey(in.getUid());
  94. for (OutRestrictProject e : list) {
  95. if (e.getType()==null){
  96. e.setType(0);
  97. }
  98. if (e.getType()==0&&u.getAid()!=null&&u.getAid().equals(AFTConstants.CAOJIN_AID)){
  99. e.setType(1);
  100. if (aname==null){
  101. Admin admin = adminMapper.selectByPrimaryKey(AFTConstants.CAOJIN_AID);
  102. aname =admin.getName();
  103. }
  104. e.setAdminName(aname);
  105. }
  106. }
  107. return list;
  108. }
  109. @Override
  110. public Object update(String ids,Integer type,String takeAid) {
  111. String[] split = ids.split(",");
  112. Date date = new Date();
  113. for (String s : split) {
  114. Integer id = Integer.parseInt(s);
  115. RestrictProject in = new RestrictProject();
  116. RestrictProject use = restrictProjectMapper.selectByPrimaryKey(id);
  117. in.setId(id);
  118. if (type==0){
  119. in.setReleaseTime(date);
  120. in.setType(0);
  121. addUserLog(use,1);
  122. }else if (type==1){
  123. in.setLockTime(date);
  124. in.setAid(takeAid);
  125. in.setPid(use.getPid());
  126. in.setUid(use.getUid());
  127. addUserLog(use,2,takeAid);
  128. }
  129. restrictProjectMapper.updateByPrimaryKeySelective(in);
  130. }
  131. return 1;
  132. }
  133. @Override
  134. public Object pageList(InputRestrictProject in) {
  135. Map<String,Object> param = new HashMap<>();
  136. if (in.getUserName()!=null)param.put("userName",in.getUserName());
  137. if (in.getType()!=null)param.put("type",in.getType());
  138. if (in.getStartTime()!=null)param.put("startTime",in.getStartTime());
  139. if (in.getEndTime()!=null)param.put("endTime",in.getEndTime()+" 23:59:59");
  140. if (in.getProjectName()!=null)param.put("projectName",in.getProjectName());
  141. if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
  142. param.put("aid",TokenManager.getAdminId());
  143. }
  144. Pagination<RestrictProjectPageList> page =
  145. (Pagination<RestrictProjectPageList>) findPage("RestrictProjectList", "RestrictProjectCount",
  146. param, in.getPageNo(), in.getPageSize());
  147. pushPageList((List<RestrictProjectPageList>)page.getList());
  148. return page;
  149. }
  150. @Override
  151. public Object getFollowDetails(String uid) {
  152. User user = userMapper.findUserAccountDetail(uid);
  153. FollowBusinessBo fbb = new FollowBusinessBo();
  154. SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
  155. fbb.setFollowTime(format.format(new Date()));
  156. fbb.setIdentifyName(user.getIdentifyName());
  157. fbb.setUid(uid);
  158. List<BusinessListBo> businessListBos = userBusinessMapper.selectBusinessByUAid(uid, TokenManager.getAdminId());
  159. fbb.setUserBusinessList(businessListBos);
  160. return fbb;
  161. }
  162. private void pushPageList(List<RestrictProjectPageList> list) {
  163. // LocalDateTime now = LocalDateTime.now();
  164. // now=now.withHour(0).withMinute(0).withSecond(0).withNano(0);
  165. for (RestrictProjectPageList e : list) {
  166. // LocalDateTime lockTime = e.getLockTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime();
  167. // lockTime=lockTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
  168. if (e.getType()==1){
  169. // LocalDateTime endTime = lockTime.plusDays(30);
  170. // long between = ChronoUnit.DAYS.between(now, endTime);
  171. // e.setPrivateDays(between>0?(int)between:0);
  172. e.setPrivateDays(e.getDays());
  173. }else if (e.getType()==2){
  174. // LocalDateTime endTime = lockTime.plusDays(270);
  175. // long between = ChronoUnit.DAYS.between(now, endTime);
  176. // e.setSignDays(between>0?(int)between:0);
  177. e.setSignDays(e.getDays());
  178. }
  179. }
  180. }
  181. private void addUserLog(RestrictProject in, int i, String takeAid) {
  182. UserTransferLog log = new UserTransferLog();
  183. log.setUid(in.getUid());
  184. log.setPid(in.getPid());
  185. if (i == 0){
  186. log.setAid(in.getAid());
  187. log.setType(21);
  188. } else if (i == 1) {
  189. log.setAid(in.getAid());
  190. log.setType(16);
  191. }else if (i == 2) {
  192. log.setAid(TokenManager.getAdminId());
  193. log.setTakeAid(takeAid);
  194. log.setType(17);
  195. }
  196. userTransferLogMapper.insertSelective(log);
  197. }
  198. @Override
  199. public Object getRestrictProjectUser(String ids) {
  200. List<UserRestrictProjectBo> list = new ArrayList<>();
  201. String aid=TokenManager.getAdminId();
  202. Admin my = adminMapper.selectByPrimaryKey(aid);
  203. boolean flag= my.getPublicPurview() == 1;
  204. if (ids!=null&& !ids.isEmpty()){
  205. String[] split = ids.split(",");
  206. for (String s : split) {
  207. UserRestrictProjectBo bo = new UserRestrictProjectBo();
  208. bo.setUid(s);
  209. bo.setAdminSalesman(0);
  210. User user = userMapper.selectByPrimaryKey(s);
  211. bo.setUserName(user.getNickname());
  212. if (!flag){
  213. if (user.getShareType()==0||user.getShareType()==2){
  214. //0私有 2签单 查询当前是否有签订限定项目
  215. if (user.getAid().equals(aid)){
  216. //是自己的
  217. bo.setType(0);
  218. }else{
  219. //不是自己的
  220. List<RestrictProject> restrictProjects = restrictProjectMapper.selectListByParam(new InputRestrictProject(s, aid));
  221. if (!restrictProjects.isEmpty()){
  222. // 有限定项目
  223. if(TokenManager.hasRole(AFTConstants.SALESMAN)){
  224. bo.setType(1);
  225. }else {
  226. bo.setType(5);
  227. }
  228. }else{
  229. //没有限定
  230. bo.setType(2);
  231. Admin admin = adminMapper.selectByPrimaryKey(user.getAid());
  232. bo.setAdminName(admin.getName());
  233. }
  234. }
  235. }else if(user.getShareType()==1){
  236. //公共客户
  237. bo.setType(3);
  238. }
  239. }else {
  240. bo.setType(4);
  241. }
  242. list.add(bo);
  243. }
  244. }
  245. return list;
  246. }
  247. @Override
  248. public boolean checkMax() {
  249. int i = userMapper.checkUserMax(TokenManager.getAdminId());
  250. int limitMax=100;
  251. //加入限定项目的数量
  252. int rpCount =restrictProjectMapper.selectPrivateByAid(TokenManager.getAdminId());
  253. i=i+rpCount;
  254. if (TokenManager.hasRole(AFTConstants.SALESMAN_DIRECTOR)){
  255. if(limitMax<YXZJ_MAX)limitMax = YXZJ_MAX;
  256. } else if (TokenManager.hasRole(AFTConstants.SALESMAN_MANAGER)){
  257. if(limitMax<YXJL_MAX)limitMax = YXJL_MAX;
  258. } else if (TokenManager.hasRole(AFTConstants.SALESMAN)){
  259. if(limitMax<YXY_MAX)limitMax = YXY_MAX;
  260. }
  261. return i >= limitMax;
  262. }
  263. }