| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- package com.goafanti.business.service.impl;
- import com.goafanti.business.bo.InputRestrictProject;
- import com.goafanti.business.bo.OutRestrictProject;
- import com.goafanti.business.bo.RestrictProjectPageList;
- import com.goafanti.business.service.RestrictProjectService;
- import com.goafanti.common.constant.AFTConstants;
- import com.goafanti.common.dao.*;
- import com.goafanti.common.error.BusinessException;
- import com.goafanti.common.model.*;
- import com.goafanti.core.mybatis.BaseMybatisDao;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.customer.bo.BusinessListBo;
- import com.goafanti.customer.bo.FollowBusinessBo;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.text.SimpleDateFormat;
- import java.time.LocalDateTime;
- import java.time.temporal.ChronoUnit;
- import java.util.*;
- @Service
- public class RestrictProjectServiceImpl extends BaseMybatisDao<RestrictProjectMapper> implements RestrictProjectService {
- @Resource
- private RestrictProjectMapper restrictProjectMapper;
- @Resource
- private UserTransferLogMapper userTransferLogMapper;
- @Resource
- private UserBusinessMapper userBusinessMapper;
- @Resource
- private UserMapper userMapper;
- @Resource
- private AdminMapper adminMapper;
- @Override
- public int add(InputRestrictProject in) {
- String aid = TokenManager.getAdminId();
- in.setAid(aid);
- in.setType(1);
- in.setLockTime(new Date());
- RestrictProject use = restrictProjectMapper.selectByPid(in);
- if (use != null && use.getType() != 0){
- throw new BusinessException("该项目已存在");
- }
- if(use ==null){
- restrictProjectMapper.insertSelective(in);
- }else if (use.getType() == 0){
- in.setId(use.getId());
- restrictProjectMapper.updateByPrimaryKeySelective(in);
- }
- UserBusiness ub=new UserBusiness();
- ub.setId(UUID.randomUUID().toString());
- ub.setAid(aid);
- ub.setUid(in.getUid());
- ub.setBusinessProjectId(in.getPid());
- ub.setCustomerStatus(in.getCustomerStatus());
- ub.setFollowSituation(in.getFollowSituation());
- ub.setRemarks("领取限定项目触发");
- userBusinessMapper.insertSelective(ub);
- addUserLog(in,0);
- return 1;
- }
- /**
- *
- * @param i 0=新增 1=移除
- */
- private void addUserLog(RestrictProject in, int i) {
- addUserLog(in,i,null);
- }
- @Override
- public Object list(InputRestrictProject in) {
- in.setAid(TokenManager.getAdminId());
- String aname=null;
- List<OutRestrictProject> list = restrictProjectMapper.selectByUidAndAid(in);
- User u = userMapper.selectByPrimaryKey(in.getUid());
- for (OutRestrictProject e : list) {
- if (e.getType()==null){
- e.setType(0);
- }
- if (!in.getAid().equals(AFTConstants.CAOJIN_AID)){
- if (u.getAid()!=null&&u.getType()==0&&u.getAid().equals(AFTConstants.CAOJIN_AID)){
- e.setType(1);
- if (aname==null){
- Admin admin = adminMapper.selectByPrimaryKey(AFTConstants.CAOJIN_AID);
- aname =admin.getName();
- }
- e.setAdminName(aname);
- }
- }
- }
- return list;
- }
- @Override
- public Object update(Integer id,Integer type,String takeAid) {
- Date date = new Date();
- RestrictProject in = new RestrictProject();
- RestrictProject use = restrictProjectMapper.selectByPrimaryKey(id);
- in.setId(id);
- if (type==0){
- in.setReleaseTime(date);
- in.setType(0);
- addUserLog(use,1);
- }else if (type==1){
- in.setLockTime(date);
- in.setAid(takeAid);
- in.setPid(use.getPid());
- in.setUid(use.getUid());
- addUserLog(use,2,takeAid);
- }
- return restrictProjectMapper.updateByPrimaryKeySelective(in);
- }
- @Override
- public Object pageList(InputRestrictProject in) {
- Map<String,Object> param = new HashMap<>();
- if (in.getUserName()!=null)param.put("userName",in.getUserName());
- if (in.getType()!=null)param.put("type",in.getType());
- if (in.getStartTime()!=null)param.put("startTime",in.getStartTime());
- if (in.getEndTime()!=null)param.put("endTime",in.getEndTime()+" 23:59:59");
- if (in.getProjectName()!=null)param.put("projectName",in.getProjectName());
- if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
- param.put("aid",TokenManager.getAdminId());
- }
- Pagination<RestrictProjectPageList> page =
- (Pagination<RestrictProjectPageList>) findPage("RestrictProjectList", "RestrictProjectCount",
- param, in.getPageNo(), in.getPageSize());
- pushPageList((List<RestrictProjectPageList>)page.getList());
- return page;
- }
- @Override
- public Object getFollowDetails(String uid) {
- User user = userMapper.findUserAccountDetail(uid);
- FollowBusinessBo fbb = new FollowBusinessBo();
- SimpleDateFormat format = new SimpleDateFormat(AFTConstants.YYYYMMDDHHMMSS);
- fbb.setFollowTime(format.format(new Date()));
- fbb.setIdentifyName(user.getIdentifyName());
- fbb.setUid(uid);
- List<BusinessListBo> businessListBos = userBusinessMapper.selectBusinessByUAid(uid, TokenManager.getAdminId());
- fbb.setUserBusinessList(businessListBos);
- return fbb;
- }
- private void pushPageList(List<RestrictProjectPageList> list) {
- LocalDateTime now = LocalDateTime.now();
- now=now.withHour(0).withMinute(0).withSecond(0).withNano(0);
- for (RestrictProjectPageList e : list) {
- LocalDateTime lockTime = e.getLockTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime();
- lockTime=lockTime.withHour(0).withMinute(0).withSecond(0).withNano(0);
- if (e.getType()==1){
- LocalDateTime endTime = lockTime.plusDays(30);
- long between = ChronoUnit.DAYS.between(now, endTime);
- e.setPrivateDays(between>0?(int)between:0);
- }else if (e.getType()==2){
- LocalDateTime endTime = lockTime.plusDays(270);
- long between = ChronoUnit.DAYS.between(now, endTime);
- e.setSignDays(between>0?(int)between:0);
- }
- }
- }
- private void addUserLog(RestrictProject in, int i, String takeAid) {
- UserTransferLog log = new UserTransferLog();
- log.setUid(in.getUid());
- log.setPid(in.getPid());
- if (i == 0){
- log.setAid(in.getAid());
- log.setType(15);
- } else if (i == 1) {
- log.setAid(in.getAid());
- log.setType(16);
- }else if (i == 2) {
- log.setAid(TokenManager.getAdminId());
- log.setTakeAid(takeAid);
- log.setType(17);
- }
- userTransferLogMapper.insertSelective(log);
- }
- }
|