| | |
| | | import com.core.common.R; |
| | | import com.zy.asrs.entity.StaDesc; |
| | | import com.zy.asrs.entity.param.StaDescInitParam; |
| | | import com.zy.asrs.mapper.StaDescMapper; |
| | | import com.zy.asrs.service.StaDescService; |
| | | import com.zy.common.web.BaseController; |
| | | import org.apache.ibatis.session.ExecutorType; |
| | | import org.apache.ibatis.session.SqlSession; |
| | | import org.apache.ibatis.session.SqlSessionFactory; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private static final Logger log = LoggerFactory.getLogger(StaDescController.class); |
| | | @Autowired |
| | | private StaDescService staDescService; |
| | | @Autowired |
| | | private SqlSessionFactory sqlSessionFactory; |
| | | |
| | | @RequestMapping(value = "/staDesc/init/auth") |
| | | @ManagerAuth(memo = "初始化站点路径") |
| | | public R init(StaDescInitParam param) { |
| | | try { |
| | | // 参数校验:确保堆垛机号不为空 |
| | | if (Cools.isEmpty(param.getCrnNo())) { |
| | | return R.error("堆垛机号不能为空"); |
| | | } |
| | | |
| | | // 格式化开关:只删除当前堆垛机号的数据,而不是全部数据 |
| | | if (param.getTypeDesc() == 1) { |
| | | staDescService.delete(new EntityWrapper<>()); |
| | | staDescService.delete(new EntityWrapper<StaDesc>() |
| | | .eq("crn_no", param.getCrnNo()) |
| | | ); |
| | | } |
| | | String[] startStaList = param.getStartStaList().split(";"); |
| | | String[] endStaList = param.getEndStaList().split(";"); |
| | | List<StaDesc> staDescList = new ArrayList<>(); |
| | | SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); |
| | | StaDescMapper sqlSessionMapper = sqlSession.getMapper(StaDescMapper.class); |
| | | Date currentTime = new Date(); |
| | | Long userId = getUserId(); |
| | | int insertCount = 0; |
| | | |
| | | // SQL Server 批量插入时无法获取自增主键,改为循环单个插入 |
| | | for (String startSta : startStaList) { |
| | | for (String endSta : endStaList) { |
| | | for (Integer type : param.getType()) { |
| | | // 检查是否已存在 |
| | | int sameRes = staDescService.selectCount(new EntityWrapper<StaDesc>() |
| | | .eq("type_no", type) |
| | | .eq("stn_no", Integer.parseInt(startSta)) |
| | |
| | | if (sameRes > 0) { |
| | | continue; |
| | | } |
| | | |
| | | // 创建并插入单条记录 |
| | | StaDesc staDesc = new StaDesc(); |
| | | staDesc.setCrnNo(param.getCrnNo()); |
| | | staDesc.setTypeNo(type); |
| | | staDesc.setStnNo(Integer.parseInt(startSta)); |
| | | staDesc.setCrnStn(Integer.parseInt(endSta)); |
| | | staDesc.setModiUser(getUserId()); |
| | | staDesc.setModiTime(new Date()); |
| | | staDesc.setAppeUser(getUserId()); |
| | | staDesc.setAppeTime(new Date()); |
| | | // staDescList.add(staDesc); |
| | | sqlSessionMapper.insert(staDesc); |
| | | |
| | | staDesc.setModiUser(userId); |
| | | staDesc.setModiTime(currentTime); |
| | | staDesc.setAppeUser(userId); |
| | | staDesc.setAppeTime(currentTime); |
| | | |
| | | // 单个插入,确保能正确获取自增主键 |
| | | if (staDescService.insert(staDesc)) { |
| | | insertCount++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | sqlSession.commit(); |
| | | sqlSession.close(); |
| | | } catch (Exception e) { |
| | | log.error("初始化站点路径异常===>sql异常:{}", e.getMessage()); |
| | | } |
| | | // staDescService.insertBatch(staDescList); |
| | | |
| | | log.info("初始化站点路径完成,共插入 {} 条记录", insertCount); |
| | | } catch (Exception e) { |
| | | log.error("初始化站点路径异常:{}", e.getMessage()); |
| | | return R.error("初始化站点路径异常:" + e.getMessage()); |