张晓波
2023-12-12 d3e6773ef7cd0e11a444b41ec3da15938fabd85b
hd/pipe/mobile/src/main/java/com/thhy/mobile/modules/biz/login/service/impl/LoginServiceImpl.java
@@ -1,5 +1,6 @@
package com.thhy.mobile.modules.biz.login.service.impl;
import com.thhy.general.common.BasicMessage;
import com.thhy.general.common.BasicStatus;
import com.thhy.general.common.entity.SysUserDto;
import com.thhy.general.config.BasicContext;
@@ -8,20 +9,24 @@
import com.thhy.general.exception.BasicException;
import com.thhy.general.utils.DeepCopyUtils;
import com.thhy.general.utils.UUIDUtils;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.general.utils.password.PasswdUtils;
import com.thhy.mobile.modules.biz.login.entity.LoginVo;
import com.thhy.mobile.modules.biz.login.entity.PdaMenuVo;
import com.thhy.mobile.modules.biz.login.entity.SysUsers;
import com.thhy.mobile.modules.biz.login.entity.*;
import com.thhy.mobile.modules.biz.login.mapper.SysUserMapper;
import com.thhy.mobile.modules.biz.login.service.LoginService;
import com.thhy.mobile.modules.biz.menu.entity.Menu;
import com.thhy.mobile.modules.biz.menu.mapper.MenuMapper;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.C;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@Service
@@ -74,4 +79,91 @@
        BasicContext.setToken(token);
        return new LoginVo(token,menuList,sysUserInfo);
    }
    @Override
    public List<HashMap<String,Object>> proLines() {
        return sysUsersMapper.queryAllProLine();
    }
    @Override
    public Map<String, Object> choseLine(ProLineDto proLineDto, HttpServletRequest request) {
        SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
        String token = request.getHeader("usertoken");
        String proLineName = sysUsersMapper.queryProLineNameById(proLineDto.getProLineId());
        userInfo.setProLineId(proLineDto.getProLineId());
        userInfo.setProLineName(proLineName);
        long min = tokentime();
        redissonClient.getBucket(globalConfig.getKeyPrefix()+":usertoken:"+ token).trySet(userInfo,min, TimeUnit.MINUTES);
        int count = sysUsersMapper.countTodayLinePlanByLineId(proLineDto.getProLineId());
        Map<String,Object> map = new HashMap<>();
        if(count>0){
            map.put("dateset",false);
        }else {
            map.put("dateset",true);
        }
        return map;
    }
    @Transactional
    @Override
    public void commitLinePlan(ProLineDto proLineDto) {
        List<String> ringNums = proLineDto.getRingNums();
        String ringNumExits = sysUsersMapper.checkPipeExitsByRingNums(ringNums);
        if(!StringUtils.isEmpty(ringNumExits)){
            throw new BasicException(new BasicMessage("00900",ringNumExits+"环号已存在"));
        }
        String ringNumPlanExits = sysUsersMapper.checkPlanExitsByRingNums(ringNums);
        if(!StringUtils.isEmpty(ringNumPlanExits)){
            throw new BasicException(new BasicMessage("00901",ringNumPlanExits+"环号其他产线已存在"));
        }
        ProLinePlan proLinePlan = new ProLinePlan();
        proLinePlan.setProLineId(proLineDto.getProLineId());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date start = sdf.parse(proLineDto.getDateStr()+" 07:00:00");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(start);
            calendar.add(Calendar.DAY_OF_MONTH,1);
            Date end = calendar.getTime();
            proLinePlan.setSetDayStart(start);
            proLinePlan.setSetDayEnd(end);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        for(String ringNum : ringNums){
            proLinePlan.setRingNum(ringNum);
            sysUsersMapper.insertProLinePlan(proLinePlan);
        }
    }
    public long tokentime(){
        Date currentTime = new Date();
        SimpleDateFormat sdfStand = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdfSeven = new SimpleDateFormat("yyyy-MM-dd 07:00:00");
        String todaySevenStr = sdfSeven.format(currentTime);
        Date todaySeven = null;
        try {
            todaySeven = sdfStand.parse(todaySevenStr);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        if(currentTime.getTime()>todaySeven.getTime()){
            //当前时间大于 当天7点
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(todaySeven);
            calendar.add(Calendar.DAY_OF_MONTH,1);
            Date tommSeven = calendar.getTime();
            long diff = (tommSeven.getTime()-currentTime.getTime())/1000/60;
            return diff;
        }else{
            long diff = (todaySeven.getTime()-currentTime.getTime())/1000/60;
            return diff;
        }
    }
    public static void main(String[] args) throws Exception{
    }
}